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

Always pass the new order number on unreturned exchange failures #388

Merged
merged 3 commits into from
Dec 23, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions core/lib/spree/core/unreturned_item_charger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def charge_for_items

end

private

def new_order
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this should get its own special unit test now lol

@new_order ||= Spree::Order.create!(exchange_order_attributes)
Copy link
Contributor

Choose a reason for hiding this comment

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

since we're making this public it seems like we ought to make it a bit safer to call. i.e. calling .new_order from the outside probably shouldn't mutate anything right? how about setting it explicitly inside #charge_for_items and just using an attr_reader to expose it?

end

private

def add_exchange_variants_to_order
@return_items.group_by(&:exchange_variant).map do |variant, variant_return_items|
variant_inventory_units = variant_return_items.map(&:exchange_inventory_unit)
Expand Down
5 changes: 3 additions & 2 deletions core/lib/tasks/exchanges.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ namespace :exchanges do
begin
item_charger.charge_for_items
rescue Spree::UnreturnedItemCharger::ChargeFailure => e
failure = {message: e.message, new_order: e.new_order.try(:number)}
failure = { message: e.message }
Copy link
Contributor

Choose a reason for hiding this comment

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

We can now just collapse this into the rescue => e right?

rescue Exception => e
Copy link
Member

Choose a reason for hiding this comment

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

While you're here, if you could get rid of this, I'd really appreciate it.

Instead of

rescue Exception => e

just

rescue => e

Rescuing Exception will rescue syntax errors, signal exceptions and such. Things that you shouldn't be rescuing unless you're re-raising them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good point; done.

failure = {message: "#{e.class}: #{e.message}"}
failure = { message: "#{e.class}: #{e.message}" }
end

if failure
failure[:new_order] = item_charger.new_order.number if item_charger.new_order
failures << failure.merge({
order: item_charger.original_order.number,
shipment: shipment.number,
Expand Down