Skip to content

Commit

Permalink
Merge pull request #369 from alphagov/add-reveal-response-to-cache-key
Browse files Browse the repository at this point in the history
Add reveal_response to cache keys
  • Loading branch information
alanth committed Aug 10, 2015
2 parents c742d7a + b35b066 commit 18bef54
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/helpers/cache_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def dependencies_for(name)
class Keys
attr_reader :template

delegate :assigns, to: :template
delegate :assigns, :params, to: :template
delegate :archived_petition_page?, to: :template
delegate :create_petition_page?, to: :template
delegate :home_page?, to: :template
Expand Down Expand Up @@ -56,6 +56,10 @@ def petition_page
petition_page?
end

def reveal_response
params[:reveal_response] == 'yes'
end

def site_updated_at
Site.updated_at
end
Expand Down
1 change: 1 addition & 0 deletions config/fragments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ footer:
home_page:
keys:
- :last_signature_at
- :reveal_response
options:
expires_in: 300

Expand Down
36 changes: 36 additions & 0 deletions spec/helpers/cache_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,42 @@
end
end

describe "#reveal_response" do
before do
expect(helper).to receive(:params).and_return(params)
end

context "when 'reveal_response' is set to 'yes'" do
let(:params) do
{ reveal_response: 'yes' }.with_indifferent_access
end

it "returns true" do
expect(keys.reveal_response).to eq(true)
end
end

context "when 'reveal_response' is set to 'no'" do
let(:params) do
{ reveal_response: 'no' }.with_indifferent_access
end

it "returns false" do
expect(keys.reveal_response).to eq(false)
end
end

context "when 'reveal_response' is not set" do
let(:params) do
{}.with_indifferent_access
end

it "returns false" do
expect(keys.reveal_response).to eq(false)
end
end
end

describe "#site_updated_at" do
let(:now) { Time.current }

Expand Down

0 comments on commit 18bef54

Please sign in to comment.