More model validations. Fixing one test.
This commit is contained in:
parent
ecefee485b
commit
1375095343
8 changed files with 40 additions and 11 deletions
|
@ -12,8 +12,15 @@ class Changeset < ActiveRecord::Base
|
|||
has_many :old_ways
|
||||
has_many :old_relations
|
||||
|
||||
validates_presence_of :user_id, :created_at, :closed_at
|
||||
|
||||
validates_presence_of :id, :on => :update
|
||||
validates_presence_of :user_id, :created_at, :closed_at, :num_changes
|
||||
validates_uniqueness_of :id
|
||||
validates_numericality_of :id, :on => :update, :integer_only => true
|
||||
validates_numericality_of :min_lat, :max_lat, :min_lon, :max_lat, :allow_nil => true, :integer_only => true
|
||||
validates_numericality_of :user_id, :integer_only => true, :greater_than_or_equal_to => 1
|
||||
validates_numericality_of :num_changes, :integer_only => true, :greater_than_or_equal_to => 0
|
||||
validates_associated :user
|
||||
|
||||
# over-expansion factor to use when updating the bounding box
|
||||
EXPAND = 0.1
|
||||
|
||||
|
|
|
@ -6,11 +6,6 @@ class Node < ActiveRecord::Base
|
|||
|
||||
set_table_name 'current_nodes'
|
||||
|
||||
validates_presence_of :changeset_id, :timestamp
|
||||
validates_inclusion_of :visible, :in => [ true, false ]
|
||||
validates_numericality_of :latitude, :longitude
|
||||
validate :validate_position
|
||||
|
||||
belongs_to :changeset
|
||||
|
||||
has_many :old_nodes, :foreign_key => :id
|
||||
|
@ -26,6 +21,15 @@ class Node < ActiveRecord::Base
|
|||
has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
|
||||
has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation, :extend => ObjectFinder
|
||||
|
||||
validates_presence_of :id, :on => :update
|
||||
validates_presence_of :timestamp,:version, :changeset_id
|
||||
validates_uniqueness_of :id
|
||||
validates_inclusion_of :visible, :in => [ true, false ]
|
||||
validates_numericality_of :latitude, :longitude, :changeset_id, :version, :integer_only => true
|
||||
validates_numericality_of :id, :on => :update, :integer_only => true
|
||||
validate :validate_position
|
||||
validates_associated :changeset
|
||||
|
||||
# Sanity check the latitude and longitude and add an error if it's broken
|
||||
def validate_position
|
||||
errors.add_to_base("Node is not in the world") unless in_world?
|
||||
|
|
|
@ -8,6 +8,7 @@ class OldNode < ActiveRecord::Base
|
|||
validates_inclusion_of :visible, :in => [ true, false ]
|
||||
validates_numericality_of :latitude, :longitude
|
||||
validate :validate_position
|
||||
validates_associated :changeset
|
||||
|
||||
belongs_to :changeset
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ class OldRelation < ActiveRecord::Base
|
|||
set_table_name 'relations'
|
||||
|
||||
belongs_to :changeset
|
||||
|
||||
validates_associated :changeset
|
||||
|
||||
def self.from_relation(relation)
|
||||
old_relation = OldRelation.new
|
||||
|
|
|
@ -5,6 +5,8 @@ class OldWay < ActiveRecord::Base
|
|||
|
||||
belongs_to :changeset
|
||||
|
||||
validates_associated :changeset
|
||||
|
||||
def self.from_way(way)
|
||||
old_way = OldWay.new
|
||||
old_way.visible = way.visible
|
||||
|
|
|
@ -15,6 +15,14 @@ class Relation < ActiveRecord::Base
|
|||
has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
|
||||
has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation, :extend => ObjectFinder
|
||||
|
||||
validates_presence_of :id, :on => :update
|
||||
validates_presence_of :timestamp,:version, :changeset_id
|
||||
validates_uniqueness_of :id
|
||||
validates_inclusion_of :visible, :in => [ true, false ]
|
||||
validates_numericality_of :id, :on => :update, :integer_only => true
|
||||
validates_numericality_of :changeset_id, :version, :integer_only => true
|
||||
validates_associated :changeset
|
||||
|
||||
TYPES = ["node", "way", "relation"]
|
||||
|
||||
def self.from_xml(xml, create=false)
|
||||
|
|
|
@ -4,9 +4,6 @@ class Way < ActiveRecord::Base
|
|||
include ConsistencyValidations
|
||||
|
||||
set_table_name 'current_ways'
|
||||
|
||||
validates_presence_of :changeset_id, :timestamp
|
||||
validates_inclusion_of :visible, :in => [ true, false ]
|
||||
|
||||
belongs_to :changeset
|
||||
|
||||
|
@ -20,6 +17,14 @@ class Way < ActiveRecord::Base
|
|||
has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
|
||||
has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation, :extend => ObjectFinder
|
||||
|
||||
validates_presence_of :id, :on => :update
|
||||
validates_presence_of :changeset_id,:version, :timestamp
|
||||
validates_uniqueness_of :id
|
||||
validates_inclusion_of :visible, :in => [ true, false ]
|
||||
validates_numericality_of :changeset_id, :version, :integer_only => true
|
||||
validates_numericality_of :id, :on => :update, :integer_only => true
|
||||
validates_associated :changeset
|
||||
|
||||
def self.from_xml(xml, create=false)
|
||||
begin
|
||||
p = XML::Parser.new
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue