]> git.openstreetmap.org Git - rails.git/commitdiff
Replace fixtures with factory for relation_tags
authorAndy Allan <git@gravitystorm.co.uk>
Mon, 31 Oct 2016 11:30:57 +0000 (12:30 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Mon, 31 Oct 2016 11:30:57 +0000 (12:30 +0100)
test/controllers/amf_controller_test.rb
test/controllers/relation_controller_test.rb
test/controllers/search_controller_test.rb
test/factories/relation_tags.rb [new file with mode: 0644]
test/fixtures/current_relation_tags.yml [deleted file]
test/models/relation_tag_test.rb
test/models/relation_test.rb
test/test_helper.rb

index 7c8c64ba085813f597d7353a9f86a8c49e5a024b..fde8883b053f30dbbd9ce6b36637570a1fd09133 100644 (file)
@@ -531,7 +531,10 @@ class AmfControllerTest < ActionController::TestCase
 
   def test_findrelations_by_tags
     visible_relation = current_relations(:visible_relation)
+    create(:relation_tag, :relation => visible_relation, :k => "test", :v => "yes")
     used_relation = current_relations(:used_relation)
+    create(:relation_tag, :relation => used_relation, :k => "test", :v => "yes")
+    create(:relation_tag, :relation => used_relation, :k => "name", :v => "Test Relation")
 
     amf_content "findrelations", "/1", ["yes"]
     post :amf_read
index ab0aca45ed1233e97576b737427c0ad9eaa45f1d..0366ceef03a47812f13d88ba17353de44e5df045 100644 (file)
@@ -337,6 +337,7 @@ class RelationControllerTest < ActionController::TestCase
   def test_update_relation_tags
     basic_authorization "test@example.com", "test"
     rel_id = current_relations(:multi_tag_relation).id
+    create_list(:relation_tag, 4, :relation => current_relations(:multi_tag_relation))
     cs_id = changesets(:public_user_first_change).id
 
     with_relation(rel_id) do |rel|
@@ -366,6 +367,7 @@ class RelationControllerTest < ActionController::TestCase
   def test_update_relation_tags_via_upload
     basic_authorization users(:public_user).email, "test"
     rel_id = current_relations(:multi_tag_relation).id
+    create_list(:relation_tag, 4, :relation => current_relations(:multi_tag_relation))
     cs_id = changesets(:public_user_first_change).id
 
     with_relation(rel_id) do |rel|
index a3b862419a4b8864c6bb5b19d6af14aab117b866..2e835a58758dbb88a995e85f698da6370ab4d7de 100644 (file)
@@ -64,6 +64,11 @@ class SearchControllerTest < ActionController::TestCase
   ##
   # test searching relations
   def test_search_relations
+    [:visible_relation, :invisible_relation, :used_relation].each do |relation|
+      create(:relation_tag, :relation => current_relations(relation), :k => "test", :v => "yes")
+    end
+    create(:relation_tag, :relation => current_relations(:used_relation), :k => "name", :v => "Test Relation")
+
     get :search_relations, :type => "test"
     assert_response :service_unavailable
     assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
diff --git a/test/factories/relation_tags.rb b/test/factories/relation_tags.rb
new file mode 100644 (file)
index 0000000..00ad4db
--- /dev/null
@@ -0,0 +1,9 @@
+FactoryGirl.define do
+  factory :relation_tag do
+    sequence(:k) { |n| "Key #{n}" }
+    sequence(:v) { |n| "Value #{n}" }
+
+    # Fixme requires relation factory
+    relation_id 1
+  end
+end
diff --git a/test/fixtures/current_relation_tags.yml b/test/fixtures/current_relation_tags.yml
deleted file mode 100644 (file)
index 505a761..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-t1:
-  relation_id: 1
-  k: 'test'
-  v: 'yes'
-
-t2:
-  relation_id: 2
-  k: 'test'
-  v: 'yes'
-
-t3:
-  relation_id: 3
-  k: 'test'
-  v: 'yes'
-
-t3_2:
-  relation_id: 3
-  k: 'name'
-  v: 'Test Relation'
-
-mt_1:
-  relation_id: 4
-  k: 'tag1'
-  v: 'val1'
-
-mt_2:
-  relation_id: 4
-  k: 'tag2'
-  v: 'val2'
-
-mt_3:
-  relation_id: 4
-  k: 'tag3'
-  v: 'val3'
-
-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'
index ef635cc945855aeddc5e3ff2a650e613fe4dc949..3b4d2cdfcbcd5e0fc400a7ff74c745ae56c03db5 100644 (file)
@@ -1,54 +1,34 @@
 require "test_helper"
 
 class RelationTagTest < ActiveSupport::TestCase
-  api_fixtures
-
-  def test_relation_tag_count
-    assert_equal 10, RelationTag.count
-  end
-
   def test_length_key_valid
-    key = "k"
+    tag = create(:relation_tag)
     (0..255).each do |i|
-      tag = RelationTag.new
-      tag.relation_id = 1
-      tag.k = key * i
-      tag.v = "v"
+      tag.k = "k" * i
       assert tag.valid?
     end
   end
 
   def test_length_value_valid
-    val = "v"
+    tag = create(:relation_tag)
     (0..255).each do |i|
-      tag = RelationTag.new
-      tag.relation_id = 1
-      tag.k = "k"
-      tag.v = val * i
+      tag.v = "v" * i
       assert tag.valid?
     end
   end
 
   def test_length_key_invalid
-    ["k" * 256].each do |i|
-      tag = RelationTag.new
-      tag.relation_id = 1
-      tag.k = i
-      tag.v = "v"
-      assert !tag.valid?, "Key #{i} should be too long"
-      assert tag.errors[:k].any?
-    end
+    tag = create(:relation_tag)
+    tag.k = "k" * 256
+    assert !tag.valid?, "Key should be too long"
+    assert tag.errors[:k].any?
   end
 
   def test_length_value_invalid
-    ["v" * 256].each do |i|
-      tag = RelationTag.new
-      tag.relation_id = 1
-      tag.k = "k"
-      tag.v = i
-      assert !tag.valid?, "Value #{i} should be too long"
-      assert tag.errors[:v].any?
-    end
+    tag = create(:relation_tag)
+    tag.v = "v" * 256
+    assert !tag.valid?, "Value should be too long"
+    assert tag.errors[:v].any?
   end
 
   def test_empty_tag_invalid
@@ -58,10 +38,11 @@ class RelationTagTest < ActiveSupport::TestCase
   end
 
   def test_uniquness
+    existing = create(:relation_tag)
     tag = RelationTag.new
-    tag.relation_id = current_relation_tags(:t1).relation_id
-    tag.k = current_relation_tags(:t1).k
-    tag.v = current_relation_tags(:t1).v
+    tag.relation_id = existing.relation_id
+    tag.k = existing.k
+    tag.v = existing.v
     assert tag.new_record?
     assert !tag.valid?
     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
index 028cd7d48fc95789aea4b132a09444d6fd7cc027..cb3330abe45b5721293ef2d60b038de4689ddd1d 100644 (file)
@@ -129,20 +129,25 @@ class RelationTest < ActiveSupport::TestCase
 
   def test_relation_tags
     relation = current_relations(:relation_with_versions)
+    taglist = create_list(:relation_tag, 2, :relation => relation)
+
     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
+    taglist.sort_by!(&:k).each_index do |i|
+      assert_equal taglist[i].k, tags[i].k
+      assert_equal taglist[i].v, tags[i].v
+    end
   end
 
   def test_tags
     relation = current_relations(:relation_with_versions)
+    taglist = create_list(:relation_tag, 2, :relation => relation)
+
     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"]
+    taglist.each do |tag|
+      assert_equal tag.v, tags[tag.k]
+    end
   end
 
   def test_containing_relation_members
index 8dd61448a9ae2d34f4a617a7ba8c1d06bca60409..e3d1d7a864b4b05c04c0601e69535a6f48a44bb4 100644 (file)
@@ -35,9 +35,8 @@ module ActiveSupport
       fixtures :current_relations
       set_fixture_class :current_relations => Relation
 
-      fixtures :current_relation_members, :current_relation_tags
+      fixtures :current_relation_members
       set_fixture_class :current_relation_members => RelationMember
-      set_fixture_class :current_relation_tags => RelationTag
 
       fixtures :relations
       set_fixture_class :relations => OldRelation