From: Shaun McDonald Date: Wed, 19 Nov 2008 17:23:15 +0000 (+0000) Subject: More tag validations, and finishing the node/way/relation tests. X-Git-Tag: live~8121^2~136 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/ffbc4d5cb278c1afeafea5cfe904ec48d9f4d237?ds=sidebyside More tag validations, and finishing the node/way/relation tests. --- diff --git a/app/models/node_tag.rb b/app/models/node_tag.rb index 6b21e4b01..494260112 100644 --- a/app/models/node_tag.rb +++ b/app/models/node_tag.rb @@ -5,4 +5,6 @@ class NodeTag < ActiveRecord::Base 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 diff --git a/app/models/old_node_tag.rb b/app/models/old_node_tag.rb index 392e3934e..3fd4bf86b 100644 --- a/app/models/old_node_tag.rb +++ b/app/models/old_node_tag.rb @@ -1,9 +1,10 @@ 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 diff --git a/app/models/old_relation_tag.rb b/app/models/old_relation_tag.rb index 7ce6f694e..0fcb11326 100644 --- a/app/models/old_relation_tag.rb +++ b/app/models/old_relation_tag.rb @@ -1,3 +1,10 @@ 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 diff --git a/app/models/old_way_tag.rb b/app/models/old_way_tag.rb index 68003cbeb..801532dba 100644 --- a/app/models/old_way_tag.rb +++ b/app/models/old_way_tag.rb @@ -1,8 +1,8 @@ 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] diff --git a/test/unit/node_tag_test.rb b/test/unit/node_tag_test.rb index 9d3da03b1..2ff9f9f00 100644 --- a/test/unit/node_tag_test.rb +++ b/test/unit/node_tag_test.rb @@ -68,4 +68,15 @@ class NodeTagTest < Test::Unit::TestCase 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 diff --git a/test/unit/old_node_tag_test.rb b/test/unit/old_node_tag_test.rb index 4a9bcbfcb..497184348 100644 --- a/test/unit/old_node_tag_test.rb +++ b/test/unit/old_node_tag_test.rb @@ -63,4 +63,16 @@ class OldNodeTest < Test::Unit::TestCase 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 diff --git a/test/unit/old_relation_tag_test.rb b/test/unit/old_relation_tag_test.rb index 309e2fe80..d651810c0 100644 --- a/test/unit/old_relation_tag_test.rb +++ b/test/unit/old_relation_tag_test.rb @@ -1,11 +1,11 @@ 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