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_redirected_to login_path(:referer => new_redaction_path)
53 def test_new_moderator
54 session_for(create(:moderator_user))
56 get new_redaction_path
57 assert_response :success
61 def test_new_non_moderator
62 session_for(create(:user))
64 get new_redaction_path
65 assert_redirected_to :controller => "errors", :action => "forbidden"
68 def test_create_moderator
69 session_for(create(:moderator_user))
71 post redactions_path(:redaction => { :title => "Foo", :description => "Description here." })
72 assert_redirected_to(redaction_path(Redaction.find_by(:title => "Foo")))
75 def test_create_moderator_invalid
76 session_for(create(:moderator_user))
78 post redactions_path(:redaction => { :title => "Foo", :description => "" })
79 assert_response :success
83 def test_create_non_moderator
84 session_for(create(:user))
86 post redactions_path(:redaction => { :title => "Foo", :description => "Description here." })
87 assert_redirected_to :controller => "errors", :action => "forbidden"
90 def test_destroy_moderator_empty
91 session_for(create(:moderator_user))
93 # create an empty redaction
94 redaction = create(:redaction)
96 delete redaction_path(:id => redaction)
97 assert_redirected_to(redactions_path)
100 def test_destroy_moderator_non_empty
101 session_for(create(:moderator_user))
103 # create elements in the redaction
104 redaction = create(:redaction)
105 create(:old_node, :redaction => redaction)
107 delete redaction_path(:id => redaction)
108 assert_redirected_to(redaction_path(redaction))
109 assert_match(/^Redaction is not empty/, flash[:error])
112 def test_delete_non_moderator
113 session_for(create(:user))
115 delete redaction_path(:id => create(:redaction))
116 assert_redirected_to :controller => "errors", :action => "forbidden"
120 redaction = create(:redaction)
122 get edit_redaction_path(:id => redaction)
123 assert_redirected_to login_path(:referer => edit_redaction_path(redaction))
126 def test_edit_moderator
127 session_for(create(:moderator_user))
129 get edit_redaction_path(:id => create(:redaction))
130 assert_response :success
133 def test_edit_non_moderator
134 session_for(create(:user))
136 get edit_redaction_path(:id => create(:redaction))
137 assert_redirected_to :controller => "errors", :action => "forbidden"
140 def test_update_moderator
141 session_for(create(:moderator_user))
143 redaction = create(:redaction)
145 put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "Description here." })
146 assert_redirected_to(redaction_path(redaction))
149 def test_update_moderator_invalid
150 session_for(create(:moderator_user))
152 redaction = create(:redaction)
154 put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "" })
155 assert_response :success
156 assert_template :edit
159 def test_updated_non_moderator
160 session_for(create(:user))
162 redaction = create(:redaction)
164 put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "Description here." })
165 assert_redirected_to :controller => "errors", :action => "forbidden"