1 require File.dirname(__FILE__) + '/../test_helper'
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" }
40 def test_moderators_can_create
41 session[:user] = users(:moderator_user).id
43 post :create, :redaction => { :title => "Foo", :description => "Description here." }
44 assert_response :redirect
45 assert_redirected_to(redaction_path(Redaction.find_by_title("Foo")))
48 def test_non_moderators_cant_create
49 session[:user] = users(:public_user).id
51 post :create, :redaction => { :title => "Foo", :description => "Description here." }
52 assert_response :forbidden
55 def test_moderators_can_delete_empty
56 session[:user] = users(:moderator_user).id
58 # remove all elements from the redaction
59 redaction = redactions(:example)
60 redaction.old_nodes.each { |n| n.redaction = nil; n.save! }
61 redaction.old_ways.each { |w| w.redaction = nil; w.save! }
62 redaction.old_relations.each { |r| r.redaction = nil; r.save! }
64 delete :destroy, :id => redaction.id
65 assert_response :redirect
66 assert_redirected_to(redactions_path)
69 def test_moderators_cant_delete_nonempty
70 session[:user] = users(:moderator_user).id
72 # leave elements in the redaction
73 redaction = redactions(:example)
75 delete :destroy, :id => redaction.id
76 assert_response :redirect
77 assert_redirected_to(redaction_path(redaction))
78 assert_match /^Redaction is not empty/, flash[:error]
81 def test_non_moderators_cant_delete
82 session[:user] = users(:public_user).id
84 delete :destroy, :id => redactions(:example).id
85 assert_response :forbidden
88 def test_moderators_can_edit
89 session[:user] = users(:moderator_user).id
91 get :edit, :id => redactions(:example).id
92 assert_response :success
95 def test_non_moderators_cant_edit
96 session[:user] = users(:public_user).id
98 get :edit, :id => redactions(:example).id
99 assert_response :redirect
100 assert_redirected_to(redactions_path)
103 def test_moderators_can_update
104 session[:user] = users(:moderator_user).id
106 redaction = redactions(:example)
108 put :update, :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." }
109 assert_response :redirect
110 assert_redirected_to(redaction_path(redaction))
113 def test_non_moderators_cant_update
114 session[:user] = users(:public_user).id
116 redaction = redactions(:example)
118 put :update, :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." }
119 assert_response :forbidden