]> git.openstreetmap.org Git - rails.git/blob - test/controllers/messages/replies_controller_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / controllers / messages / replies_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 module Messages
6   class RepliesControllerTest < ActionDispatch::IntegrationTest
7     ##
8     # test all routes which lead to this controller
9     def test_routes
10       assert_routing(
11         { :path => "/messages/1/reply/new", :method => :get },
12         { :controller => "messages/replies", :action => "new", :message_id => "1" }
13       )
14     end
15
16     def test_new
17       user = create(:user)
18       recipient_user = create(:user)
19       other_user = create(:user)
20       message = create(:message, :unread, :sender => user, :recipient => recipient_user)
21
22       # Check that the message reply page requires us to login
23       get new_message_reply_path(message)
24       assert_redirected_to login_path(:referer => new_message_reply_path(message))
25
26       # Login as the wrong user
27       session_for(other_user)
28
29       # Check that we can't reply to somebody else's message
30       get new_message_reply_path(message)
31       assert_redirected_to login_path(:referer => new_message_reply_path(message))
32       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]
33
34       # Login as the right user
35       session_for(recipient_user)
36
37       # Check that the message reply page loads
38       get new_message_reply_path(message)
39       assert_response :success
40       assert_template "new"
41       assert_select "title", "Re: #{message.title} | OpenStreetMap"
42       assert_select "form[action='/messages']", :count => 1 do
43         assert_select "input[type='hidden'][name='display_name'][value='#{user.display_name}']"
44         assert_select "input#message_title[value='Re: #{message.title}']", :count => 1
45         assert_select "textarea#message_body", :count => 1
46         assert_select "input[type='submit'][value='Send']", :count => 1
47       end
48       assert Message.find(message.id).message_read
49
50       # Login as the sending user
51       session_for(user)
52
53       # Check that the message reply page loads
54       get new_message_reply_path(message)
55       assert_response :success
56       assert_template "new"
57       assert_select "title", "Re: #{message.title} | OpenStreetMap"
58       assert_select "form[action='/messages']", :count => 1 do
59         assert_select "input[type='hidden'][name='display_name'][value='#{recipient_user.display_name}']"
60         assert_select "input#message_title[value='Re: #{message.title}']", :count => 1
61         assert_select "textarea#message_body", :count => 1
62         assert_select "input[type='submit'][value='Send']", :count => 1
63       end
64
65       # Asking to reply to a message with a bogus ID should fail
66       get new_message_reply_path(99999)
67       assert_response :not_found
68       assert_template "no_such_message"
69     end
70   end
71 end