Skip to content

Commit

Permalink
Rename api element version path helper
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Mar 3, 2024
1 parent e90e9fd commit 9206fd8
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 55 deletions.
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
get "node/:id/relations" => "api/relations#relations_for_node", :as => :node_relations, :id => /\d+/
get "node/:id/history" => "api/old_nodes#history", :as => :api_node_history, :id => /\d+/
post "node/:id/:version/redact" => "api/old_nodes#redact", :as => :node_version_redact, :version => /\d+/, :id => /\d+/
get "node/:id/:version" => "api/old_nodes#show", :as => :node_version, :id => /\d+/, :version => /\d+/
resources :old_nodes, :path => "node/:id", :controller => "api/old_nodes", :as => :api_old_node, :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
get "node/:id" => "api/nodes#show", :as => :api_node, :id => /\d+/
put "node/:id" => "api/nodes#update", :id => /\d+/
delete "node/:id" => "api/nodes#delete", :id => /\d+/
Expand All @@ -46,7 +46,7 @@
get "way/:id/full" => "api/ways#full", :as => :way_full, :id => /\d+/
get "way/:id/relations" => "api/relations#relations_for_way", :as => :way_relations, :id => /\d+/
post "way/:id/:version/redact" => "api/old_ways#redact", :as => :way_version_redact, :version => /\d+/, :id => /\d+/
get "way/:id/:version" => "api/old_ways#show", :as => :way_version, :id => /\d+/, :version => /\d+/
resources :old_ways, :path => "way/:id", :controller => "api/old_ways", :as => :api_old_way, :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
get "way/:id" => "api/ways#show", :as => :api_way, :id => /\d+/
put "way/:id" => "api/ways#update", :id => /\d+/
delete "way/:id" => "api/ways#delete", :id => /\d+/
Expand All @@ -57,7 +57,7 @@
get "relation/:id/history" => "api/old_relations#history", :as => :api_relation_history, :id => /\d+/
get "relation/:id/full" => "api/relations#full", :as => :relation_full, :id => /\d+/
post "relation/:id/:version/redact" => "api/old_relations#redact", :as => :relation_version_redact, :version => /\d+/, :id => /\d+/
get "relation/:id/:version" => "api/old_relations#show", :as => :relation_version, :id => /\d+/, :version => /\d+/
resources :old_relations, :path => "relation/:id", :controller => "api/old_relations", :as => :api_old_relation, :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
get "relation/:id" => "api/relations#show", :as => :api_relation, :id => /\d+/
put "relation/:id" => "api/relations#update", :id => /\d+/
delete "relation/:id" => "api/relations#delete", :id => /\d+/
Expand Down
22 changes: 11 additions & 11 deletions test/controllers/api/old_nodes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_version

# check all the versions
versions.each_key do |key|
get node_version_path(:id => nodeid, :version => key.to_i)
get api_old_node_path(:id => nodeid, :version => key.to_i)

assert_response :success,
"couldn't get version #{key.to_i} of node #{nodeid}"
Expand Down Expand Up @@ -283,12 +283,12 @@ def test_version_redacted
node_v1 = node.old_nodes.find_by(:version => 1)
node_v1.redact!(create(:redaction))

get node_version_path(:id => node_v1.node_id, :version => node_v1.version)
get api_old_node_path(:id => node_v1.node_id, :version => node_v1.version)
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."

# not even to a logged-in user
auth_header = basic_authorization_header create(:user).email, "test"
get node_version_path(:id => node_v1.node_id, :version => node_v1.version), :headers => auth_header
get api_old_node_path(:id => node_v1.node_id, :version => node_v1.version), :headers => auth_header
assert_response :forbidden, "Redacted node shouldn't be visible via the version API, even when logged in."
end

Expand Down Expand Up @@ -325,9 +325,9 @@ def test_redact_node_moderator

# check moderator can still see the redacted data, when passing
# the appropriate flag
get node_version_path(:id => node_v3.node_id, :version => node_v3.version), :headers => auth_header
get api_old_node_path(:id => node_v3.node_id, :version => node_v3.version), :headers => auth_header
assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
get node_version_path(:id => node_v3.node_id, :version => node_v3.version), :params => { :show_redactions => "true" }, :headers => auth_header
get api_old_node_path(:id => node_v3.node_id, :version => node_v3.version), :params => { :show_redactions => "true" }, :headers => auth_header
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."

