3 class RelationTagTest < ActiveSupport::TestCase
6 def test_length_key_valid
7 tag = create(:relation_tag)
14 def test_length_value_valid
15 tag = create(:relation_tag)
22 def test_length_key_invalid
23 tag = create(:relation_tag)
25 assert !tag.valid?, "Key should be too long"
26 assert tag.errors[:k].any?
29 def test_length_value_invalid
30 tag = create(:relation_tag)
32 assert !tag.valid?, "Value should be too long"
33 assert tag.errors[:v].any?
36 def test_empty_tag_invalid
38 assert !tag.valid?, "Empty relation tag should be invalid"
39 assert tag.errors[:relation].any?
43 existing = create(:relation_tag)
45 tag.relation_id = existing.relation_id
48 assert tag.new_record?
50 assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
51 assert tag.new_record?
55 # test that tags can be updated and saved uniquely, i.e: tag.save!
56 # only affects the single tag that the activerecord object
57 # represents. this amounts to testing that the primary key is
60 # Commenting this out - I attempted to fix it, but composite primary keys
61 # wasn't playing nice with the column already called :id. Seemed to be
62 # impossible to have validations on the :id column. If someone knows better
63 # please fix, otherwise this test is shelved.
66 # v = "probably unique string here 3142592654"
67 # assert_equal 0, RelationTag.count(:conditions => ['v=?', v])
69 # # make sure we select a tag on a relation which has more than one tag
70 # id = current_relations(:multi_tag_relation).relation_id
71 # tag = RelationTag.find(:first, :conditions => ["id = ?", id])
75 # assert_equal 1, RelationTag.count(:conditions => ['v=?', v])