diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-09-17 17:39:51 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-09-17 17:39:51 +0100 |
commit | 6fbcb461025dc315d688038d9f0a8e138d00ba33 (patch) | |
tree | 628ad3d7bf9cb2310bc2bed2e94b8670532a0dd4 /spec/controllers/admin_outgoing_message_controller_spec.rb | |
parent | abde5e4a1139c41c6db23ce041fba090674f65ac (diff) | |
parent | f41ec6d1cb167058a808b7820da5345c6da962fd (diff) |
Merge branch 'feature/hide-individual-responses' into rails-3-develop
Conflicts:
Gemfile
app/views/admin_request/edit_outgoing.html.erb
config/packages
doc/CHANGES.md
doc/INSTALL.md
spec/models/info_request_spec.rb
spec/models/public_body_spec.rb
Diffstat (limited to 'spec/controllers/admin_outgoing_message_controller_spec.rb')
-rw-r--r-- | spec/controllers/admin_outgoing_message_controller_spec.rb | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/spec/controllers/admin_outgoing_message_controller_spec.rb b/spec/controllers/admin_outgoing_message_controller_spec.rb new file mode 100644 index 000000000..0dde53b86 --- /dev/null +++ b/spec/controllers/admin_outgoing_message_controller_spec.rb @@ -0,0 +1,105 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe AdminOutgoingMessageController do + + describe 'when editing an outgoing message' do + + before do + @info_request = FactoryGirl.create(:info_request) + @outgoing = @info_request.outgoing_messages.first + end + + it 'should be successful' do + get :edit, :id => @outgoing.id + response.should be_success + end + + it 'should assign the incoming message to the view' do + get :edit, :id => @outgoing.id + assigns[:outgoing_message].should == @outgoing + end + + end + + describe 'when updating an outgoing message' do + + before do + @info_request = FactoryGirl.create(:info_request) + @outgoing = @info_request.outgoing_messages.first + @default_params = {:id => @outgoing.id, + :outgoing_message => {:prominence => 'hidden', + :prominence_reason => 'dull', + :body => 'changed body'} } + end + + def make_request(params=@default_params) + post :update, params + end + + it 'should save a change to the body of the message' do + make_request + @outgoing.reload + @outgoing.body.should == 'changed body' + end + + it 'should save the prominence of the message' do + make_request + @outgoing.reload + @outgoing.prominence.should == 'hidden' + end + + it 'should save a prominence reason for the message' do + make_request + @outgoing.reload + @outgoing.prominence_reason.should == 'dull' + end + + it 'should log an "edit_outgoing" event on the info_request' do + @controller.stub!(:admin_current_user).and_return("Admin user") + make_request + @info_request.reload + last_event = @info_request.info_request_events.last + last_event.event_type.should == 'edit_outgoing' + last_event.params.should == { :outgoing_message_id => @outgoing.id, + :editor => "Admin user", + :old_prominence => "normal", + :prominence => "hidden", + :old_prominence_reason => nil, + :old_body => 'Some information please', + :body => 'changed body', + :prominence_reason => "dull" } + end + + it 'should expire the file cache for the info request' do + @controller.should_receive(:expire_for_request).with(@info_request) + make_request + end + + context 'if the outgoing message saves correctly' do + + it 'should redirect to the admin info request view' do + make_request + response.should redirect_to admin_request_show_url(@info_request) + end + + it 'should show a message that the incoming message has been updated' do + make_request + flash[:notice].should == 'Outgoing message successfully updated.' + end + + end + + context 'if the incoming message is not valid' do + + it 'should render the edit template' do + make_request({:id => @outgoing.id, + :outgoing_message => {:prominence => 'fantastic', + :prominence_reason => 'dull', + :body => 'Some information please'}}) + response.should render_template("edit") + end + + end + end + +end |