mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #10487 from mkllnk/time-spec
Prepare caching spec for Rails 7
This commit is contained in:
@@ -5,7 +5,7 @@ require 'spec_helper'
|
||||
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) }
|
||||
|
||||
@@ -22,30 +22,26 @@ describe Enterprise do
|
||||
|
||||
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
|
||||
|
||||
@@ -70,45 +66,39 @@ describe Enterprise do
|
||||
|
||||
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
|
||||
|
||||
@@ -118,9 +108,8 @@ describe Enterprise do
|
||||
|
||||
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
|
||||
|
||||
@@ -133,25 +122,26 @@ describe Enterprise do
|
||||
|
||||
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
|
||||
|
||||
@@ -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)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user