]> git.openstreetmap.org Git - rails.git/blob - test/controllers/redactions_controller_test.rb
Remove assert_response when followed by assert_redirected_to
[rails.git] / test / controllers / redactions_controller_test.rb
1 require "test_helper"
2
3 class RedactionsControllerTest < ActionDispatch::IntegrationTest
4   ##
5   # test all routes which lead to this controller
6   def test_routes
7     assert_routing(
8       { :path => "/redactions", :method => :get },
9       { :controller => "redactions", :action => "index" }
10     )
11     assert_routing(
12       { :path => "/redactions/new", :method => :get },
13       { :controller => "redactions", :action => "new" }
14     )
15     assert_routing(
16       { :path => "/redactions", :method => :post },
17       { :controller => "redactions", :action => "create" }
18     )
19     assert_routing(
20       { :path => "/redactions/1", :method => :get },
21       { :controller => "redactions", :action => "show", :id => "1" }
22     )
23     assert_routing(
24       { :path => "/redactions/1/edit", :method => :get },
25       { :controller => "redactions", :action => "edit", :id => "1" }
26     )
27     assert_routing(
28       { :path => "/redactions/1", :method => :put },
29       { :controller => "redactions", :action => "update", :id => "1" }
30     )
31     assert_routing(
32       { :path => "/redactions/1", :method => :delete },
33       { :controller => "redactions", :action => "destroy", :id => "1" }
34     )
35   end
36
37   def test_index
38     create(:redaction)
39
40     get redactions_path
41     assert_response :success
42     assert_template :index
43     assert_select "ul#redaction_list", 1 do
44       assert_select "li", Redaction.count
45     end
46   end
47
48   def test_new
49     get new_redaction_path
50     assert_redirected_to login_path(:referer => new_redaction_path)
51   end
52
53   def test_new_moderator
54     session_for(create(:moderator_user))
55
56     get new_redaction_path
57     assert_response :success
58     assert_template :new
59   end
60
61   def test_new_non_moderator
62     session_for(create(:user))
63
64     get new_redaction_path
65     assert_redirected_to :controller => "errors", :action => "forbidden"
66   end
67
68   def test_create_moderator
69     session_for(create(:moderator_user))
70
71     post redactions_path(:redaction => { :title => "Foo", :description => "Description here." })
72     assert_redirected_to(redaction_path(Redaction.find_by(:title => "Foo")))
73   end
74
75   def test_create_moderator_invalid
76     session_for(create(:moderator_user))
77
78     post redactions_path(:redaction => { :title => "Foo", :description => "" })
79     assert_response :success
80     assert_template :new
81   end
82
83   def test_create_non_moderator
84     session_for(create(:user))
85
86     post redactions_path(:redaction => { :title => "Foo", :description => "Description here." })
87     assert_redirected_to :controller => "errors", :action => "forbidden"
88   end
89
90   def test_destroy_moderator_empty
91     session_for(create(:moderator_user))
92
93     # create an empty redaction
94     redaction = create(:redaction)
95
96     delete redaction_path(:id => redaction)
97     assert_redirected_to(redactions_path)
98   end
99
100   def test_destroy_moderator_non_empty
101     session_for(create(:moderator_user))
102
103     # create elements in the redaction
104     redaction = create(:redaction)
105     create(:old_node, :redaction => redaction)
106
107     delete redaction_path(:id => redaction)
108     assert_redirected_to(redaction_path(redaction))
109     assert_match(/^Redaction is not empty/, flash[:error])
110   end
111
112   def test_delete_non_moderator
113     session_for(create(:user))
114
115     delete redaction_path(:id => create(:redaction))
116     assert_redirected_to :controller => "errors", :action => "forbidden"
117   end
118
119   def test_edit
120     redaction = create(:redaction)
121
122     get edit_redaction_path(:id => redaction)
123     assert_redirected_to login_path(:referer => edit_redaction_path(redaction))
124   end
125
126   def test_edit_moderator
127     session_for(create(:moderator_user))
128
129     get edit_redaction_path(:id => create(:redaction))
130     assert_response :success
131   end
132
133   def test_edit_non_moderator
134     session_for(create(:user))
135
136     get edit_redaction_path(:id => create(:redaction))
137     assert_redirected_to :controller => "errors", :action => "forbidden"
138   end
139
140   def test_update_moderator
141     session_for(create(:moderator_user))
142
143     redaction = create(:redaction)
144
145     put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "Description here." })
146     assert_redirected_to(redaction_path(redaction))
147   end
148
149   def test_update_moderator_invalid
150     session_for(create(:moderator_user))
151
152     redaction = create(:redaction)
153
154     put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "" })
155     assert_response :success
156     assert_template :edit
157   end
158
159   def test_updated_non_moderator
160     session_for(create(:user))
161
162     redaction = create(:redaction)
163
164     put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "Description here." })
165     assert_redirected_to :controller => "errors", :action => "forbidden"
166   end
167 end