diff options
| author | Gareth Rees <gareth@mysociety.org> | 2015-06-29 14:31:13 +0100 |
|---|---|---|
| committer | Gareth Rees <gareth@mysociety.org> | 2015-06-29 14:31:13 +0100 |
| commit | 5543eb36a87297675c155f5897af24843892a3cc (patch) | |
| tree | 483aea688ba7e211301a690702e64d9860aa9d8a | |
| parent | 98ae1c241d360feb21e76876813578cd58332c53 (diff) | |
Extract mock cookie value to method
| -rw-r--r-- | spec/controllers/widgets_controller_spec.rb | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb index 7c60b847a..a8702f2a5 100644 --- a/spec/controllers/widgets_controller_spec.rb +++ b/spec/controllers/widgets_controller_spec.rb @@ -62,10 +62,9 @@ describe WidgetsController do context 'for a non-logged-in user with a tracking cookie' do it 'assigns the cookie to tracking_cookie' do - cookie_value = SecureRandom.hex(10) - request.cookies['widget_vote'] = cookie_value + request.cookies['widget_vote'] = mock_cookie get :show, :request_id => @info_request.id - expect(assigns[:tracking_cookie]).to eq(cookie_value) + expect(assigns[:tracking_cookie]).to eq(mock_cookie) end end @@ -195,16 +194,16 @@ describe WidgetsController do context 'for a non-logged-in user without a tracking cookie' do it 'sets a tracking cookie' do - SecureRandom.stub!(:hex).and_return('0300fd3e1177127cebff') + SecureRandom.stub!(:hex).and_return(mock_cookie) put :update, :request_id => @info_request.id - expect(cookies[:widget_vote]).to eq('0300fd3e1177127cebff') + expect(cookies[:widget_vote]).to eq(mock_cookie) end it 'creates a widget vote' do - SecureRandom.stub!(:hex).and_return('0300fd3e1177127cebff') + SecureRandom.stub!(:hex).and_return(mock_cookie) votes = @info_request. widget_votes. - where(:cookie => '0300fd3e1177127cebff') + where(:cookie => mock_cookie) put :update, :request_id => @info_request.id @@ -217,16 +216,16 @@ describe WidgetsController do context 'for a non-logged-in user with a tracking cookie' do it 'retains the existing tracking cookie' do - request.cookies['widget_vote'] = '0300fd3e1177127cebff' + request.cookies['widget_vote'] = mock_cookie put :update, :request_id => @info_request.id - expect(cookies[:widget_vote]).to eq('0300fd3e1177127cebff') + expect(cookies[:widget_vote]).to eq(mock_cookie) end it 'creates a widget vote' do - request.cookies['widget_vote'] = '0300fd3e1177127cebff' + request.cookies['widget_vote'] = mock_cookie votes = @info_request. widget_votes. - where(:cookie => '0300fd3e1177127cebff') + where(:cookie => mock_cookie) put :update, :request_id => @info_request.id @@ -260,3 +259,6 @@ describe WidgetsController do end +def mock_cookie + '0300fd3e1177127cebff' +end |
