4 class OldRelationsControllerTest < ActionDispatch::IntegrationTest
6 # test all routes which lead to this controller
9 { :path => "/api/0.6/relation/1/history", :method => :get },
10 { :controller => "api/old_relations", :action => "index", :relation_id => "1" }
13 { :path => "/api/0.6/relation/1/history.json", :method => :get },
14 { :controller => "api/old_relations", :action => "index", :relation_id => "1", :format => "json" }
17 { :path => "/api/0.6/relation/1/2", :method => :get },
18 { :controller => "api/old_relations", :action => "show", :relation_id => "1", :version => "2" }
21 { :path => "/api/0.6/relation/1/2.json", :method => :get },
22 { :controller => "api/old_relations", :action => "show", :relation_id => "1", :version => "2", :format => "json" }
27 # check that a visible relations is returned properly
29 relation = create(:relation, :with_history, :version => 2)
31 get api_relation_versions_path(relation)
33 assert_response :success
34 assert_dom "osm:root", 1 do
35 assert_dom "> relation", 2 do |dom_relations|
36 assert_dom dom_relations[0], "> @id", relation.id.to_s
37 assert_dom dom_relations[0], "> @version", "1"
39 assert_dom dom_relations[1], "> @id", relation.id.to_s
40 assert_dom dom_relations[1], "> @version", "2"
46 # check that a non-existent relations is not returned
47 def test_index_invalid
48 get api_relation_versions_path(0)
49 assert_response :not_found
53 # test that redacted relations aren't visible in the history
54 def test_index_redacted_unauthorised
55 relation = create(:relation, :with_history, :version => 2)
56 relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
58 get api_relation_versions_path(relation)
60 assert_response :success, "Redaction shouldn't have stopped history working."
61 assert_dom "osm relation[id='#{relation.id}'][version='1']", 0,
62 "redacted relation #{relation.id} version 1 shouldn't be present in the history."
64 get api_relation_versions_path(relation, :show_redactions => "true")
66 assert_response :success, "Redaction shouldn't have stopped history working."
67 assert_dom "osm relation[id='#{relation.id}'][version='1']", 0,
68 "redacted relation #{relation.id} version 1 shouldn't be present in the history when passing flag."
71 def test_index_redacted_normal_user
72 relation = create(:relation, :with_history, :version => 2)
73 relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
75 get api_relation_versions_path(relation), :headers => bearer_authorization_header
77 assert_response :success, "Redaction shouldn't have stopped history working."
78 assert_dom "osm relation[id='#{relation.id}'][version='1']", 0,
79 "redacted relation #{relation.id} version 1 shouldn't be present in the history, even when logged in."
81 get api_relation_versions_path(relation, :show_redactions => "true"), :headers => bearer_authorization_header
83 assert_response :success, "Redaction shouldn't have stopped history working."
84 assert_dom "osm relation[id='#{relation.id}'][version='1']", 0,
85 "redacted relation #{relation.id} version 1 shouldn't be present in the history, even when logged in and passing flag."
88 def test_index_redacted_moderator
89 relation = create(:relation, :with_history, :version => 2)
90 relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
91 auth_header = bearer_authorization_header create(:moderator_user)
93 get api_relation_versions_path(relation), :headers => auth_header
95 assert_response :success, "Redaction shouldn't have stopped history working."
96 assert_dom "osm relation[id='#{relation.id}'][version='1']", 0,
97 "relation #{relation.id} version 1 should not be present in the history for moderators when not passing flag."
99 get api_relation_versions_path(relation, :show_redactions => "true"), :headers => auth_header
101 assert_response :success, "Redaction shouldn't have stopped history working."
102 assert_dom "osm relation[id='#{relation.id}'][version='1']", 1,
103 "relation #{relation.id} version 1 should still be present in the history for moderators when passing flag."
107 relation = create(:relation, :with_history, :version => 2)
108 create(:old_relation_tag, :old_relation => relation.old_relations[0], :k => "k1", :v => "v1")
109 create(:old_relation_tag, :old_relation => relation.old_relations[1], :k => "k2", :v => "v2")
111 get api_relation_version_path(relation, 1)
113 assert_response :success
114 assert_dom "osm:root", 1 do
115 assert_dom "> relation", 1 do
116 assert_dom "> @id", relation.id.to_s
117 assert_dom "> @version", "1"
118 assert_dom "> tag", 1 do
119 assert_dom "> @k", "k1"
120 assert_dom "> @v", "v1"
125 get api_relation_version_path(relation, 2)
127 assert_response :success
128 assert_dom "osm:root", 1 do
129 assert_dom "> relation", 1 do
130 assert_dom "> @id", relation.id.to_s
131 assert_dom "> @version", "2"
132 assert_dom "> tag", 1 do
133 assert_dom "> @k", "k2"
134 assert_dom "> @v", "v2"
141 # test that redacted relations aren't visible, regardless of
142 # authorisation except as moderator...
143 def test_show_redacted_unauthorised
144 relation = create(:relation, :with_history, :version => 2)
145 relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
147 get api_relation_version_path(relation, 1)
149 assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."
151 get api_relation_version_path(relation, 1, :show_redactions => "true")
153 assert_response :forbidden, "Redacted relation shouldn't be visible via the version API when passing flag."
156 def test_show_redacted_normal_user
157 relation = create(:relation, :with_history, :version => 2)
158 relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
160 get api_relation_version_path(relation, 1), :headers => bearer_authorization_header
162 assert_response :forbidden, "Redacted relation shouldn't be visible via the version API, even when logged in."
164 get api_relation_version_path(relation, 1, :show_redactions => "true"), :headers => bearer_authorization_header
166 assert_response :forbidden, "Redacted relation shouldn't be visible via the version API, even when logged in and passing flag."
169 def test_show_redacted_moderator
170 relation = create(:relation, :with_history, :version => 2)
171 relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
172 auth_header = bearer_authorization_header create(:moderator_user)
174 get api_relation_version_path(relation, 1), :headers => auth_header
176 assert_response :forbidden, "Redacted relation should be gone for moderator, when flag not passed."
178 get api_relation_version_path(relation, 1, :show_redactions => "true"), :headers => auth_header
180 assert_response :success, "Redacted relation should not be gone for moderator, when flag passed."