From 1887774daee72298174901d10b4e75492b9911d2 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 8 Aug 2013 17:14:51 +0100 Subject: Move incoming message admin to its own controller. Make specs that depend on multiple controllers and models interacting integration specs. --- .../admin_incoming_message_controller_spec.rb | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 spec/controllers/admin_incoming_message_controller_spec.rb (limited to 'spec/controllers/admin_incoming_message_controller_spec.rb') diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb new file mode 100644 index 000000000..7439197ef --- /dev/null +++ b/spec/controllers/admin_incoming_message_controller_spec.rb @@ -0,0 +1,51 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe AdminIncomingMessageController, "when administering incoming messages" do + + before(:each) do + basic_auth_login @request + load_raw_emails_data + end + + describe 'when destroying an incoming message' do + + before do + @im = incoming_messages(:useless_incoming_message) + @controller.stub!(:expire_for_request) + end + + it "destroys the raw email file" do + raw_email = @im.raw_email.filepath + assert_equal File.exists?(raw_email), true + post :destroy_incoming, :incoming_message_id => @im.id + assert_equal File.exists?(raw_email), false + end + + it 'asks the incoming message to fully destroy itself' do + IncomingMessage.stub!(:find).and_return(@im) + @im.should_receive(:fully_destroy) + post :destroy_incoming, :incoming_message_id => @im.id + end + + it 'expires the file cache for the associated info_request' do + @controller.should_receive(:expire_for_request).with(@im.info_request) + post :destroy_incoming, :incoming_message_id => @im.id + end + + end + + describe 'when redelivering an incoming message' do + + it 'expires the file cache for the previous request' do + current_info_request = info_requests(:fancy_dog_request) + destination_info_request = info_requests(:naughty_chicken_request) + incoming_message = incoming_messages(:useless_incoming_message) + @controller.should_receive(:expire_for_request).with(current_info_request) + post :redeliver_incoming, :redeliver_incoming_message_id => incoming_message.id, + :url_title => destination_info_request.url_title + end + + + end + +end -- cgit v1.2.3 From c62b1ea80b3f3efa801c0adaad0b17edebc63570 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 8 Aug 2013 17:16:54 +0100 Subject: Slightly nicer action names. --- spec/controllers/admin_incoming_message_controller_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/controllers/admin_incoming_message_controller_spec.rb') diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb index 7439197ef..1ee78cd35 100644 --- a/spec/controllers/admin_incoming_message_controller_spec.rb +++ b/spec/controllers/admin_incoming_message_controller_spec.rb @@ -17,19 +17,19 @@ describe AdminIncomingMessageController, "when administering incoming messages" it "destroys the raw email file" do raw_email = @im.raw_email.filepath assert_equal File.exists?(raw_email), true - post :destroy_incoming, :incoming_message_id => @im.id + post :destroy, :incoming_message_id => @im.id assert_equal File.exists?(raw_email), false end it 'asks the incoming message to fully destroy itself' do IncomingMessage.stub!(:find).and_return(@im) @im.should_receive(:fully_destroy) - post :destroy_incoming, :incoming_message_id => @im.id + post :destroy, :incoming_message_id => @im.id end it 'expires the file cache for the associated info_request' do @controller.should_receive(:expire_for_request).with(@im.info_request) - post :destroy_incoming, :incoming_message_id => @im.id + post :destroy, :incoming_message_id => @im.id end end @@ -41,8 +41,8 @@ describe AdminIncomingMessageController, "when administering incoming messages" destination_info_request = info_requests(:naughty_chicken_request) incoming_message = incoming_messages(:useless_incoming_message) @controller.should_receive(:expire_for_request).with(current_info_request) - post :redeliver_incoming, :redeliver_incoming_message_id => incoming_message.id, - :url_title => destination_info_request.url_title + post :redeliver, :redeliver_incoming_message_id => incoming_message.id, + :url_title => destination_info_request.url_title end -- cgit v1.2.3 From 1a5d3b6f389075bd9699a749f9dc2287b93c1b10 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 12 Aug 2013 18:37:03 +0100 Subject: Add a simple edit action and template --- .../admin_incoming_message_controller_spec.rb | 33 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'spec/controllers/admin_incoming_message_controller_spec.rb') diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb index 1ee78cd35..bca0e7b17 100644 --- a/spec/controllers/admin_incoming_message_controller_spec.rb +++ b/spec/controllers/admin_incoming_message_controller_spec.rb @@ -2,13 +2,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminIncomingMessageController, "when administering incoming messages" do - before(:each) do - basic_auth_login @request - load_raw_emails_data - end - describe 'when destroying an incoming message' do + before(:each) do + basic_auth_login @request + load_raw_emails_data + end + before do @im = incoming_messages(:useless_incoming_message) @controller.stub!(:expire_for_request) @@ -36,6 +36,11 @@ describe AdminIncomingMessageController, "when administering incoming messages" describe 'when redelivering an incoming message' do + before(:each) do + basic_auth_login @request + load_raw_emails_data + end + it 'expires the file cache for the previous request' do current_info_request = info_requests(:fancy_dog_request) destination_info_request = info_requests(:naughty_chicken_request) @@ -48,4 +53,22 @@ describe AdminIncomingMessageController, "when administering incoming messages" end + describe 'when editing an incoming message' do + + before do + @incoming = FactoryGirl.create(:incoming_message) + end + + it 'should be successful' do + get :edit, :id => @incoming.id + response.should be_success + end + + it 'should assign the incoming message to the view' do + get :edit, :id => @incoming.id + assigns[:incoming_message].should == @incoming + end + + end + end -- cgit v1.2.3 From df8f107d9185a8fc00ef2789596a1512e930de37 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 12 Aug 2013 18:55:24 +0100 Subject: Add the meat of the update action. --- .../admin_incoming_message_controller_spec.rb | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'spec/controllers/admin_incoming_message_controller_spec.rb') diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb index bca0e7b17..c73fedbc0 100644 --- a/spec/controllers/admin_incoming_message_controller_spec.rb +++ b/spec/controllers/admin_incoming_message_controller_spec.rb @@ -71,4 +71,74 @@ describe AdminIncomingMessageController, "when administering incoming messages" end + describe 'when updating an incoming message' do + + before do + @incoming = FactoryGirl.create(:incoming_message, prominence: 'normal') + @default_params = {:id => @incoming.id, + :incoming_message => {:prominence => 'hidden', + :prominence_reason => 'dull'} } + end + + def make_request(params=@default_params) + post :update, params + end + + it 'should save the prominence of the request' do + make_request + @incoming.reload + @incoming.prominence.should == 'hidden' + end + + it 'should save a prominence reason for the request' do + make_request + @incoming.reload + @incoming.prominence_reason.should == 'dull' + end + + it 'should log an "edit_incoming" event on the info_request' do + @controller.stub!(:admin_current_user).and_return("Admin user") + make_request + @incoming.reload + last_event = @incoming.info_request_events.last + last_event.event_type.should == 'edit_incoming' + last_event.params.should == { :incoming_message_id => @incoming.id, + :editor => "Admin user", + :old_prominence => "normal", + :prominence => "hidden", + :old_prominence_reason => nil, + :prominence_reason => "dull" } + end + + it 'should expire the file cache for the info request' do + @controller.should_receive(:expire_for_request).with(@incoming.info_request) + make_request + end + + context 'if the incoming message saves correctly' do + + it 'should redirect to the admin info request view' do + make_request + response.should redirect_to admin_request_show_url(@incoming.info_request) + end + + it 'should show a message that the incoming message has been updated' do + make_request + flash[:notice].should == 'Incoming message successfully updated.' + end + + end + + context 'if the incoming message is not valid' do + + it 'should render the edit template' do + make_request({:id => @incoming.id, + :incoming_message => {:prominence => 'fantastic', + :prominence_reason => 'dull'}}) + response.should render_template("edit") + end + + end + end + end -- cgit v1.2.3 From a1538a90bbca7d37e506d92e52804c2386a3e716 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 27 Aug 2013 12:55:51 +0100 Subject: Fix spec descriptions --- spec/controllers/admin_incoming_message_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/controllers/admin_incoming_message_controller_spec.rb') diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb index c73fedbc0..879258e43 100644 --- a/spec/controllers/admin_incoming_message_controller_spec.rb +++ b/spec/controllers/admin_incoming_message_controller_spec.rb @@ -84,13 +84,13 @@ describe AdminIncomingMessageController, "when administering incoming messages" post :update, params end - it 'should save the prominence of the request' do + it 'should save the prominence of the message' do make_request @incoming.reload @incoming.prominence.should == 'hidden' end - it 'should save a prominence reason for the request' do + it 'should save a prominence reason for the message' do make_request @incoming.reload @incoming.prominence_reason.should == 'dull' -- cgit v1.2.3 From 6b29b23dc1690d09e1ef5bd9cc277562483c9ef8 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Wed, 28 Aug 2013 10:50:23 +0100 Subject: Use earlier factory_girl syntax --- spec/controllers/admin_incoming_message_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers/admin_incoming_message_controller_spec.rb') diff --git a/spec/controllers/admin_incoming_message_controller_spec.rb b/spec/controllers/admin_incoming_message_controller_spec.rb index 879258e43..b969a8a3f 100644 --- a/spec/controllers/admin_incoming_message_controller_spec.rb +++ b/spec/controllers/admin_incoming_message_controller_spec.rb @@ -74,7 +74,7 @@ describe AdminIncomingMessageController, "when administering incoming messages" describe 'when updating an incoming message' do before do - @incoming = FactoryGirl.create(:incoming_message, prominence: 'normal') + @incoming = FactoryGirl.create(:incoming_message, :prominence => 'normal') @default_params = {:id => @incoming.id, :incoming_message => {:prominence => 'hidden', :prominence_reason => 'dull'} } -- cgit v1.2.3