diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 11 | ||||
-rw-r--r-- | spec/factories.rb | 1 | ||||
-rw-r--r-- | spec/models/info_request_batch_spec.rb | 45 |
3 files changed, 57 insertions, 0 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 6652d8f1f..c61e0c780 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2573,6 +2573,17 @@ describe RequestController, "#new_batch", :focus => true do response.should redirect_to(info_request_batch_path(new_info_request_batch)) end + it 'should prevent double submission of a batch request' do + params = @default_post_params.merge(:preview => 0) + post :new_batch, params, { :user_id => @user.id } + new_info_request_batch = assigns[:info_request_batch] + response.should redirect_to(info_request_batch_path(new_info_request_batch)) + post :new_batch, params, { :user_id => @user.id } + response.should render_template('new') + assigns[:existing_batch].should_not be_nil + end + + context "when the user is banned" do before do diff --git a/spec/factories.rb b/spec/factories.rb index 66388af6e..3ea943030 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -148,5 +148,6 @@ FactoryGirl.define do factory :info_request_batch do title "Example title" user + body "Some text" end end diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb index f6d9bea0c..787b812cf 100644 --- a/spec/models/info_request_batch_spec.rb +++ b/spec/models/info_request_batch_spec.rb @@ -18,4 +18,49 @@ describe InfoRequestBatch, "when validating" do @info_request_batch.errors.full_messages.should == ["Title can't be blank"] end + it 'should require a body' do + @info_request_batch.body = nil + @info_request_batch.valid?.should be_false + @info_request_batch.errors.full_messages.should == ["Body can't be blank"] + end + +end + +describe InfoRequestBatch, "when finding an existing batch" do + + before do + @info_request_batch = FactoryGirl.create(:info_request_batch, :title => 'Matched title', + :body => 'Matched body') + @first_request = FactoryGirl.create(:info_request, :info_request_batch => @info_request_batch) + @second_request = FactoryGirl.create(:info_request, :info_request_batch => @info_request_batch) + end + + it 'should return a batch with the same user, title and body sent to one of the same public bodies' do + InfoRequestBatch.find_existing(@info_request_batch.user, + @info_request_batch.title, + @info_request_batch.body, + [@first_request.public_body_id]).should_not be_nil + end + + it 'should not return a batch with the same title and body sent to another public body' do + InfoRequestBatch.find_existing(@info_request_batch.user, + @info_request_batch.title, + @info_request_batch.body, + [FactoryGirl.create(:public_body).id]).should be_nil + end + + it 'should not return a batch sent the same public bodies with a different title and body' do + InfoRequestBatch.find_existing(@info_request_batch.user, + 'Other title', + 'Other body', + [@first_request.public_body_id]).should be_nil + end + + it 'should not return a batch sent to one of the same public bodies with the same title and body by + a different user' do + InfoRequestBatch.find_existing(FactoryGirl.create(:user), + @info_request_batch.title, + @info_request_batch.body, + [@first_request.public_body_id]).should be_nil + end end |