Merge remote-tracking branch 'openstreetmap/pull/1367'

This commit is contained in:
Tom Hughes 2016-12-18 16:29:33 +00:00
commit 970e1a99d7
36 changed files with 366 additions and 735 deletions

View file

@ -64,7 +64,7 @@ Metrics/BlockNesting:
# Offense count: 62 # Offense count: 62
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/ClassLength: Metrics/ClassLength:
Max: 1659 Max: 1660
# Offense count: 69 # Offense count: 69
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:

View file

@ -531,7 +531,10 @@ class AmfControllerTest < ActionController::TestCase
def test_findrelations_by_tags def test_findrelations_by_tags
visible_relation = current_relations(:visible_relation) visible_relation = current_relations(:visible_relation)
create(:relation_tag, :relation => visible_relation, :k => "test", :v => "yes")
used_relation = current_relations(:used_relation) used_relation = current_relations(:used_relation)
create(:relation_tag, :relation => used_relation, :k => "test", :v => "yes")
create(:relation_tag, :relation => used_relation, :k => "name", :v => "Test Relation")
amf_content "findrelations", "/1", ["yes"] amf_content "findrelations", "/1", ["yes"]
post :amf_read post :amf_read

View file

@ -53,6 +53,7 @@ class ApiControllerTest < ActionController::TestCase
def test_map def test_map
node = current_nodes(:used_node_1) node = current_nodes(:used_node_1)
tag = create(:node_tag, :node => node)
# Need to split the min/max lat/lon out into their own variables here # Need to split the min/max lat/lon out into their own variables here
# so that we can test they are returned later. # so that we can test they are returned later.
minlon = node.lon - 0.1 minlon = node.lon - 0.1
@ -70,7 +71,7 @@ class ApiControllerTest < ActionController::TestCase
assert_select "bounds[minlon='#{minlon}'][minlat='#{minlat}'][maxlon='#{maxlon}'][maxlat='#{maxlat}']", :count => 1 assert_select "bounds[minlon='#{minlon}'][minlat='#{minlat}'][maxlon='#{maxlon}'][maxlat='#{maxlat}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{node.lat}'][lon='#{node.lon}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do assert_select "node[id='#{node.id}'][lat='#{node.lat}'][lon='#{node.lon}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
# This should really be more generic # This should really be more generic
assert_select "tag[k='test'][v='yes']" assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end end
assert_select "way", :count => 2 assert_select "way", :count => 2
assert_select "way[id='1']", :count => 1 assert_select "way[id='1']", :count => 1
@ -84,6 +85,7 @@ class ApiControllerTest < ActionController::TestCase
# the same as the node we are looking at # the same as the node we are looking at
def test_map_inclusive def test_map_inclusive
node = current_nodes(:used_node_1) node = current_nodes(:used_node_1)
tag = create(:node_tag, :node => node)
bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}" bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
get :map, :bbox => bbox get :map, :bbox => bbox
assert_response :success, "The map call should have succeeded" assert_response :success, "The map call should have succeeded"
@ -91,7 +93,7 @@ class ApiControllerTest < ActionController::TestCase
assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1 assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
assert_select "node[id='#{node.id}'][lat='#{node.lat}'][lon='#{node.lon}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do assert_select "node[id='#{node.id}'][lat='#{node.lat}'][lon='#{node.lon}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
# This should really be more generic # This should really be more generic
assert_select "tag[k='test'][v='yes']" assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end end
assert_select "way", :count => 2 assert_select "way", :count => 2
assert_select "way[id='1']", :count => 1 assert_select "way[id='1']", :count => 1

View file

@ -1388,7 +1388,10 @@ EOF
end end
def test_changeset_download def test_changeset_download
tag = create(:old_node_tag, :old_node => nodes(:used_node_2))
get :download, :id => changesets(:normal_user_first_change).id get :download, :id => changesets(:normal_user_first_change).id
assert_response :success assert_response :success
assert_template nil assert_template nil
# print @response.body # print @response.body
@ -1396,7 +1399,7 @@ EOF
assert_select "osmChange[version='#{API_VERSION}'][generator='#{GENERATOR}']" do assert_select "osmChange[version='#{API_VERSION}'][generator='#{GENERATOR}']" do
assert_select "create", :count => 5 assert_select "create", :count => 5
assert_select "create>node[id='#{nodes(:used_node_2).node_id}'][visible='#{nodes(:used_node_2).visible?}'][version='#{nodes(:used_node_2).version}']" do assert_select "create>node[id='#{nodes(:used_node_2).node_id}'][visible='#{nodes(:used_node_2).visible?}'][version='#{nodes(:used_node_2).version}']" do
assert_select "tag[k='#{node_tags(:t3).k}'][v='#{node_tags(:t3).v}']" assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
end end
assert_select "create>node[id='#{nodes(:visible_node).node_id}']" assert_select "create>node[id='#{nodes(:visible_node).node_id}']"
end end

View file

@ -437,13 +437,14 @@ class NodeControllerTest < ActionController::TestCase
## ##
# test adding tags to a node # test adding tags to a node
def test_duplicate_tags def test_duplicate_tags
existing = create(:node_tag, :node => current_nodes(:public_visible_node))
# setup auth # setup auth
basic_authorization(users(:public_user).email, "test") basic_authorization(users(:public_user).email, "test")
# add an identical tag to the node # add an identical tag to the node
tag_xml = XML::Node.new("tag") tag_xml = XML::Node.new("tag")
tag_xml["k"] = current_node_tags(:public_v_t1).k tag_xml["k"] = existing.k
tag_xml["v"] = current_node_tags(:public_v_t1).v tag_xml["v"] = existing.v
# add the tag into the existing xml # add the tag into the existing xml
node_xml = current_nodes(:public_visible_node).to_xml node_xml = current_nodes(:public_visible_node).to_xml
@ -454,7 +455,7 @@ class NodeControllerTest < ActionController::TestCase
put :update, :id => current_nodes(:public_visible_node).id put :update, :id => current_nodes(:public_visible_node).id
assert_response :bad_request, assert_response :bad_request,
"adding duplicate tags to a node should fail with 'bad request'" "adding duplicate tags to a node should fail with 'bad request'"
assert_equal "Element node/#{current_nodes(:public_visible_node).id} has duplicate tags with key #{current_node_tags(:t1).k}", @response.body assert_equal "Element node/#{current_nodes(:public_visible_node).id} has duplicate tags with key #{existing.k}", @response.body
end end
# test whether string injection is possible # test whether string injection is possible

View file

@ -86,10 +86,14 @@ class OldNodeControllerTest < ActionController::TestCase
basic_authorization(users(:public_user).email, "test") basic_authorization(users(:public_user).email, "test")
# setup a simple XML node # setup a simple XML node
create_list(:node_tag, 2, :node => current_nodes(:node_with_versions))
xml_doc = current_nodes(:node_with_versions).to_xml xml_doc = current_nodes(:node_with_versions).to_xml
xml_node = xml_doc.find("//osm/node").first xml_node = xml_doc.find("//osm/node").first
nodeid = current_nodes(:node_with_versions).id nodeid = current_nodes(:node_with_versions).id
# Ensure that the current tags are propagated to the history too
propagate_tags(current_nodes(:node_with_versions), nodes(:node_with_versions_v4))
# keep a hash of the versions => string, as we'll need something # keep a hash of the versions => string, as we'll need something
# to test against later # to test against later
versions = {} versions = {}
@ -161,6 +165,17 @@ class OldNodeControllerTest < ActionController::TestCase
# Test that getting the current version is identical to picking # Test that getting the current version is identical to picking
# that version with the version URI call. # that version with the version URI call.
def test_current_version def test_current_version
create(:node_tag, :node => current_nodes(:visible_node))
create(:node_tag, :node => current_nodes(:used_node_1))
create(:node_tag, :node => current_nodes(:used_node_2))
create(:node_tag, :node => current_nodes(:node_used_by_relationship))
create(:node_tag, :node => current_nodes(:node_with_versions))
propagate_tags(current_nodes(:visible_node), nodes(:visible_node))
propagate_tags(current_nodes(:used_node_1), nodes(:used_node_1))
propagate_tags(current_nodes(:used_node_2), nodes(:used_node_2))
propagate_tags(current_nodes(:node_used_by_relationship), nodes(:node_used_by_relationship))
propagate_tags(current_nodes(:node_with_versions), nodes(:node_with_versions_v4))
check_current_version(current_nodes(:visible_node)) check_current_version(current_nodes(:visible_node))
check_current_version(current_nodes(:used_node_1)) check_current_version(current_nodes(:used_node_1))
check_current_version(current_nodes(:used_node_2)) check_current_version(current_nodes(:used_node_2))
@ -377,4 +392,10 @@ class OldNodeControllerTest < ActionController::TestCase
def precision(f) def precision(f)
(f * GeoRecord::SCALE).round.to_f / GeoRecord::SCALE (f * GeoRecord::SCALE).round.to_f / GeoRecord::SCALE
end end
def propagate_tags(node, old_node)
node.tags.each do |k, v|
create(:old_node_tag, :old_node => old_node, :k => k, :v => v)
end
end
end end

View file

@ -46,6 +46,13 @@ class OldWayControllerTest < ActionController::TestCase
## ##
# check that we can retrieve versions of a way # check that we can retrieve versions of a way
def test_version def test_version
create(:way_tag, :way => current_ways(:visible_way))
create(:way_tag, :way => current_ways(:used_way))
create(:way_tag, :way => current_ways(:way_with_versions))
propagate_tags(current_ways(:visible_way), ways(:visible_way))
propagate_tags(current_ways(:used_way), ways(:used_way))
propagate_tags(current_ways(:way_with_versions), ways(:way_with_versions_v4))
check_current_version(current_ways(:visible_way).id) check_current_version(current_ways(:visible_way).id)
check_current_version(current_ways(:used_way).id) check_current_version(current_ways(:used_way).id)
check_current_version(current_ways(:way_with_versions).id) check_current_version(current_ways(:way_with_versions).id)
@ -276,4 +283,10 @@ class OldWayControllerTest < ActionController::TestCase
# now redact it # now redact it
post :redact, :id => way.way_id, :version => way.version, :redaction => redaction.id post :redact, :id => way.way_id, :version => way.version, :redaction => redaction.id
end end
def propagate_tags(way, old_way)
way.tags.each do |k, v|
create(:old_way_tag, :old_way => old_way, :k => k, :v => v)
end
end
end end

View file

@ -337,6 +337,7 @@ class RelationControllerTest < ActionController::TestCase
def test_update_relation_tags def test_update_relation_tags
basic_authorization "test@example.com", "test" basic_authorization "test@example.com", "test"
rel_id = current_relations(:multi_tag_relation).id rel_id = current_relations(:multi_tag_relation).id
create_list(:relation_tag, 4, :relation => current_relations(:multi_tag_relation))
cs_id = changesets(:public_user_first_change).id cs_id = changesets(:public_user_first_change).id
with_relation(rel_id) do |rel| with_relation(rel_id) do |rel|
@ -366,6 +367,7 @@ class RelationControllerTest < ActionController::TestCase
def test_update_relation_tags_via_upload def test_update_relation_tags_via_upload
basic_authorization users(:public_user).email, "test" basic_authorization users(:public_user).email, "test"
rel_id = current_relations(:multi_tag_relation).id rel_id = current_relations(:multi_tag_relation).id
create_list(:relation_tag, 4, :relation => current_relations(:multi_tag_relation))
cs_id = changesets(:public_user_first_change).id cs_id = changesets(:public_user_first_change).id
with_relation(rel_id) do |rel| with_relation(rel_id) do |rel|

View file

@ -43,6 +43,11 @@ class SearchControllerTest < ActionController::TestCase
## ##
# test searching ways # test searching ways
def test_search_ways def test_search_ways
[:visible_way, :invisible_way, :used_way].each do |way|
create(:way_tag, :way => current_ways(way), :k => "test", :v => "yes")
end
create(:way_tag, :way => current_ways(:used_way), :k => "name", :v => "Test Way")
get :search_ways, :type => "test" get :search_ways, :type => "test"
assert_response :service_unavailable assert_response :service_unavailable
assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"] assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
@ -59,6 +64,11 @@ class SearchControllerTest < ActionController::TestCase
## ##
# test searching relations # test searching relations
def test_search_relations def test_search_relations
[:visible_relation, :invisible_relation, :used_relation].each do |relation|
create(:relation_tag, :relation => current_relations(relation), :k => "test", :v => "yes")
end
create(:relation_tag, :relation => current_relations(:used_relation), :k => "name", :v => "Test Relation")
get :search_relations, :type => "test" get :search_relations, :type => "test"
assert_response :service_unavailable assert_response :service_unavailable
assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"] assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]

View file

@ -538,10 +538,12 @@ class WayControllerTest < ActionController::TestCase
# setup auth # setup auth
basic_authorization(users(:normal_user).email, "test") basic_authorization(users(:normal_user).email, "test")
existing = create(:way_tag, :way => current_ways(:visible_way))
# add an identical tag to the way # add an identical tag to the way
tag_xml = XML::Node.new("tag") tag_xml = XML::Node.new("tag")
tag_xml["k"] = current_way_tags(:t1).k tag_xml["k"] = existing.k
tag_xml["v"] = current_way_tags(:t1).v tag_xml["v"] = existing.v
# add the tag into the existing xml # add the tag into the existing xml
way_xml = current_ways(:visible_way).to_xml way_xml = current_ways(:visible_way).to_xml
@ -559,8 +561,8 @@ class WayControllerTest < ActionController::TestCase
# add an identical tag to the way # add an identical tag to the way
tag_xml = XML::Node.new("tag") tag_xml = XML::Node.new("tag")
tag_xml["k"] = current_way_tags(:t1).k tag_xml["k"] = existing.k
tag_xml["v"] = current_way_tags(:t1).v tag_xml["v"] = existing.v
# add the tag into the existing xml # add the tag into the existing xml
way_xml = current_ways(:visible_way).to_xml way_xml = current_ways(:visible_way).to_xml
@ -571,7 +573,7 @@ class WayControllerTest < ActionController::TestCase
put :update, :id => current_ways(:visible_way).id put :update, :id => current_ways(:visible_way).id
assert_response :bad_request, assert_response :bad_request,
"adding a duplicate tag to a way should fail with 'bad request'" "adding a duplicate tag to a way should fail with 'bad request'"
assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key #{current_way_tags(:t1).k}", @response.body assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key #{existing.k}", @response.body
end end
## ##

View file

@ -0,0 +1,9 @@
FactoryGirl.define do
factory :node_tag do
sequence(:k) { |n| "Key #{n}" }
sequence(:v) { |n| "Value #{n}" }
# Fixme requires node factory
node_id 1
end
end

View file

@ -0,0 +1,10 @@
FactoryGirl.define do
factory :old_node_tag do
sequence(:k) { |n| "Key #{n}" }
sequence(:v) { |n| "Value #{n}" }
# Fixme requires old_node factory
node_id 1
version 1
end
end

View file

@ -0,0 +1,10 @@
FactoryGirl.define do
factory :old_relation_tag do
sequence(:k) { |n| "Key #{n}" }
sequence(:v) { |n| "Value #{n}" }
# Fixme requires old_relation factory
relation_id 1
version 1
end
end

View file

@ -0,0 +1,10 @@
FactoryGirl.define do
factory :old_way_tag do
sequence(:k) { |n| "Key #{n}" }
sequence(:v) { |n| "Value #{n}" }
# Fixme requires old_way factory
way_id 1
version 1
end
end

View file

@ -0,0 +1,9 @@
FactoryGirl.define do
factory :relation_tag do
sequence(:k) { |n| "Key #{n}" }
sequence(:v) { |n| "Value #{n}" }
# Fixme requires relation factory
relation_id 1
end
end

View file

@ -0,0 +1,9 @@
FactoryGirl.define do
factory :way_tag do
sequence(:k) { |n| "Key #{n}" }
sequence(:v) { |n| "Value #{n}" }
# Fixme requires way factory
way_id 1
end
end

View file

@ -1,64 +0,0 @@
t1:
node_id: 1
k: 'testvisible'
v: 'yes'
t2:
node_id: 2
k: 'testused'
v: 'yes'
t3:
node_id: 3
k: 'test'
v: 'yes'
t4:
node_id: 4
k: 'test'
v: 'yes'
nv_t1:
node_id: 15
k: 'testing'
v: 'added in node version 3'
nv_t2:
node_id: 15
k: 'testing two'
v: 'modified in node version 4'
public_v_t1:
node_id: 16
k: 'testvisible'
v: 'yes'
nwn_name:
node_id: 18
k: 'name'
v: 'Test Node'
nwn_name_pt:
node_id: 18
k: 'name:pt'
v: 'Nó teste'
nwn_building:
node_id: 18
k: 'building'
v: 'yes'
nwn_tourism:
node_id: 18
k: 'tourism'
v: 'museum'
nwn_shop:
node_id: 18
k: 'shop'
v: 'gift'
nwrwn_ref:
node_id: 19
k: 'ref'
v: '3.1415926'

View file

@ -1,49 +0,0 @@
t1:
relation_id: 1
k: 'test'
v: 'yes'
t2:
relation_id: 2
k: 'test'
v: 'yes'
t3:
relation_id: 3
k: 'test'
v: 'yes'
t3_2:
relation_id: 3
k: 'name'
v: 'Test Relation'
mt_1:
relation_id: 4
k: 'tag1'
v: 'val1'
mt_2:
relation_id: 4
k: 'tag2'
v: 'val2'
mt_3:
relation_id: 4
k: 'tag3'
v: 'val3'
mt_4:
relation_id: 4
k: 'tag4'
v: 'val4'
rv_t1:
relation_id: 8
k: 'testing'
v: 'added in relation version 3'
rv_t2:
relation_id: 8
k: 'testing two'
v: 'modified in relation version 4'

View file

@ -1,29 +0,0 @@
t1:
way_id: 1
k: 'test'
v: 'yes'
t2:
way_id: 2
k: 'test'
v: 'yes'
t3:
way_id: 3
k: 'test'
v: 'yes'
t3_t2:
way_id: 3
k: 'name'
v: 'Test Way'
wv_t1:
way_id: 4
k: 'testing'
v: 'added in way version 3'
wv_t2:
way_id: 4
k: 'testing two'
v: 'modified in way version 4'

View file

@ -1,113 +0,0 @@
t1:
node_id: 1
k: 'testvisible'
v: 'yes'
version: 1
t2:
node_id: 3
k: 'test'
v: 'yes'
version: 1
t3:
node_id: 4
k: 'test'
v: 'yes'
version: 1
nv3_t1:
node_id: 15
k: 'testing'
v: 'added in node version 3'
version: 3
nv3_t2:
node_id: 15
k: 'testing two'
v: 'added in node version 3'
version: 3
nv3_t3:
node_id: 15
k: 'testing three'
v: 'added in node version 3'
version: 3
nv4_t1:
node_id: 15
k: 'testing'
v: 'added in node version 3'
version: 4
nv4_t2:
node_id: 15
k: 'testing two'
v: 'modified in node version 4'
version: 4
public_v_t1:
node_id: 16
k: 'testvisible'
v: 'yes'
version: 1
nwnv1_name:
node_id: 18
k: 'name'
v: 'Test Node'
version: 1
nwnv1_name_pt:
node_id: 18
k: 'name:pt'
v: 'Nó teste'
version: 1
nwnv1_building:
node_id: 18
k: 'building'
v: 'yes'
version: 1
nwnv1_tourism:
node_id: 18
k: 'tourism'
v: 'museum'
version: 1
nwnv1_shop:
node_id: 18
k: 'shop'
v: 'gift'
version: 1
nwnv2_name:
node_id: 18
k: 'name'
v: 'Test Node'
version: 2
nwnv2_name_pt:
node_id: 18
k: 'name:pt'
v: 'Nó teste'
version: 2
nwnv2_building:
node_id: 18
k: 'building'
v: 'yes'
version: 2
nwnv2_tourism:
node_id: 18
k: 'tourism'
v: 'museum'
version: 2
nwnv2_shop:
node_id: 18
k: 'shop'
v: 'gift'
version: 2

View file

@ -1,77 +0,0 @@
t1:
relation_id: 1
k: 'test'
v: 'yes'
version: 1
t2:
relation_id: 2
k: 'test'
v: 'yes'
version: 1
t3:
relation_id: 3
k: 'test'
v: 'yes'
version: 1
t3_2:
relation_id: 3
k: 'name'
v: 'Test Relation'
version: 1
mt_1:
relation_id: 4
k: 'tag1'
v: 'val1'
version: 1
mt_2:
relation_id: 4
k: 'tag2'
v: 'val2'
version: 1
mt_3:
relation_id: 4
k: 'tag3'
v: 'val3'
version: 1
mt_4:
relation_id: 4
k: 'tag4'
v: 'val4'
version: 1
rv3_t1:
relation_id: 8
k: 'testing'
v: 'added in relation version 3'
version: 3
rv3_t2:
relation_id: 8
k: 'testing two'
v: 'added in relation version 3'
version: 3
rv3_t3:
relation_id: 8
k: 'testing three'
v: 'added in relation version 3'
version: 3
rv4_t1:
relation_id: 8
k: 'testing'
v: 'added in relation version 3'
version: 4
rv4_t2:
relation_id: 8
k: 'testing two'
v: 'modified in relation version 4'
version: 4

View file

@ -1,77 +0,0 @@
t1:
way_id: 1
k: 'test'
v: 'yes'
version: 1
t2:
way_id: 2
k: 'test'
v: 'yes'
version: 1
t3:
way_id: 3
k: 'test'
v: 'yes'
version: 1
t3_t2:
way_id: 3
k: 'name'
v: 'Test Way'
version: 1
wv3_t1:
way_id: 4
k: 'testing'
v: 'added in way version 3'
version: 3
wv3_t2:
way_id: 4
k: 'testing two'
v: 'added in way version 3'
version: 3
wv3_t3:
way_id: 4
k: 'testing three'
v: 'added in way version 3'
version: 3
wv4_t1:
way_id: 4
k: 'testing'
v: 'added in way version 3'
version: 4
wv4_t2:
way_id: 4
k: 'testing two'
v: 'modified in way version 4'
version: 4
t6_v1:
way_id: 6
k: 'test'
v: 'yes'
version: 1
t6_v2:
way_id: 6
k: 'test'
v: 'yes'
version: 2
t6_v3:
way_id: 6
k: 'test'
v: 'yes'
version: 3
t6_v4:
way_id: 6
k: 'test'
v: 'yes'
version: 4

View file

@ -17,6 +17,12 @@ class BrowseHelperTest < ActionView::TestCase
end end
def test_printable_name def test_printable_name
add_tags_selection(current_nodes(:node_with_name))
create(:node_tag, :node => current_nodes(:node_with_ref_without_name), :k => "ref", :v => "3.1415926")
add_old_tags_selection(nodes(:node_with_name_current_version))
add_old_tags_selection(nodes(:node_with_name_redacted_version))
# current_nodes(:redacted_node) is deleted, so has no tags.
assert_dom_equal "17", printable_name(current_nodes(:redacted_node)) assert_dom_equal "17", printable_name(current_nodes(:redacted_node))
assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name)) assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(current_nodes(:node_with_name))
assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version)) assert_dom_equal "<bdi>Test Node</bdi> (<bdi>18</bdi>)", printable_name(nodes(:node_with_name_current_version))
@ -57,19 +63,29 @@ class BrowseHelperTest < ActionView::TestCase
end end
def test_link_class def test_link_class
add_tags_selection(current_nodes(:node_with_name))
assert_equal "node", link_class("node", current_nodes(:visible_node)) assert_equal "node", link_class("node", current_nodes(:visible_node))
assert_equal "node deleted", link_class("node", current_nodes(:invisible_node)) assert_equal "node deleted", link_class("node", current_nodes(:invisible_node))
assert_equal "node deleted", link_class("node", current_nodes(:redacted_node)) assert_equal "node deleted", link_class("node", current_nodes(:redacted_node))
assert_equal "node building yes shop gift tourism museum", link_class("node", current_nodes(:node_with_name)) assert_equal "node building yes shop gift tourism museum", link_class("node", current_nodes(:node_with_name))
add_old_tags_selection(nodes(:node_with_name_current_version))
add_old_tags_selection(nodes(:node_with_name_redacted_version))
assert_equal "node building yes shop gift tourism museum", link_class("node", nodes(:node_with_name_current_version)) assert_equal "node building yes shop gift tourism museum", link_class("node", nodes(:node_with_name_current_version))
assert_equal "node deleted", link_class("node", nodes(:node_with_name_redacted_version)) assert_equal "node deleted", link_class("node", nodes(:node_with_name_redacted_version))
end end
def test_link_title def test_link_title
add_tags_selection(current_nodes(:node_with_name))
assert_equal "", link_title(current_nodes(:visible_node)) assert_equal "", link_title(current_nodes(:visible_node))
assert_equal "", link_title(current_nodes(:invisible_node)) assert_equal "", link_title(current_nodes(:invisible_node))
assert_equal "", link_title(current_nodes(:redacted_node)) assert_equal "", link_title(current_nodes(:redacted_node))
assert_equal "building=yes, shop=gift, and tourism=museum", link_title(current_nodes(:node_with_name)) assert_equal "building=yes, shop=gift, and tourism=museum", link_title(current_nodes(:node_with_name))
add_old_tags_selection(nodes(:node_with_name_current_version))
add_old_tags_selection(nodes(:node_with_name_redacted_version))
assert_equal "building=yes, shop=gift, and tourism=museum", link_title(nodes(:node_with_name_current_version)) assert_equal "building=yes, shop=gift, and tourism=museum", link_title(nodes(:node_with_name_current_version))
assert_equal "", link_title(nodes(:node_with_name_redacted_version)) assert_equal "", link_title(nodes(:node_with_name_redacted_version))
end end
@ -106,12 +122,17 @@ class BrowseHelperTest < ActionView::TestCase
end end
def test_icon_tags def test_icon_tags
add_tags_selection(current_nodes(:node_with_name))
tags = icon_tags(current_nodes(:node_with_name)) tags = icon_tags(current_nodes(:node_with_name))
assert_equal 3, tags.count assert_equal 3, tags.count
assert tags.include?(%w(building yes)) assert tags.include?(%w(building yes))
assert tags.include?(%w(tourism museum)) assert tags.include?(%w(tourism museum))
assert tags.include?(%w(shop gift)) assert tags.include?(%w(shop gift))
add_old_tags_selection(nodes(:node_with_name_current_version))
add_old_tags_selection(nodes(:node_with_name_redacted_version))
tags = icon_tags(nodes(:node_with_name_current_version)) tags = icon_tags(nodes(:node_with_name_current_version))
assert_equal 3, tags.count assert_equal 3, tags.count
assert tags.include?(%w(building yes)) assert tags.include?(%w(building yes))
@ -306,4 +327,24 @@ class BrowseHelperTest < ActionView::TestCase
link = telephone_link("phone", "+1 (234) 567-890") link = telephone_link("phone", "+1 (234) 567-890")
assert_equal "tel:+1(234)567-890", link assert_equal "tel:+1(234)567-890", link
end end
def add_old_tags_selection(old_node)
{ "building" => "yes",
"shop" => "gift",
"tourism" => "museum",
"name" => "Test Node",
"name:pt" => "Nó teste" }.each do |key, value|
create(:old_node_tag, :old_node => old_node, :k => key, :v => value)
end
end
def add_tags_selection(node)
{ "building" => "yes",
"shop" => "gift",
"tourism" => "museum",
"name" => "Test Node",
"name:pt" => "Nó teste" }.each do |key, value|
create(:node_tag, :node => node, :k => key, :v => value)
end
end
end end

