diff options
| author | Gareth Rees <gareth@mysociety.org> | 2015-06-26 16:15:22 +0100 |
|---|---|---|
| committer | Gareth Rees <gareth@mysociety.org> | 2015-06-26 16:15:22 +0100 |
| commit | 369995eb27747b1480aa20392defbe8eea7f6f61 (patch) | |
| tree | d29063ab829cb73bcee8c81e4ae24ded0b0059c7 | |
| parent | 2d0fb9a10fd3557db4cd452e0409a943c87b6122 (diff) | |
Assign the widget_vote cookie if available
Reorganised the specs a little in to better contexts
| -rw-r--r-- | app/controllers/widgets_controller.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/widgets_controller_spec.rb | 27 |
2 files changed, 22 insertions, 7 deletions
diff --git a/app/controllers/widgets_controller.rb b/app/controllers/widgets_controller.rb index 333a38e86..8841c2aeb 100644 --- a/app/controllers/widgets_controller.rb +++ b/app/controllers/widgets_controller.rb @@ -20,6 +20,8 @@ class WidgetsController < ApplicationController if @user @existing_track = TrackThing.find_existing(@user, @track_thing) + else + @tracking_cookie = cookies[:widget_vote] end unless @user || cookies[:widget_vote] cookies.permanent[:widget_vote] = SecureRandom.hex(10) diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb index 6c6985a33..53451a39a 100644 --- a/spec/controllers/widgets_controller_spec.rb +++ b/spec/controllers/widgets_controller_spec.rb @@ -37,16 +37,29 @@ describe WidgetsController do response.headers["X-Frame-Options"].should be_nil end - context 'for a non-logged-in user' do + context 'for a non-logged-in user with a tracking cookie' do - context 'if no widget-vote cookie is set' do + it 'assigns the cookie to tracking_cookie' do + cookie_value = SecureRandom.hex(10) + request.cookies['widget_vote'] = cookie_value + get :show, :request_id => @info_request.id + expect(assigns[:tracking_cookie]).to eq(cookie_value) + end + + end - it 'should set a widget-vote cookie' do - cookies[:widget_vote].should be_nil - get :show, :request_id => @info_request.id - cookies[:widget_vote].should_not be_nil - end + context 'for a non-logged-in user without a tracking cookie' do + it 'tracking_cookie will be nil' do + request.cookies['widget_vote'] = nil + get :show, :request_id => @info_request.id + expect(assigns[:tracking_cookie]).to be_nil + end + + it 'should set a widget-vote cookie' do + cookies[:widget_vote].should be_nil + get :show, :request_id => @info_request.id + cookies[:widget_vote].should_not be_nil end end |
