3 class RedactionsControllerTest < ActionController::TestCase
5 # test all routes which lead to this controller
8 { :path => "/redactions", :method => :get },
9 { :controller => "redactions", :action => "index" }
12 { :path => "/redactions/new", :method => :get },
13 { :controller => "redactions", :action => "new" }
16 { :path => "/redactions", :method => :post },
17 { :controller => "redactions", :action => "create" }
20 { :path => "/redactions/1", :method => :get },
21 { :controller => "redactions", :action => "show", :id => "1" }
24 { :path => "/redactions/1/edit", :method => :get },
25 { :controller => "redactions", :action => "edit", :id => "1" }
28 { :path => "/redactions/1", :method => :put },
29 { :controller => "redactions", :action => "update", :id => "1" }
32 { :path => "/redactions/1", :method => :delete },
33 { :controller => "redactions", :action => "destroy", :id => "1" }
41 assert_response :success
42 assert_template :index
43 assert_select "ul#redaction_list", 1 do
44 assert_select "li", Redaction.count
50 assert_response :redirect
51 assert_redirected_to login_path(:referer => new_redaction_path)
54 def test_new_moderator
55 session[:user] = create(:moderator_user).id
58 assert_response :success
62 def test_new_non_moderator
63 session[:user] = create(:user).id
66 assert_response :forbidden
69 def test_create_moderator
70 session[:user] = create(:moderator_user).id
72 post :create, :params => { :redaction => { :title => "Foo", :description => "Description here." } }
73 assert_response :redirect
74 assert_redirected_to(redaction_path(Redaction.find_by(:title => "Foo")))
77 def test_create_moderator_invalid
78 session[:user] = create(:moderator_user).id
80 post :create, :params => { :redaction => { :title => "Foo", :description => "" } }
81 assert_response :success
85 def test_create_non_moderator
86 session[:user] = create(:user).id
88 post :create, :params => { :redaction => { :title => "Foo", :description => "Description here." } }
89 assert_response :forbidden
92 def test_destroy_moderator_empty
93 session[:user] = create(:moderator_user).id
95 # create an empty redaction
96 redaction = create(:redaction)
98 delete :destroy, :params => { :id => redaction.id }
99 assert_response :redirect
100 assert_redirected_to(redactions_path)
103 def test_destroy_moderator_non_empty
104 session[:user] = create(:moderator_user).id
106 # create elements in the redaction
107 redaction = create(:redaction)
108 create(:old_node, :redaction => redaction)
110 delete :destroy, :params => { :id => redaction.id }
111 assert_response :redirect
112 assert_redirected_to(redaction_path(redaction))
113 assert_match(/^Redaction is not empty/, flash[:error])
116 def test_delete_non_moderator
117 session[:user] = create(:user).id
119 delete :destroy, :params => { :id => create(:redaction).id }
120 assert_response :forbidden
124 redaction = create(:redaction)
126 get :edit, :params => { :id => redaction.id }
127 assert_response :redirect
128 assert_redirected_to login_path(:referer => edit_redaction_path(redaction))
131 def test_edit_moderator
132 session[:user] = create(:moderator_user).id
134 get :edit, :params => { :id => create(:redaction).id }
135 assert_response :success
138 def test_edit_non_moderator
139 session[:user] = create(:user).id
141 get :edit, :params => { :id => create(:redaction).id }
142 assert_response :forbidden
145 def test_update_moderator
146 session[:user] = create(:moderator_user).id
148 redaction = create(:redaction)
150 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
151 assert_response :redirect
152 assert_redirected_to(redaction_path(redaction))
155 def test_update_moderator_invalid
156 session[:user] = create(:moderator_user).id
158 redaction = create(:redaction)
160 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "" } }
161 assert_response :success
162 assert_template :edit
165 def test_updated_non_moderator
166 session[:user] = create(:user).id
168 redaction = create(:redaction)
170 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
171 assert_response :forbidden