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

Correctly record last_ip_address on order #1658

Merged
merged 1 commit into from
Jun 21, 2017

Conversation

bbuchalter
Copy link
Contributor

The assignment of last_ip_address was not persisted where it was set.
When this module is included in a custom storefront, the assignment of
last_ip_address is lost. There was also a case in simple_current_order
where the last_ip_address was never assigned.

Copy link
Member

@gmacdougall gmacdougall left a comment

Choose a reason for hiding this comment

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

👍

Seems reasonable.

Copy link
Contributor

@cbrunsdon cbrunsdon left a comment

Choose a reason for hiding this comment

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

I have a concern with this in which simple_current_order can now cause some very unexpected side effects as we're calling the update on the memoized object.

it 'is called twice' do
  order1 = controller.simple_current_order
  order1.email = "[email protected]"

   order2 = controller.simple_current_order
   expect(order2.email).to_not eq('[email protected]')
end

The second simple_current_order returns the same (modified) memoized object, which will call .update and persist that email change to the database.

Maybe we can look at shifting when we make the method call to update the current IP address to take all the modification out of this read method?

@bbuchalter
Copy link
Contributor Author

@cbrunsdon I added a spec that checks for persistence when simple_current_order is called a second time to show that it's not persisted. Did I misunderstand you or write the spec incorrectly?

@cbrunsdon
Copy link
Contributor

@bbuchalter doesn't subject memoize as well? I don't believe your spec addition actually runs simple_current_order twice.

@cbrunsdon
Copy link
Contributor

@bbuchalter hey, my apologies, the return in simple_current_order means if its memoized its only going to be executed once, so right you are.

@cbrunsdon
Copy link
Contributor

I have objections to the existence of simple_current_order, but are not appropriate for this PR, so thanks @bbuchalter and double thanks for helping me through that misunderstanding

@bbuchalter
Copy link
Contributor Author

@cbrunsdon would you like me to rebase the fixup or remove it?

@@ -21,10 +21,10 @@ def simple_current_order
@simple_current_order = find_order_by_token_or_user

if @simple_current_order
@simple_current_order.last_ip_address = ip_address
@simple_current_order.update(last_ip_address: ip_address)
Copy link
Contributor

@jhawthorn jhawthorn Jan 4, 2017

Choose a reason for hiding this comment

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

One though before merging: should this be update!? We don't check the result so it probably should.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree this should be an update!. Also before merge, there is this question about my fixup commit in this PR: #1658 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

The test in the fixup looks good to me (it can't hurt to have). I'd like it rebased please :)

@bbuchalter
Copy link
Contributor Author

Done.

@bbuchalter
Copy link
Contributor Author

Test fail does not seem legit. I can't seem to trigger a rebuild. Thoughts?

@gmacdougall
Copy link
Member

I triggered a rebuild. Here's a link to the odd failure: https://circleci.com/gh/solidusio/solidus/4985

I was not able to reproduce it locally.

@bbuchalter
Copy link
Contributor Author

Poke.

The assignment of last_ip_address was not persisted where it was set.
When this module is included in a custom storefront, the assignment of
last_ip_address is lost.
@bbuchalter
Copy link
Contributor Author

I have rebased this PR on master. Given that simple_current_order is now deprecated, I've removed any of my changes related to that method.

@tvdeyen tvdeyen merged commit be5c16a into solidusio:master Jun 21, 2017
@tvdeyen
Copy link
Member

tvdeyen commented Jun 21, 2017

Thanks!

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.

5 participants