]> git.openstreetmap.org Git - rails.git/blob - test/functional/redactions_controller_test.rb
Allowing wrapping inside the content of a richtext editor
[rails.git] / test / functional / redactions_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'redactions_controller'
3
4 class RedactionsControllerTest < ActionController::TestCase
5   api_fixtures
6
7   ##
8   # test all routes which lead to this controller
9   def test_routes
10     assert_routing(
11       { :path => "/redactions", :method => :get },
12       { :controller => "redactions", :action => "index" }
13     )
14     assert_routing(
15       { :path => "/redactions/new", :method => :get },
16       { :controller => "redactions", :action => "new" }
17     )
18     assert_routing(
19       { :path => "/redactions", :method => :post },
20       { :controller => "redactions", :action => "create" }
21     )
22     assert_routing(
23       { :path => "/redactions/1", :method => :get },
24       { :controller => "redactions", :action => "show", :id => "1" }
25     )
26     assert_routing(
27       { :path => "/redactions/1/edit", :method => :get },
28       { :controller => "redactions", :action => "edit", :id => "1" }
29     )
30     assert_routing(
31       { :path => "/redactions/1", :method => :put },
32       { :controller => "redactions", :action => "update", :id => "1" }
33     )
34     assert_routing(
35       { :path => "/redactions/1", :method => :delete },
36       { :controller => "redactions", :action => "destroy", :id => "1" }
37     )
38   end
39
40   def test_moderators_can_create
41     session[:user] = users(:moderator_user).id
42     cookies["_osm_username"] = users(:moderator_user).display_name
43
44     post :create, :redaction => { :title => "Foo", :description => "Description here." }
45     assert_response :redirect
46     assert_redirected_to(redaction_path(Redaction.find_by_title("Foo")))
47   end
48
49   def test_non_moderators_cant_create
50     session[:user] = users(:public_user).id
51     cookies["_osm_username"] = users(:public_user).display_name
52
53     post :create, :redaction => { :title => "Foo", :description => "Description here." }
54     assert_response :forbidden
55   end
56
57   def test_moderators_can_delete_empty
58     session[:user] = users(:moderator_user).id
59     cookies["_osm_username"] = users(:moderator_user).display_name
60
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! }
66
67     delete :destroy, :id => redaction.id
68     assert_response :redirect
69     assert_redirected_to(redactions_path)
70   end
71
72   def test_moderators_cant_delete_nonempty
73     session[:user] = users(:moderator_user).id
74     cookies["_osm_username"] = users(:moderator_user).display_name
75
76     # leave elements in the redaction
77     redaction = redactions(:example)
78
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]
83   end
84
85   def test_non_moderators_cant_delete
86     session[:user] = users(:public_user).id
87     cookies["_osm_username"] = users(:public_user).display_name
88
89     delete :destroy, :id => redactions(:example).id
90     assert_response :forbidden
91   end
92
93   def test_moderators_can_edit
94     session[:user] = users(:moderator_user).id
95     cookies["_osm_username"] = users(:moderator_user).display_name
96
97     get :edit, :id => redactions(:example).id
98     assert_response :success
99   end
100
101   def test_non_moderators_cant_edit
102     session[:user] = users(:public_user).id
103     cookies["_osm_username"] = users(:public_user).display_name
104
105     get :edit, :id => redactions(:example).id
106     assert_response :redirect
107     assert_redirected_to(redactions_path)
108   end
109
110   def test_moderators_can_update
111     session[:user] = users(:moderator_user).id
112     cookies["_osm_username"] = users(:moderator_user).display_name
113
114     redaction = redactions(:example)
115
116     put :update, :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." }
117     assert_response :redirect
118     assert_redirected_to(redaction_path(redaction))
119   end
120
121   def test_non_moderators_cant_update
122     session[:user] = users(:public_user).id
123     cookies["_osm_username"] = users(:public_user).display_name
124
125     redaction = redactions(:example)
126
127     put :update, :id => redaction.id, :redaction => { :title => "Foo", :description => "Description here." }
128     assert_response :forbidden
129   end
130 end