From 1f52e5227faa08c10f6d383c0dad65415c1f91df Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 5 Dec 2013 00:38:25 +0000 Subject: [PATCH] Add tests for member methods on relation models --- app/models/old_relation.rb | 2 +- test/fixtures/current_relation_members.yml | 26 +++++++++ test/fixtures/relation_members.yml | 65 ++++++++++++++++++++++ test/unit/old_relation_test.rb | 64 +++++++++++++++++++++ test/unit/relation_member_test.rb | 3 +- test/unit/relation_test.rb | 24 ++++++++ 6 files changed, 181 insertions(+), 3 deletions(-) diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index 9f80a81b9..61c49eb59 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -63,7 +63,7 @@ class OldRelation < ActiveRecord::Base unless @members @members = Array.new self.old_members.order(:sequence_id).each do |m| - @members += [[m.type,m.id,m.role]] + @members += [[m.member_type,m.member_id,m.member_role]] end end @members diff --git a/test/fixtures/current_relation_members.yml b/test/fixtures/current_relation_members.yml index 31dccbc22..67911b8d5 100644 --- a/test/fixtures/current_relation_members.yml +++ b/test/fixtures/current_relation_members.yml @@ -1,29 +1,34 @@ t1: relation_id: 1 + sequence_id: 1 member_role: "some" member_type: "Way" member_id: 3 t2: relation_id: 1 + sequence_id: 2 member_role: "some" member_type: "Node" member_id: 5 t3: relation_id: 1 + sequence_id: 3 member_role: "some" member_type: "Relation" member_id: 3 t4: relation_id: 3 + sequence_id: 1 member_role: "some" member_type: "Node" member_id: 5 t5: relation_id: 2 + sequence_id: 1 member_role: "some" member_type: "Node" member_id: 5 @@ -33,3 +38,24 @@ public_used: member_role: "used by other relation" member_type: "Relation" member_id: 5 + +r8_m1: + relation_id: 8 + sequence_id: 1 + member_role: "some node" + member_type: "Node" + member_id: 15 + +r8_m2: + relation_id: 8 + sequence_id: 2 + member_role: "some way" + member_type: "Way" + member_id: 4 + +r8_m3: + relation_id: 8 + sequence_id: 3 + member_role: "some relation" + member_type: "Relation" + member_id: 7 diff --git a/test/fixtures/relation_members.yml b/test/fixtures/relation_members.yml index 931728dc7..a5f04f1ef 100644 --- a/test/fixtures/relation_members.yml +++ b/test/fixtures/relation_members.yml @@ -1,23 +1,30 @@ t1: relation_id: 1 + sequence_id: 1 member_role: "some" member_type: "Way" member_id: 3 version: 1 + t2: relation_id: 1 + sequence_id: 2 member_role: "some" member_type: "Node" member_id: 5 version: 1 + t3: relation_id: 1 + sequence_id: 3 member_role: "some" member_type: "Relation" member_id: 3 version: 1 + t4: relation_id: 3 + sequence_id: 1 member_role: "some" member_type: "Node" member_id: 5 @@ -25,6 +32,7 @@ t4: t5: relation_id: 2 + sequence_id: 1 member_role: "some" member_type: "Node" member_id: 5 @@ -32,7 +40,64 @@ t5: public_used: relation_id: 6 + sequence_id: 1 member_role: "used by other relation" member_type: "Relation" member_id: 5 version: 1 + +r8_v1_m1: + relation_id: 8 + sequence_id: 1 + member_role: "some node" + member_type: "Node" + member_id: 15 + version: 1 + +r8_v2_m1: + relation_id: 8 + sequence_id: 1 + member_role: "some changed node" + member_type: "Node" + member_id: 15 + version: 2 + +r8_v3_m1: + relation_id: 8 + sequence_id: 1 + member_role: "some changed node" + member_type: "Node" + member_id: 15 + version: 3 + +r8_v3_m3: + relation_id: 8 + sequence_id: 2 + member_role: "some relation" + member_type: "Relation" + member_id: 7 + version: 3 + +r8_v4_m1: + relation_id: 8 + sequence_id: 1 + member_role: "some node" + member_type: "Node" + member_id: 15 + version: 4 + +r8_v4_m2: + relation_id: 8 + sequence_id: 2 + member_role: "some way" + member_type: "Way" + member_id: 4 + version: 4 + +r8_v4_m3: + relation_id: 8 + sequence_id: 3 + member_role: "some relation" + member_type: "Relation" + member_id: 7 + version: 4 diff --git a/test/unit/old_relation_test.rb b/test/unit/old_relation_test.rb index c99491079..31ff83197 100644 --- a/test/unit/old_relation_test.rb +++ b/test/unit/old_relation_test.rb @@ -35,6 +35,70 @@ class OldRelationTest < ActiveSupport::TestCase assert_equal "modified in relation version 4", tags[1].v end + def test_relation_members + relation = relations(:relation_with_versions_v1) + members = OldRelation.find(relation.id).relation_members + assert_equal 1, members.count + assert_equal "some node", members[0].member_role + assert_equal "Node", members[0].member_type + assert_equal 15, members[0].member_id + + relation = relations(:relation_with_versions_v2) + members = OldRelation.find(relation.id).relation_members + assert_equal 1, members.count + assert_equal "some changed node", members[0].member_role + assert_equal "Node", members[0].member_type + assert_equal 15, members[0].member_id + + relation = relations(:relation_with_versions_v3) + members = OldRelation.find(relation.id).relation_members + assert_equal 2, members.count + assert_equal "some changed node", members[0].member_role + assert_equal "Node", members[0].member_type + assert_equal 15, members[0].member_id + assert_equal "some relation", members[1].member_role + assert_equal "Relation", members[1].member_type + assert_equal 7, members[1].member_id + + relation = relations(:relation_with_versions_v4) + members = OldRelation.find(relation.id).relation_members + assert_equal 3, members.count + assert_equal "some node", members[0].member_role + assert_equal "Node", members[0].member_type + assert_equal 15, members[0].member_id + assert_equal "some way", members[1].member_role + assert_equal "Way", members[1].member_type + assert_equal 4, members[1].member_id + assert_equal "some relation", members[2].member_role + assert_equal "Relation", members[2].member_type + assert_equal 7, members[2].member_id + end + + def test_relations + relation = relations(:relation_with_versions_v1) + members = OldRelation.find(relation.id).members + assert_equal 1, members.count + assert_equal ["Node", 15, "some node"], members[0] + + relation = relations(:relation_with_versions_v2) + members = OldRelation.find(relation.id).members + assert_equal 1, members.count + assert_equal ["Node", 15, "some changed node"], members[0] + + relation = relations(:relation_with_versions_v3) + members = OldRelation.find(relation.id).members + assert_equal 2, members.count + assert_equal ["Node", 15, "some changed node"], members[0] + assert_equal ["Relation", 7, "some relation"], members[1] + + relation = relations(:relation_with_versions_v4) + members = OldRelation.find(relation.id).members + assert_equal 3, members.count + assert_equal ["Node", 15, "some node"], members[0] + assert_equal ["Way", 4, "some way"], members[1] + assert_equal ["Relation", 7, "some relation"], members[2] + end + def test_tags relation = relations(:relation_with_versions_v1) tags = OldRelation.find(relation.id).tags diff --git a/test/unit/relation_member_test.rb b/test/unit/relation_member_test.rb index b4f817b05..2b1fe113f 100644 --- a/test/unit/relation_member_test.rb +++ b/test/unit/relation_member_test.rb @@ -4,7 +4,6 @@ class RelationMemberTest < ActiveSupport::TestCase api_fixtures def test_relation_member_count - assert_equal 6, RelationMember.count + assert_equal 9, RelationMember.count end - end diff --git a/test/unit/relation_test.rb b/test/unit/relation_test.rb index 75a55e389..4caa6ce41 100644 --- a/test/unit/relation_test.rb +++ b/test/unit/relation_test.rb @@ -103,6 +103,30 @@ class RelationTest < ActiveSupport::TestCase assert_equal "Element relation/23 has duplicate tags with key dup", message_update.message end + def test_relation_members + relation = current_relations(:relation_with_versions) + members = Relation.find(relation.id).relation_members + assert_equal 3, members.count + assert_equal "some node", members[0].member_role + assert_equal "Node", members[0].member_type + assert_equal 15, members[0].member_id + assert_equal "some way", members[1].member_role + assert_equal "Way", members[1].member_type + assert_equal 4, members[1].member_id + assert_equal "some relation", members[2].member_role + assert_equal "Relation", members[2].member_type + assert_equal 7, members[2].member_id + end + + def test_relations + relation = current_relations(:relation_with_versions) + members = Relation.find(relation.id).members + assert_equal 3, members.count + assert_equal ["Node", 15, "some node"], members[0] + assert_equal ["Way", 4, "some way"], members[1] + assert_equal ["Relation", 7, "some relation"], members[2] + end + def test_relation_tags relation = current_relations(:relation_with_versions) tags = Relation.find(relation.id).relation_tags.order(:k) -- 2.39.5