4   class RepliesControllerTest < ActionDispatch::IntegrationTest
 
   6     # test all routes which lead to this controller
 
   9         { :path => "/messages/1/reply/new", :method => :get },
 
  10         { :controller => "messages/replies", :action => "new", :message_id => "1" }
 
  16       recipient_user = create(:user)
 
  17       other_user = create(:user)
 
  18       message = create(:message, :unread, :sender => user, :recipient => recipient_user)
 
  20       # Check that the message reply page requires us to login
 
  21       get new_message_reply_path(message)
 
  22       assert_redirected_to login_path(:referer => new_message_reply_path(message))
 
  24       # Login as the wrong user
 
  25       session_for(other_user)
 
  27       # Check that we can't reply to somebody else's message
 
  28       get new_message_reply_path(message)
 
  29       assert_redirected_to login_path(:referer => new_message_reply_path(message))
 
  30       assert_equal "You are logged in as '#{other_user.display_name}' but the message you have asked to reply to was not sent to that user. Please log in as the correct user in order to reply.", flash[:notice]
 
  32       # Login as the right user
 
  33       session_for(recipient_user)
 
  35       # Check that the message reply page loads
 
  36       get new_message_reply_path(message)
 
  37       assert_response :success
 
  39       assert_select "title", "Re: #{message.title} | OpenStreetMap"
 
  40       assert_select "form[action='/messages']", :count => 1 do
 
  41         assert_select "input[type='hidden'][name='display_name'][value='#{user.display_name}']"
 
  42         assert_select "input#message_title[value='Re: #{message.title}']", :count => 1
 
  43         assert_select "textarea#message_body", :count => 1
 
  44         assert_select "input[type='submit'][value='Send']", :count => 1
 
  46       assert Message.find(message.id).message_read
 
  48       # Login as the sending user
 
  51       # Check that the message reply page loads
 
  52       get new_message_reply_path(message)
 
  53       assert_response :success
 
  55       assert_select "title", "Re: #{message.title} | OpenStreetMap"
 
  56       assert_select "form[action='/messages']", :count => 1 do
 
  57         assert_select "input[type='hidden'][name='display_name'][value='#{recipient_user.display_name}']"
 
  58         assert_select "input#message_title[value='Re: #{message.title}']", :count => 1
 
  59         assert_select "textarea#message_body", :count => 1
 
  60         assert_select "input[type='submit'][value='Send']", :count => 1
 
  63       # Asking to reply to a message with a bogus ID should fail
 
  64       get new_message_reply_path(99999)
 
  65       assert_response :not_found
 
  66       assert_template "no_such_message"