]> git.openstreetmap.org Git - rails.git/blob - test/controllers/messages/mutes_controller_test.rb
Create message mute resource
[rails.git] / test / controllers / messages / mutes_controller_test.rb
1 require "test_helper"
2
3 module Messages
4   class MutesControllerTest < ActionDispatch::IntegrationTest
5     ##
6     # test all routes which lead to this controller
7     def test_routes
8       assert_routing(
9         { :path => "/messages/1/mute", :method => :delete },
10         { :controller => "messages/mutes", :action => "destroy", :message_id => "1" }
11       )
12     end
13
14     def test_destroy_when_not_logged_in
15       sender_user = create(:user)
16       recipient_user = create(:user)
17       create(:user_mute, :owner => recipient_user, :subject => sender_user)
18       message = create(:message, :unread, :sender => sender_user, :recipient => recipient_user)
19
20       delete message_mute_path(message)
21       assert_response :forbidden
22     end
23
24     def test_destroy_as_other_user
25       sender_user = create(:user)
26       recipient_user = create(:user)
27       create(:user_mute, :owner => recipient_user, :subject => sender_user)
28       message = create(:message, :unread, :sender => sender_user, :recipient => recipient_user)
29       session_for(create(:user))
30
31       delete message_mute_path(message)
32       assert_response :not_found
33       assert_template "no_such_message"
34     end
35
36     def test_destroy_as_sender
37       sender_user = create(:user)
38       recipient_user = create(:user)
39       create(:user_mute, :owner => recipient_user, :subject => sender_user)
40       message = create(:message, :unread, :sender => sender_user, :recipient => recipient_user)
41       session_for(sender_user)
42
43       delete message_mute_path(message)
44       assert_response :not_found
45       assert_template "no_such_message"
46     end
47
48     def test_destroy_as_recipient
49       sender_user = create(:user)
50       recipient_user = create(:user)
51       create(:user_mute, :owner => recipient_user, :subject => sender_user)
52       message = create(:message, :unread, :sender => sender_user, :recipient => recipient_user)
53       session_for(recipient_user)
54
55       delete message_mute_path(message)
56       assert_redirected_to messages_inbox_path
57       assert_not message.reload.muted
58     end
59
60     def test_destroy_on_missing_message
61       session_for(create(:user))
62
63       delete message_mute_path(99999)
64       assert_response :not_found
65       assert_template "no_such_message"
66     end
67   end
68 end