View file

@ -1,64 +1,34 @@
require "test_helper" require "test_helper"
class NodeTagTest < ActiveSupport::TestCase class NodeTagTest < ActiveSupport::TestCase
api_fixtures
def test_tag_count
assert_equal 13, NodeTag.count
node_tag_count(:visible_node, 1)
node_tag_count(:invisible_node, 1)
node_tag_count(:used_node_1, 1)
node_tag_count(:used_node_2, 1)
node_tag_count(:node_with_versions, 2)
end
def node_tag_count(node, count)
nod = current_nodes(node)
assert_equal count, nod.node_tags.count
end
def test_length_key_valid def test_length_key_valid
key = "k" tag = create(:node_tag)
(0..255).each do |i| (0..255).each do |i|
tag = NodeTag.new tag.k = "k" * i
tag.node_id = current_node_tags(:t1).node_id
tag.k = key * i
tag.v = "v"
assert tag.valid? assert tag.valid?
end end
end end
def test_length_value_valid def test_length_value_valid
val = "v" tag = create(:node_tag)
(0..255).each do |i| (0..255).each do |i|
tag = NodeTag.new tag.v = "v" * i
tag.node_id = current_node_tags(:t1).node_id
tag.k = "k"
tag.v = val * i
assert tag.valid? assert tag.valid?
end end
end end
def test_length_key_invalid def test_length_key_invalid
["k" * 256].each do |i| tag = create(:node_tag)
tag = NodeTag.new tag.k = "k" * 256
tag.node_id = current_node_tags(:t1).node_id assert !tag.valid?, "Key should be too long"
tag.k = i assert tag.errors[:k].any?
tag.v = "v"
assert !tag.valid?, "Key should be too long"
assert tag.errors[:k].any?
end
end end
def test_length_value_invalid def test_length_value_invalid
["k" * 256].each do |i| tag = create(:node_tag)
tag = NodeTag.new tag.v = "v" * 256
tag.node_id = current_node_tags(:t1).node_id assert !tag.valid?, "Value should be too long"
tag.k = "k" assert tag.errors[:v].any?
tag.v = i
assert !tag.valid?, "Value should be too long"
assert tag.errors[:v].any?
end
end end
def test_empty_node_tag_invalid def test_empty_node_tag_invalid
@ -68,10 +38,11 @@ class NodeTagTest < ActiveSupport::TestCase
end end
def test_uniqueness def test_uniqueness
existing = create(:node_tag)
tag = NodeTag.new tag = NodeTag.new
tag.node_id = current_node_tags(:t1).node_id tag.node_id = existing.node_id
tag.k = current_node_tags(:t1).k tag.k = existing.k
tag.v = current_node_tags(:t1).v tag.v = existing.v
assert tag.new_record? assert tag.new_record?
assert !tag.valid? assert !tag.valid?
assert_raise(ActiveRecord::RecordInvalid) { tag.save! } assert_raise(ActiveRecord::RecordInvalid) { tag.save! }

