3 class RelationTagTest < ActiveSupport::TestCase
 
   4   def test_length_key_valid
 
   5     tag = create(:relation_tag)
 
   8       assert_predicate tag, :valid?
 
  12   def test_length_value_valid
 
  13     tag = create(:relation_tag)
 
  16       assert_predicate tag, :valid?
 
  20   def test_length_key_invalid
 
  21     tag = create(:relation_tag)
 
  23     assert_not_predicate tag, :valid?, "Key should be too long"
 
  24     assert_predicate tag.errors[:k], :any?
 
  27   def test_length_value_invalid
 
  28     tag = create(:relation_tag)
 
  30     assert_not_predicate tag, :valid?, "Value should be too long"
 
  31     assert_predicate tag.errors[:v], :any?
 
  34   def test_orphaned_tag_invalid
 
  35     tag = create(:relation_tag)
 
  37     assert_not_predicate tag, :valid?, "Orphaned tag should be invalid"
 
  38     assert_predicate tag.errors[:relation], :any?
 
  42     existing = create(:relation_tag)
 
  43     tag = build(:relation_tag, :relation => existing.relation, :k => existing.k, :v => existing.v)
 
  44     assert_predicate tag, :new_record?
 
  45     assert_not_predicate tag, :valid?
 
  46     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
 
  47     assert_predicate tag, :new_record?
 
  51   # test that tags can be updated and saved uniquely, i.e: tag.save!
 
  52   # only affects the single tag that the activerecord object
 
  53   # represents. this amounts to testing that the primary key is
 
  56   # Commenting this out - I attempted to fix it, but composite primary keys
 
  57   # wasn't playing nice with the column already called :id. Seemed to be
 
  58   # impossible to have validations on the :id column. If someone knows better
 
  59   # please fix, otherwise this test is shelved.
 
  62   #   v = "probably unique string here 3142592654"
 
  63   #   assert_equal 0, RelationTag.count(:conditions => ['v=?', v])
 
  65   #   # make sure we select a tag on a relation which has more than one tag
 
  66   #   id = current_relations(:multi_tag_relation).relation_id
 
  67   #   tag = RelationTag.find(:first, :conditions => ["id = ?", id])
 
  71   #   assert_equal 1, RelationTag.count(:conditions => ['v=?', v])