Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Attempt at cache testing. it is hard.
Browse files Browse the repository at this point in the history
  • Loading branch information
adelevie committed Aug 15, 2016
1 parent e0fcf0c commit 5754c90
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 10 deletions.
4 changes: 3 additions & 1 deletion 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
20 changes: 18 additions & 2 deletions features/guest_views_insights.feature
Expand Up @@ -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
14 changes: 7 additions & 7 deletions features/step_definitions/auction_create_steps.rb
Expand Up @@ -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
8 changes: 8 additions & 0 deletions 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
18 changes: 18 additions & 0 deletions features/step_definitions/previous_winners_steps.rb
Expand Up @@ -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
10 changes: 10 additions & 0 deletions features/support/env.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/factories/auctions.rb
Expand Up @@ -116,6 +116,7 @@
end

trait :accepted do
ended_at { Time.now - 1.days }
result :accepted
accepted_at { Time.now }
end
Expand Down
7 changes: 7 additions & 0 deletions spec/services/clear_cache_spec.rb
@@ -0,0 +1,7 @@
# require 'rails_helper'
#
# describe ClearCache do
# describe '#perform' do
# it 'calls '
# end
# end

0 comments on commit 5754c90

Please sign in to comment.