diff options
| author | Gareth Rees <gareth@mysociety.org> | 2015-06-29 12:29:07 +0100 |
|---|---|---|
| committer | Gareth Rees <gareth@mysociety.org> | 2015-06-29 12:29:07 +0100 |
| commit | d3480d94da4c2ad3a76c8063b7e325bbaf48a396 (patch) | |
| tree | e2d8b5194703869f88706672623dd18faba95eef | |
| parent | 3cc27686f65f4efd466db16500d58025c3912d8f (diff) | |
Improve specs for creating a WidgetVote
Better context blocks now spec file has grown
| -rw-r--r-- | spec/controllers/widgets_controller_spec.rb | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb index e52a52e4f..eb4480ebf 100644 --- a/spec/controllers/widgets_controller_spec.rb +++ b/spec/controllers/widgets_controller_spec.rb @@ -198,24 +198,32 @@ describe WidgetsController do 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 + context 'for a non-logged-in user without a tracking cookie' do - before do - @cookie_value = 'x' * 20 - end + it 'creates a widget vote' do + SecureRandom.stub!(:hex).and_return('0300fd3e1177127cebff') + votes = @info_request. + widget_votes. + where(:cookie => '0300fd3e1177127cebff') - 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 put :update, :request_id => @info_request.id - @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 1 + + expect(votes).to have(1).item 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 + end + + context 'for a non-logged-in user with a tracking cookie' do + + it 'creates a widget vote' do + request.cookies['widget_vote'] = '0300fd3e1177127cebff' + votes = @info_request. + widget_votes. + where(:cookie => '0300fd3e1177127cebff') + put :update, :request_id => @info_request.id - @info_request.widget_votes.where(:cookie => @cookie_value).size.should == 1 + + expect(votes).to have(1).item end end |
