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 redactions_path
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 :redirect
144 assert_redirected_to(redactions_path)
147 def test_update_moderator
148 session[:user] = create(:moderator_user).id
150 redaction = create(:redaction)
152 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
153 assert_response :redirect
154 assert_redirected_to(redaction_path(redaction))
157 def test_update_moderator_invalid
158 session[:user] = create(:moderator_user).id
160 redaction = create(:redaction)
162 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "" } }
163 assert_response :success
164 assert_template :edit
167 def test_updated_non_moderator
168 session[:user] = create(:user).id
170 redaction = create(:redaction)
172 put :update, :params => { :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." } }
173 assert_response :forbidden