]> git.openstreetmap.org Git - rails.git/blob - test/controllers/user_mutes_controller_test.rb
Merge remote-tracking branch 'upstream/pull/4440'
[rails.git] / test / controllers / user_mutes_controller_test.rb
1 require "test_helper"
2
3 class UserMutesControllerTest < ActionDispatch::IntegrationTest
4   def test_routes
5     assert_routing(
6       { :path => "/user/username/mute", :method => :post },
7       { :controller => "user_mutes", :action => "create", :display_name => "username" }
8     )
9     assert_routing(
10       { :path => "/user/username/mute", :method => :delete },
11       { :controller => "user_mutes", :action => "destroy", :display_name => "username" }
12     )
13     assert_routing(
14       { :path => "/user_mutes", :method => :get },
15       { :controller => "user_mutes", :action => "index" }
16     )
17   end
18
19   def test_index
20     user = create(:user)
21     user.mutes.create(:subject => create(:user))
22     session_for(user)
23
24     get user_mutes_path
25     assert_match "You have muted 1 User", @response.body
26   end
27
28   def test_create
29     user = create(:user)
30     session_for(user)
31
32     assert_equal 0, user.muted_users.count
33     subject = create(:user, :display_name => "Bob")
34     post user_mute_path(subject)
35     assert_match "You muted Bob", flash[:notice]
36
37     assert_equal 1, user.muted_users.count
38     assert_equal subject, user.muted_users.first
39
40     post user_mute_path(subject)
41     assert_match "Bob could not be muted. Is already muted", flash[:error]
42     assert_equal 1, user.muted_users.count
43   end
44
45   def test_destroy
46     user = create(:user)
47     session_for(user)
48
49     subject = create(:user, :display_name => "Bob")
50     user.mutes.create(:subject => subject)
51     assert_equal 1, user.muted_users.count
52
53     delete user_mute_path(subject)
54     assert_match "You unmuted Bob", flash[:notice]
55     assert_equal 0, user.muted_users.count
56
57     delete user_mute_path(subject)
58     assert_response :not_found
59   end
60 end