From: Tom Hughes Date: Wed, 4 Dec 2013 18:39:07 +0000 (+0000) Subject: Add tests for tag methods on object models X-Git-Tag: live~5107 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/5ed8ee39e9a85862c36e0a54a73c1e3a880730f5 Add tests for tag methods on object models --- diff --git a/test/fixtures/current_relation_tags.yml b/test/fixtures/current_relation_tags.yml index 6030b9853..ab48f8e22 100644 --- a/test/fixtures/current_relation_tags.yml +++ b/test/fixtures/current_relation_tags.yml @@ -32,3 +32,13 @@ 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' diff --git a/test/fixtures/current_way_tags.yml b/test/fixtures/current_way_tags.yml index c2c27414d..386b48f71 100644 --- a/test/fixtures/current_way_tags.yml +++ b/test/fixtures/current_way_tags.yml @@ -13,3 +13,12 @@ t3: k: 'test' 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' diff --git a/test/fixtures/relation_tags.yml b/test/fixtures/relation_tags.yml index 31b329ed7..beccd471c 100644 --- a/test/fixtures/relation_tags.yml +++ b/test/fixtures/relation_tags.yml @@ -39,3 +39,33 @@ mt_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 diff --git a/test/fixtures/way_tags.yml b/test/fixtures/way_tags.yml index 6fb77d71b..195be7e54 100644 --- a/test/fixtures/way_tags.yml +++ b/test/fixtures/way_tags.yml @@ -16,6 +16,36 @@ t3: v: 'yes' 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' diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index c62e15b29..2b28b3ee6 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -313,4 +313,22 @@ class NodeTest < ActiveSupport::TestCase } assert_equal "Element node/23 has duplicate tags with key dup", message_update.message 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 diff --git a/test/unit/old_node_test.rb b/test/unit/old_node_test.rb index 84ea65b68..fdd61f090 100644 --- a/test/unit/old_node_test.rb +++ b/test/unit/old_node_test.rb @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' class OldNodeTest < ActiveSupport::TestCase api_fixtures - def test_old_node_count + def test_node_count assert_equal 21, OldNode.count 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 false, node.valid? 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 diff --git a/test/unit/old_relation_tag_test.rb b/test/unit/old_relation_tag_test.rb index 1d0880822..faff45dd0 100644 --- a/test/unit/old_relation_tag_test.rb +++ b/test/unit/old_relation_tag_test.rb @@ -4,7 +4,7 @@ class OldRelationTagTest < ActiveSupport::TestCase api_fixtures def test_tag_count - assert_equal 7, OldRelationTag.count + assert_equal 12, OldRelationTag.count end def test_length_key_valid diff --git a/test/unit/old_relation_test.rb b/test/unit/old_relation_test.rb new file mode 100644 index 000000000..c99491079 --- /dev/null +++ b/test/unit/old_relation_test.rb @@ -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 diff --git a/test/unit/old_way_tag_test.rb b/test/unit/old_way_tag_test.rb index 107111b10..dbc001980 100644 --- a/test/unit/old_way_tag_test.rb +++ b/test/unit/old_way_tag_test.rb @@ -4,7 +4,7 @@ class OldWayTagTest < ActiveSupport::TestCase api_fixtures def test_tag_count - assert_equal 7, OldWayTag.count + assert_equal 12, OldWayTag.count end def test_length_key_valid diff --git a/test/unit/old_way_test.rb b/test/unit/old_way_test.rb new file mode 100644 index 000000000..e75f98b9c --- /dev/null +++ b/test/unit/old_way_test.rb @@ -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 diff --git a/test/unit/relation_tag_test.rb b/test/unit/relation_tag_test.rb index 39a2ff828..0833c572d 100644 --- a/test/unit/relation_tag_test.rb +++ b/test/unit/relation_tag_test.rb @@ -4,7 +4,7 @@ class RelationTagTest < ActiveSupport::TestCase api_fixtures def test_relation_tag_count - assert_equal 7, RelationTag.count + assert_equal 9, RelationTag.count end def test_length_key_valid diff --git a/test/unit/relation_test.rb b/test/unit/relation_test.rb index a62320cc7..75a55e389 100644 --- a/test/unit/relation_test.rb +++ b/test/unit/relation_test.rb @@ -102,4 +102,22 @@ class RelationTest < ActiveSupport::TestCase } assert_equal "Element relation/23 has duplicate tags with key dup", message_update.message 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 diff --git a/test/unit/way_tag_test.rb b/test/unit/way_tag_test.rb index b338f9c25..9766e9c77 100644 --- a/test/unit/way_tag_test.rb +++ b/test/unit/way_tag_test.rb @@ -4,7 +4,7 @@ class WayTagTest < ActiveSupport::TestCase api_fixtures def test_way_tag_count - assert_equal 3, WayTag.count + assert_equal 5, WayTag.count end def test_length_key_valid diff --git a/test/unit/way_test.rb b/test/unit/way_test.rb index d2a447e40..6c2cdc0be 100644 --- a/test/unit/way_test.rb +++ b/test/unit/way_test.rb @@ -135,4 +135,22 @@ class WayTest < ActiveSupport::TestCase } assert_equal "Element way/23 has duplicate tags with key dup", message_update.message 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