Skip to content

Commit

Permalink
Explicitely touch instead of noop save
Browse files Browse the repository at this point in the history
When calling `save!` without changing any attributes then Rails doesn't
always touch other records because nothing changed. So I changed the
spec to `touch` explicitely and it turns out that everything passes.

Tada, our code seems correct and it was only the spec which seemed
broken in Rails 7.
  • Loading branch information
mkllnk committed Mar 3, 2023
1 parent f157b7a commit dd655fa
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions spec/models/enterprise_caching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
enterprise.set_producer_property 'Biodynamic', 'ASDF 4321'
end

pending "touches enterprise when a classification on that product changes" do
it "touches enterprise when a classification on that product changes" do
expect {
later { classification.save! }
later { classification.touch }
}.to change { enterprise.reload.updated_at }
end

pending "touches enterprise when a property on that product changes" do
it "touches enterprise when a property on that product changes" do
expect {
later { property.save! }
later { property.touch }
}.to change { enterprise.reload.updated_at }
end

pending "touches enterprise when a producer property on that product changes" do
it "touches enterprise when a producer property on that product changes" do
expect {
later { producer_property.save! }
later { producer_property.touch }
}.to change { enterprise.reload.updated_at }
end

Expand Down Expand Up @@ -64,21 +64,21 @@
context "with an order cycle" do
before { oc }

pending "touches enterprise when a classification on that product changes" do
it "touches enterprise when a classification on that product changes" do
expect {
later { classification.save! }
later { classification.touch }
}.to change { enterprise.reload.updated_at }
end

pending "touches enterprise when a property on that product changes" do
it "touches enterprise when a property on that product changes" do
expect {
later { property.save! }
later { property.touch }
}.to change { enterprise.reload.updated_at }
end

pending "touches enterprise when a producer property on that product changes" do
it "touches enterprise when a producer property on that product changes" do
expect {
later { producer_property.save! }
later { producer_property.touch }
}.to change { enterprise.reload.updated_at }
end

Expand Down Expand Up @@ -106,9 +106,9 @@
let(:child_enterprise) { create(:supplier_enterprise) }
let!(:er) { create(:enterprise_relationship, parent: enterprise, child: child_enterprise) }

pending "touches enterprise when enterprise relationship is updated" do
it "touches enterprise when enterprise relationship is updated" do
expect {
later { er.save! }
later { er.touch }
}.to change { enterprise.reload.updated_at }
end
end
Expand All @@ -120,9 +120,9 @@
enterprise.shipping_methods << sm
end

pending "touches enterprise when distributor_shipping_method is updated" do
it "touches enterprise when distributor_shipping_method is updated" do
expect {
later { enterprise.distributor_shipping_methods.first.save! }
later { enterprise.distributor_shipping_methods.first.touch }
}.to change { enterprise.reload.updated_at }
end

Expand Down

0 comments on commit dd655fa

Please sign in to comment.