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

2262/purchase error messages #2267

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/purchases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create
else
load_form_collections
@purchase.line_items.build if @purchase.line_items.count.zero?
flash[:error] = "There was an error starting this purchase, try again?"
flash[:error] = "Failed to create purchase due to: #{@purchase.errors.full_messages}"
Rails.logger.error "[!] PurchasesController#create ERROR: #{@purchase.errors.full_messages}"
render action: :new
end
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/purchases_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
it "renders GET#new with error" do
post purchases_path(default_params.merge(purchase: { storage_location_id: nil, amount_spent_in_cents: nil }))
expect(response).to be_successful # Will render :new
expect(response).to have_error(/error/i)
expect(response.body).to include('Failed to create purchase due to: ["Storage location must exist", "Vendor must exist", "Amount spent in cents is not a number"]')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is ok, basically copied from the POST#create failure test in partners_request_spec

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhilipDeFraties this is okay :)!

end
end
end
Expand Down Expand Up @@ -243,4 +243,4 @@
end
end
end
end
end
27 changes: 17 additions & 10 deletions spec/system/purchase_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,23 @@
expect(Purchase.last.line_items.first.quantity).to eq(16)
end

# Bug fix -- Issue #71
# When a user creates a purchase without it passing validation, the items
# dropdown is not populated on the return trip.
it "items dropdown is still repopulated even if initial submission doesn't validate" do
item_count = @organization.items.count + 1 # Adds 1 for the "choose an item" option
expect(page).to have_css("#purchase_line_items_attributes_0_item_id option", count: item_count + 1)
click_button "Save"

expect(page).to have_content("error")
expect(page).to have_css("#purchase_line_items_attributes_0_item_id option", count: item_count + 1)
context 'when creating a purchase incorrectly' do
# Bug fix -- Issue #71
# When a user creates a purchase without it passing validation, the items
# dropdown is not populated on the return trip.
it "items dropdown is still repopulated even if initial submission doesn't validate" do
item_count = @organization.items.count + 1 # Adds 1 for the "choose an item" option
expect(page).to have_css("#purchase_line_items_attributes_0_item_id option", count: item_count + 1)
click_button "Save"

expect(page).to have_content("Failed to create purchase due to:")
expect(page).to have_css("#purchase_line_items_attributes_0_item_id option", count: item_count + 1)
end

it "should display failure with error messages" do
click_button "Save"
expect(page).to have_content('Failed to create purchase due to: ["Vendor must exist", "Amount spent in cents must be greater than 0"]')
end
end
end

Expand Down