Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Incorrect Item Request no preserving values #4135

Closed
2 tasks done
elasticspoon opened this issue Feb 22, 2024 · 0 comments · Fixed by #4142
Closed
2 tasks done

[BUG]: Incorrect Item Request no preserving values #4135

elasticspoon opened this issue Feb 22, 2024 · 0 comments · Fixed by #4142
Assignees
Labels

Comments

@elasticspoon
Copy link
Collaborator

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When an incorrect individuals request is submitted all values in the form are cleared

Expected Behavior

The values should be retained

Steps To Reproduce

Sign in as a partner. Click on "Create request" under "# of individuals.
Fill in a valid item and an invalid item
Click submit request.
You get a fresh form, instead of values being preserved

Environment

No response

Criteria for Completion

No response

Anything else?

Here is a test for it managing_requests_system_spec.rb:171:

      context 'WHEN they create a request partly improperly' do
        let(:items_to_select) { partner_user.partner.organization.valid_items.sample(3) }
        let(:item_details) do
          items_to_select.map do |item|
            {
              name: item[:name],
              quantity: Faker::Number.within(range: 5..25)
            }
          end
        end

        before do
          fill_in 'Comments', with: Faker::Lorem.paragraph

          # Select items
          item_details.each_with_index do |item, idx|
            if idx != 0
              click_link 'Add Another Item'
            end

            last_row = find_all('tr').last
            last_row.find('option', text: item[:name], exact_text: true).select_option
            last_row.find_all('.form-control').last.fill_in(with: item[:quantity])
          end

          last_row = find_all('tr').last
          last_row.find_all('.form-control').last.fill_in(with: -1)
          click_button 'Submit Essentials Request'
        end

        it 'should will retain inputs' do
          rows = find_all('tr')
          expect(rows.size).to eq(4)
          expect(rows.last.find('input').value).to eq('-1')
        end

        context 'THEN remove improper item' do
          before do
            # delete an item
            find_all('td').last.click

            # Trigger another row but keep it empty. It should still be valid!
            click_link 'Add Another Item'
          end
          context 'THEN a request records will be created and the partner will be notified via flash message on the dashboard' do
            before do
              expect { click_button 'Submit Essentials Request' }.to change { Request.count }.by(1)

              expect(current_path).to eq(partners_request_path(Request.last.id))
              expect(page).to have_content('Request has been successfully created!')
              expect(page).to have_content("#{partner.organization.name} should have received the request.")
            end

            it 'AND the partner_user can view the details of the created request in a seperate page' do
              visit partners_request_path(id: Request.last.id)

              deleted_item = item_details.pop
              item_details.each do |item|
                expect(page).to have_content("#{item[:quantity]} of #{item[:name]}")
              end

              # Should not have the last item: it was deleted.
              expect(page).not_to have_content("#{deleted_item[:quantity]} of #{deleted_item[:name]}")
            end
          end
        end
      end

Code of Conduct

  • I've read the Code of Conduct and understand my responsibilities as a member of the Ruby for Good community
elasticspoon added a commit to elasticspoon/human-essentials that referenced this issue Feb 27, 2024
Fixes rubyforgood#4135

When individuals requests were submitted with incorrect values
the error page did not perserve correct or incorrect inputs. This
was happening because the controller created a new request on
error.

Now the new request will be populated with the items from the
failed request.

I attempted to reuse the failed request, however, because the
individuals request is a wrapper around a family request that
behavior was not possible.
elasticspoon added a commit to elasticspoon/human-essentials that referenced this issue Feb 27, 2024
Fixes rubyforgood#4135

When individuals requests were submitted with incorrect values
the error page did not perserve correct or incorrect inputs. This
was happening because the controller created a new request on
error.

Now the new request will be populated with the items from the
failed request.

I attempted to reuse the failed request, however, because the
individuals request is a wrapper around a family request that
behavior was not possible.
elasticspoon added a commit to elasticspoon/human-essentials that referenced this issue Feb 28, 2024
Fixes rubyforgood#4135

When individuals requests were submitted with incorrect values
the error page did not preserve correct or incorrect inputs. This
was happening because the controller created a new request on
error.

Now the new request will be populated with the items from the
failed request.

I attempted to reuse the failed request, however, because the
individuals request is a wrapper around a family request that
behavior was not possible.
dorner pushed a commit that referenced this issue Mar 8, 2024
* fix: individuals request preserve values

Fixes #4135

When individuals requests were submitted with incorrect values
the error page did not preserve correct or incorrect inputs. This
was happening because the controller created a new request on
error.

Now the new request will be populated with the items from the
failed request.

I attempted to reuse the failed request, however, because the
individuals request is a wrapper around a family request that
behavior was not possible.

* refactor: system specs moved to request specs

* fix: minor code review changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant