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 redaction = create(:redaction, :title => "tested-redaction")
51 get redaction_path(redaction)
52 assert_response :success
53 assert_dom "h1", :text => /tested-redaction/
54 assert_dom "a[href='#{user_path redaction.user}']", :text => redaction.user.display_name
58 get new_redaction_path
59 assert_redirected_to login_path(:referer => new_redaction_path)
62 def test_new_moderator
63 session_for(create(:moderator_user))
65 get new_redaction_path
66 assert_response :success
70 def test_new_non_moderator
71 session_for(create(:user))
73 get new_redaction_path
74 assert_redirected_to :controller => "errors", :action => "forbidden"
77 def test_create_moderator
78 session_for(create(:moderator_user))
80 post redactions_path(:redaction => { :title => "Foo", :description => "Description here." })
81 assert_redirected_to(redaction_path(Redaction.find_by(:title => "Foo")))
84 def test_create_moderator_invalid
85 session_for(create(:moderator_user))
87 post redactions_path(:redaction => { :title => "Foo", :description => "" })
88 assert_response :success
92 def test_create_non_moderator
93 session_for(create(:user))
95 post redactions_path(:redaction => { :title => "Foo", :description => "Description here." })
96 assert_redirected_to :controller => "errors", :action => "forbidden"
99 def test_destroy_moderator_empty
100 session_for(create(:moderator_user))
102 # create an empty redaction
103 redaction = create(:redaction)
105 delete redaction_path(:id => redaction)
106 assert_redirected_to(redactions_path)
109 def test_destroy_moderator_non_empty
110 session_for(create(:moderator_user))
112 # create elements in the redaction
113 redaction = create(:redaction)
114 create(:old_node, :redaction => redaction)
116 delete redaction_path(:id => redaction)
117 assert_redirected_to(redaction_path(redaction))
118 assert_match(/^Redaction is not empty/, flash[:error])
121 def test_delete_non_moderator
122 session_for(create(:user))
124 delete redaction_path(:id => create(:redaction))
125 assert_redirected_to :controller => "errors", :action => "forbidden"
129 redaction = create(:redaction)
131 get edit_redaction_path(:id => redaction)
132 assert_redirected_to login_path(:referer => edit_redaction_path(redaction))
135 def test_edit_moderator
136 session_for(create(:moderator_user))
138 get edit_redaction_path(:id => create(:redaction))
139 assert_response :success
142 def test_edit_non_moderator
143 session_for(create(:user))
145 get edit_redaction_path(:id => create(:redaction))
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_redirected_to(redaction_path(redaction))
158 def test_update_moderator_invalid
159 session_for(create(:moderator_user))
161 redaction = create(:redaction)
163 put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "" })
164 assert_response :success
165 assert_template :edit
168 def test_updated_non_moderator
169 session_for(create(:user))
171 redaction = create(:redaction)
173 put redaction_path(:id => redaction, :redaction => { :title => "Foo", :description => "Description here." })
174 assert_redirected_to :controller => "errors", :action => "forbidden"