]> git.openstreetmap.org Git - rails.git/blob - test/controllers/user_mutes_controller_test.rb
Use section elements instead of div.section on about page
[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     muted_user = create(:user)
22     user.mutes.create(:subject => muted_user)
23     session_for(user)
24
25     get user_mutes_path
26     assert_match "You have muted 1 User", @response.body
27     assert_dom "tr a[href='#{user_path muted_user}']", :text => muted_user.display_name
28   end
29
30   def test_create
31     user = create(:user)
32     session_for(user)
33
34     assert_equal 0, user.muted_users.count
35     subject = create(:user, :display_name => "Bob")
36     post user_mute_path(subject)
37     assert_match "You muted Bob", flash[:notice]
38
39     assert_equal 1, user.muted_users.count
40     assert_equal subject, user.muted_users.first
41
42     post user_mute_path(subject)
43     assert_match "Bob could not be muted. Is already muted", flash[:error]
44     assert_equal 1, user.muted_users.count
45   end
46
47   def test_destroy
48     user = create(:user)
49     session_for(user)
50
51     subject = create(:user, :display_name => "Bob")
52     user.mutes.create(:subject => subject)
53     assert_equal 1, user.muted_users.count
54
55     delete user_mute_path(subject)
56     assert_match "You unmuted Bob", flash[:notice]
57     assert_equal 0, user.muted_users.count
58
59     delete user_mute_path(subject)
60     assert_response :not_found
61   end
62 end