View file

@ -316,20 +316,23 @@ class NodeTest < ActiveSupport::TestCase
def test_node_tags def test_node_tags
node = current_nodes(:node_with_versions) node = current_nodes(:node_with_versions)
taglist = create_list(:node_tag, 2, :node => node)
tags = Node.find(node.id).node_tags.order(:k) tags = Node.find(node.id).node_tags.order(:k)
assert_equal 2, tags.count assert_equal 2, tags.count
assert_equal "testing", tags[0].k taglist.sort_by!(&:k).each_index do |i|
assert_equal "added in node version 3", tags[0].v assert_equal taglist[i].k, tags[i].k
assert_equal "testing two", tags[1].k assert_equal taglist[i].v, tags[i].v
assert_equal "modified in node version 4", tags[1].v end
end end
def test_tags def test_tags
node = current_nodes(:node_with_versions) node = current_nodes(:node_with_versions)
taglist = create_list(:node_tag, 2, :node => node)
tags = Node.find(node.id).tags tags = Node.find(node.id).tags
assert_equal 2, tags.size assert_equal 2, tags.size
assert_equal "added in node version 3", tags["testing"] taglist.each do |tag|
assert_equal "modified in node version 4", tags["testing two"] assert_equal tag.v, tags[tag.k]
end
end end
def test_containing_relation_members def test_containing_relation_members

