end
end
else
+ @message = Message.new(:recipient => @this_user)
@title = t 'message.new.title'
end
end
if message.to_user_id == @user.id then
message.update_attribute(:message_read, true)
- @body = "On #{message.sent_on} #{message.sender.display_name} wrote:\n\n#{message.body.gsub(/^/, '> ')}"
- @title = @subject = "Re: #{message.title.sub(/^Re:\s*/, '')}"
- @this_user = User.find(message.from_user_id)
+ @message = Message.new(
+ :recipient => message.sender,
+ :title => "Re: #{message.title.sub(/^Re:\s*/, '')}",
+ :body => "On #{message.sent_on} #{message.sender.display_name} wrote:\n\n#{message.body.gsub(/^/, '> ')}",
+ )
+
+ @title = @message.title
render :action => 'new'
else
<% content_for :heading do %>
- <h2><%= raw(t'message.new.send_message_to', :name => link_to(h(@this_user.display_name), {:controller => 'user', :action => 'view', :display_name => @this_user.display_name})) %></h2>
+ <h2><%= raw(t'message.new.send_message_to', :name => link_to(h(@message.recipient.display_name), {:controller => 'user', :action => 'view', :display_name => @message.recipient.display_name})) %></h2>
<% end %>
<%= error_messages_for 'message' %>
-<%= form_for :message, :html => { :class => 'standard-form' }, :url => { :action => "new", :display_name => @this_user.display_name } do |f| %>
+<%= form_for :message, :html => { :class => 'standard-form' }, :url => { :action => "new", :display_name => @message.recipient.display_name } do |f| %>
<fieldset>
<div class='form-row'>
<label class="standard-label"><%= t'message.new.subject' %></label>
- <%= f.text_field :title, :size => 60, :value => @subject, :class => "richtext_title" %>
+ <%= f.text_field :title, :size => 60, :class => "richtext_title" %>
</div>
<div class='form-row'>
<label class="standard-label"><%= t'message.new.body' %></label>
- <%= richtext_area :message, :body, :cols => 80, :rows => 20, :value => @body %>
+ <%= richtext_area :message, :body, :cols => 80, :rows => 20 %>
</div>
<div class='buttons'>
<%= submit_tag t('message.new.send_button') %>
assert_select "input[type='submit'][value='Send']", :count => 1
end
+ # Check that the subject is preserved over errors
+ assert_difference "ActionMailer::Base.deliveries.size", 0 do
+ assert_difference "Message.count", 0 do
+ post :new,
+ :display_name => users(:public_user).display_name,
+ :message => { :title => "Test Message", :body => "" }
+ end
+ end
+ assert_response :success
+ assert_template "new"
+ assert_select "title", "OpenStreetMap | Send message"
+ assert_select "form[action='#{new_message_path(:display_name => users(:public_user).display_name)}']", :count => 1 do
+ assert_select "input#message_title", :count => 1 do
+ assert_select "[value=Test Message]"
+ end
+ assert_select "textarea#message_body", :text => "", :count => 1
+ assert_select "input[type='submit'][value='Send']", :count => 1
+ end
+
+ # Check that the body text is preserved over errors
+ assert_difference "ActionMailer::Base.deliveries.size", 0 do
+ assert_difference "Message.count", 0 do
+ post :new,
+ :display_name => users(:public_user).display_name,
+ :message => { :title => "", :body => "Test message body" }
+ end
+ end
+ assert_response :success
+ assert_template "new"
+ assert_select "title", "OpenStreetMap | Send message"
+ assert_select "form[action='#{new_message_path(:display_name => users(:public_user).display_name)}']", :count => 1 do
+ assert_select "input#message_title", :count => 1 do
+ assert_select "[value=]"
+ end
+ assert_select "textarea#message_body", :text => "Test message body", :count => 1
+ assert_select "input[type='submit'][value='Send']", :count => 1
+ end
+
# Check that sending a message works
assert_difference "ActionMailer::Base.deliveries.size", 1 do
assert_difference "Message.count", 1 do