Add tests for member methods on relation models
authorTom Hughes <tom@compton.nu>
Thu, 5 Dec 2013 00:38:25 +0000 (00:38 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 5 Dec 2013 00:38:25 +0000 (00:38 +0000)
app/models/old_relation.rb
test/fixtures/current_relation_members.yml
test/fixtures/relation_members.yml
test/unit/old_relation_test.rb
test/unit/relation_member_test.rb
test/unit/relation_test.rb

index 9f80a81b9fc6b1e1edd32523a93073e6fe7863af..61c49eb590e803c2857248fd76df12ff92ea5a13 100644 (file)
@@ -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
index 31dccbc229c5e8d2c486f0a837b81559b5c1b817..67911b8d57c45fff716f0d87ae4417d913d22123 100644 (file)
@@ -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
index 931728dc7b8c843bd20aac074c8d91c4ddd7b218..a5f04f1ef28bada604572422d7047f2c13f6aebc 100644 (file)
@@ -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
index c99491079d71fc6b5c4cc6125aba98e3de9d51e3..31ff831971322d5015862e8d966cce0744a8487d 100644 (file)
@@ -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
index b4f817b05c3bd585f89f93de33ad9e9073247dcc..2b1fe113f9d0644fcbcfe0446c43e2dd0a31d30d 100644 (file)
@@ -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
index 75a55e389a393909e63673ae6c6a29f68298e621..4caa6ce41c856a634eee83eff2caf5af52219a19 100644 (file)
@@ -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)