View file

@ -1,58 +1,34 @@
require "test_helper" require "test_helper"
class OldNodeTagTest < ActiveSupport::TestCase class OldNodeTagTest < ActiveSupport::TestCase
api_fixtures
def test_old_node_tag_count
assert_equal 19, OldNodeTag.count, "Unexpected number of fixtures loaded."
end
def test_length_key_valid def test_length_key_valid
key = "k" tag = create(:old_node_tag)
(0..255).each do |i| (0..255).each do |i|
tag = OldNodeTag.new tag.k = "k" * i
tag.node_id = node_tags(:t1).node_id
tag.version = node_tags(:t1).version
tag.k = key * i
tag.v = "v"
assert tag.valid? assert tag.valid?
end end
end end
def test_length_value_valid def test_length_value_valid
val = "v" tag = create(:old_node_tag)
(0..255).each do |i| (0..255).each do |i|
tag = OldNodeTag.new tag.v = "v" * i
tag.node_id = node_tags(:t1).node_id
tag.version = node_tags(:t1).version
tag.k = "k"
tag.v = val * i
assert tag.valid? assert tag.valid?
end end
end end
def test_length_key_invalid def test_length_key_invalid
["k" * 256].each do |i| tag = create(:old_node_tag)
tag = OldNodeTag.new tag.k = "k" * 256
tag.node_id = node_tags(:t1).node_id assert !tag.valid?
tag.version = node_tags(:t1).version assert tag.errors[:k].any?
tag.k = i
tag.v = "v", "Key should be too long"
assert !tag.valid?
assert tag.errors[:k].any?
end
end end
def test_length_value_invalid def test_length_value_invalid
["k" * 256].each do |i| tag = create(:old_node_tag)
tag = OldNodeTag.new tag.v = "v" * 256
tag.node_id = node_tags(:t1).node_id assert !tag.valid?, "Value should be too long"
tag.version = node_tags(:t1).version assert tag.errors[:v].any?
tag.k = "k"
tag.v = i
assert !tag.valid?, "Value should be too long"
assert tag.errors[:v].any?
end
end end
def test_empty_tag_invalid def test_empty_tag_invalid
@ -62,11 +38,12 @@ class OldNodeTagTest < ActiveSupport::TestCase
end end
def test_uniqueness def test_uniqueness
existing = create(:old_node_tag)
tag = OldNodeTag.new tag = OldNodeTag.new
tag.node_id = node_tags(:t1).node_id tag.node_id = existing.node_id
tag.version = node_tags(:t1).version tag.version = existing.version
tag.k = node_tags(:t1).k tag.k = existing.k
tag.v = node_tags(:t1).v tag.v = existing.v
assert tag.new_record? assert tag.new_record?
assert !tag.valid? assert !tag.valid?
assert_raise(ActiveRecord::RecordInvalid) { tag.save! } assert_raise(ActiveRecord::RecordInvalid) { tag.save! }

View file

@ -76,6 +76,9 @@ class OldNodeTest < ActiveSupport::TestCase
end end
def test_node_tags def test_node_tags
taglist_v3 = create_list(:old_node_tag, 3, :old_node => nodes(:node_with_versions_v3))
taglist_v4 = create_list(:old_node_tag, 2, :old_node => nodes(:node_with_versions_v4))
node = nodes(:node_with_versions_v1) node = nodes(:node_with_versions_v1)
tags = OldNode.find(node.id).old_tags.order(:k) tags = OldNode.find(node.id).old_tags.order(:k)
assert_equal 0, tags.count assert_equal 0, tags.count
@ -87,23 +90,24 @@ class OldNodeTest < ActiveSupport::TestCase
node = nodes(:node_with_versions_v3) node = nodes(:node_with_versions_v3)
tags = OldNode.find(node.id).old_tags.order(:k) tags = OldNode.find(node.id).old_tags.order(:k)
assert_equal 3, tags.count assert_equal 3, tags.count
assert_equal "testing", tags[0].k taglist_v3.sort_by!(&:k).each_index do |i|
assert_equal "added in node version 3", tags[0].v assert_equal taglist_v3[i].k, tags[i].k
assert_equal "testing three", tags[1].k assert_equal taglist_v3[i].v, tags[i].v
assert_equal "added in node version 3", tags[1].v end
assert_equal "testing two", tags[2].k
assert_equal "added in node version 3", tags[2].v
node = nodes(:node_with_versions_v4) node = nodes(:node_with_versions_v4)
tags = OldNode.find(node.id).old_tags.order(:k) tags = OldNode.find(node.id).old_tags.order(:k)
assert_equal 2, tags.count assert_equal 2, tags.count
assert_equal "testing", tags[0].k taglist_v4.sort_by!(&:k).each_index do |i|
assert_equal "added in node version 3", tags[0].v assert_equal taglist_v4[i].k, tags[i].k
assert_equal "testing two", tags[1].k assert_equal taglist_v4[i].v, tags[i].v
assert_equal "modified in node version 4", tags[1].v end
end end
def test_tags def test_tags
taglist_v3 = create_list(:old_node_tag, 3, :old_node => nodes(:node_with_versions_v3))
taglist_v4 = create_list(:old_node_tag, 2, :old_node => nodes(:node_with_versions_v4))
node = nodes(:node_with_versions_v1) node = nodes(:node_with_versions_v1)
tags = OldNode.find(node.id).tags tags = OldNode.find(node.id).tags
assert_equal 0, tags.size assert_equal 0, tags.size
@ -115,14 +119,15 @@ class OldNodeTest < ActiveSupport::TestCase
node = nodes(:node_with_versions_v3) node = nodes(:node_with_versions_v3)
tags = OldNode.find(node.id).tags tags = OldNode.find(node.id).tags
assert_equal 3, tags.size assert_equal 3, tags.size
assert_equal "added in node version 3", tags["testing"] taglist_v3.each do |tag|
assert_equal "added in node version 3", tags["testing two"] assert_equal tag.v, tags[tag.k]
assert_equal "added in node version 3", tags["testing three"] end
node = nodes(:node_with_versions_v4) node = nodes(:node_with_versions_v4)
tags = OldNode.find(node.id).tags tags = OldNode.find(node.id).tags
assert_equal 2, tags.size assert_equal 2, tags.size
assert_equal "added in node version 3", tags["testing"] taglist_v4.each do |tag|
assert_equal "modified in node version 4", tags["testing two"] assert_equal tag.v, tags[tag.k]
end
end end
end end

View file

