aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/track_controller_spec.rb46
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