Skip to content

Commit

Permalink
Merge pull request #2691 from jhawthorn/assert_written_to_cache
Browse files Browse the repository at this point in the history
Remove assert_written_to_cache
  • Loading branch information
jhawthorn authored Apr 11, 2018
2 parents ecc348a + 5f3a775 commit fb9c66e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 26 deletions.
16 changes: 0 additions & 16 deletions core/lib/spree/testing_support/caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@ def cache_writes
@cache_write_events
end

def assert_written_to_cache(key)
unless @cache_write_events.detect { |event| event[:key].starts_with?(key) }
fail %{Expected to find #{key} in the cache, but didn't.
Cache writes:
#{@cache_write_events.join("\n")}
}
end
end

def clear_cache_events
@cache_read_events = []
@cache_write_events = []
end
end
Expand All @@ -31,11 +20,6 @@ def clear_cache_events
config.before(:each, caching: true) do
ActionController::Base.perform_caching = true

ActiveSupport::Notifications.subscribe("read_fragment.action_controller") do |_event, _start_time, _finish_time, _, details|
@cache_read_events ||= []
@cache_read_events << details
end

ActiveSupport::Notifications.subscribe("write_fragment.action_controller") do |_event, _start_time, _finish_time, _, details|
@cache_write_events ||= []
@cache_write_events << details
Expand Down
8 changes: 0 additions & 8 deletions frontend/spec/features/caching/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
product2.update_column(:updated_at, 1.day.ago)
# warm up the cache
visit spree.root_path
assert_written_to_cache("views/en/USD/spree/products/all--#{product.updated_at.utc.to_s(:number)}")
assert_written_to_cache("views/en/USD/spree/products/#{product.id}-#{product.updated_at.utc.to_s(:number)}")
assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")

clear_cache_events
end
Expand All @@ -27,30 +24,25 @@
it "busts the cache when a product is updated" do
product.update_column(:updated_at, 1.day.from_now)
visit spree.root_path
assert_written_to_cache("views/en/USD/spree/products/all--#{product.updated_at.utc.to_s(:number)}")
assert_written_to_cache("views/en/USD/spree/products/#{product.id}-#{product.updated_at.utc.to_s(:number)}")
expect(cache_writes.count).to eq(2)
end

it "busts the cache when all products are soft-deleted" do
product.discard
product2.discard
visit spree.root_path
assert_written_to_cache("views/en/USD/spree/products/all--#{Date.today.to_s(:number)}-0")
expect(cache_writes.count).to eq(1)
end

it "busts the cache when the newest product is soft-deleted" do
product.discard
visit spree.root_path
assert_written_to_cache("views/en/USD/spree/products/all--#{product2.updated_at.utc.to_s(:number)}")
expect(cache_writes.count).to eq(1)
end

it "busts the cache when an older product is soft-deleted" do
product2.discard
visit spree.root_path
assert_written_to_cache("views/en/USD/spree/products/all--#{product.updated_at.utc.to_s(:number)}")
expect(cache_writes.count).to eq(1)
end
end
2 changes: 0 additions & 2 deletions frontend/spec/features/caching/taxons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
before do
# warm up the cache
visit spree.root_path
assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")

clear_cache_events
end

it "busts the cache when max_level_in_taxons_menu conf changes" do
Spree::Config[:max_level_in_taxons_menu] = 5
visit spree.root_path
assert_written_to_cache("views/en/spree/taxonomies/#{taxonomy.id}")
expect(cache_writes.count).to eq(1)
end
end

0 comments on commit fb9c66e

Please sign in to comment.