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
42 cookies["_osm_username"] = users(:moderator_user).display_name
44 post :create, :redaction => { :title => "Foo", :description => "Description here." }
45 assert_response :redirect
46 assert_redirected_to(redaction_path(Redaction.find_by_title("Foo")))
49 def test_non_moderators_cant_create
50 session[:user] = users(:public_user).id
51 cookies["_osm_username"] = users(:public_user).display_name
53 post :create, :redaction => { :title => "Foo", :description => "Description here." }
54 assert_response :forbidden
57 def test_moderators_can_delete_empty
58 session[:user] = users(:moderator_user).id
59 cookies["_osm_username"] = users(:moderator_user).display_name
61 # remove all elements from the redaction
62 redaction = redactions(:example)
63 redaction.old_nodes.each { |n| n.redaction = nil; n.save! }
64 redaction.old_ways.each { |w| w.redaction = nil; w.save! }
65 redaction.old_relations.each { |r| r.redaction = nil; r.save! }
67 delete :destroy, :id => redaction.id
68 assert_response :redirect
69 assert_redirected_to(redactions_path)
72 def test_moderators_cant_delete_nonempty
73 session[:user] = users(:moderator_user).id
74 cookies["_osm_username"] = users(:moderator_user).display_name
76 # leave elements in the redaction
77 redaction = redactions(:example)
79 delete :destroy, :id => redaction.id
80 assert_response :redirect
81 assert_redirected_to(redaction_path(redaction))
82 assert_match /^Redaction is not empty/, flash[:error]
85 def test_non_moderators_cant_delete
86 session[:user] = users(:public_user).id
87 cookies["_osm_username"] = users(:public_user).display_name
89 delete :destroy, :id => redactions(:example).id
90 assert_response :forbidden
93 def test_moderators_can_edit
94 session[:user] = users(:moderator_user).id
95 cookies["_osm_username"] = users(:moderator_user).display_name
97 get :edit, :id => redactions(:example).id
98 assert_response :success
101 def test_non_moderators_cant_edit
102 session[:user] = users(:public_user).id
103 cookies["_osm_username"] = users(:public_user).display_name
105 get :edit, :id => redactions(:example).id
106 assert_response :redirect
107 assert_redirected_to(redactions_path)
110 def test_moderators_can_update
111 session[:user] = users(:moderator_user).id
112 cookies["_osm_username"] = users(:moderator_user).display_name
114 redaction = redactions(:example)
116 put :update, :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." }
117 assert_response :redirect
118 assert_redirected_to(redaction_path(redaction))
121 def test_non_moderators_cant_update
122 session[:user] = users(:public_user).id
123 cookies["_osm_username"] = users(:public_user).display_name
125 redaction = redactions(:example)
127 put :update, :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." }
128 assert_response :forbidden