@ -1,58 +1,34 @@
require "test_helper" require "test_helper"
class OldRelationTagTest < ActiveSupport::TestCase class OldRelationTagTest < ActiveSupport::TestCase
api_fixtures
def test_tag_count
assert_equal 13, OldRelationTag.count
end
def test_length_key_valid def test_length_key_valid
key = "k" tag = create(:old_relation_tag)
(0..255).each do |i| (0..255).each do |i|
tag = OldRelationTag.new tag.k = "k" * i
tag.relation_id = relation_tags(:t1).relation_id
tag.version = 1
tag.k = key * i
tag.v = "v"
assert tag.valid? assert tag.valid?
end end
end end
def test_length_value_valid def test_length_value_valid
val = "v" tag = create(:old_relation_tag)
(0..255).each do |i| (0..255).each do |i|
tag = OldRelationTag.new tag.v = "v" * i
tag.relation_id = relation_tags(:t1).relation_id
tag.version = 1
tag.k = "k"
tag.v = val * i
assert tag.valid? assert tag.valid?
end end
end end
def test_length_key_invalid def test_length_key_invalid
["k" * 256].each do |i| tag = create(:old_relation_tag)
tag = OldRelationTag.new tag.k = "k" * 256
tag.relation_id = relation_tags(:t1).relation_id assert !tag.valid?, "Key should be too long"
tag.version = 1 assert tag.errors[:k].any?
tag.k = i
tag.v = "v"
assert !tag.valid?, "Key should be too long"
assert tag.errors[:k].any?
end
end end
def test_length_value_invalid def test_length_value_invalid
["k" * 256].each do |i| tag = create(:old_relation_tag)
tag = OldRelationTag.new tag.v = "v" * 256
tag.relation_id = relation_tags(:t1).relation_id assert !tag.valid?, "Value should be too long"
tag.version = 1 assert tag.errors[:v].any?
tag.k = "k"
tag.v = i
assert !tag.valid?, "Value should be too long"
assert tag.errors[:v].any?
end
end end
def test_empty_tag_invalid def test_empty_tag_invalid
@ -62,11 +38,12 @@ class OldRelationTagTest < ActiveSupport::TestCase
end end
def test_uniqueness def test_uniqueness
existing = create(:old_relation_tag)
tag = OldRelationTag.new tag = OldRelationTag.new
tag.relation_id = relation_tags(:t1).relation_id tag.relation_id = existing.relation_id
tag.version = relation_tags(:t1).version tag.version = existing.version
tag.k = relation_tags(:t1).k tag.k = existing.k
tag.v = relation_tags(:t1).v tag.v = existing.v
assert tag.new_record? assert tag.new_record?
assert !tag.valid? assert !tag.valid?
assert_raise(ActiveRecord::RecordInvalid) { tag.save! } assert_raise(ActiveRecord::RecordInvalid) { tag.save! }

View file

@ -8,6 +8,9 @@ class OldRelationTest < ActiveSupport::TestCase
end end
def test_relation_tags def test_relation_tags
taglist_v3 = create_list(:old_relation_tag, 3, :old_relation => relations(:relation_with_versions_v3))
taglist_v4 = create_list(:old_relation_tag, 2, :old_relation => relations(:relation_with_versions_v4))
relation = relations(:relation_with_versions_v1) relation = relations(:relation_with_versions_v1)
tags = OldRelation.find(relation.id).old_tags.order(:k) tags = OldRelation.find(relation.id).old_tags.order(:k)
assert_equal 0, tags.count assert_equal 0, tags.count
@ -19,20 +22,18 @@ class OldRelationTest < ActiveSupport::TestCase
relation = relations(:relation_with_versions_v3) relation = relations(:relation_with_versions_v3)
tags = OldRelation.find(relation.id).old_tags.order(:k) tags = OldRelation.find(relation.id).old_tags.order(:k)
assert_equal 3, tags.count assert_equal 3, tags.count
assert_equal "testing", tags[0].k taglist_v3.sort_by!(&:k).each_index do |i|
assert_equal "added in relation version 3", tags[0].v assert_equal taglist_v3[i].k, tags[i].k
assert_equal "testing three", tags[1].k assert_equal taglist_v3[i].v, tags[i].v
assert_equal "added in relation version 3", tags[1].v end
assert_equal "testing two", tags[2].k
assert_equal "added in relation version 3", tags[2].v
relation = relations(:relation_with_versions_v4) relation = relations(:relation_with_versions_v4)
tags = OldRelation.find(relation.id).old_tags.order(:k) tags = OldRelation.find(relation.id).old_tags.order(:k)
assert_equal 2, tags.count assert_equal 2, tags.count
assert_equal "testing", tags[0].k taglist_v4.sort_by!(&:k).each_index do |i|
assert_equal "added in relation version 3", tags[0].v assert_equal taglist_v4[i].k, tags[i].k
assert_equal "testing two", tags[1].k assert_equal taglist_v4[i].v, tags[i].v
assert_equal "modified in relation version 4", tags[1].v end
end end
def test_relation_members def test_relation_members
@ -100,6 +101,9 @@ class OldRelationTest < ActiveSupport::TestCase
end end
def test_tags def test_tags
taglist_v3 = create_list(:old_relation_tag, 3, :old_relation => relations(:relation_with_versions_v3))
taglist_v4 = create_list(:old_relation_tag, 2, :old_relation => relations(:relation_with_versions_v4))
relation = relations(:relation_with_versions_v1) relation = relations(:relation_with_versions_v1)
tags = OldRelation.find(relation.id).tags tags = OldRelation.find(relation.id).tags
assert_equal 0, tags.size assert_equal 0, tags.size
@ -111,14 +115,15 @@ class OldRelationTest < ActiveSupport::TestCase
relation = relations(:relation_with_versions_v3) relation = relations(:relation_with_versions_v3)
tags = OldRelation.find(relation.id).tags tags = OldRelation.find(relation.id).tags
assert_equal 3, tags.size assert_equal 3, tags.size
assert_equal "added in relation version 3", tags["testing"] taglist_v3.each do |tag|
assert_equal "added in relation version 3", tags["testing two"] assert_equal tag.v, tags[tag.k]
assert_equal "added in relation version 3", tags["testing three"] end
relation = relations(:relation_with_versions_v4) relation = relations(:relation_with_versions_v4)
tags = OldRelation.find(relation.id).tags tags = OldRelation.find(relation.id).tags
assert_equal 2, tags.size assert_equal 2, tags.size
assert_equal "added in relation version 3", tags["testing"] taglist_v4.each do |tag|
assert_equal "modified in relation version 4", tags["testing two"] assert_equal tag.v, tags[tag.k]
end
end end
end end

View file

@ -1,58 +1,34 @@
require "test_helper" require "test_helper"
class OldWayTagTest < ActiveSupport::TestCase class OldWayTagTest < ActiveSupport::TestCase
api_fixtures
def test_tag_count
assert_equal 13, OldWayTag.count
end
def test_length_key_valid def test_length_key_valid
key = "k" tag = create(:old_way_tag)
(0..255).each do |i| (0..255).each do |i|
tag = OldWayTag.new tag.k = "k" * i
tag.way_id = way_tags(:t1).way_id
tag.version = 1
tag.k = key * i
tag.v = "v"
assert tag.valid? assert tag.valid?
end end
end end
def test_length_value_valid def test_length_value_valid
val = "v" tag = create(:old_way_tag)
(0..255).each do |i| (0..255).each do |i|
tag = OldWayTag.new tag.v = "v" * i
tag.way_id = way_tags(:t1).way_id
tag.version = 1
tag.k = "k"
tag.v = val * i
assert tag.valid? assert tag.valid?
end end
end end
def test_length_key_invalid def test_length_key_invalid
["k" * 256].each do |i| tag = create(:old_way_tag)
tag = OldWayTag.new tag.k = "k" * 256
tag.way_id = way_tags(:t1).way_id assert !tag.valid?, "Key should be too long"
tag.version = 1 assert tag.errors[:k].any?
tag.k = i
tag.v = "v"
assert !tag.valid?, "Key should be too long"
assert tag.errors[:k].any?
end
end end
def test_length_value_invalid def test_length_value_invalid
["k" * 256].each do |i| tag = create(:old_way_tag)
tag = OldWayTag.new tag.v = "v" * 256
tag.way_id = way_tags(:t1).way_id assert !tag.valid?, "Value should be too long"
tag.version = 1 assert tag.errors[:v].any?
tag.k = "k"
tag.v = i
assert !tag.valid?, "Value should be too long"
assert tag.errors[:v].any?
end
end end
def test_empty_tag_invalid def test_empty_tag_invalid
@ -62,11 +38,12 @@ class OldWayTagTest < ActiveSupport::TestCase
end end
def test_uniqueness def test_uniqueness
existing = create(:old_way_tag)
tag = OldWayTag.new tag = OldWayTag.new
tag.way_id = way_tags(:t1).way_id tag.way_id = existing.way_id
tag.version = way_tags(:t1).version tag.version = existing.version
tag.k = way_tags(:t1).k tag.k = existing.k
tag.v = way_tags(:t1).v tag.v = existing.v
assert tag.new_record? assert tag.new_record?
assert !tag.valid? assert !tag.valid?
assert_raise(ActiveRecord::RecordInvalid) { tag.save! } assert_raise(ActiveRecord::RecordInvalid) { tag.save! }

