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

Remove assert_written_to_cache #2691

Merged
merged 2 commits into from
Apr 11, 2018
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
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