validates_presence_of :id
validates_length_of :k, :v, :maximum => 255, :allow_blank => true
+ validates_uniqueness_of :id, :scope => :k
+ validates_numericality_of :id, :only_integer => true
end
class OldNodeTag < ActiveRecord::Base
- belongs_to :user
-
set_table_name 'node_tags'
+
+ belongs_to :user
validates_presence_of :id, :version
validates_length_of :k, :v, :maximum => 255, :allow_blank => true
-
+ validates_uniqueness_of :id, :scope => [:k, :version]
+ validates_numericality_of :id, :version, :only_integer => true
end
class OldRelationTag < ActiveRecord::Base
set_table_name 'relation_tags'
+
+ belongs_to :old_relation, :foreign_key => [:id, :version]
+
+ validates_presence_of :id, :version
+ validates_length_of :k, :v, :maximum => 255, :allow_blank => true
+ validates_uniqueness_of :id, :scope => [:k, :version]
+ validates_numericality_of :id, :version, :only_integer => true
end
class OldWayTag < ActiveRecord::Base
- belongs_to :old_way
-
set_table_name 'way_tags'
+ belongs_to :old_way, :foreign_key => [:id, :version]
+
validates_presence_of :id
validates_length_of :k, :v, :maximum => 255, :allow_blank => true
validates_uniqueness_of :id, :scope => [:k, :version]
assert !tag.valid?, "Empty tag should be invalid"
assert tag.errors.invalid?(:id)
end
+
+ def test_uniqueness
+ tag = NodeTag.new
+ tag.id = current_node_tags(:t1).id
+ tag.k = current_node_tags(:t1).k
+ tag.v = current_node_tags(:t1).v
+ assert tag.new_record?
+ assert !tag.valid?
+ assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
+ assert tag.new_record?
+ end
end
assert tag.errors.invalid?(:id)
assert tag.errors.invalid?(:version)
end
+
+ def test_uniqueness
+ tag = OldNodeTag.new
+ tag.id = node_tags(:t1).id
+ tag.version = node_tags(:t1).version
+ tag.k = node_tags(:t1).k
+ tag.v = node_tags(:t1).v
+ assert tag.new_record?
+ assert !tag.valid?
+ assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
+ assert tag.new_record?
+ end
end
require File.dirname(__FILE__) + '/../test_helper'
-class RelationTagTest < Test::Unit::TestCase
+class OldRelationTagTest < Test::Unit::TestCase
fixtures :relation_tags
set_fixture_class :relation_tags => OldRelationTag
def test_tag_count
- assert_equal 3, OldRlationTag.count
+ assert_equal 3, OldRelationTag.count
end
def test_length_key_valid