aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/widget_vote_spec.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2015-01-05 17:43:38 +0000
committerLouise Crow <louise.crow@gmail.com>2015-04-27 16:55:02 +0100
commit61faadbac1b4a71148248382425beb4368cb4cb0 (patch)
treea86c572057b20b89d24c112a1c81375caeaac737 /spec/models/widget_vote_spec.rb
parentd16b7e1f15e9c7abe3db986850f5e60ff186c271 (diff)
Validate the uniqueness of cookies within the scope of info requests.
Diffstat (limited to 'spec/models/widget_vote_spec.rb')
-rw-r--r--spec/models/widget_vote_spec.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/spec/models/widget_vote_spec.rb b/spec/models/widget_vote_spec.rb
index f1e30ed22..db5e4385d 100644
--- a/spec/models/widget_vote_spec.rb
+++ b/spec/models/widget_vote_spec.rb
@@ -32,6 +32,22 @@ describe WidgetVote do
widget_vote.should be_valid
end
+ it 'enforces uniqueness of cookie per info request' do
+ info_request = FactoryGirl.create(:info_request)
+ widget_vote = info_request.widget_votes.create(:cookie => 'x' * 20)
+ duplicate_vote = info_request.widget_votes.build(:cookie => 'x' * 20)
+ duplicate_vote.should_not be_valid
+ duplicate_vote.errors[:cookie].should == ["has already been taken"]
+ end
+
+ it 'allows the same cookie to be used across info requests' do
+ info_request = FactoryGirl.create(:info_request)
+ second_info_request = FactoryGirl.create(:info_request)
+ widget_vote = info_request.widget_votes.create(:cookie => 'x' * 20)
+ second_request_vote = second_info_request.widget_votes.build(:cookie => 'x' * 20)
+ second_request_vote.should be_valid
+ end
+
end
end