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] = 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, :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, :redaction => { :title => "Foo", :description => "" }
83 assert_response :success
87 def test_create_non_moderator
88 session[:user] = create(:user).id
90 post :create, :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, :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, :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, :id => create(:redaction).id
122 assert_response :forbidden
126 redaction = create(:redaction)
128 get :edit, :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, :id => create(:redaction).id
137 assert_response :success
140 def test_edit_non_moderator
141 session[:user] = create(:user).id
143 get :edit, :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, :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, :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, :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." }
174 assert_response :forbidden