diff options
author | louise <louise> | 2009-04-03 14:22:02 +0000 |
---|---|---|
committer | louise <louise> | 2009-04-03 14:22:02 +0000 |
commit | 9e589e9a7cf2bb2f7b9a36440cd3e723ea09e6f4 (patch) | |
tree | e77245ef5ea0e76ed0bbbbe3453371f29c3f4827 /spec/controllers/request_controller_spec.rb | |
parent | 228edc7b70f35be0c7b8aa101d7e16538bca9f88 (diff) |
Rebuild xapian index before specs that require it - to allow tests to be more independent, so they can be run in any order. Nest specs so that specs that do not need views generated do not have integrate_views set - mocks for these specs can now be simpler. Add new specs and code for handling an update_status param.
Diffstat (limited to 'spec/controllers/request_controller_spec.rb')
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 92 |
1 files changed, 62 insertions, 30 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index e37d5bf7a..856b4c804 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1,6 +1,11 @@ require File.dirname(__FILE__) + '/../spec_helper' describe RequestController, "when listing recent requests" do + + before(:all) do + rebuild_xapian_index + end + it "should be successful" do get :list, :view => 'recent' response.should be_success @@ -20,8 +25,9 @@ describe RequestController, "when listing recent requests" do end end + describe RequestController, "when showing one request" do - integrate_views + fixtures :info_requests, :info_request_events, :public_bodies, :users, :incoming_messages, :raw_emails, :outgoing_messages # all needed as integrating views it "should be successful" do @@ -43,39 +49,65 @@ describe RequestController, "when showing one request" do get :show, :url_title => info_requests(:naughty_chicken_request).id response.should redirect_to(:action => 'show', :url_title => info_requests(:naughty_chicken_request).url_title) end + + describe 'when handling an update_status parameter' do + + before do + mock_request = mock_model(InfoRequest, :url_title => 'test_title', + :title => 'test title', + :null_object => true) + InfoRequest.stub!(:find_by_url_title).and_return(mock_request) + end - it "should receive incoming messages, send email to creator, and show them" do - get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - size_before = assigns[:info_request_events].size - - ir = info_requests(:fancy_dog_request) - receive_incoming_mail('incoming-request-plain.email', ir.incoming_email) - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - mail = deliveries[0] - mail.body.should =~ /You have a new response to the Freedom of Information request/ + it 'should assign the "update status" flag to the view as true if the parameter is present' do + get :show, :url_title => 'test_title', :update_status => 1 + assigns[:update_status].should be_true + end - get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - (assigns[:info_request_events].size - size_before).should == 1 + it 'should assign the "update status" flag to the view as true if the parameter is present' do + get :show, :url_title => 'test_title' + assigns[:update_status].should be_false + end + end - it "should download attachments" do - get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - response.content_type.should == "text/html" - size_before = assigns[:info_request_events].size - - ir = info_requests(:fancy_dog_request) - receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) - - get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' - (assigns[:info_request_events].size - size_before).should == 1 - - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2 - response.content_type.should == "text/plain" - response.should have_text(/Second hello/) - get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3 - response.content_type.should == "text/plain" - response.should have_text(/First hello/) + describe 'when handling incoming mail' do + + integrate_views + + it "should receive incoming messages, send email to creator, and show them" do + get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' + size_before = assigns[:info_request_events].size + + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-plain.email', ir.incoming_email) + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /You have a new response to the Freedom of Information request/ + + get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' + (assigns[:info_request_events].size - size_before).should == 1 + end + + it "should download attachments" do + get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' + response.content_type.should == "text/html" + size_before = assigns[:info_request_events].size + + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) + + get :show, :url_title => 'why_do_you_have_such_a_fancy_dog' + (assigns[:info_request_events].size - size_before).should == 1 + + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2 + response.content_type.should == "text/plain" + response.should have_text(/Second hello/) + get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3 + response.content_type.should == "text/plain" + response.should have_text(/First hello/) + end end end |