# and when accessed via history
Expand Down Expand Up @@ -355,7 +355,7 @@ def test_redact_node_is_redacted
auth_header = basic_authorization_header create(:user).email, "test"

# check can't see the redacted data
get node_version_path(:id => node_v3.node_id, :version => node_v3.version), :headers => auth_header
get api_old_node_path(:id => node_v3.node_id, :version => node_v3.version), :headers => auth_header
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."

# and when accessed via history
Expand Down Expand Up @@ -408,7 +408,7 @@ def test_unredact_node_moderator

# check moderator can now see the redacted data, when not
# passing the aspecial flag
get node_version_path(:id => node_v1.node_id, :version => node_v1.version), :headers => auth_header
get api_old_node_path(:id => node_v1.node_id, :version => node_v1.version), :headers => auth_header
assert_response :success, "After unredaction, node should not be gone for moderator."

# and when accessed via history
Expand All @@ -420,7 +420,7 @@ def test_unredact_node_moderator
auth_header = basic_authorization_header create(:user).email, "test"

# check normal user can now see the redacted data
get node_version_path(:id => node_v1.node_id, :version => node_v1.version), :headers => auth_header
get api_old_node_path(:id => node_v1.node_id, :version => node_v1.version), :headers => auth_header
assert_response :success, "After unredaction, node should be visible to normal users."

# and when accessed via history
Expand All @@ -446,7 +446,7 @@ def do_redact_redactable_node(headers = {})
end

def do_redact_node(node, redaction, headers = {})
get node_version_path(:id => node.node_id, :version => node.version), :headers => headers
get api_old_node_path(:id => node.node_id, :version => node.version), :headers => headers
assert_response :success, "should be able to get version #{node.version} of node #{node.node_id}."

# now redact it
Expand All @@ -463,7 +463,7 @@ def check_current_version(node_id)
assert_not_nil current_node, "getting node #{node_id} returned nil"

# get the "old" version of the node from the old_node interface
get node_version_path(:id => node_id, :version => current_node.version)
get api_old_node_path(:id => node_id, :version => current_node.version)
assert_response :success, "cant get old node #{node_id}, v#{current_node.version}"
old_node = Node.from_xml(@response.body)

Expand All @@ -472,7 +472,7 @@ def check_current_version(node_id)
end

def check_not_found_id_version(id, version)
get node_version_path(:id => id, :version => version)
get api_old_node_path(:id => id, :version => version)
assert_response :not_found
rescue ActionController::UrlGenerationError => e
assert_match(/No route matches/, e.to_s)
Expand Down
18 changes: 9 additions & 9 deletions test/controllers/api/old_relations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ def test_version_redacted
relation_v1 = relation.old_relations.find_by(:version => 1)
relation_v1.redact!(create(:redaction))

get relation_version_path(:id => relation_v1.relation_id, :version => relation_v1.version)
get api_old_relation_path(:id => relation_v1.relation_id, :version => relation_v1.version)
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."

# not even to a logged-in user
auth_header = basic_authorization_header create(:user).email, "test"
get relation_version_path(:id => relation_v1.relation_id, :version => relation_v1.version), :headers => auth_header
get api_old_relation_path(:id => relation_v1.relation_id, :version => relation_v1.version), :headers => auth_header
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API, even when logged in."
end

Expand All @@ -145,7 +145,7 @@ def test_history_redacted

