4 class MutesControllerTest < ActionDispatch::IntegrationTest
6 # test all routes which lead to this controller
9 { :path => "/messages/1/mute", :method => :delete },
10 { :controller => "messages/mutes", :action => "destroy", :message_id => "1" }
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)
20 delete message_mute_path(message)
21 assert_response :forbidden
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))
31 delete message_mute_path(message)
32 assert_response :not_found
33 assert_template "no_such_message"
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)
43 delete message_mute_path(message)
44 assert_response :not_found
45 assert_template "no_such_message"
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)
55 delete message_mute_path(message)
56 assert_redirected_to messages_inbox_path
57 assert_not message.reload.muted
60 def test_destroy_on_missing_message
61 session_for(create(:user))
63 delete message_mute_path(99999)
64 assert_response :not_found
65 assert_template "no_such_message"