X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/db30ea642e9891b2f25eb420dbfdc4cd4014fd70..1b1d90a0f951a4aa26a6cb6f912a35efd5762962:/test/controllers/messages_controller_test.rb diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb index e3756f042..0348163ba 100644 --- a/test/controllers/messages_controller_test.rb +++ b/test/controllers/messages_controller_test.rb @@ -29,11 +29,11 @@ class MessagesControllerTest < ActionController::TestCase { :controller => "messages", :action => "mark", :message_id => "1" } ) assert_routing( - { :path => "/message/reply/1", :method => :get }, + { :path => "/messages/1/reply", :method => :get }, { :controller => "messages", :action => "reply", :message_id => "1" } ) assert_routing( - { :path => "/message/reply/1", :method => :post }, + { :path => "/messages/1/reply", :method => :post }, { :controller => "messages", :action => "reply", :message_id => "1" } ) assert_routing( @@ -83,9 +83,11 @@ class MessagesControllerTest < ActionController::TestCase # Check that we can't send a message from a GET request assert_difference "ActionMailer::Base.deliveries.size", 0 do assert_difference "Message.count", 0 do - get :new, - :params => { :display_name => recipient_user.display_name, - :message => { :title => "Test Message", :body => "Test message body" } } + perform_enqueued_jobs do + get :new, + :params => { :display_name => recipient_user.display_name, + :message => { :title => "Test Message", :body => "Test message body" } } + end end end assert_response :success @@ -112,9 +114,11 @@ class MessagesControllerTest < ActionController::TestCase # Check that the subject is preserved over errors assert_difference "ActionMailer::Base.deliveries.size", 0 do assert_difference "Message.count", 0 do - post :new, - :params => { :display_name => recipient_user.display_name, - :message => { :title => "Test Message", :body => "" } } + perform_enqueued_jobs do + post :new, + :params => { :display_name => recipient_user.display_name, + :message => { :title => "Test Message", :body => "" } } + end end end assert_response :success @@ -141,9 +145,11 @@ class MessagesControllerTest < ActionController::TestCase # 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, - :params => { :display_name => recipient_user.display_name, - :message => { :title => "", :body => "Test message body" } } + perform_enqueued_jobs do + post :new, + :params => { :display_name => recipient_user.display_name, + :message => { :title => "", :body => "Test message body" } } + end end end assert_response :success @@ -170,9 +176,11 @@ class MessagesControllerTest < ActionController::TestCase # Check that sending a message works assert_difference "ActionMailer::Base.deliveries.size", 1 do assert_difference "Message.count", 1 do - post :create, - :params => { :display_name => recipient_user.display_name, - :message => { :title => "Test Message", :body => "Test message body" } } + perform_enqueued_jobs do + post :create, + :params => { :display_name => recipient_user.display_name, + :message => { :title => "Test Message", :body => "Test message body" } } + end end end assert_redirected_to inbox_messages_path @@ -180,9 +188,9 @@ class MessagesControllerTest < ActionController::TestCase e = ActionMailer::Base.deliveries.first assert_equal [recipient_user.email], e.to assert_equal "[OpenStreetMap] Test Message", e.subject - assert_match /Test message body/, e.text_part.decoded - assert_match /Test message body/, e.html_part.decoded - assert_match %r{#{SERVER_URL}/messages/[0-9]+}, e.text_part.decoded + assert_match(/Test message body/, e.text_part.decoded) + assert_match(/Test message body/, e.html_part.decoded) + assert_match %r{#{Settings.server_url}/messages/[0-9]+}, e.text_part.decoded ActionMailer::Base.deliveries.clear m = Message.last assert_equal user.id, m.from_user_id @@ -195,7 +203,7 @@ class MessagesControllerTest < ActionController::TestCase # Asking to send a message with a bogus user name should fail get :new, :params => { :display_name => "non_existent_user" } assert_response :not_found - assert_template "user/no_such_user" + assert_template "users/no_such_user" assert_select "h1", "The user non_existent_user does not exist" end @@ -211,12 +219,14 @@ class MessagesControllerTest < ActionController::TestCase assert_no_difference "ActionMailer::Base.deliveries.size" do assert_no_difference "Message.count" do with_message_limit(0) do - post :create, - :params => { :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/ + perform_enqueued_jobs do + post :create, + :params => { :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/ + end end end end @@ -232,14 +242,14 @@ class MessagesControllerTest < ActionController::TestCase # Check that the message reply page requires us to login get :reply, :params => { :message_id => unread_message.id } - assert_redirected_to login_path(:referer => reply_message_path(:message_id => unread_message.id)) + assert_redirected_to login_path(:referer => message_reply_path(:message_id => unread_message.id)) # Login as the wrong user session[:user] = other_user.id # Check that we can't reply to somebody else's message get :reply, :params => { :message_id => unread_message.id } - assert_redirected_to login_path(:referer => reply_message_path(:message_id => unread_message.id)) + 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] # Login as the right user @@ -473,12 +483,11 @@ class MessagesControllerTest < ActionController::TestCase private def with_message_limit(value) - max_messages_per_hour = Object.send("remove_const", "MAX_MESSAGES_PER_HOUR") - Object.const_set("MAX_MESSAGES_PER_HOUR", value) + max_messages_per_hour = Settings.max_messages_per_hour + Settings.max_messages_per_hour = value yield - Object.send("remove_const", "MAX_MESSAGES_PER_HOUR") - Object.const_set("MAX_MESSAGES_PER_HOUR", max_messages_per_hour) + Settings.max_messages_per_hour = max_messages_per_hour end end