# not even to a logged-in user
auth_header = basic_authorization_header create(:user).email, "test"
get relation_version_path(:id => relation_v1.relation_id, :version => relation_v1.version), :headers => auth_header
get api_old_relation_path(:id => relation_v1.relation_id, :version => relation_v1.version), :headers => auth_header
get api_relation_history_path(:id => relation_v1.relation_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 0,
Expand All @@ -166,9 +166,9 @@ def test_redact_relation_moderator

# check moderator can still see the redacted data, when passing
# the appropriate flag
get relation_version_path(:id => relation_v3.relation_id, :version => relation_v3.version), :headers => auth_header
get api_old_relation_path(:id => relation_v3.relation_id, :version => relation_v3.version), :headers => auth_header
assert_response :forbidden, "After redaction, relation should be gone for moderator, when flag not passed."
get relation_version_path(:id => relation_v3.relation_id, :version => relation_v3.version), :params => { :show_redactions => "true" }, :headers => auth_header
get api_old_relation_path(:id => relation_v3.relation_id, :version => relation_v3.version), :params => { :show_redactions => "true" }, :headers => auth_header
assert_response :success, "After redaction, relation should not be gone for moderator, when flag passed."

# and when accessed via history
Expand Down Expand Up @@ -197,7 +197,7 @@ def test_redact_relation_is_redacted
auth_header = basic_authorization_header create(:user).email, "test"

# check can't see the redacted data
get relation_version_path(:id => relation_v3.relation_id, :version => relation_v3.version), :headers => auth_header
get api_old_relation_path(:id => relation_v3.relation_id, :version => relation_v3.version), :headers => auth_header
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."

# and when accessed via history
Expand Down Expand Up @@ -248,7 +248,7 @@ def test_unredact_relation_moderator

# check moderator can still see the redacted data, without passing
# the appropriate flag
get relation_version_path(:id => relation_v1.relation_id, :version => relation_v1.version), :headers => auth_header
get api_old_relation_path(:id => relation_v1.relation_id, :version => relation_v1.version), :headers => auth_header
assert_response :success, "After unredaction, relation should not be gone for moderator."

# and when accessed via history
Expand All @@ -260,7 +260,7 @@ def test_unredact_relation_moderator
auth_header = basic_authorization_header create(:user).email, "test"

# check normal user can now see the redacted data
get relation_version_path(:id => relation_v1.relation_id, :version => relation_v1.version), :headers => auth_header
get api_old_relation_path(:id => relation_v1.relation_id, :version => relation_v1.version), :headers => auth_header
assert_response :success, "After redaction, node should not be gone for normal user."

# and when accessed via history
Expand Down Expand Up @@ -329,7 +329,7 @@ def do_redact_redactable_relation(headers = {})
end

def do_redact_relation(relation, redaction, headers = {})
get relation_version_path(:id => relation.relation_id, :version => relation.version)
get api_old_relation_path(:id => relation.relation_id, :version => relation.version)
assert_response :success, "should be able to get version #{relation.version} of relation #{relation.relation_id}."

# now redact it
Expand Down
21 changes: 10 additions & 11 deletions test/controllers/api/old_ways_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ def test_version_redacted
way_v1 = way.old_ways.find_by(:version => 1)
way_v1.redact!(create(:redaction))

get way_version_path(:id => way_v1.way_id, :version => way_v1.version)
get api_old_way_path(:id => way_v1.way_id, :version => way_v1.version)
assert_response :forbidden, "Redacted way shouldn't be visible via the version API."

# not even to a logged-in user
auth_header = basic_authorization_header create(:user).email, "test"
get way_version_path(:id => way_v1.way_id, :version => way_v1.version), :headers => auth_header
get api_old_way_path(:id => way_v1.way_id, :version => way_v1.version), :headers => auth_header
assert_response :forbidden, "Redacted way shouldn't be visible via the version API, even when logged in."
end

Expand All @@ -186,7 +186,6 @@ def test_history_redacted

# not even to a logged-in user
auth_header = basic_authorization_header create(:user).email, "test"
get way_version_path(:id => way_v1.way_id, :version => way_v1.version), :headers => auth_header
get api_way_history_path(:id => way_v1.way_id), :headers => auth_header
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 0,
Expand All @@ -206,9 +205,9 @@ def test_redact_way_moderator

# check moderator can still see the redacted data, when passing
# the appropriate flag
get way_version_path(:id => way_v3.way_id, :version => way_v3.version), :headers => auth_header
get api_old_way_path(:id => way_v3.way_id, :version => way_v3.version), :headers => auth_header
assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
get way_version_path(:id => way_v3.way_id, :version => way_v3.version), :params => { :show_redactions => "true" }, :headers => auth_header
get api_old_way_path(:id => way_v3.way_id, :version => way_v3.version), :params => { :show_redactions => "true" }, :headers => auth_header
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."

# and when accessed via history
Expand Down Expand Up @@ -236,7 +235,7 @@ def test_redact_way_is_redacted
auth_header = basic_authorization_header create(:user).email, "test"

# check can't see the redacted data
get way_version_path(:id => way_v3.way_id, :version => way_v3.version), :headers => auth_header
get api_old_way_path(:id => way_v3.way_id, :version => way_v3.version), :headers => auth_header
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."

# and when accessed via history
Expand Down Expand Up @@ -288,7 +287,7 @@ def test_unredact_way_moderator

# check moderator can still see the unredacted data, without passing
# the appropriate flag
get way_version_path(:id => way_v1.way_id, :version => way_v1.version), :headers => auth_header
get api_old_way_path(:id => way_v1.way_id, :version => way_v1.version), :headers => auth_header
assert_response :success, "After unredaction, node should not be gone for moderator."

# and when accessed via history
Expand All @@ -300,7 +299,7 @@ def test_unredact_way_moderator
auth_header = basic_authorization_header create(:user).email, "test"

# check normal user can now see the unredacted data
get way_version_path(:id => way_v1.way_id, :version => way_v1.version), :headers => auth_header
get api_old_way_path(:id => way_v1.way_id, :version => way_v1.version), :headers => auth_header
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."

# and when accessed via history
Expand All @@ -325,7 +324,7 @@ def check_current_version(way_id)
assert_not_nil current_way, "getting way #{way_id} returned nil"

# get the "old" version of the way from the version method
get way_version_path(:id => way_id, :version => current_way.version)
get api_old_way_path(:id => way_id, :version => current_way.version)
assert_response :success, "can't get old way #{way_id}, v#{current_way.version}"
old_way = Way.from_xml(@response.body)

Expand All @@ -346,7 +345,7 @@ def check_history_equals_versions(way_id)
history_way = Way.from_xml_node(way_doc)
assert_not_nil history_way, "parsing way #{way_id} version failed"

get way_version_path(:id => way_id, :version => history_way.version)
get api_old_way_path(:id => way_id, :version => history_way.version)
assert_response :success, "couldn't get way #{way_id}, v#{history_way.version}"
version_way = Way.from_xml(@response.body)
assert_not_nil version_way, "failed to parse #{way_id}, v#{history_way.version}"
Expand All @@ -369,7 +368,7 @@ def do_redact_redactable_way(headers = {})
end

def do_redact_way(way, redaction, headers = {})
get way_version_path(:id => way.way_id, :version => way.version)
get api_old_way_path(:id => way.way_id, :version => way.version)
assert_response :success, "should be able to get version #{way.version} of way #{way.way_id}."

# now redact it
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/api/relations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def test_relation_member_ordering

# check the ordering in the history tables:
with_controller(OldRelationsController.new) do
get relation_version_path(:id => relation_id, :version => 2)
get api_old_relation_path(:id => relation_id, :version => 2)
assert_response :success, "can't read back version 2 of the relation #{relation_id}"
check_ordering(doc, @response.body)
end
Expand Down Expand Up @@ -868,7 +868,7 @@ def test_history_ordering

# check the ordering in the history tables:
with_controller(OldRelationsController.new) do
get relation_version_path(:id => relation_id, :version => 1)
get api_old_relation_path(:id => relation_id, :version => 1)
assert_response :success, "can't read back version 1 of the relation: #{@response.body}"
check_ordering(doc, @response.body)
end
Expand Down Expand Up @@ -1109,7 +1109,7 @@ def with_relation(id, ver = nil)
get api_relation_path(:id => id)
else
with_controller(OldRelationsController.new) do
get relation_version_path(:id => id, :version => ver)
get api_old_relation_path(:id => id, :version => ver)
end
end
assert_response :success
Expand Down
Loading

0 comments on commit 9206fd8

Please sign in to comment.