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 :redirect
67 assert_redirected_to :controller => "errors", :action => "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 :redirect
91 assert_redirected_to :controller => "errors", :action => "forbidden"
94 def test_destroy_moderator_empty
95 session[:user] = create(:moderator_user).id
97 # create an empty redaction
98 redaction = create(:redaction)
100 delete :destroy, :params => { :id => redaction.id }
101 assert_response :redirect
102 assert_redirected_to(redactions_path)
105 def test_destroy_moderator_non_empty
106 session[:user] = create(:moderator_user).id
108 # create elements in the redaction
109 redaction = create(:redaction)
110 create(:old_node, :redaction => redaction)
112 delete :destroy, :params => { :id => redaction.id }
113 assert_response :redirect
114 assert_redirected_to(redaction_path(redaction))
115 assert_match(/^Redaction is not empty/, flash[:error])
118 def test_delete_non_moderator
119 session[:user] = create(:user).id
121 delete :destroy, :params => { :id => create(:redaction).id }
122 assert_response :redirect
123 assert_redirected_to :controller => "errors", :action => "forbidden"
127 redaction = create(:redaction)
129 get :edit, :params => { :id => redaction.id }
130 assert_response :redirect
131 assert_redirected_to login_path(:referer => edit_redaction_path(redaction))
134 def test_edit_moderator
135 session[:user] = create(:moderator_user).id
137 get :edit, :params => { :id => create(:redaction).id }
138 assert_response :success
141 def test_edit_non_moderator
142 session[:user] = create(:user).id
144 get :edit, :params => { :id => create(:redaction).id }
145 assert_response :redirect
146 assert_redirected_to :controller => "errors", :action => "forbidden"
149 def test_update_moderator
150 session[:user] = create(:moderator_user).id
152 redaction = create(:redaction)
154 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
155 assert_response :redirect
156 assert_redirected_to(redaction_path(redaction))
159 def test_update_moderator_invalid
160 session[:user] = create(:moderator_user).id
162 redaction = create(:redaction)
164 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "" } }
165 assert_response :success
166 assert_template :edit
169 def test_updated_non_moderator
170 session[:user] = create(:user).id
172 redaction = create(:redaction)
174 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
175 assert_response :redirect
176 assert_redirected_to :controller => "errors", :action => "forbidden"