3 class RedactionsControllerTest < ActionDispatch::IntegrationTest
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
49 get new_redaction_path
50 assert_response :redirect
51 assert_redirected_to login_path(:referer => new_redaction_path)
54 def test_new_moderator
55 session_for(create(:moderator_user))
57 get new_redaction_path
58 assert_response :success
62 def test_new_non_moderator
63 session_for(create(:user))
65 get new_redaction_path
66 assert_response :redirect
67 assert_redirected_to :controller => "errors", :action => "forbidden"
70 def test_create_moderator
71 session_for(create(:moderator_user))
73 post redactions_path(: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_for(create(:moderator_user))
81 post redactions_path(:redaction => { :title => "Foo", :description => "" })
82 assert_response :success
86 def test_create_non_moderator
87 session_for(create(:user))
89 post redactions_path(: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_for(create(:moderator_user))
97 # create an empty redaction
98 redaction = create(:redaction)
100 delete redaction_path(:id => redaction)
101 assert_response :redirect
102 assert_redirected_to(redactions_path)
105 def test_destroy_moderator_non_empty
106 session_for(create(:moderator_user))
108 # create elements in the redaction
109 redaction = create(:redaction)
110 create(:old_node, :redaction => redaction)
112 delete redaction_path(:id => redaction)
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_for(create(:user))
121 delete redaction_path(:id => create(:redaction))
122 assert_response :redirect
123 assert_redirected_to :controller => "errors", :action => "forbidden"
127 redaction = create(:redaction)
129 get edit_redaction_path(:id => redaction)
130 assert_response :redirect
131 assert_redirected_to login_path(:referer => edit_redaction_path(redaction))
134 def test_edit_moderator
135 session_for(create(:moderator_user))
137 get edit_redaction_path(:id => create(:redaction))
138 assert_response :success
141 def test_edit_non_moderator
142 session_for(create(:user))
144 get edit_redaction_path(:id => create(:redaction))
145 assert_response :redirect
146 assert_redirected_to :controller => "errors", :action => "forbidden"
149 def test_update_moderator
150 session_for(create(:moderator_user))
152 redaction = create(:redaction)
154 put redaction_path(:id => redaction, :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_for(create(:moderator_user))
162 redaction = create(:redaction)
164 put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "" })
165 assert_response :success
166 assert_template :edit
169 def test_updated_non_moderator
170 session_for(create(:user))
172 redaction = create(:redaction)
174 put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "Description here." })
175 assert_response :redirect
176 assert_redirected_to :controller => "errors", :action => "forbidden"