Add tests for tag methods on object models

This commit is contained in:
Tom Hughes 2013-12-04 18:39:07 +00:00
parent 10e92b85a7
commit 5ed8ee39e9
14 changed files with 309 additions and 5 deletions

View file

@ -32,3 +32,13 @@ mt_4:
relation_id: 4 relation_id: 4
k: 'tag4' k: 'tag4'
v: 'val4' 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

@ -13,3 +13,12 @@ t3:
k: 'test' k: 'test'
v: 'yes' v: 'yes'
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

@ -39,3 +39,33 @@ mt_4:
k: 'tag4' k: 'tag4'
v: 'val4' v: 'val4'
version: 1 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

@ -16,6 +16,36 @@ t3:
v: 'yes' v: 'yes'
version: 1 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: t6_v1:
way_id: 6 way_id: 6
k: 'test' k: 'test'

View file

@ -313,4 +313,22 @@ class NodeTest < ActiveSupport::TestCase
} }
assert_equal "Element node/23 has duplicate tags with key dup", message_update.message assert_equal "Element node/23 has duplicate tags with key dup", message_update.message
end end
def test_node_tags
node = current_nodes(:node_with_versions)
tags = Node.find(node.id).node_tags.order(:k)
assert_equal 2, tags.count
assert_equal "testing", tags[0].k
assert_equal "added in node version 3", tags[0].v
assert_equal "testing two", tags[1].k
assert_equal "modified in node version 4", tags[1].v
end
def test_tags
node = current_nodes(:node_with_versions)
tags = Node.find(node.id).tags
assert_equal 2, tags.size
assert_equal "added in node version 3", tags["testing"]
assert_equal "modified in node version 4", tags["testing two"]
end
end end

View file

@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper'
class OldNodeTest < ActiveSupport::TestCase class OldNodeTest < ActiveSupport::TestCase
api_fixtures api_fixtures
def test_old_node_count def test_node_count
assert_equal 21, OldNode.count assert_equal 21, OldNode.count
end end
@ -74,4 +74,55 @@ class OldNodeTest < ActiveSupport::TestCase
#assert_equal node.tile, QuadTile.tile_for_point(nodes(nod).lat, nodes(nod).lon) #assert_equal node.tile, QuadTile.tile_for_point(nodes(nod).lat, nodes(nod).lon)
assert_equal false, node.valid? assert_equal false, node.valid?
end end
def test_node_tags
node = nodes(:node_with_versions_v1)
tags = OldNode.find(node.id).old_tags.order(:k)
assert_equal 0, tags.count
node = nodes(:node_with_versions_v2)
tags = OldNode.find(node.id).old_tags.order(:k)
assert_equal 0, tags.count
node = nodes(:node_with_versions_v3)
tags = OldNode.find(node.id).old_tags.order(:k)
assert_equal 3, tags.count
assert_equal "testing", tags[0].k
assert_equal "added in node version 3", tags[0].v
assert_equal "testing three", tags[1].k
assert_equal "added in node version 3", tags[1].v
assert_equal "testing two", tags[2].k
assert_equal "added in node version 3", tags[2].v
node = nodes(:node_with_versions_v4)
tags = OldNode.find(node.id).old_tags.order(:k)
assert_equal 2, tags.count
assert_equal "testing", tags[0].k
assert_equal "added in node version 3", tags[0].v
assert_equal "testing two", tags[1].k
assert_equal "modified in node version 4", tags[1].v
end
def test_tags
node = nodes(:node_with_versions_v1)
tags = OldNode.find(node.id).tags
assert_equal 0, tags.size
node = nodes(:node_with_versions_v2)
tags = OldNode.find(node.id).tags
assert_equal 0, tags.size
node = nodes(:node_with_versions_v3)
tags = OldNode.find(node.id).tags
assert_equal 3, tags.size
assert_equal "added in node version 3", tags["testing"]
assert_equal "added in node version 3", tags["testing two"]
assert_equal "added in node version 3", tags["testing three"]
node = nodes(:node_with_versions_v4)
tags = OldNode.find(node.id).tags
assert_equal 2, tags.size
assert_equal "added in node version 3", tags["testing"]
assert_equal "modified in node version 4", tags["testing two"]
end
end end

View file

@ -4,7 +4,7 @@ class OldRelationTagTest < ActiveSupport::TestCase
api_fixtures api_fixtures
def test_tag_count def test_tag_count
assert_equal 7, OldRelationTag.count assert_equal 12, OldRelationTag.count
end end
def test_length_key_valid def test_length_key_valid

View file

@ -0,0 +1,60 @@
require File.dirname(__FILE__) + '/../test_helper'
class OldRelationTest < ActiveSupport::TestCase
api_fixtures
def test_db_count
assert_equal 14, OldRelation.count
end
def test_relation_tags
relation = relations(:relation_with_versions_v1)
tags = OldRelation.find(relation.id).old_tags.order(:k)
assert_equal 0, tags.count
relation = relations(:relation_with_versions_v2)
tags = OldRelation.find(relation.id).old_tags.order(:k)
assert_equal 0, tags.count
relation = relations(:relation_with_versions_v3)
tags = OldRelation.find(relation.id).old_tags.order(:k)
assert_equal 3, tags.count
assert_equal "testing", tags[0].k
assert_equal "added in relation version 3", tags[0].v
assert_equal "testing three", tags[1].k
assert_equal "added in relation version 3", tags[1].v
assert_equal "testing two", tags[2].k
assert_equal "added in relation version 3", tags[2].v
relation = relations(:relation_with_versions_v4)
tags = OldRelation.find(relation.id).old_tags.order(:k)
assert_equal 2, tags.count
assert_equal "testing", tags[0].k
assert_equal "added in relation version 3", tags[0].v
assert_equal "testing two", tags[1].k
assert_equal "modified in relation version 4", tags[1].v
end
def test_tags
relation = relations(:relation_with_versions_v1)
tags = OldRelation.find(relation.id).tags
assert_equal 0, tags.size
relation = relations(:relation_with_versions_v2)
tags = OldRelation.find(relation.id).tags
assert_equal 0, tags.size
relation = relations(:relation_with_versions_v3)
tags = OldRelation.find(relation.id).tags
assert_equal 3, tags.size
assert_equal "added in relation version 3", tags["testing"]
assert_equal "added in relation version 3", tags["testing two"]
assert_equal "added in relation version 3", tags["testing three"]
relation = relations(:relation_with_versions_v4)
tags = OldRelation.find(relation.id).tags
assert_equal 2, tags.size
assert_equal "added in relation version 3", tags["testing"]
assert_equal "modified in relation version 4", tags["testing two"]
end
end

