2 require "redactions_controller"
4 class RedactionsControllerTest < ActionController::TestCase
8 # test all routes which lead to this controller
11 { :path => "/redactions", :method => :get },
12 { :controller => "redactions", :action => "index" }
15 { :path => "/redactions/new", :method => :get },
16 { :controller => "redactions", :action => "new" }
19 { :path => "/redactions", :method => :post },
20 { :controller => "redactions", :action => "create" }
23 { :path => "/redactions/1", :method => :get },
24 { :controller => "redactions", :action => "show", :id => "1" }
27 { :path => "/redactions/1/edit", :method => :get },
28 { :controller => "redactions", :action => "edit", :id => "1" }
31 { :path => "/redactions/1", :method => :put },
32 { :controller => "redactions", :action => "update", :id => "1" }
35 { :path => "/redactions/1", :method => :delete },
36 { :controller => "redactions", :action => "destroy", :id => "1" }
42 assert_response :success
43 assert_template :index
44 assert_select "ul#redaction_list", 1 do
45 assert_select "li", Redaction.count
51 assert_response :redirect
52 assert_redirected_to login_path(:referer => new_redaction_path)
55 def test_new_moderator
56 session[:user] = users(:moderator_user).id
59 assert_response :success
63 def test_new_non_moderator
64 session[:user] = users(:public_user).id
67 assert_response :redirect
68 assert_redirected_to redactions_path
71 def test_create_moderator
72 session[:user] = users(:moderator_user).id
74 post :create, :redaction => { :title => "Foo", :description => "Description here." }
75 assert_response :redirect
76 assert_redirected_to(redaction_path(Redaction.find_by_title("Foo")))
79 def test_create_moderator_invalid
80 session[:user] = users(:moderator_user).id
82 post :create, :redaction => { :title => "Foo", :description => "" }
83 assert_response :success
87 def test_create_non_moderator
88 session[:user] = users(:public_user).id
90 post :create, :redaction => { :title => "Foo", :description => "Description here." }
91 assert_response :forbidden
94 def test_destroy_moderator_empty
95 session[:user] = users(:moderator_user).id
97 # remove all elements from the redaction
98 redaction = redactions(:example)
99 redaction.old_nodes.each { |n| n.update!(:redaction => nil) }
100 redaction.old_ways.each { |w| w.update!(:redaction => nil) }
101 redaction.old_relations.each { |r| r.update!(:redaction => nil) }
103 delete :destroy, :id => redaction.id
104 assert_response :redirect
105 assert_redirected_to(redactions_path)
108 def test_destroy_moderator_non_empty
109 session[:user] = users(:moderator_user).id
111 # leave elements in the redaction
112 redaction = redactions(:example)
114 delete :destroy, :id => redaction.id
115 assert_response :redirect
116 assert_redirected_to(redaction_path(redaction))
117 assert_match /^Redaction is not empty/, flash[:error]
120 def test_delete_non_moderator
121 session[:user] = users(:public_user).id
123 delete :destroy, :id => redactions(:example).id
124 assert_response :forbidden
128 get :edit, :id => redactions(:example).id
129 assert_response :redirect
130 assert_redirected_to login_path(:referer => edit_redaction_path(redactions(:example)))
133 def test_edit_moderator
134 session[:user] = users(:moderator_user).id
136 get :edit, :id => redactions(:example).id
137 assert_response :success
140 def test_edit_non_moderator
141 session[:user] = users(:public_user).id
143 get :edit, :id => redactions(:example).id
144 assert_response :redirect
145 assert_redirected_to(redactions_path)
148 def test_update_moderator
149 session[:user] = users(:moderator_user).id
151 redaction = redactions(:example)
153 put :update, :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." }
154 assert_response :redirect
155 assert_redirected_to(redaction_path(redaction))
158 def test_update_moderator_invalid
159 session[:user] = users(:moderator_user).id
161 redaction = redactions(:example)
163 put :update, :id => redaction.id, :redaction => { :title => "Foo", :description => "" }
164 assert_response :success
165 assert_template :edit
168 def test_updated_non_moderator
169 session[:user] = users(:public_user).id
171 redaction = redactions(:example)
173 put :update, :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." }
174 assert_response :forbidden