Skip to content

Ensure transition to payment processing state happens outside transaction#4542

Closed
shioyama wants to merge 4 commits intospree:masterfrom
shioyama:double_submission_master
Closed

Ensure transition to payment processing state happens outside transaction#4542
shioyama wants to merge 4 commits intospree:masterfrom
shioyama:double_submission_master

Conversation

@shioyama
Copy link
Copy Markdown
Contributor

@shioyama shioyama commented Apr 4, 2014

The current method for preventing double payment submissions is simply not working, because the payment state is set in a transaction (see discusion in #4499). This PR turns off transactions on the order state machine and in addition aliases save_state to save to make this work (see these inline notes for more details on why this is necessary).

@shioyama
Copy link
Copy Markdown
Contributor Author

shioyama commented Apr 4, 2014

Sorry, there appear to be a bunch of other errors on master with this commit that didn't come up in #4499. Will investigate.

Chris Salzberg added 3 commits April 4, 2014 12:49
This test is now failing but it is unclear if it was ever really
testing what it claims to be testing. An order with no email
is not valid and should not save, so the test should not pass.
@shioyama
Copy link
Copy Markdown
Contributor Author

shioyama commented Apr 4, 2014

Ok fixed, problem was with the test which was not cleaning up properly in the after block. Tests now pass except for the one I marked as pending.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm curious about the use of save_state here. Why are you calling that method which is just an alias to save?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes this is an issue with state_machine. Using save as the action name triggers methods which run the state callbacks as ActiveRecord callbacks on the model, which means that they are inside the save transaction. To get around that, you rename save to save_state and alias the method itself. It seems to no longer be mentioned in the inline comments on state machine 1.2.0 but it was there in 1.1.2.

@huoxito
Copy link
Copy Markdown
Member

huoxito commented Apr 4, 2014

Looks good 👍 thanks! I'm ok with marking that spec as pending for now.

@shioyama
Copy link
Copy Markdown
Contributor Author

shioyama commented Apr 4, 2014

Ah forgot changelog. Will add now.

@huoxito huoxito closed this in a4b31ae Apr 4, 2014
huoxito pushed a commit to huoxito/spree that referenced this pull request Apr 4, 2014
Add failing test showing payment processing is set in a transaction.

Mark test of subclassed order as pending.

This test is now failing but it is unclear if it was ever really
testing what it claims to be testing. An order with no email
is not valid and should not save, so the test should not pass.

Add changelog entry.

Fixes spree#4542
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.

3 participants