From 90fd2c06e48c17909b9a7d2aae6d01c41047b4de Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 28 Oct 2013 13:33:08 +0000 Subject: Add the specific salutations to each request. Also, wrap model creation in a transaction and do the message sending separately - we may ultimately want to do this outside the request cycle. --- spec/models/info_request_batch_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'spec/models/info_request_batch_spec.rb') diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb index 787b812cf..ba4bcd181 100644 --- a/spec/models/info_request_batch_spec.rb +++ b/spec/models/info_request_batch_spec.rb @@ -64,3 +64,25 @@ describe InfoRequestBatch, "when finding an existing batch" do [@first_request.public_body_id]).should be_nil end end + +describe InfoRequestBatch, "when creating a batch", :focus => true do + + it 'should substitute authority name for the placeholder in each request' do + info_request_params = {:title => 'A test title'} + outgoing_message_params = {:body => "Dear [Authority name],\nA message\nYours faithfully,\nRequester", + } + first_public_body = FactoryGirl.create(:public_body) + second_public_body = FactoryGirl.create(:public_body) + user = FactoryGirl.create(:user) + results = InfoRequestBatch.create_batch!(info_request_params, + outgoing_message_params, + [first_public_body.id, second_public_body.id], + user) + info_requests = results[:batch].info_requests + [first_public_body, second_public_body].each do |public_body| + request = info_requests.detect{|info_request| info_request.public_body == public_body} + request.outgoing_messages.first.body.should == "Dear #{public_body.name},\nA message\nYours faithfully,\nRequester" + end + end + +end -- cgit v1.2.3