-
Notifications
You must be signed in to change notification settings - Fork 45
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
SLE15 product tree support -- 4702 #72
Conversation
1f30ffb
to
84dd088
Compare
07a3cab
to
61663f7
Compare
I want to add one more spec for the |
@lagartoflojo will review your pull request 👯 check https://trello.com/c/p2hEsVT1/4702-5-rmt-sles-15-product-tree-support
|
OK, that should be it. |
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.
Haven't tried it out locally yet. I'll do that now.
level_two_extension_b_not_mirrored | ||
level_two_extension_a_mirrored | ||
level_two_extension_b_mirrored | ||
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.
This looks funny, why not use let!
?
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.
Because Rubocop complains about it:
spec/models/product_spec.rb:93:5: C: RSpec/LetSetup: Do not use let! for test setup.
let!(:level_two_extension_a_not_mirrored) { FactoryGirl.create(:product, :extension, base_products: [level_one_extension], root_product: base_a) }
I guess using the before
block makes the initialization order more explicit.
But I can disable the check if you think it doesn't make sense.
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.
Hmm strange rule. It must be new. We use let!
all over the place (even in RMT hehe)
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 seems it doesn't complain about all of the let!
calls, but only about the ones that aren't called from anywhere.
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.
Here's the discussion about why it's useful.
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 see. With that logic, they actual create
calls should be moved into the before
block then.
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.
Moving into the create
block would make it impossible to reference them later in the expect
block.
A couple of those aren't referenced, so yes, those could be moved in, but I'd say it's not very important.
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.
Ok, let's leave it as is then.
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.
@thutterer ^^^
|
||
it 'has base system extension' do | ||
expect(top_extension[:name]).to eq(basesystem.name) | ||
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.
These can be re-written as:
its([:name]) { is_expected.to eq basesystem.name }
Same for the tests below.
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.
Not really, it's not the subject
of the spec.
For the top level specs I'd need to do:
subject { described_class.new(sled15, root_product: sled15, base_url: base_url)[:extensions].first }
And for nested extensions I'd need to do:
subject { described_class.new(sled15, root_product: sled15, base_url: base_url)[:extensions].first[:extensions].first }
That doesn't seem to make anything better, though.
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, didn't catch that, you're right.
This PR is not working for me:
The same command works fine in master. |
object.mirrored_extensions.map do |extension| | ||
::V3::ProductSerializer.new(extension, base_url: base_url).attributes | ||
object.extensions.for_root_product(root_product).map do |extension| | ||
::V3::ProductSerializer.new(extension, base_url: base_url, root_product: root_product).attributes | ||
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.
In glue we simply have a has_many :extensions
, and all the instance_options
are passed down to the child serializers automatically, so you don't need to specify base_url
or root_product
.
That leaves you with:
has_many :extensions, serializer: V3::ProductSerializer
def extensions
object.extensions.for_root_product(root_product)
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.
I remember I was looking into this at the very beginning and the current code is the solution that works correctly.
The problem is that for some reason it doesn't serialize all of the attributes of the relation, namely the ones that are declared on the serializer and don't exist on the model (like available
and recommended
). With the has_many
relation they seem to be just missing.
If you have any idea what's going on with that -- feel free to share.
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.
Hmm weird, has_many
also doesn't work for me. But because it doesn't output the nested extension... Anyway!
@lagartoflojo, syncing should work without issues now. |
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.
one missing test, otherwise lgtm
@@ -69,6 +77,10 @@ def change_repositories_mirroring!(conditions, mirroring_enabled) | |||
repositories.where(conditions).update_all(mirroring_enabled: mirroring_enabled) | |||
end | |||
|
|||
def recommended_for?(root_product) |
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 we're missing unit tests for 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.
Yep, it was covered only by serializer specs. I've added a test for this method.
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 left a refactoring for your spec, if you want to incorporate it. If not, still LGTM.
spec/models/product_spec.rb
Outdated
extension = FactoryGirl.create(:product, :extension, base_products: [base_a], recommended: true) | ||
expect(extension.recommended_for?(base_b)).to be(false) | ||
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.
To follow the http://www.betterspecs.org/ convention, I would write these tests like this.
(Take it or leave it 😄)
describe '#recommended_for?' do
let(:base) { create :product }
let(:extension) { create(:product, :extension, base_products: [base], recommended: recommended) }
subject { extension.recommended_for?(queried_base) }
context 'when the extension is recommended for its base' do
let(:recommended) { true }
let(:queried_base) { base }
it { is_expected.to be true }
end
context 'when the extension is not recommended for its base' do
let(:recommended) { false }
let(:queried_base) { base }
it { is_expected.to be false }
end
context "when the queried base is not the extension's base" do
let(:recommended) { true }
let(:queried_base) { create(:product) }
it { is_expected.to be false }
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.
Yep, I definitely like it! Just commit those changes yourself, maybe?
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.
Done!
🙈 rubocop.... |
🤖 |
No description provided.