-
-
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
Merged
luisramos0
merged 2 commits into
openfoodfoundation:2-0-stable
from
mkllnk:3121-spree-gateway-inheritance
Feb 13, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require "spec_helper" | ||
|
||
# We extended Spree::PaymentMethod to be taggable. Unfortunately, an inheritance | ||
# bug prevented the taggable code to be passed on to the descendants of | ||
# PaymentMethod. We fixed that in config/initializers/spree.rb. | ||
# | ||
# This spec tests several descendants for their taggability. The tests are in | ||
# a separate file, because they cover one aspect of several classes. | ||
shared_examples "taggable" do |expected_taggable_type| | ||
it "provides a tag list" do | ||
expect(subject.tag_list).to eq [] | ||
end | ||
|
||
it "stores tags for the root taggable type" do | ||
subject.tag_list.add("one") | ||
subject.save! | ||
|
||
expect(subject.taggings.last.taggable_type).to eq expected_taggable_type | ||
end | ||
end | ||
|
||
module Spree | ||
describe "PaymentMethod and descendants" do | ||
|
||
let(:shop) { create(:enterprise) } | ||
let(:valid_subject) do | ||
# Supply required parameters so that it can be saved to attach taggings. | ||
described_class.new( | ||
name: "Some payment method", | ||
distributor_ids: [shop.id] | ||
) | ||
end | ||
subject { valid_subject } | ||
|
||
describe PaymentMethod do | ||
it_behaves_like "taggable", "Spree::PaymentMethod" | ||
end | ||
|
||
describe Gateway do | ||
it_behaves_like "taggable", "Spree::PaymentMethod" | ||
end | ||
|
||
describe Gateway::PayPalExpress do | ||
it_behaves_like "taggable", "Spree::PaymentMethod" | ||
end | ||
|
||
describe Gateway::StripeConnect do | ||
subject do | ||
# StripeConnect needs an owner to be valid. | ||
valid_subject.tap { |m| m.preferred_enterprise_id = shop.id } | ||
end | ||
|
||
it_behaves_like "taggable", "Spree::PaymentMethod" | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same for the other models. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 calledTaggablePaymentMethod
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.