diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-12-23 15:55:57 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2015-04-27 16:50:31 +0100 |
commit | 5b99495ef39feda47da098f896a801beafc892c5 (patch) | |
tree | d81f2986cb67c2f364487fea967444bfd9e6a1a8 /spec/controllers/track_controller_spec.rb | |
parent | 681c5f0c42f5e48a0cdc1e2437675f067f0c299e (diff) |
Add some specs for the vote tracking action.
Diffstat (limited to 'spec/controllers/track_controller_spec.rb')
-rw-r--r-- | spec/controllers/track_controller_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 29f5c7fe1..b7f679cdb 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -275,3 +275,49 @@ describe TrackController, "when tracking a public body" do end end + +describe TrackController do + include LinkToHelper + + describe :widget_vote do + + before do + @info_request = FactoryGirl.create(:info_request) + end + + it 'should find the info request' do + get :widget_vote, :info_request_id => @info_request.id + assigns[:info_request].should == @info_request + end + + it 'should redirect to the track path for the info request' do + get :widget_vote, :info_request_id => @info_request.id + track_thing = TrackThing.create_track_for_request(@info_request) + expect(response).to redirect_to(do_track_path(track_thing)) + end + + context 'when there is no logged-in user and a widget vote cookie' do + + before do + @cookie_value = 'x' * 20 + end + + it 'should create a widget vote if none exists for the info request and cookie' do + @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 0 + request.cookies['widget_vote'] = @cookie_value + get :widget_vote, :info_request_id => @info_request.id + @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 1 + end + + it 'should not create a widget vote if one exists for the info request and cookie' do + @info_request.widget_votes.create(:cookie => @cookie_value) + request.cookies['widget_vote'] = @cookie_value + get :widget_vote, :info_request_id => @info_request.id + @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 1 + end + + end + + end + +end |