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 :redirect
68 assert_redirected_to redactions_path
71 def test_create_moderator
72 session[:user] = create(:moderator_user).id
74 post :create, :params => { :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] = create(:moderator_user).id
82 post :create, :params => { :redaction => { :title => "Foo", :description => "" } }
83 assert_response :success
87 def test_create_non_moderator
88 session[:user] = create(:user).id
90 post :create, :params => { :redaction => { :title => "Foo", :description => "Description here." } }
91 assert_response :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 :forbidden
126 redaction = create(:redaction)
128 get :edit, :params => { :id => redaction.id }
129 assert_response :redirect
130 assert_redirected_to login_path(:referer => edit_redaction_path(redaction))
133 def test_edit_moderator
134 session[:user] = create(:moderator_user).id
136 get :edit, :params => { :id => create(:redaction).id }
137 assert_response :success
140 def test_edit_non_moderator
141 session[:user] = create(:user).id
143 get :edit, :params => { :id => create(:redaction).id }
144 assert_response :redirect
145 assert_redirected_to(redactions_path)
148 def test_update_moderator
149 session[:user] = create(:moderator_user).id
151 redaction = create(:redaction)
153 put :update, :params => { :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] = create(:moderator_user).id
161 redaction = create(:redaction)
163 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "" } }
164 assert_response :success
165 assert_template :edit
168 def test_updated_non_moderator
169 session[:user] = create(:user).id
171 redaction = create(:redaction)
173 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
174 assert_response :forbidden