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

Prepare caching spec for Rails 7 #10487

Merged
merged 4 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 33 additions & 43 deletions spec/models/enterprise_caching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe Enterprise do
context "key-based caching invalidation" do
describe "is touched when a(n)" do
let(:enterprise) { create(:distributor_enterprise, updated_at: Time.zone.now - 1.week) }
let(:enterprise) { create(:distributor_enterprise) }
let(:taxon) { create(:taxon) }
let(:supplier2) { create(:supplier_enterprise) }

Expand All @@ -22,30 +22,26 @@

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

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

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

it "touches enterprise when the supplier of a product changes" do
expect {
product.update!(supplier: supplier2)
enterprise.reload
}.to change { enterprise.updated_at }
later { product.update!(supplier: supplier2) }
}.to change { enterprise.reload.updated_at }
end
end

Expand All @@ -70,45 +66,39 @@

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

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

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

it "touches enterprise when the supplier of a product changes" do
expect {
product.update!(supplier: supplier2)
enterprise.reload
}.to change { enterprise.updated_at }
later { product.update!(supplier: supplier2) }
}.to change { enterprise.reload.updated_at }
end

it "touches enterprise when a relevant exchange is updated" do
expect {
oc.exchanges.first.update!(updated_at: Time.zone.now)
enterprise.reload
}.to change { enterprise.updated_at }
later { oc.exchanges.first.update!(updated_at: Time.zone.now) }
}.to change { enterprise.reload.updated_at }
end
end

it "touches enterprise when the product's variant is added to order cycle" do
expect {
oc
enterprise.reload
}.to change { enterprise.updated_at }
later { oc }
}.to change { enterprise.reload.updated_at }
end
end

Expand All @@ -118,9 +108,8 @@

it "touches enterprise when enterprise relationship is updated" do
expect {
er.save!
enterprise.reload
}.to change { enterprise.updated_at }
later { er.touch }
}.to change { enterprise.reload.updated_at }
end
end

Expand All @@ -133,25 +122,26 @@

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

it "touches enterprise when shipping method is updated" do
expect {
sm.save!
enterprise.reload
}.to change { enterprise.updated_at }
later { sm.save! }
}.to change { enterprise.reload.updated_at }
end
end

it "touches enterprise when address is updated" do
expect {
enterprise.address.save!
enterprise.reload
}.to change { enterprise.updated_at }
later { enterprise.address.save! }
}.to change { enterprise.reload.updated_at }
end
end
end

def later(&block)
Timecop.travel(1.day.from_now, &block)
end
end
2 changes: 1 addition & 1 deletion spec/models/spree/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ module Spree
it "defaults available_on to now" do
Timecop.freeze do
product = Product.new
expect(product.available_on).to eq(Time.zone.now)
expect(product.available_on).to be_within(0.000001).of(Time.zone.now)
Copy link
Member

Choose a reason for hiding this comment

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

I'm just wondering, would be_within(1) be good enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, I'm using the full precision of the timestamp but you are probably right, from a user perspective, "now" just needs the accuracy to the second.

end
end

Expand Down