Add tests for member methods on relation models
[rails.git] / test / unit / old_relation_test.rb
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