aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-11-27 12:05:11 +0000
committerLouise Crow <louise.crow@gmail.com>2013-12-04 09:32:44 +0000
commitd898b9308f98f84c4f44bcc3316193e80b007b23 (patch)
tree1203dd2112087e506a61ee76bae29fe075337a23
parent51c80db7a35a41fbbab9b28e86a5d60166791b4c (diff)
Use public bodies not requests in find_existing
The requests may not have been created at this point.
-rw-r--r--app/models/info_request_batch.rb8
-rw-r--r--spec/models/info_request_batch_spec.rb14
2 files changed, 12 insertions, 10 deletions
diff --git a/app/models/info_request_batch.rb b/app/models/info_request_batch.rb
index d6227808b..745cfe7d2 100644
--- a/app/models/info_request_batch.rb
+++ b/app/models/info_request_batch.rb
@@ -21,12 +21,12 @@ class InfoRequestBatch < ActiveRecord::Base
# When constructing a new batch, use this to check user hasn't double submitted.
def InfoRequestBatch.find_existing(user, title, body, public_body_ids)
- find(:first, :conditions => ['info_request_batches.user_id = ?
- AND info_request_batches.title = ?
+ find(:first, :conditions => ['user_id = ?
+ AND title = ?
AND body = ?
- AND info_requests.public_body_id in (?)',
+ AND info_request_batches_public_bodies.public_body_id in (?)',
user, title, body, public_body_ids],
- :include => :info_requests)
+ :include => :public_bodies)
end
# Create a batch of information requests, returning a list of public bodies
diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb
index 7f6905c8e..2323c3bd3 100644
--- a/spec/models/info_request_batch_spec.rb
+++ b/spec/models/info_request_batch_spec.rb
@@ -29,31 +29,33 @@ end
describe InfoRequestBatch, "when finding an existing batch" do
before do
+ @first_body = FactoryGirl.create(:public_body)
+ @second_body = FactoryGirl.create(:public_body)
@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)
+ :body => 'Matched body',
+ :public_bodies => [@first_body,
+ @second_body])
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
+ [@first_body]).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
+ [FactoryGirl.create(:public_body)]).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
+ [@first_body]).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