2 require "redactions_controller"
4 class RedactionsControllerTest < ActionController::TestCase
6 # test all routes which lead to this controller
9 { :path => "/redactions", :method => :get },
10 { :controller => "redactions", :action => "index" }
13 { :path => "/redactions/new", :method => :get },
14 { :controller => "redactions", :action => "new" }
17 { :path => "/redactions", :method => :post },
18 { :controller => "redactions", :action => "create" }
21 { :path => "/redactions/1", :method => :get },
22 { :controller => "redactions", :action => "show", :id => "1" }
25 { :path => "/redactions/1/edit", :method => :get },
26 { :controller => "redactions", :action => "edit", :id => "1" }
29 { :path => "/redactions/1", :method => :put },
30 { :controller => "redactions", :action => "update", :id => "1" }
33 { :path => "/redactions/1", :method => :delete },
34 { :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] = create(:moderator_user).id
59 assert_response :success
63 def test_new_non_moderator
64 session[:user] = create(:user).id
67 assert_response :forbidden
70 def test_create_moderator
71 session[:user] = create(:moderator_user).id
73 post :create, :params => { :redaction => { :title => "Foo", :description => "Description here." } }
74 assert_response :redirect
75 assert_redirected_to(redaction_path(Redaction.find_by(:title => "Foo")))
78 def test_create_moderator_invalid
79 session[:user] = create(:moderator_user).id
81 post :create, :params => { :redaction => { :title => "Foo", :description => "" } }
82 assert_response :success
86 def test_create_non_moderator
87 session[:user] = create(:user).id
89 post :create, :params => { :redaction => { :title => "Foo", :description => "Description here." } }
90 assert_response :forbidden
93 def test_destroy_moderator_empty
94 session[:user] = create(:moderator_user).id
96 # create an empty redaction
97 redaction = create(:redaction)
99 delete :destroy, :params => { :id => redaction.id }
100 assert_response :redirect
101 assert_redirected_to(redactions_path)
104 def test_destroy_moderator_non_empty
105 session[:user] = create(:moderator_user).id
107 # create elements in the redaction
108 redaction = create(:redaction)
109 create(:old_node, :redaction => redaction)
111 delete :destroy, :params => { :id => redaction.id }
112 assert_response :redirect
113 assert_redirected_to(redaction_path(redaction))
114 assert_match(/^Redaction is not empty/, flash[:error])
117 def test_delete_non_moderator
118 session[:user] = create(:user).id
120 delete :destroy, :params => { :id => create(:redaction).id }
121 assert_response :forbidden
125 redaction = create(:redaction)
127 get :edit, :params => { :id => redaction.id }
128 assert_response :redirect
129 assert_redirected_to login_path(:referer => edit_redaction_path(redaction))
132 def test_edit_moderator
133 session[:user] = create(:moderator_user).id
135 get :edit, :params => { :id => create(:redaction).id }
136 assert_response :success
139 def test_edit_non_moderator
140 session[:user] = create(:user).id
142 get :edit, :params => { :id => create(:redaction).id }
143 assert_response :forbidden
146 def test_update_moderator
147 session[:user] = create(:moderator_user).id
149 redaction = create(:redaction)
151 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
152 assert_response :redirect
153 assert_redirected_to(redaction_path(redaction))
156 def test_update_moderator_invalid
157 session[:user] = create(:moderator_user).id
159 redaction = create(:redaction)
161 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "" } }
162 assert_response :success
163 assert_template :edit
166 def test_updated_non_moderator
167 session[:user] = create(:user).id
169 redaction = create(:redaction)
171 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
172 assert_response :forbidden