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

[RFC] Rename order.update! to order.recalculate #2072

Merged
merged 1 commit into from
Jul 12, 2017

Conversation

jhawthorn
Copy link
Contributor

@jhawthorn jhawthorn commented Jul 7, 2017

I expect this to be contentious, and it definitely introduces some work for users upgrading, which I'm always cautious of.

ActiveRecord::Base has an update!(attributes) which as of Rails 4.0 is the recommended way to update the attributes on a model. The PR introducing it describes the older update_attributes! as "soft-deprecated".

Because we've overridden update!, we can't use that method to update the the attributes on order (as update! does for every other model), and have to use update_attributes!.

This isn't great because Rails devs (as well as documentation) are going to expect update! to work and might not even be aware of update_attributes!. This is doubly confusing because we have access to ActiveRecord's order.update, and one really expects that to do approximately the same thing as the ! version.

This PR adds Order#recalculate, which does exactly what Order#update! did, invoking the OrderUpdater.

Order#update! will now, if given attributes, will behave like AR's update!. If given no attributes it will emit a deprecation warning and call recalculate.

If we decide to do this, we should probably do the same for Adjustment#update! and Shipment#update!

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Yes! Thanks 🙏🏼

updater.update
end

alias_method :update!, :recalculate
Copy link
Member

Choose a reason for hiding this comment

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

Why this alias?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mistake. Fixed

@jhawthorn jhawthorn force-pushed the order_recalculate branch from f3b6b57 to a1dc526 Compare July 7, 2017 22:52
Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

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

<3 John. This is amazing.

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

👍 I agree that we should rename this method (also in Adjustment and Shipment). Thanks!

@gmacdougall
Copy link
Member

I am also on board with this.

Copy link
Contributor

@bbuchalter bbuchalter left a comment

Choose a reason for hiding this comment

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

A CHANGELOG entry would be welcome.

Copy link
Contributor

@jordan-brough jordan-brough left a comment

Choose a reason for hiding this comment

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

Nice, that's a great way to do the deprecation

Copy link
Contributor

@ericsaupe ericsaupe left a comment

Choose a reason for hiding this comment

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

Ditto on the CHANGELOG entry but I really like this!

@jhawthorn jhawthorn added this to the 2.4.0 milestone Jul 10, 2017
@subhashsaran
Copy link
Contributor

recalculate Sounds better than spree update_with_updater!
https://github.com/spree/spree/blob/v3.1.5/core/app/models/spree/order.rb#L235-L243
👍

@jhawthorn
Copy link
Contributor Author

jhawthorn commented Jul 12, 2017

Thanks for the feedback everyone. This was a lot less contentious than I expected.

Merging now. As the 2.3 branch has been forked, this will be in our future 2.4.0 release.

@jhawthorn jhawthorn merged commit 530d578 into solidusio:master Jul 12, 2017
elia added a commit to elia/solidus that referenced this pull request May 10, 2019
After update! => recalculate rename.

ref:
- solidusio#1689
- solidusio#2072
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants