aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-08-27 12:55:25 +0100
committerLouise Crow <louise.crow@gmail.com>2013-09-16 14:03:22 +0100
commitca294ea3cbcc90851bed388a8b5449f81eafa32d (patch)
tree0b744c3db45de6bf12d4ce9d4def27afcd5f4ac2
parentfca2037a243a8e0b0afaf7fc779a96bb86f39b7f (diff)
Add prominence fields and cache expiry to outgoing admin
-rw-r--r--app/controllers/admin_outgoing_message_controller.rb19
-rw-r--r--app/views/admin_outgoing_message/edit.html.erb24
-rw-r--r--spec/controllers/admin_outgoing_message_controller_spec.rb108
3 files changed, 131 insertions, 20 deletions
diff --git a/app/controllers/admin_outgoing_message_controller.rb b/app/controllers/admin_outgoing_message_controller.rb
index 3f53838d6..ec0981677 100644
--- a/app/controllers/admin_outgoing_message_controller.rb
+++ b/app/controllers/admin_outgoing_message_controller.rb
@@ -21,12 +21,23 @@ class AdminOutgoingMessageController < AdminController
@outgoing_message = OutgoingMessage.find(params[:id])
old_body = @outgoing_message.body
-
- if @outgoing_message.update_attributes(params[:outgoing_message])
+ old_prominence = @outgoing_message.prominence
+ old_prominence_reason = @outgoing_message.prominence_reason
+ @outgoing_message.prominence = params[:outgoing_message][:prominence]
+ @outgoing_message.prominence_reason = params[:outgoing_message][:prominence_reason]
+ @outgoing_message.body = params[:outgoing_message][:body]
+ if @outgoing_message.save
@outgoing_message.info_request.log_event("edit_outgoing",
- { :outgoing_message_id => @outgoing_message.id, :editor => admin_current_user(),
- :old_body => old_body, :body => @outgoing_message.body })
+ { :outgoing_message_id => @outgoing_message.id,
+ :editor => admin_current_user(),
+ :old_body => old_body,
+ :body => @outgoing_message.body,
+ :old_prominence => old_prominence,
+ :old_prominence_reason => old_prominence_reason,
+ :prominence => @outgoing_message.prominence,
+ :prominence_reason => @outgoing_message.prominence_reason })
flash[:notice] = 'Outgoing message successfully updated.'
+ expire_for_request(@outgoing_message.info_request)
redirect_to admin_request_show_url(@outgoing_message.info_request)
else
render :action => 'edit'
diff --git a/app/views/admin_outgoing_message/edit.html.erb b/app/views/admin_outgoing_message/edit.html.erb
index b52884bae..d40ea03ef 100644
--- a/app/views/admin_outgoing_message/edit.html.erb
+++ b/app/views/admin_outgoing_message/edit.html.erb
@@ -3,9 +3,25 @@
<%= error_messages_for 'outgoing_message' %>
<%= form_tag admin_outgoing_update_path(@outgoing_message) do %>
+ <div class="control-group">
+ <label class="control-label" for="outgoing_message_prominence"> Prominence</label>
+ <div class="controls">
+ <%= select('outgoing_message', "prominence", OutgoingMessage.prominence_states) %>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <label class="control-label" for="outgoing_message_prominence_reason">Reason for prominence</label>
+ <div class="controls">
+ <%= text_area "outgoing_message", "prominence_reason", :rows => 5, :class => "span6" %>
+ </div>
+ </div>
- <p><label for="outgoing_message_body">Body of message</label><br/>
- <%= text_area 'outgoing_message', 'body', :rows => 10, :cols => 60 %></p>
+ <div class="control-group">
+ <label class="control-label" for="outgoing_message_body">Body of message</label>
+ <div class="controls">
+ <%= text_area 'outgoing_message', 'body', :rows => 10, :cols => 60 %>
+ </div>
<p><strong>Note:</strong> This is mainly to be used to excise information
that users inadvertently put in their messages, not realising it would be
@@ -14,7 +30,9 @@
this site. You could also use this to edit a message before resending it, but
only the edited version will be shown on the public page if you do that.</p>
- <p><%= submit_tag 'Save', :accesskey => 's' %></p>
+<div class="form-actions" >
+<%= submit_tag 'Save', :accesskey => 's', :class => 'btn' %>
+</div>
<% end %>
<p>
diff --git a/spec/controllers/admin_outgoing_message_controller_spec.rb b/spec/controllers/admin_outgoing_message_controller_spec.rb
index b97df69d5..0dde53b86 100644
--- a/spec/controllers/admin_outgoing_message_controller_spec.rb
+++ b/spec/controllers/admin_outgoing_message_controller_spec.rb
@@ -1,23 +1,105 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe AdminOutgoingMessageController do
- render_views
- before { basic_auth_login @request }
- before(:each) do
- load_raw_emails_data
- end
+ 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
- it "edits an outgoing message" do
- get :edit, :id => outgoing_messages(:useless_outgoing_message)
end
- it "saves edits to an outgoing_message" do
- outgoing_messages(:useless_outgoing_message).body.should include("fancy dog")
- post :update, { :id => outgoing_messages(:useless_outgoing_message), :outgoing_message => { :body => "Why do you have such a delicious cat?" } }
- request.flash[:notice].should include('successful')
- ir = OutgoingMessage.find(outgoing_messages(:useless_outgoing_message).id)
- ir.body.should include("delicious cat")
+ 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