Permalink
Browse files

Add guard for the missing key.

  • Loading branch information...
1 parent 614da55 commit 5b4366a3f0bed6baa53ada8c3eda07eedd4c67e1 @piotrmurach committed Jul 8, 2012
Showing with 10 additions and 0 deletions.
  1. +1 −0 lib/rack/policy/helpers.rb
  2. +9 −0 spec/helpers_spec.rb
@@ -5,6 +5,7 @@ module Policy
module Helpers
def cookies_accepted?
+ return false unless request.env.has_key? 'rack-policy.consent'
accepted = !request.env['rack-policy.consent'].nil?
yield if block_given? && accepted
accepted
View
@@ -18,6 +18,15 @@ def initialize; @env = {}; end
let(:helper_test) { HelperTest.new }
+ before do
+ helper_test.request.env.stub(:has_key?).and_return true
+ end
+
+ it "guards against missing key" do
+ helper_test.request.env.stub(:has_key?).and_return false
+ helper_test.cookies_accepted?.should be_false
+ end
+
it "doesn't accept cookies" do
helper_test.request.env.stub(:[]).with('rack-policy.consent') { nil }
helper_test.cookies_accepted?.should be_false

0 comments on commit 5b4366a

Please sign in to comment.