Convert api element history actions to versions resources
This commit is contained in:
parent
974e404a6e
commit
98af87d1cb
16 changed files with 175 additions and 134 deletions
|
@ -15,8 +15,7 @@ class ApiAbility
|
||||||
can [:read, :download], Changeset
|
can [:read, :download], Changeset
|
||||||
can :read, Tracepoint
|
can :read, Tracepoint
|
||||||
can :read, User
|
can :read, User
|
||||||
can :read, [Node, Way, Relation]
|
can :read, [Node, Way, Relation, OldNode, OldWay, OldRelation]
|
||||||
can [:history, :read], [OldNode, OldWay, OldRelation]
|
|
||||||
can :read, UserBlock
|
can :read, UserBlock
|
||||||
|
|
||||||
if user&.active?
|
if user&.active?
|
||||||
|
|
|
@ -4,17 +4,17 @@
|
||||||
module Api
|
module Api
|
||||||
class OldElementsController < ApiController
|
class OldElementsController < ApiController
|
||||||
before_action :check_api_writable, :only => [:redact]
|
before_action :check_api_writable, :only => [:redact]
|
||||||
before_action :setup_user_auth, :only => [:history, :show]
|
before_action :setup_user_auth, :only => [:index, :show]
|
||||||
before_action :authorize, :only => [:redact]
|
before_action :authorize, :only => [:redact]
|
||||||
|
|
||||||
authorize_resource
|
authorize_resource
|
||||||
|
|
||||||
before_action :lookup_old_element, :except => [:history]
|
before_action :lookup_old_element, :except => [:index]
|
||||||
before_action :lookup_old_element_versions, :only => [:history]
|
before_action :lookup_old_element_versions, :only => [:index]
|
||||||
|
|
||||||
before_action :set_request_formats, :except => [:redact]
|
before_action :set_request_formats, :except => [:redact]
|
||||||
|
|
||||||
def history
|
def index
|
||||||
# the .where() method used in the lookup_old_element_versions
|
# the .where() method used in the lookup_old_element_versions
|
||||||
# call won't throw an error if no records are found, so we have
|
# call won't throw an error if no records are found, so we have
|
||||||
# to do that ourselves.
|
# to do that ourselves.
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def lookup_old_element_versions
|
def lookup_old_element_versions
|
||||||
@elements = OldNode.where(:node_id => params[:id]).order(:version)
|
@elements = OldNode.where(:node_id => params[:node_id]).order(:version)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def lookup_old_element_versions
|
def lookup_old_element_versions
|
||||||
@elements = OldRelation.where(:relation_id => params[:id]).order(:version)
|
@elements = OldRelation.where(:relation_id => params[:relation_id]).order(:version)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def lookup_old_element_versions
|
def lookup_old_element_versions
|
||||||
@elements = OldWay.where(:way_id => params[:id]).order(:version)
|
@elements = OldWay.where(:way_id => params[:way_id]).order(:version)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<%= render :partial => "browse/#{@type}", :collection => @feature.send(:"old_#{@type}s").reverse %>
|
<%= render :partial => "browse/#{@type}", :collection => @feature.send(:"old_#{@type}s").reverse %>
|
||||||
|
|
||||||
<div class='secondary-actions'>
|
<div class='secondary-actions'>
|
||||||
<%= link_to t("browse.download_xml"), :controller => "api/old_#{@type.pluralize}", :action => "history" %>
|
<%= link_to t("browse.download_xml"), send(:"api_#{@type}_versions_path", @feature.id) %>
|
||||||
·
|
·
|
||||||
<%= link_to t("browse.view_details"), :controller => @type.pluralize, :action => :show %>
|
<%= link_to t("browse.view_details"), :controller => @type.pluralize, :action => :show %>
|
||||||
<% if params[:show_redactions] %>
|
<% if params[:show_redactions] %>
|
||||||
|
|
|
@ -30,15 +30,12 @@ OpenStreetMap::Application.routes.draw do
|
||||||
post "changeset/comment/:id/hide" => "changeset_comments#destroy", :as => :changeset_comment_hide, :id => /\d+/
|
post "changeset/comment/:id/hide" => "changeset_comments#destroy", :as => :changeset_comment_hide, :id => /\d+/
|
||||||
post "changeset/comment/:id/unhide" => "changeset_comments#restore", :as => :changeset_comment_unhide, :id => /\d+/
|
post "changeset/comment/:id/unhide" => "changeset_comments#restore", :as => :changeset_comment_unhide, :id => /\d+/
|
||||||
|
|
||||||
get "node/:id/history" => "old_nodes#history", :as => :api_node_history, :id => /\d+/
|
|
||||||
post "node/:id/:version/redact" => "old_nodes#redact", :as => :node_version_redact, :version => /\d+/, :id => /\d+/
|
post "node/:id/:version/redact" => "old_nodes#redact", :as => :node_version_redact, :version => /\d+/, :id => /\d+/
|
||||||
get "node/:id/:version" => "old_nodes#show", :as => :api_old_node, :id => /\d+/, :version => /\d+/
|
get "node/:id/:version" => "old_nodes#show", :as => :api_old_node, :id => /\d+/, :version => /\d+/
|
||||||
|
|
||||||
get "way/:id/history" => "old_ways#history", :as => :api_way_history, :id => /\d+/
|
|
||||||
post "way/:id/:version/redact" => "old_ways#redact", :as => :way_version_redact, :version => /\d+/, :id => /\d+/
|
post "way/:id/:version/redact" => "old_ways#redact", :as => :way_version_redact, :version => /\d+/, :id => /\d+/
|
||||||
get "way/:id/:version" => "old_ways#show", :as => :api_old_way, :id => /\d+/, :version => /\d+/
|
get "way/:id/:version" => "old_ways#show", :as => :api_old_way, :id => /\d+/, :version => /\d+/
|
||||||
|
|
||||||
get "relation/:id/history" => "old_relations#history", :as => :api_relation_history, :id => /\d+/
|
|
||||||
post "relation/:id/:version/redact" => "old_relations#redact", :as => :relation_version_redact, :version => /\d+/, :id => /\d+/
|
post "relation/:id/:version/redact" => "old_relations#redact", :as => :relation_version_redact, :version => /\d+/, :id => /\d+/
|
||||||
get "relation/:id/:version" => "old_relations#show", :as => :api_old_relation, :id => /\d+/, :version => /\d+/
|
get "relation/:id/:version" => "old_relations#show", :as => :api_old_relation, :id => /\d+/, :version => /\d+/
|
||||||
end
|
end
|
||||||
|
@ -50,6 +47,7 @@ OpenStreetMap::Application.routes.draw do
|
||||||
resources :ways, :only => :index
|
resources :ways, :only => :index
|
||||||
resources :relations, :only => :index
|
resources :relations, :only => :index
|
||||||
end
|
end
|
||||||
|
resources :versions, :path => "history", :controller => :old_nodes, :only => :index
|
||||||
end
|
end
|
||||||
put "node/create" => "nodes#create", :as => nil
|
put "node/create" => "nodes#create", :as => nil
|
||||||
|
|
||||||
|
@ -61,6 +59,7 @@ OpenStreetMap::Application.routes.draw do
|
||||||
scope :module => :ways do
|
scope :module => :ways do
|
||||||
resources :relations, :only => :index
|
resources :relations, :only => :index
|
||||||
end
|
end
|
||||||
|
resources :versions, :path => "history", :controller => :old_ways, :only => :index
|
||||||
end
|
end
|
||||||
put "way/create" => "ways#create", :as => nil
|
put "way/create" => "ways#create", :as => nil
|
||||||
|
|
||||||
|
@ -72,6 +71,7 @@ OpenStreetMap::Application.routes.draw do
|
||||||
scope :module => :relations do
|
scope :module => :relations do
|
||||||
resources :relations, :only => :index
|
resources :relations, :only => :index
|
||||||
end
|
end
|
||||||
|
resources :versions, :path => "history", :controller => :old_relations, :only => :index
|
||||||
end
|
end
|
||||||
put "relation/create" => "relations#create", :as => nil
|
put "relation/create" => "relations#create", :as => nil
|
||||||
|
|
||||||
|
|
|
@ -2,25 +2,21 @@ require "test_helper"
|
||||||
|
|
||||||
module Api
|
module Api
|
||||||
class OldNodesControllerTest < ActionDispatch::IntegrationTest
|
class OldNodesControllerTest < ActionDispatch::IntegrationTest
|
||||||
#
|
|
||||||
# TODO: test history
|
|
||||||
#
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# test all routes which lead to this controller
|
# test all routes which lead to this controller
|
||||||
def test_routes
|
def test_routes
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/api/0.6/node/1/history", :method => :get },
|
{ :path => "/api/0.6/node/1/history", :method => :get },
|
||||||
{ :controller => "api/old_nodes", :action => "history", :id => "1" }
|
{ :controller => "api/old_nodes", :action => "index", :node_id => "1" }
|
||||||
|
)
|
||||||
|
assert_routing(
|
||||||
|
{ :path => "/api/0.6/node/1/history.json", :method => :get },
|
||||||
|
{ :controller => "api/old_nodes", :action => "index", :node_id => "1", :format => "json" }
|
||||||
)
|
)
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/api/0.6/node/1/2", :method => :get },
|
{ :path => "/api/0.6/node/1/2", :method => :get },
|
||||||
{ :controller => "api/old_nodes", :action => "show", :id => "1", :version => "2" }
|
{ :controller => "api/old_nodes", :action => "show", :id => "1", :version => "2" }
|
||||||
)
|
)
|
||||||
assert_routing(
|
|
||||||
{ :path => "/api/0.6/node/1/history.json", :method => :get },
|
|
||||||
{ :controller => "api/old_nodes", :action => "history", :id => "1", :format => "json" }
|
|
||||||
)
|
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/api/0.6/node/1/2.json", :method => :get },
|
{ :path => "/api/0.6/node/1/2.json", :method => :get },
|
||||||
{ :controller => "api/old_nodes", :action => "show", :id => "1", :version => "2", :format => "json" }
|
{ :controller => "api/old_nodes", :action => "show", :id => "1", :version => "2", :format => "json" }
|
||||||
|
@ -31,6 +27,49 @@ module Api
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_index
|
||||||
|
node = create(:node, :version => 2)
|
||||||
|
create(:old_node, :node_id => node.id, :version => 1, :latitude => 60 * OldNode::SCALE, :longitude => 30 * OldNode::SCALE)
|
||||||
|
create(:old_node, :node_id => node.id, :version => 2, :latitude => 61 * OldNode::SCALE, :longitude => 31 * OldNode::SCALE)
|
||||||
|
|
||||||
|
get api_node_versions_path(node)
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_dom "osm:root", 1 do
|
||||||
|
assert_dom "> node", 2 do |dom_nodes|
|
||||||
|
assert_dom dom_nodes[0], "> @id", node.id.to_s
|
||||||
|
assert_dom dom_nodes[0], "> @version", "1"
|
||||||
|
assert_dom dom_nodes[0], "> @lat", "60.0000000"
|
||||||
|
assert_dom dom_nodes[0], "> @lon", "30.0000000"
|
||||||
|
|
||||||
|
assert_dom dom_nodes[1], "> @id", node.id.to_s
|
||||||
|
assert_dom dom_nodes[1], "> @version", "2"
|
||||||
|
assert_dom dom_nodes[1], "> @lat", "61.0000000"
|
||||||
|
assert_dom dom_nodes[1], "> @lon", "31.0000000"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# test that redacted nodes aren't visible in the history
|
||||||
|
def test_index_redacted
|
||||||
|
node = create(:node, :with_history, :version => 2)
|
||||||
|
node_v1 = node.old_nodes.find_by(:version => 1)
|
||||||
|
node_v1.redact!(create(:redaction))
|
||||||
|
|
||||||
|
get api_node_versions_path(node)
|
||||||
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
|
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0,
|
||||||
|
"redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history."
|
||||||
|
|
||||||
|
# not even to a logged-in user
|
||||||
|
auth_header = bearer_authorization_header
|
||||||
|
get api_node_versions_path(node), :headers => auth_header
|
||||||
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
|
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0,
|
||||||
|
"redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history, even when logged in."
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# test the version call by submitting several revisions of a new node
|
# test the version call by submitting several revisions of a new node
|
||||||
# to the API and ensuring that later calls to version return the
|
# to the API and ensuring that later calls to version return the
|
||||||
|
@ -191,7 +230,7 @@ module Api
|
||||||
def test_lat_lon_xml_format
|
def test_lat_lon_xml_format
|
||||||
old_node = create(:old_node, :latitude => (0.00004 * OldNode::SCALE).to_i, :longitude => (0.00008 * OldNode::SCALE).to_i)
|
old_node = create(:old_node, :latitude => (0.00004 * OldNode::SCALE).to_i, :longitude => (0.00008 * OldNode::SCALE).to_i)
|
||||||
|
|
||||||
get api_node_history_path(old_node.node_id)
|
get api_node_versions_path(old_node.node_id)
|
||||||
assert_match(/lat="0.0000400"/, response.body)
|
assert_match(/lat="0.0000400"/, response.body)
|
||||||
assert_match(/lon="0.0000800"/, response.body)
|
assert_match(/lon="0.0000800"/, response.body)
|
||||||
end
|
end
|
||||||
|
@ -279,26 +318,6 @@ module Api
|
||||||
assert_response :forbidden, "Redacted node shouldn't be visible via the version API, even when logged in."
|
assert_response :forbidden, "Redacted node shouldn't be visible via the version API, even when logged in."
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
|
||||||
# test that redacted nodes aren't visible in the history
|
|
||||||
def test_history_redacted
|
|
||||||
node = create(:node, :with_history, :version => 2)
|
|
||||||
node_v1 = node.old_nodes.find_by(:version => 1)
|
|
||||||
node_v1.redact!(create(:redaction))
|
|
||||||
|
|
||||||
get api_node_history_path(node)
|
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
|
||||||
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0,
|
|
||||||
"redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history."
|
|
||||||
|
|
||||||
# not even to a logged-in user
|
|
||||||
auth_header = bearer_authorization_header
|
|
||||||
get api_node_history_path(node), :headers => auth_header
|
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
|
||||||
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0,
|
|
||||||
"redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history, even when logged in."
|
|
||||||
end
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# test the redaction of an old version of a node, while being
|
# test the redaction of an old version of a node, while being
|
||||||
# authorised as a moderator.
|
# authorised as a moderator.
|
||||||
|
@ -318,11 +337,11 @@ module Api
|
||||||
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
|
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_node_history_path(node)
|
get api_node_versions_path(node)
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0,
|
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0,
|
||||||
"node #{node_v3.node_id} version #{node_v3.version} should not be present in the history for moderators when not passing flag."
|
"node #{node_v3.node_id} version #{node_v3.version} should not be present in the history for moderators when not passing flag."
|
||||||
get api_node_history_path(node, :show_redactions => "true"), :headers => auth_header
|
get api_node_versions_path(node, :show_redactions => "true"), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 1,
|
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 1,
|
||||||
"node #{node_v3.node_id} version #{node_v3.version} should still be present in the history for moderators when passing flag."
|
"node #{node_v3.node_id} version #{node_v3.version} should still be present in the history for moderators when passing flag."
|
||||||
|
@ -346,7 +365,7 @@ module Api
|
||||||
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
|
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_node_history_path(node), :headers => auth_header
|
get api_node_versions_path(node), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0,
|
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0,
|
||||||
"redacted node #{node_v3.node_id} version #{node_v3.version} shouldn't be present in the history."
|
"redacted node #{node_v3.node_id} version #{node_v3.version} shouldn't be present in the history."
|
||||||
|
@ -399,7 +418,7 @@ module Api
|
||||||
assert_response :success, "After unredaction, node should not be gone for moderator."
|
assert_response :success, "After unredaction, node should not be gone for moderator."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_node_history_path(node)
|
get api_node_versions_path(node)
|
||||||
assert_response :success, "Unredaction shouldn't have stopped history working."
|
assert_response :success, "Unredaction shouldn't have stopped history working."
|
||||||
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1,
|
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1,
|
||||||
"node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for moderators without passing flag."
|
"node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for moderators without passing flag."
|
||||||
|
@ -411,7 +430,7 @@ module Api
|
||||||
assert_response :success, "After unredaction, node should be visible to normal users."
|
assert_response :success, "After unredaction, node should be visible to normal users."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_node_history_path(node)
|
get api_node_versions_path(node)
|
||||||
assert_response :success, "Unredaction shouldn't have stopped history working."
|
assert_response :success, "Unredaction shouldn't have stopped history working."
|
||||||
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1,
|
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1,
|
||||||
"node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for normal users without passing flag."
|
"node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for normal users without passing flag."
|
||||||
|
|
|
@ -7,16 +7,16 @@ module Api
|
||||||
def test_routes
|
def test_routes
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/api/0.6/relation/1/history", :method => :get },
|
{ :path => "/api/0.6/relation/1/history", :method => :get },
|
||||||
{ :controller => "api/old_relations", :action => "history", :id => "1" }
|
{ :controller => "api/old_relations", :action => "index", :relation_id => "1" }
|
||||||
|
)
|
||||||
|
assert_routing(
|
||||||
|
{ :path => "/api/0.6/relation/1/history.json", :method => :get },
|
||||||
|
{ :controller => "api/old_relations", :action => "index", :relation_id => "1", :format => "json" }
|
||||||
)
|
)
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/api/0.6/relation/1/2", :method => :get },
|
{ :path => "/api/0.6/relation/1/2", :method => :get },
|
||||||
{ :controller => "api/old_relations", :action => "show", :id => "1", :version => "2" }
|
{ :controller => "api/old_relations", :action => "show", :id => "1", :version => "2" }
|
||||||
)
|
)
|
||||||
assert_routing(
|
|
||||||
{ :path => "/api/0.6/relation/1/history.json", :method => :get },
|
|
||||||
{ :controller => "api/old_relations", :action => "history", :id => "1", :format => "json" }
|
|
||||||
)
|
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/api/0.6/relation/1/2.json", :method => :get },
|
{ :path => "/api/0.6/relation/1/2.json", :method => :get },
|
||||||
{ :controller => "api/old_relations", :action => "show", :id => "1", :version => "2", :format => "json" }
|
{ :controller => "api/old_relations", :action => "show", :id => "1", :version => "2", :format => "json" }
|
||||||
|
@ -27,19 +27,52 @@ module Api
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# -------------------------------------
|
##
|
||||||
# Test reading old relations.
|
|
||||||
# -------------------------------------
|
|
||||||
def test_history
|
|
||||||
# check that a visible relations is returned properly
|
# check that a visible relations is returned properly
|
||||||
get api_relation_history_path(create(:relation, :with_history))
|
def test_index
|
||||||
assert_response :success
|
relation = create(:relation, :with_history, :version => 2)
|
||||||
|
|
||||||
# check chat a non-existent relations is not returned
|
get api_relation_versions_path(relation)
|
||||||
get api_relation_history_path(0)
|
|
||||||
|
assert_response :success
|
||||||
|
assert_dom "osm:root", 1 do
|
||||||
|
assert_dom "> relation", 2 do |dom_relations|
|
||||||
|
assert_dom dom_relations[0], "> @id", relation.id.to_s
|
||||||
|
assert_dom dom_relations[0], "> @version", "1"
|
||||||
|
|
||||||
|
assert_dom dom_relations[1], "> @id", relation.id.to_s
|
||||||
|
assert_dom dom_relations[1], "> @version", "2"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# check that a non-existent relations is not returned
|
||||||
|
def test_index_invalid
|
||||||
|
get api_relation_versions_path(0)
|
||||||
assert_response :not_found
|
assert_response :not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# test that redacted relations aren't visible in the history
|
||||||
|
def test_index_redacted
|
||||||
|
relation = create(:relation, :with_history, :version => 2)
|
||||||
|
relation_v1 = relation.old_relations.find_by(:version => 1)
|
||||||
|
relation_v1.redact!(create(:redaction))
|
||||||
|
|
||||||
|
get api_relation_versions_path(relation)
|
||||||
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
|
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 0,
|
||||||
|
"redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history."
|
||||||
|
|
||||||
|
# not even to a logged-in user
|
||||||
|
auth_header = bearer_authorization_header
|
||||||
|
get api_relation_versions_path(relation), :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,
|
||||||
|
"redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history, even when logged in."
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# test the redaction of an old version of a relation, while not being
|
# test the redaction of an old version of a relation, while not being
|
||||||
# authorised.
|
# authorised.
|
||||||
|
@ -118,27 +151,6 @@ module Api
|
||||||
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API, even when logged in."
|
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API, even when logged in."
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
|
||||||
# test that redacted relations aren't visible in the history
|
|
||||||
def test_history_redacted
|
|
||||||
relation = create(:relation, :with_history, :version => 2)
|
|
||||||
relation_v1 = relation.old_relations.find_by(:version => 1)
|
|
||||||
relation_v1.redact!(create(:redaction))
|
|
||||||
|
|
||||||
get api_relation_history_path(relation)
|
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
|
||||||
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 0,
|
|
||||||
"redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history."
|
|
||||||
|
|
||||||
# not even to a logged-in user
|
|
||||||
auth_header = bearer_authorization_header
|
|
||||||
get api_old_relation_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
|
|
||||||
get api_relation_history_path(relation), :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,
|
|
||||||
"redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history, even when logged in."
|
|
||||||
end
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# test the redaction of an old version of a relation, while being
|
# test the redaction of an old version of a relation, while being
|
||||||
# authorised as a moderator.
|
# authorised as a moderator.
|
||||||
|
@ -159,11 +171,11 @@ module Api
|
||||||
assert_response :success, "After redaction, relation should not be gone for moderator, when flag passed."
|
assert_response :success, "After redaction, relation should not be gone for moderator, when flag passed."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_relation_history_path(relation), :headers => auth_header
|
get api_relation_versions_path(relation), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0,
|
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0,
|
||||||
"relation #{relation_v3.relation_id} version #{relation_v3.version} should not be present in the history for moderators when not passing flag."
|
"relation #{relation_v3.relation_id} version #{relation_v3.version} should not be present in the history for moderators when not passing flag."
|
||||||
get api_relation_history_path(relation, :show_redactions => "true"), :headers => auth_header
|
get api_relation_versions_path(relation, :show_redactions => "true"), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 1,
|
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 1,
|
||||||
"relation #{relation_v3.relation_id} version #{relation_v3.version} should still be present in the history for moderators when passing flag."
|
"relation #{relation_v3.relation_id} version #{relation_v3.version} should still be present in the history for moderators when passing flag."
|
||||||
|
@ -188,7 +200,7 @@ module Api
|
||||||
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."
|
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_relation_history_path(relation), :headers => auth_header
|
get api_relation_versions_path(relation), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0,
|
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0,
|
||||||
"redacted relation #{relation_v3.relation_id} version #{relation_v3.version} shouldn't be present in the history."
|
"redacted relation #{relation_v3.relation_id} version #{relation_v3.version} shouldn't be present in the history."
|
||||||
|
@ -239,7 +251,7 @@ module Api
|
||||||
assert_response :success, "After unredaction, relation should not be gone for moderator."
|
assert_response :success, "After unredaction, relation should not be gone for moderator."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_relation_history_path(relation), :headers => auth_header
|
get api_relation_versions_path(relation), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1,
|
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1,
|
||||||
"relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for moderators."
|
"relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for moderators."
|
||||||
|
@ -251,7 +263,7 @@ module Api
|
||||||
assert_response :success, "After redaction, node should not be gone for normal user."
|
assert_response :success, "After redaction, node should not be gone for normal user."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_relation_history_path(relation), :headers => auth_header
|
get api_relation_versions_path(relation), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1,
|
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1,
|
||||||
"relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for normal users."
|
"relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for normal users."
|
||||||
|
|
|
@ -7,16 +7,16 @@ module Api
|
||||||
def test_routes
|
def test_routes
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/api/0.6/way/1/history", :method => :get },
|
{ :path => "/api/0.6/way/1/history", :method => :get },
|
||||||
{ :controller => "api/old_ways", :action => "history", :id => "1" }
|
{ :controller => "api/old_ways", :action => "index", :way_id => "1" }
|
||||||
|
)
|
||||||
|
assert_routing(
|
||||||
|
{ :path => "/api/0.6/way/1/history.json", :method => :get },
|
||||||
|
{ :controller => "api/old_ways", :action => "index", :way_id => "1", :format => "json" }
|
||||||
)
|
)
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/api/0.6/way/1/2", :method => :get },
|
{ :path => "/api/0.6/way/1/2", :method => :get },
|
||||||
{ :controller => "api/old_ways", :action => "show", :id => "1", :version => "2" }
|
{ :controller => "api/old_ways", :action => "show", :id => "1", :version => "2" }
|
||||||
)
|
)
|
||||||
assert_routing(
|
|
||||||
{ :path => "/api/0.6/way/1/history.json", :method => :get },
|
|
||||||
{ :controller => "api/old_ways", :action => "history", :id => "1", :format => "json" }
|
|
||||||
)
|
|
||||||
assert_routing(
|
assert_routing(
|
||||||
{ :path => "/api/0.6/way/1/2.json", :method => :get },
|
{ :path => "/api/0.6/way/1/2.json", :method => :get },
|
||||||
{ :controller => "api/old_ways", :action => "show", :id => "1", :version => "2", :format => "json" }
|
{ :controller => "api/old_ways", :action => "show", :id => "1", :version => "2", :format => "json" }
|
||||||
|
@ -27,28 +27,59 @@ module Api
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# -------------------------------------
|
##
|
||||||
# Test reading old ways.
|
|
||||||
# -------------------------------------
|
|
||||||
|
|
||||||
def test_history_visible
|
|
||||||
# check that a visible way is returned properly
|
# check that a visible way is returned properly
|
||||||
get api_way_history_path(create(:way, :with_history))
|
def test_index
|
||||||
|
way = create(:way, :with_history, :version => 2)
|
||||||
|
|
||||||
|
get api_way_versions_path(way)
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
assert_dom "osm:root", 1 do
|
||||||
|
assert_dom "> way", 2 do |dom_ways|
|
||||||
|
assert_dom dom_ways[0], "> @id", way.id.to_s
|
||||||
|
assert_dom dom_ways[0], "> @version", "1"
|
||||||
|
|
||||||
|
assert_dom dom_ways[1], "> @id", way.id.to_s
|
||||||
|
assert_dom dom_ways[1], "> @version", "2"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_history_invisible
|
##
|
||||||
# check that an invisible way's history is returned properly
|
# check that an invisible way's history is returned properly
|
||||||
get api_way_history_path(create(:way, :with_history, :deleted))
|
def test_index_invisible
|
||||||
|
get api_way_versions_path(create(:way, :with_history, :deleted))
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_history_invalid
|
##
|
||||||
# check chat a non-existent way is not returned
|
# check chat a non-existent way is not returned
|
||||||
get api_way_history_path(0)
|
def test_index_invalid
|
||||||
|
get api_way_versions_path(0)
|
||||||
assert_response :not_found
|
assert_response :not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# test that redacted ways aren't visible in the history
|
||||||
|
def test_index_redacted
|
||||||
|
way = create(:way, :with_history, :version => 2)
|
||||||
|
way_v1 = way.old_ways.find_by(:version => 1)
|
||||||
|
way_v1.redact!(create(:redaction))
|
||||||
|
|
||||||
|
get api_way_versions_path(way)
|
||||||
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
|
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 0,
|
||||||
|
"redacted way #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history."
|
||||||
|
|
||||||
|
# not even to a logged-in user
|
||||||
|
auth_header = bearer_authorization_header
|
||||||
|
get api_way_versions_path(way), :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,
|
||||||
|
"redacted node #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history, even when logged in."
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# check that we can retrieve versions of a way
|
# check that we can retrieve versions of a way
|
||||||
def test_version
|
def test_version
|
||||||
|
@ -159,26 +190,6 @@ module Api
|
||||||
assert_response :forbidden, "Redacted way shouldn't be visible via the version API, even when logged in."
|
assert_response :forbidden, "Redacted way shouldn't be visible via the version API, even when logged in."
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
|
||||||
# test that redacted ways aren't visible in the history
|
|
||||||
def test_history_redacted
|
|
||||||
way = create(:way, :with_history, :version => 2)
|
|
||||||
way_v1 = way.old_ways.find_by(:version => 1)
|
|
||||||
way_v1.redact!(create(:redaction))
|
|
||||||
|
|
||||||
get api_way_history_path(way)
|
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
|
||||||
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 0,
|
|
||||||
"redacted way #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history."
|
|
||||||
|
|
||||||
# not even to a logged-in user
|
|
||||||
auth_header = bearer_authorization_header
|
|
||||||
get api_way_history_path(way), :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,
|
|
||||||
"redacted node #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history, even when logged in."
|
|
||||||
end
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# test the redaction of an old version of a way, while being
|
# test the redaction of an old version of a way, while being
|
||||||
# authorised as a moderator.
|
# authorised as a moderator.
|
||||||
|
@ -198,11 +209,11 @@ module Api
|
||||||
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
|
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_way_history_path(way), :headers => auth_header
|
get api_way_versions_path(way), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0,
|
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0,
|
||||||
"way #{way_v3.way_id} version #{way_v3.version} should not be present in the history for moderators when not passing flag."
|
"way #{way_v3.way_id} version #{way_v3.version} should not be present in the history for moderators when not passing flag."
|
||||||
get api_way_history_path(way, :show_redactions => "true"), :headers => auth_header
|
get api_way_versions_path(way, :show_redactions => "true"), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 1,
|
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 1,
|
||||||
"way #{way_v3.way_id} version #{way_v3.version} should still be present in the history for moderators when passing flag."
|
"way #{way_v3.way_id} version #{way_v3.version} should still be present in the history for moderators when passing flag."
|
||||||
|
@ -226,7 +237,7 @@ module Api
|
||||||
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
|
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_way_history_path(way), :headers => auth_header
|
get api_way_versions_path(way), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0,
|
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0,
|
||||||
"redacted way #{way_v3.way_id} version #{way_v3.version} shouldn't be present in the history."
|
"redacted way #{way_v3.way_id} version #{way_v3.version} shouldn't be present in the history."
|
||||||
|
@ -278,7 +289,7 @@ module Api
|
||||||
assert_response :success, "After unredaction, node should not be gone for moderator."
|
assert_response :success, "After unredaction, node should not be gone for moderator."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_way_history_path(way), :headers => auth_header
|
get api_way_versions_path(way), :headers => auth_header
|
||||||
assert_response :success, "Unredaction shouldn't have stopped history working."
|
assert_response :success, "Unredaction shouldn't have stopped history working."
|
||||||
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1,
|
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1,
|
||||||
"way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for moderators."
|
"way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for moderators."
|
||||||
|
@ -290,7 +301,7 @@ module Api
|
||||||
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
|
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
|
||||||
|
|
||||||
# and when accessed via history
|
# and when accessed via history
|
||||||
get api_way_history_path(way), :headers => auth_header
|
get api_way_versions_path(way), :headers => auth_header
|
||||||
assert_response :success, "Redaction shouldn't have stopped history working."
|
assert_response :success, "Redaction shouldn't have stopped history working."
|
||||||
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1,
|
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1,
|
||||||
"way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for normal users."
|
"way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for normal users."
|
||||||
|
@ -323,7 +334,7 @@ module Api
|
||||||
# look at all the versions of the way in the history and get each version from
|
# look at all the versions of the way in the history and get each version from
|
||||||
# the versions call. check that they're the same.
|
# the versions call. check that they're the same.
|
||||||
def check_history_equals_versions(way_id)
|
def check_history_equals_versions(way_id)
|
||||||
get api_way_history_path(way_id)
|
get api_way_versions_path(way_id)
|
||||||
assert_response :success, "can't get way #{way_id} from API"
|
assert_response :success, "can't get way #{way_id} from API"
|
||||||
history_doc = XML::Parser.string(@response.body).parse
|
history_doc = XML::Parser.string(@response.body).parse
|
||||||
assert_not_nil history_doc, "parsing way #{way_id} history failed"
|
assert_not_nil history_doc, "parsing way #{way_id} history failed"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue