diff --git a/app/services/clear_cache.rb b/app/services/clear_cache.rb index 9d8709f1..1866bdd8 100644 --- a/app/services/clear_cache.rb +++ b/app/services/clear_cache.rb @@ -1,5 +1,7 @@ class ClearCache + include Rails.application.routes.url_helpers + def perform - ApplicationController.expire_page(app.insights_path) + ApplicationController.expire_page(insights_path) end end diff --git a/features/guest_views_insights.feature b/features/guest_views_insights.feature index e3793384..71f00919 100644 --- a/features/guest_views_insights.feature +++ b/features/guest_views_insights.feature @@ -3,11 +3,27 @@ Feature: Guest Views Insights page I want to be able to see previous auction winners So that I can learn about micropurchase - Scenario: Visiting the insights page page - Given there is a closed auction + Scenario: Visiting the insights page + Given there is an accepted auction When I visit the insights page Then I should see seven numbers on the page + And I should see that there is one total auction And I should see a section with two donut charts And I should see a Winning bid section And I should see a Community section And I should see a Bids by auction section + + @enable_caching + Scenario: Visiting the insights page before and after cache clearing + Given there is an accepted auction + And I visit the insights page + Then I should see that there is one total auction + + When there is another accepted auction + And I refresh the page + And the cache has not yet cleared + Then I should see that there is one total auction + + And the cache clears + And I refresh the page + Then I should see that there are two total auctions diff --git a/features/step_definitions/auction_create_steps.rb b/features/step_definitions/auction_create_steps.rb index 5e8e3e2c..1a89e338 100644 --- a/features/step_definitions/auction_create_steps.rb +++ b/features/step_definitions/auction_create_steps.rb @@ -174,11 +174,11 @@ end Given(/^there is an accepted auction$/) do - @auction = FactoryGirl.create( - :auction, - :with_bidders, - :published, - result: :accepted, - accepted_at: nil, - ) + @auction = FactoryGirl.create(:auction, :accepted, :with_bidders) +end + +When(/^there is another accepted auction$/) do + # not creating another @auction-like instance variable + # just creating the record without saving to a variable + FactoryGirl.create(:auction, :accepted, :with_bidders) end diff --git a/features/step_definitions/cache_steps.rb b/features/step_definitions/cache_steps.rb new file mode 100644 index 00000000..ee323847 --- /dev/null +++ b/features/step_definitions/cache_steps.rb @@ -0,0 +1,8 @@ +When(/^the cache clears$/) do + ClearCache.new.perform +end + +When(/^the cache has not yet cleared$/) do + # here for readability + # does nothing +end diff --git a/features/step_definitions/previous_winners_steps.rb b/features/step_definitions/previous_winners_steps.rb index 83021940..11057b88 100644 --- a/features/step_definitions/previous_winners_steps.rb +++ b/features/step_definitions/previous_winners_steps.rb @@ -26,3 +26,21 @@ expect(page).to have_selector("#chart5") end + +Then(/^I should see that there is one total auction$/) do + xpath = '/html/body/div[2]/section[1]/div/a[1]' + + within(:xpath, xpath) do + expect(page).to have_content '1' + expect(page).to have_content 'total auctions' + end +end + +Then(/^I should see that there are two total auctions$/) do + xpath = '/html/body/div[2]/section[1]/div/a[1]' + + within(:xpath, xpath) do + expect(page).to have_content '2' + expect(page).to have_content 'total auctions' + end +end diff --git a/features/support/env.rb b/features/support/env.rb index b57467e4..329a024f 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -23,6 +23,16 @@ Delayed::Worker.delay_jobs = false end +Before '@enable_caching' do + ActionController::Base.perform_caching = true + ClearCache.new.perform +end + +After '@enable_caching' do + ClearCache.new.perform + ActionController::Base.perform_caching = false +end + ActionController::Base.allow_rescue = false begin diff --git a/spec/factories/auctions.rb b/spec/factories/auctions.rb index 4cf5411e..f23b70ef 100644 --- a/spec/factories/auctions.rb +++ b/spec/factories/auctions.rb @@ -116,6 +116,7 @@ end trait :accepted do + ended_at { Time.now - 1.days } result :accepted accepted_at { Time.now } end diff --git a/spec/services/clear_cache_spec.rb b/spec/services/clear_cache_spec.rb new file mode 100644 index 00000000..f10ef9a6 --- /dev/null +++ b/spec/services/clear_cache_spec.rb @@ -0,0 +1,7 @@ +# require 'rails_helper' +# +# describe ClearCache do +# describe '#perform' do +# it 'calls ' +# end +# end