Replace fixtures with factory for relation_tags
This commit is contained in:
parent
97d63db369
commit
aa185bf4f8
8 changed files with 47 additions and 92 deletions
|
@ -531,7 +531,10 @@ class AmfControllerTest < ActionController::TestCase
|
||||||
|
|
||||||
def test_findrelations_by_tags
|
def test_findrelations_by_tags
|
||||||
visible_relation = current_relations(:visible_relation)
|
visible_relation = current_relations(:visible_relation)
|
||||||
|
create(:relation_tag, :relation => visible_relation, :k => "test", :v => "yes")
|
||||||
used_relation = current_relations(:used_relation)
|
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"]
|
amf_content "findrelations", "/1", ["yes"]
|
||||||
post :amf_read
|
post :amf_read
|
||||||
|
|
|
@ -337,6 +337,7 @@ class RelationControllerTest < ActionController::TestCase
|
||||||
def test_update_relation_tags
|
def test_update_relation_tags
|
||||||
basic_authorization "test@example.com", "test"
|
basic_authorization "test@example.com", "test"
|
||||||
rel_id = current_relations(:multi_tag_relation).id
|
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
|
cs_id = changesets(:public_user_first_change).id
|
||||||
|
|
||||||
with_relation(rel_id) do |rel|
|
with_relation(rel_id) do |rel|
|
||||||
|
@ -366,6 +367,7 @@ class RelationControllerTest < ActionController::TestCase
|
||||||
def test_update_relation_tags_via_upload
|
def test_update_relation_tags_via_upload
|
||||||
basic_authorization users(:public_user).email, "test"
|
basic_authorization users(:public_user).email, "test"
|
||||||
rel_id = current_relations(:multi_tag_relation).id
|
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
|
cs_id = changesets(:public_user_first_change).id
|
||||||
|
|
||||||
with_relation(rel_id) do |rel|
|
with_relation(rel_id) do |rel|
|
||||||
|
|
|
@ -64,6 +64,11 @@ class SearchControllerTest < ActionController::TestCase
|
||||||
##
|
##
|
||||||
# test searching relations
|
# test searching relations
|
||||||
def test_search_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"
|
get :search_relations, :type => "test"
|
||||||
assert_response :service_unavailable
|
assert_response :service_unavailable
|
||||||
assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
|
assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
|
||||||
|
|
9
test/factories/relation_tags.rb
Normal file
9
test/factories/relation_tags.rb
Normal file
|
@ -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
|
49
test/fixtures/current_relation_tags.yml
vendored
49
test/fixtures/current_relation_tags.yml
vendored
|
@ -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'
|
|
|
@ -1,55 +1,35 @@
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class RelationTagTest < ActiveSupport::TestCase
|
class RelationTagTest < ActiveSupport::TestCase
|
||||||
api_fixtures
|
|
||||||
|
|
||||||
def test_relation_tag_count
|
|
||||||
assert_equal 10, RelationTag.count
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_length_key_valid
|
def test_length_key_valid
|
||||||
key = "k"
|
tag = create(:relation_tag)
|
||||||
(0..255).each do |i|
|
(0..255).each do |i|
|
||||||
tag = RelationTag.new
|
tag.k = "k" * i
|
||||||
tag.relation_id = 1
|
|
||||||
tag.k = key * i
|
|
||||||
tag.v = "v"
|
|
||||||
assert tag.valid?
|
assert tag.valid?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_length_value_valid
|
def test_length_value_valid
|
||||||
val = "v"
|
tag = create(:relation_tag)
|
||||||
(0..255).each do |i|
|
(0..255).each do |i|
|
||||||
tag = RelationTag.new
|
tag.v = "v" * i
|
||||||
tag.relation_id = 1
|
|
||||||
tag.k = "k"
|
|
||||||
tag.v = val * i
|
|
||||||
assert tag.valid?
|
assert tag.valid?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_length_key_invalid
|
def test_length_key_invalid
|
||||||
["k" * 256].each do |i|
|
tag = create(:relation_tag)
|
||||||
tag = RelationTag.new
|
tag.k = "k" * 256
|
||||||
tag.relation_id = 1
|
assert !tag.valid?, "Key should be too long"
|
||||||
tag.k = i
|
|
||||||
tag.v = "v"
|
|
||||||
assert !tag.valid?, "Key #{i} should be too long"
|
|
||||||
assert tag.errors[:k].any?
|
assert tag.errors[:k].any?
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_length_value_invalid
|
def test_length_value_invalid
|
||||||
["v" * 256].each do |i|
|
tag = create(:relation_tag)
|
||||||
tag = RelationTag.new
|
tag.v = "v" * 256
|
||||||
tag.relation_id = 1
|
assert !tag.valid?, "Value should be too long"
|
||||||
tag.k = "k"
|
|
||||||
tag.v = i
|
|
||||||
assert !tag.valid?, "Value #{i} should be too long"
|
|
||||||
assert tag.errors[:v].any?
|
assert tag.errors[:v].any?
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def test_empty_tag_invalid
|
def test_empty_tag_invalid
|
||||||
tag = RelationTag.new
|
tag = RelationTag.new
|
||||||
|
@ -58,10 +38,11 @@ class RelationTagTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_uniquness
|
def test_uniquness
|
||||||
|
existing = create(:relation_tag)
|
||||||
tag = RelationTag.new
|
tag = RelationTag.new
|
||||||
tag.relation_id = current_relation_tags(:t1).relation_id
|
tag.relation_id = existing.relation_id
|
||||||
tag.k = current_relation_tags(:t1).k
|
tag.k = existing.k
|
||||||
tag.v = current_relation_tags(:t1).v
|
tag.v = existing.v
|
||||||
assert tag.new_record?
|
assert tag.new_record?
|
||||||
assert !tag.valid?
|
assert !tag.valid?
|
||||||
assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
|
assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
|
||||||
|
|
|
@ -129,20 +129,25 @@ class RelationTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
def test_relation_tags
|
def test_relation_tags
|
||||||
relation = current_relations(:relation_with_versions)
|
relation = current_relations(:relation_with_versions)
|
||||||
|
taglist = create_list(:relation_tag, 2, :relation => relation)
|
||||||
|
|
||||||
tags = Relation.find(relation.id).relation_tags.order(:k)
|
tags = Relation.find(relation.id).relation_tags.order(:k)
|
||||||
assert_equal 2, tags.count
|
assert_equal 2, tags.count
|
||||||
assert_equal "testing", tags[0].k
|
taglist.sort_by!(&:k).each_index do |i|
|
||||||
assert_equal "added in relation version 3", tags[0].v
|
assert_equal taglist[i].k, tags[i].k
|
||||||
assert_equal "testing two", tags[1].k
|
assert_equal taglist[i].v, tags[i].v
|
||||||
assert_equal "modified in relation version 4", tags[1].v
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tags
|
def test_tags
|
||||||
relation = current_relations(:relation_with_versions)
|
relation = current_relations(:relation_with_versions)
|
||||||
|
taglist = create_list(:relation_tag, 2, :relation => relation)
|
||||||
|
|
||||||
tags = Relation.find(relation.id).tags
|
tags = Relation.find(relation.id).tags
|
||||||
assert_equal 2, tags.size
|
assert_equal 2, tags.size
|
||||||
assert_equal "added in relation version 3", tags["testing"]
|
taglist.each do |tag|
|
||||||
assert_equal "modified in relation version 4", tags["testing two"]
|
assert_equal tag.v, tags[tag.k]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_containing_relation_members
|
def test_containing_relation_members
|
||||||
|
|
|
@ -35,9 +35,8 @@ module ActiveSupport
|
||||||
fixtures :current_relations
|
fixtures :current_relations
|
||||||
set_fixture_class :current_relations => Relation
|
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_members => RelationMember
|
||||||
set_fixture_class :current_relation_tags => RelationTag
|
|
||||||
|
|
||||||
fixtures :relations
|
fixtures :relations
|
||||||
set_fixture_class :relations => OldRelation
|
set_fixture_class :relations => OldRelation
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue