1 require File.dirname(__FILE__) + '/../test_helper'
3 class RelationTagTest < Test::Unit::TestCase
6 def test_relation_tag_count
7 assert_equal 7, RelationTag.count
10 def test_length_key_valid
21 def test_length_value_valid
32 def test_length_key_invalid
38 assert !tag.valid?, "Key #{i} should be too long"
39 assert tag.errors.invalid?(:k)
43 def test_length_value_invalid
49 assert !tag.valid?, "Value #{i} should be too long"
50 assert tag.errors.invalid?(:v)
54 def test_empty_tag_invalid
56 assert !tag.valid?, "Empty relation tag should be invalid"
57 assert tag.errors.invalid?(:id)
62 tag.id = current_relation_tags(:t1).id
63 tag.k = current_relation_tags(:t1).k
64 tag.v = current_relation_tags(:t1).v
65 assert tag.new_record?
67 assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
68 assert tag.new_record?
72 # test that tags can be updated and saved uniquely, i.e: tag.save!
73 # only affects the single tag that the activerecord object
74 # represents. this amounts to testing that the primary key is
77 v = "probably unique string here 3142592654"
78 assert_equal 0, RelationTag.count(:conditions => ['v=?', v])
80 # make sure we select a tag on a relation which has more than one tag
81 id = current_relations(:multi_tag_relation).id
82 tag = RelationTag.find(:first, :conditions => ["id = ?", id])
86 assert_equal 1, RelationTag.count(:conditions => ['v=?', v])