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
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|
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|
##
# 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"]
--- /dev/null
+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
+++ /dev/null
-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'
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
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! }
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
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