X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/b5f06e06c14f440d3c014b348149fe9ec1b67657..c7cc05c078b540641b6c8bac51f218807a83a914:/test/controllers/messages_controller_test.rb diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb index 1193d3b25..df7146ad6 100644 --- a/test/controllers/messages_controller_test.rb +++ b/test/controllers/messages_controller_test.rb @@ -47,8 +47,8 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest def test_new_no_login # Check that the new message page requires us to login user = create(:user) - get new_message_path(:display_name => user.display_name) - assert_redirected_to login_path(:referer => new_message_path(:display_name => user.display_name)) + get new_message_path(user) + assert_redirected_to login_path(:referer => new_message_path(user)) end ## @@ -60,10 +60,11 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest session_for(user) # Check that the new message page loads - get new_message_path(:display_name => recipient_user.display_name) + get new_message_path(recipient_user) assert_response :success assert_template "new" assert_select "title", "Send message | OpenStreetMap" + assert_select "a[href='#{user_path recipient_user}']", :text => recipient_user.display_name 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", :count => 1 @@ -84,8 +85,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_difference "ActionMailer::Base.deliveries.size", 0 do assert_difference "Message.count", 0 do perform_enqueued_jobs do - get new_message_path(:display_name => recipient_user.display_name, - :message => { :title => "Test Message", :body => "Test message body" }) + get new_message_path(recipient_user, :message => { :title => "Test Message", :body => "Test message body" }) end end end @@ -197,7 +197,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_equal "markdown", m.body_format # Asking to send a message with a bogus user name should fail - get new_message_path(:display_name => "non_existent_user") + get new_message_path("non_existent_user") assert_response :not_found assert_template "users/no_such_user" assert_select "h1", "The user non_existent_user does not exist" @@ -214,13 +214,13 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest # Check that sending a message fails when the message limit is hit assert_no_difference "ActionMailer::Base.deliveries.size" do assert_no_difference "Message.count" do - with_message_limit(0) do + with_settings(:max_messages_per_hour => 0) do perform_enqueued_jobs do post messages_path(:display_name => recipient_user.display_name, :message => { :title => "Test Message", :body => "Test message body" }) assert_response :success assert_template "new" - assert_select ".error", /wait a while/ + assert_select ".alert.alert-danger", /wait a while/ end end end @@ -245,7 +245,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest # Check that we can't reply to somebody else's message get message_reply_path(:message_id => unread_message) assert_redirected_to login_path(:referer => message_reply_path(:message_id => unread_message.id)) - 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 login as the correct user in order to reply.", flash[:notice] + 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] # Login as the right user session_for(recipient_user) @@ -291,7 +291,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest # Check that we can't read the message get message_path(:id => unread_message) assert_redirected_to login_path(:referer => message_path(:id => unread_message.id)) - assert_equal "You are logged in as `#{other_user.display_name}' but the message you have asked to read was not sent by or to that user. Please login as the correct user in order to read it.", flash[:notice] + assert_equal "You are logged in as `#{other_user.display_name}' but the message you have asked to read was not sent by or to that user. Please log in as the correct user in order to read it.", flash[:notice] # Login as the message sender session_for(user) @@ -300,6 +300,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest get message_path(:id => unread_message) assert_response :success assert_template "show" + assert_select "a[href='#{user_path recipient_user}']", :text => recipient_user.display_name assert_not Message.find(unread_message.id).message_read # Login as the message recipient @@ -309,6 +310,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest get message_path(:id => unread_message) assert_response :success assert_template "show" + assert_select "a[href='#{user_path user}']", :text => user.display_name assert Message.find(unread_message.id).message_read # Asking to read a message with no ID should fail @@ -339,7 +341,10 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_template "inbox" assert_select ".content-inner > table", :count => 1 do assert_select "tr", :count => 2 - assert_select "tr#inbox-#{read_message.id}.inbox-row", :count => 1 + assert_select "tr#inbox-#{read_message.id}.inbox-row", :count => 1 do + assert_select "a[href='#{user_path read_message.sender}']", :text => read_message.sender.display_name + assert_select "a[href='#{message_path read_message}']", :text => read_message.title + end end end @@ -347,7 +352,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest # test the outbox action def test_outbox user = create(:user) - create(:message, :sender => user) + message = create(:message, :sender => user) # Check that the outbox page requires us to login get outbox_messages_path @@ -362,7 +367,10 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_template "outbox" assert_select ".content-inner > table", :count => 1 do assert_select "tr", :count => 2 - assert_select "tr.inbox-row", :count => 1 + assert_select "tr.inbox-row", :count => 1 do + assert_select "a[href='#{user_path message.recipient}']", :text => message.recipient.display_name + assert_select "a[href='#{message_path message}']", :text => message.title + end end end @@ -413,7 +421,6 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest # Asking to mark a message with no ID should fail post message_mark_path - assert_response :redirect assert_redirected_to inbox_messages_path # Asking to mark a message with a bogus ID should fail @@ -464,7 +471,6 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest # Asking to destroy a message with no ID should fail delete message_path - assert_response :redirect assert_redirected_to inbox_messages_path # Asking to destroy a message with a bogus ID should fail @@ -472,15 +478,4 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_response :not_found assert_template "no_such_message" end - - private - - def with_message_limit(value) - max_messages_per_hour = Settings.max_messages_per_hour - Settings.max_messages_per_hour = value - - yield - - Settings.max_messages_per_hour = max_messages_per_hour - end end