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

set_position conflicts with acts_as_list #5509

Merged
merged 2 commits into from
Nov 15, 2023

Conversation

tkimi
Copy link
Contributor

@tkimi tkimi commented Nov 12, 2023

Summary

Fixes #5508

Remove set_position callback

I thought about changing the test as in this diff, but decided to just remove it since this is just testing acts_as_list.

diff --git a/core/spec/models/spree/variant_spec.rb b/core/spec/models/spree/variant_spec.rb
index 84cab17c1f..7246a74e60 100644
--- a/core/spec/models/spree/variant_spec.rb
+++ b/core/spec/models/spree/variant_spec.rb
@@ -574,11 +574,13 @@ RSpec.describe Spree::Variant, type: :model do
     end
   end
 
-  # Regression test for https://github.com/spree/spree/issues/2744
-  describe "set_position" do
-    it "sets variant position after creation" do
-      variant = create(:variant)
-      expect(variant.position).to_not be_nil
+  describe "acts_as_list" do
+    it "sets variant position by acts_as_list" do
+      expect(variant.product.master.position).to eq 1
+      expect(variant.position).to eq 2
+
+      multi_variant = create(:variant, product: variant.product)
+      expect(multi_variant.position).to eq 3
     end
   end

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@tkimi tkimi requested a review from a team as a code owner November 12, 2023 09:43
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Nov 12, 2023
Comment on lines 577 to 584
# Regression test for https://github.com/spree/spree/issues/2744
describe "set_position" do
it "sets variant position after creation" do
variant = create(:variant)
expect(variant.position).to_not be_nil
end
end

Copy link
Member

Choose a reason for hiding this comment

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

Do we really want to remove this test? We still want to persist this behaviour, even if we're removing the callback, right?

Copy link
Contributor Author

@tkimi tkimi Nov 14, 2023

Choose a reason for hiding this comment

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

I wonder if I should write a test for "acts as list" only for Variant, but we feel safer with a spec.
So I added this test! 77aceb0

@tkimi tkimi force-pushed the remove-set_position branch from a560a6b to 77aceb0 Compare November 14, 2023 04:37
Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (378ed49) 88.65% compared to head (77aceb0) 88.65%.
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5509      +/-   ##
==========================================
- Coverage   88.65%   88.65%   -0.01%     
==========================================
  Files         627      627              
  Lines       15037    15034       -3     
==========================================
- Hits        13331    13328       -3     
  Misses       1706     1706              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tkimi tkimi requested a review from jarednorman November 14, 2023 22:50
@kennyadsl kennyadsl merged commit cb53a12 into solidusio:main Nov 15, 2023
10 checks passed
@tkimi tkimi deleted the remove-set_position branch November 15, 2023 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spree::Variant#set_position conflicts with acts_as_list
3 participants