View file

@ -4,7 +4,7 @@ class OldWayTagTest < ActiveSupport::TestCase
api_fixtures api_fixtures
def test_tag_count def test_tag_count
assert_equal 7, OldWayTag.count assert_equal 12, OldWayTag.count
end end
def test_length_key_valid def test_length_key_valid

60
test/unit/old_way_test.rb Normal file
View file

@ -0,0 +1,60 @@
require File.dirname(__FILE__) + '/../test_helper'
class OldWayTest < ActiveSupport::TestCase
api_fixtures
def test_db_count
assert_equal 12, OldWay.count
end
def test_way_tags
way = ways(:way_with_versions_v1)
tags = OldWay.find(way.id).old_tags.order(:k)
assert_equal 0, tags.count
way = ways(:way_with_versions_v2)
tags = OldWay.find(way.id).old_tags.order(:k)
assert_equal 0, tags.count
way = ways(:way_with_versions_v3)
tags = OldWay.find(way.id).old_tags.order(:k)
assert_equal 3, tags.count
assert_equal "testing", tags[0].k
assert_equal "added in way version 3", tags[0].v
assert_equal "testing three", tags[1].k
assert_equal "added in way version 3", tags[1].v
assert_equal "testing two", tags[2].k
assert_equal "added in way version 3", tags[2].v
way = ways(:way_with_versions_v4)
tags = OldWay.find(way.id).old_tags.order(:k)
assert_equal 2, tags.count
assert_equal "testing", tags[0].k
assert_equal "added in way version 3", tags[0].v
assert_equal "testing two", tags[1].k
assert_equal "modified in way version 4", tags[1].v
end
def test_tags
way = ways(:way_with_versions_v1)
tags = OldWay.find(way.id).tags
assert_equal 0, tags.size
way = ways(:way_with_versions_v2)
tags = OldWay.find(way.id).tags
assert_equal 0, tags.size
way = ways(:way_with_versions_v3)
tags = OldWay.find(way.id).tags
assert_equal 3, tags.size
assert_equal "added in way version 3", tags["testing"]
assert_equal "added in way version 3", tags["testing two"]
assert_equal "added in way version 3", tags["testing three"]
way = ways(:way_with_versions_v4)
tags = OldWay.find(way.id).tags
assert_equal 2, tags.size
assert_equal "added in way version 3", tags["testing"]
assert_equal "modified in way version 4", tags["testing two"]
end
end

View file

@ -4,7 +4,7 @@ class RelationTagTest < ActiveSupport::TestCase
api_fixtures api_fixtures
def test_relation_tag_count def test_relation_tag_count
assert_equal 7, RelationTag.count assert_equal 9, RelationTag.count
end end
def test_length_key_valid def test_length_key_valid

View file

@ -102,4 +102,22 @@ class RelationTest < ActiveSupport::TestCase
} }
assert_equal "Element relation/23 has duplicate tags with key dup", message_update.message assert_equal "Element relation/23 has duplicate tags with key dup", message_update.message
end end
def test_relation_tags
relation = current_relations(:relation_with_versions)
tags = Relation.find(relation.id).relation_tags.order(:k)
assert_equal 2, tags.count
assert_equal "testing", tags[0].k
assert_equal "added in relation version 3", tags[0].v
assert_equal "testing two", tags[1].k
assert_equal "modified in relation version 4", tags[1].v
end
def test_tags
relation = current_relations(:relation_with_versions)
tags = Relation.find(relation.id).tags
assert_equal 2, tags.size
assert_equal "added in relation version 3", tags["testing"]
assert_equal "modified in relation version 4", tags["testing two"]
end
end end

View file

@ -4,7 +4,7 @@ class WayTagTest < ActiveSupport::TestCase
api_fixtures api_fixtures
def test_way_tag_count def test_way_tag_count
assert_equal 3, WayTag.count assert_equal 5, WayTag.count
end end
def test_length_key_valid def test_length_key_valid

View file

@ -135,4 +135,22 @@ class WayTest < ActiveSupport::TestCase
} }
assert_equal "Element way/23 has duplicate tags with key dup", message_update.message assert_equal "Element way/23 has duplicate tags with key dup", message_update.message
end end
def test_way_tags
way = current_ways(:way_with_versions)
tags = Way.find(way.id).way_tags.order(:k)
assert_equal 2, tags.count
assert_equal "testing", tags[0].k
assert_equal "added in way version 3", tags[0].v
assert_equal "testing two", tags[1].k
assert_equal "modified in way version 4", tags[1].v
end
def test_tags
way = current_ways(:way_with_versions)
tags = Way.find(way.id).tags
assert_equal 2, tags.size
assert_equal "added in way version 3", tags["testing"]
assert_equal "modified in way version 4", tags["testing two"]
end
end end