-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
[Spree upgrade] Workaround Rails inheritance bug in Spree::Gateway #3370
[Spree upgrade] Workaround Rails inheritance bug in Spree::Gateway #3370
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!!!
If the spec is not green yet, maybe we leave #3121 open to cover the task of fixing the spec?
I created a new issue #3379. The old one became a bit long and the agenda changed already. |
Semaphore failed at another point in the spec:
That has to do with tags, so I should double-check my PR. |
Ah, I needed to include |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yes, there were two attributes.
this PR fixes the same problem in 3 specs in spec/features/admin/subscriptions_spec.rb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice investigation, @mkllnk!
I tested what happens when you assign tags to a PayPalExpress gateway and they are correctly stored with
:taggable_type => "Spree::PaymentMethod"
.
Could you cover this with a test, so we will find out if this changes in future implementations or upgrade-related work?
|
||
module Spree | ||
describe PaymentMethod do | ||
it_behaves_like "taggable" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not moving this to the payment_method_spec.rb? That is where I'd go check that if I had to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This spec is actually not about the PaymentMethod but about its descendants. Since I'm testing several classes for the same thing I do it in one place instead of scattering these tests in the spec files of every descendant. We are actually testing Ruby's inheritance here which doesn't belong to one specific class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added more comments to explain this so that the next developer doesn't have the same question. Thank you for prompting. 👍 :-)
describe Gateway::StripeConnect do | ||
it_behaves_like "taggable" | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same for the other models.
Spree::Gateway.class_eval do | ||
acts_as_taggable | ||
attr_accessible :tag_list | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but if essentially this is a order-related bug doesn't a require 'spree/payment_method'
in the appropriate place helps us here? apart from that, from rails/rails#3847 looks like some gem could be messing things up as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is order-related. Yes, it could be a gem. It could even be Spree.
A require 'spree/payment_method'
doesn't help, because the inheritance already happened when we access the Spree code. I tried that in many places, for hours, after Luis tried that in many places, for hours. You can have another go and maybe you can find a better solution. But we spent several dev days on this already and couldn't find any better solution.
Since this bug is hopefully fixed in the next version of Rails we shouldn't invest much more time.
One experiment I would support as a tech-debt task: Instead of adding tags to Spree::PaymentMethod
, we could try to have a new class called TaggablePaymentMethod
which basically decorates any other payment method. All code using tagging interface would use that class instead of using the payment method instance directly.
What do you think? Should I create an issue for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine. It doesn't make sense to spend any more time on this. I wouldn't add the tech debt task either for now.
Due to a bug in ActiveRecord we need to load the tagging code in Gateway which should have inherited it from its parent PaymentMethod. We have to call it before loading the PaymentMethod decorator because the tagging code won't load twice within the inheritance chain. #3121
@kristinalim, thank you for nudging me to increase the test coverage. I hesitated because it makes everything more complicated. It actually took me several hours to write a spec I'm content with. The difficult trade-off was between a flexible shared example that works with any payment method and using our factories. Let me know what you think about the new commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome @mkllnk, lets move on :-)
Waiting for @kristinalim 's answer to merge this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is great. 🙂
🎉 |
What? Why?
Closes #3121
Due to a bug in ActiveRecord we need to load the tagging code in Gateway which should have inherited it from its parent PaymentMethod. We have to call it before loading the PaymentMethod decorator because the tagging code won't load twice within the inheritance chain.
I tested what happens when you assign tags to a PayPalExpress gateway and they are correctly stored with
:taggable_type => "Spree::PaymentMethod"
.I also considered a tagging implementation that doesn't require decorating, but we would be working against the used gem which assumes to be called on the tagged ActiveRecord model. It may still be an option, but needs deeper study of the acts_as_taggable_on code.
What should we test?
If we test this: Create a PayPal payment method from the admin interface.
Please note: the affected
spec/features/admin/payment_method_spec.rb:72
executes further, but does not pass. The following failure means that this pull request is successful:How is this related to the Spree upgrade?
This is part of the Spree upgrade.