X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/0b189373848583f848439516a1471f103af9bf0e..e5c5776e65f1a461d7d1aa678e843c9cf83316c2:/test/controllers/messages_controller_test.rb?ds=inline diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb index db3a200b6..52a856beb 100644 --- a/test/controllers/messages_controller_test.rb +++ b/test/controllers/messages_controller_test.rb @@ -263,6 +263,21 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest end assert Message.find(message.id).message_read + # Login as the sending user + session_for(user) + + # Check that the message reply page loads + get message_reply_path(message) + assert_response :success + assert_template "new" + assert_select "title", "Re: #{message.title} | OpenStreetMap" + assert_select "form[action='/messages']", :count => 1 do + assert_select "input[type='hidden'][name='display_name'][value='#{recipient_user.display_name}']" + assert_select "input#message_title[value='Re: #{message.title}']", :count => 1 + assert_select "textarea#message_body", :count => 1 + assert_select "input[type='submit'][value='Send']", :count => 1 + end + # Asking to reply to a message with a bogus ID should fail get message_reply_path(99999) assert_response :not_found @@ -292,21 +307,23 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest # Login as the message sender session_for(user) - # Check that the message sender can read the message + # Check that the message sender can read the message and that Reply button is available get message_path(message) assert_response :success assert_template "show" assert_select "a[href='#{user_path recipient_user}']", :text => recipient_user.display_name + assert_select "a.btn.btn-primary", :text => "Reply" assert_not Message.find(message.id).message_read # Login as the message recipient session_for(recipient_user) - # Check that the message recipient can read the message + # Check that the message recipient can read the message and that Reply button is available get message_path(message) assert_response :success assert_template "show" assert_select "a[href='#{user_path user}']", :text => user.display_name + assert_select "a.btn.btn-primary", :text => "Reply" assert Message.find(message.id).message_read # Asking to read a message with a bogus ID should fail @@ -369,10 +386,10 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest ## # test the mark action def test_mark - user = create(:user) + sender_user = create(:user) recipient_user = create(:user) other_user = create(:user) - message = create(:message, :unread, :sender => user, :recipient => recipient_user) + message = create(:message, :unread, :sender => sender_user, :recipient => recipient_user) # Check that the marking a message requires us to login post message_mark_path(message) @@ -386,6 +403,14 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_response :not_found assert_template "no_such_message" + # Login as the message sender_user + session_for(sender_user) + + # Check that marking a message we sent fails + post message_mark_path(message) + assert_response :not_found + assert_template "no_such_message" + # Login as the message recipient_user session_for(recipient_user) @@ -415,6 +440,27 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_template "no_such_message" end + ## + # test the mark action for messages from muted users + def test_mark_muted + sender_user = create(:user) + recipient_user = create(:user) + create(:user_mute, :owner => recipient_user, :subject => sender_user) + message = create(:message, :unread, :sender => sender_user, :recipient => recipient_user) + + session_for(recipient_user) + + # Check that the marking a message read works + post message_mark_path(message, :mark => "read") + assert_redirected_to muted_messages_path + assert Message.find(message.id).message_read + + # Check that the marking a message unread works + post message_mark_path(message, :mark => "unread") + assert_redirected_to muted_messages_path + assert_not Message.find(message.id).message_read + end + ## # test the destroy action def test_destroy