View file

@ -38,6 +38,9 @@ class OldWayTest < ActiveSupport::TestCase
end end
def test_way_tags def test_way_tags
taglist_v3 = create_list(:old_way_tag, 3, :old_way => ways(:way_with_versions_v3))
taglist_v4 = create_list(:old_way_tag, 2, :old_way => ways(:way_with_versions_v4))
way = ways(:way_with_versions_v1) way = ways(:way_with_versions_v1)
tags = OldWay.find(way.id).old_tags.order(:k) tags = OldWay.find(way.id).old_tags.order(:k)
assert_equal 0, tags.count assert_equal 0, tags.count
@ -49,23 +52,24 @@ class OldWayTest < ActiveSupport::TestCase
way = ways(:way_with_versions_v3) way = ways(:way_with_versions_v3)
tags = OldWay.find(way.id).old_tags.order(:k) tags = OldWay.find(way.id).old_tags.order(:k)
assert_equal 3, tags.count assert_equal 3, tags.count
assert_equal "testing", tags[0].k taglist_v3.sort_by!(&:k).each_index do |i|
assert_equal "added in way version 3", tags[0].v assert_equal taglist_v3[i].k, tags[i].k
assert_equal "testing three", tags[1].k assert_equal taglist_v3[i].v, tags[i].v
assert_equal "added in way version 3", tags[1].v end
assert_equal "testing two", tags[2].k
assert_equal "added in way version 3", tags[2].v
way = ways(:way_with_versions_v4) way = ways(:way_with_versions_v4)
tags = OldWay.find(way.id).old_tags.order(:k) tags = OldWay.find(way.id).old_tags.order(:k)
assert_equal 2, tags.count assert_equal 2, tags.count
assert_equal "testing", tags[0].k taglist_v4.sort_by!(&:k).each_index do |i|
assert_equal "added in way version 3", tags[0].v assert_equal taglist_v4[i].k, tags[i].k
assert_equal "testing two", tags[1].k assert_equal taglist_v4[i].v, tags[i].v
assert_equal "modified in way version 4", tags[1].v end
end end
def test_tags def test_tags
taglist_v3 = create_list(:old_way_tag, 3, :old_way => ways(:way_with_versions_v3))
taglist_v4 = create_list(:old_way_tag, 2, :old_way => ways(:way_with_versions_v4))
way = ways(:way_with_versions_v1) way = ways(:way_with_versions_v1)
tags = OldWay.find(way.id).tags tags = OldWay.find(way.id).tags
assert_equal 0, tags.size assert_equal 0, tags.size
@ -77,28 +81,32 @@ class OldWayTest < ActiveSupport::TestCase
way = ways(:way_with_versions_v3) way = ways(:way_with_versions_v3)
tags = OldWay.find(way.id).tags tags = OldWay.find(way.id).tags
assert_equal 3, tags.size assert_equal 3, tags.size
assert_equal "added in way version 3", tags["testing"] taglist_v3.each do |tag|
assert_equal "added in way version 3", tags["testing two"] assert_equal tag.v, tags[tag.k]
assert_equal "added in way version 3", tags["testing three"] end
way = ways(:way_with_versions_v4) way = ways(:way_with_versions_v4)
tags = OldWay.find(way.id).tags tags = OldWay.find(way.id).tags
assert_equal 2, tags.size assert_equal 2, tags.size
assert_equal "added in way version 3", tags["testing"] taglist_v4.each do |tag|
assert_equal "modified in way version 4", tags["testing two"] assert_equal tag.v, tags[tag.k]
end
end end
def test_get_nodes_undelete def test_get_nodes_undelete
way = ways(:way_with_versions_v3) way = ways(:way_with_versions_v3)
node_tag = create(:node_tag, :node => current_nodes(:node_with_versions))
node_tag2 = create(:node_tag, :node => current_nodes(:used_node_1))
nodes = OldWay.find(way.id).get_nodes_undelete nodes = OldWay.find(way.id).get_nodes_undelete
assert_equal 2, nodes.size assert_equal 2, nodes.size
assert_equal [1.0, 1.0, 15, 4, { "testing" => "added in node version 3", "testing two" => "modified in node version 4" }, true], nodes[0] assert_equal [1.0, 1.0, 15, 4, { node_tag.k => node_tag.v }, true], nodes[0]
assert_equal [3.0, 3.0, 3, 1, { "test" => "yes" }, true], nodes[1] assert_equal [3.0, 3.0, 3, 1, { node_tag2.k => node_tag2.v }, true], nodes[1]
way = ways(:way_with_redacted_versions_v2) way = ways(:way_with_redacted_versions_v2)
node_tag3 = create(:node_tag, :node => current_nodes(:invisible_node))
nodes = OldWay.find(way.id).get_nodes_undelete nodes = OldWay.find(way.id).get_nodes_undelete
assert_equal 2, nodes.size assert_equal 2, nodes.size
assert_equal [3.0, 3.0, 3, 1, { "test" => "yes" }, true], nodes[0] assert_equal [3.0, 3.0, 3, 1, { node_tag2.k => node_tag2.v }, true], nodes[0]
assert_equal [2.0, 2.0, 2, 1, { "testused" => "yes" }, false], nodes[1] assert_equal [2.0, 2.0, 2, 1, { node_tag3.k => node_tag3.v }, false], nodes[1]
end end
end end

View file

@ -1,54 +1,34 @@
require "test_helper" require "test_helper"
class RelationTagTest < ActiveSupport::TestCase class RelationTagTest < ActiveSupport::TestCase
api_fixtures
def test_relation_tag_count
assert_equal 10, RelationTag.count
end
def test_length_key_valid def test_length_key_valid
key = "k" tag = create(:relation_tag)
(0..255).each do |i| (0..255).each do |i|
tag = RelationTag.new tag.k = "k" * i
tag.relation_id = 1
tag.k = key * i
tag.v = "v"
assert tag.valid? assert tag.valid?
end end
end end
def test_length_value_valid def test_length_value_valid
val = "v" tag = create(:relation_tag)
(0..255).each do |i| (0..255).each do |i|
tag = RelationTag.new tag.v = "v" * i
tag.relation_id = 1
tag.k = "k"
tag.v = val * i
assert tag.valid? assert tag.valid?
end end
end end
def test_length_key_invalid def test_length_key_invalid
["k" * 256].each do |i| tag = create(:relation_tag)
tag = RelationTag.new tag.k = "k" * 256
tag.relation_id = 1 assert !tag.valid?, "Key should be too long"
tag.k = i assert tag.errors[:k].any?
tag.v = "v"
assert !tag.valid?, "Key #{i} should be too long"
assert tag.errors[:k].any?
end
end end
def test_length_value_invalid def test_length_value_invalid
["v" * 256].each do |i| tag = create(:relation_tag)
tag = RelationTag.new tag.v = "v" * 256
tag.relation_id = 1 assert !tag.valid?, "Value should be too long"
tag.k = "k" assert tag.errors[:v].any?
tag.v = i
assert !tag.valid?, "Value #{i} should be too long"
assert tag.errors[:v].any?
end
end end
def test_empty_tag_invalid def test_empty_tag_invalid
@ -58,10 +38,11 @@ class RelationTagTest < ActiveSupport::TestCase
end end
def test_uniquness def test_uniquness
existing = create(:relation_tag)
tag = RelationTag.new tag = RelationTag.new
tag.relation_id = current_relation_tags(:t1).relation_id tag.relation_id = existing.relation_id
tag.k = current_relation_tags(:t1).k tag.k = existing.k
tag.v = current_relation_tags(:t1).v tag.v = existing.v
assert tag.new_record? assert tag.new_record?
assert !tag.valid? assert !tag.valid?
assert_raise(ActiveRecord::RecordInvalid) { tag.save! } assert_raise(ActiveRecord::RecordInvalid) { tag.save! }

View file

@ -129,20 +129,25 @@ class RelationTest < ActiveSupport::TestCase
def test_relation_tags def test_relation_tags
relation = current_relations(:relation_with_versions) relation = current_relations(:relation_with_versions)
taglist = create_list(:relation_tag, 2, :relation => relation)
tags = Relation.find(relation.id).relation_tags.order(:k) tags = Relation.find(relation.id).relation_tags.order(:k)
assert_equal 2, tags.count assert_equal 2, tags.count
assert_equal "testing", tags[0].k taglist.sort_by!(&:k).each_index do |i|
assert_equal "added in relation version 3", tags[0].v assert_equal taglist[i].k, tags[i].k
assert_equal "testing two", tags[1].k assert_equal taglist[i].v, tags[i].v
assert_equal "modified in relation version 4", tags[1].v end
end end
def test_tags def test_tags
relation = current_relations(:relation_with_versions) relation = current_relations(:relation_with_versions)
taglist = create_list(:relation_tag, 2, :relation => relation)
tags = Relation.find(relation.id).tags tags = Relation.find(relation.id).tags
assert_equal 2, tags.size assert_equal 2, tags.size
assert_equal "added in relation version 3", tags["testing"] taglist.each do |tag|
assert_equal "modified in relation version 4", tags["testing two"] assert_equal tag.v, tags[tag.k]
end
end end
def test_containing_relation_members def test_containing_relation_members

View file

@ -1,54 +1,34 @@
require "test_helper" require "test_helper"
class WayTagTest < ActiveSupport::TestCase class WayTagTest < ActiveSupport::TestCase
api_fixtures
def test_way_tag_count
assert_equal 6, WayTag.count
end
def test_length_key_valid def test_length_key_valid
key = "k" tag = create(:way_tag)
(0..255).each do |i| (0..255).each do |i|
tag = WayTag.new tag.k = "k" * i
tag.way_id = current_way_tags(:t1).way_id
tag.k = key * i
tag.v = current_way_tags(:t1).v
assert tag.valid? assert tag.valid?
end end
end end
def test_length_value_valid def test_length_value_valid
val = "v" tag = create(:way_tag)
(0..255).each do |i| (0..255).each do |i|
tag = WayTag.new tag.v = "v" * i
tag.way_id = current_way_tags(:t1).way_id
tag.k = "k"
tag.v = val * i
assert tag.valid? assert tag.valid?
end end
end end
def test_length_key_invalid def test_length_key_invalid
["k" * 256].each do |i| tag = create(:way_tag)
tag = WayTag.new tag.k = "k" * 256
tag.way_id = current_way_tags(:t1).way_id assert !tag.valid?, "Key should be too long"
tag.k = i assert tag.errors[:k].any?
tag.v = "v"
assert !tag.valid?, "Key #{i} should be too long"
assert tag.errors[:k].any?
end
end end
def test_length_value_invalid def test_length_value_invalid
["v" * 256].each do |i| tag = create(:way_tag)
tag = WayTag.new tag.v = "v" * 256
tag.way_id = current_way_tags(:t1).way_id assert !tag.valid?, "Value should be too long"
tag.k = "k" assert tag.errors[:v].any?
tag.v = i
assert !tag.valid?, "Value #{i} should be too long"
assert tag.errors[:v].any?
end
end end
def test_empty_tag_invalid def test_empty_tag_invalid
@ -58,10 +38,11 @@ class WayTagTest < ActiveSupport::TestCase
end end
def test_uniqueness def test_uniqueness
existing = create(:way_tag)
tag = WayTag.new tag = WayTag.new
tag.way_id = current_way_tags(:t1).way_id tag.way_id = existing.way_id
tag.k = current_way_tags(:t1).k tag.k = existing.k
tag.v = current_way_tags(:t1).v tag.v = existing.v
assert tag.new_record? assert tag.new_record?
assert !tag.valid? assert !tag.valid?
assert_raise(ActiveRecord::RecordInvalid) { tag.save! } assert_raise(ActiveRecord::RecordInvalid) { tag.save! }

View file

@ -165,20 +165,23 @@ class WayTest < ActiveSupport::TestCase
def test_way_tags def test_way_tags
way = current_ways(:way_with_versions) way = current_ways(:way_with_versions)
taglist = create_list(:way_tag, 2, :way => way)
tags = Way.find(way.id).way_tags.order(:k) tags = Way.find(way.id).way_tags.order(:k)
assert_equal 2, tags.count assert_equal 2, tags.count
assert_equal "testing", tags[0].k taglist.sort_by!(&:k).each_index do |i|
assert_equal "added in way version 3", tags[0].v assert_equal taglist[i].k, tags[i].k
assert_equal "testing two", tags[1].k assert_equal taglist[i].v, tags[i].v
assert_equal "modified in way version 4", tags[1].v end
end end
def test_tags def test_tags
way = current_ways(:way_with_versions) way = current_ways(:way_with_versions)
taglist = create_list(:way_tag, 2, :way => way)
tags = Way.find(way.id).tags tags = Way.find(way.id).tags
assert_equal 2, tags.size assert_equal 2, tags.size
assert_equal "added in way version 3", tags["testing"] taglist.each do |tag|
assert_equal "modified in way version 4", tags["testing two"] assert_equal tag.v, tags[tag.k]
end
end end
def test_containing_relation_members def test_containing_relation_members

View file

@ -21,37 +21,29 @@ module ActiveSupport
set_fixture_class :current_nodes => Node set_fixture_class :current_nodes => Node
set_fixture_class :nodes => OldNode set_fixture_class :nodes => OldNode
fixtures :current_node_tags, :node_tags
set_fixture_class :current_node_tags => NodeTag
set_fixture_class :node_tags => OldNodeTag
fixtures :current_ways fixtures :current_ways
set_fixture_class :current_ways => Way set_fixture_class :current_ways => Way
fixtures :current_way_nodes, :current_way_tags fixtures :current_way_nodes
set_fixture_class :current_way_nodes => WayNode set_fixture_class :current_way_nodes => WayNode
set_fixture_class :current_way_tags => WayTag
fixtures :ways fixtures :ways
set_fixture_class :ways => OldWay set_fixture_class :ways => OldWay
fixtures :way_nodes, :way_tags fixtures :way_nodes
set_fixture_class :way_nodes => OldWayNode set_fixture_class :way_nodes => OldWayNode
set_fixture_class :way_tags => OldWayTag
fixtures :current_relations fixtures :current_relations
set_fixture_class :current_relations => Relation set_fixture_class :current_relations => Relation
fixtures :current_relation_members, :current_relation_tags fixtures :current_relation_members
set_fixture_class :current_relation_members => RelationMember set_fixture_class :current_relation_members => RelationMember
set_fixture_class :current_relation_tags => RelationTag
fixtures :relations fixtures :relations
set_fixture_class :relations => OldRelation set_fixture_class :relations => OldRelation
fixtures :relation_members, :relation_tags fixtures :relation_members
set_fixture_class :relation_members => OldRelationMember set_fixture_class :relation_members => OldRelationMember
set_fixture_class :relation_tags => OldRelationTag
fixtures :gpx_files, :gps_points, :gpx_file_tags fixtures :gpx_files, :gps_points, :gpx_file_tags
set_fixture_class :gpx_files => Trace set_fixture_class :gpx_files => Trace