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
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
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?
validates_inclusion_of :visible, :in => [ true, false ]
validates_numericality_of :latitude, :longitude
validate :validate_position
+ validates_associated :changeset
belongs_to :changeset
set_table_name 'relations'
belongs_to :changeset
+
+ validates_associated :changeset
def self.from_relation(relation)
old_relation = OldRelation.new
belongs_to :changeset
+ validates_associated :changeset
+
def self.from_way(way)
old_way = OldWay.new
old_way.visible = way.visible
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)
include ConsistencyValidations
set_table_name 'current_ways'
-
- validates_presence_of :changeset_id, :timestamp
- validates_inclusion_of :visible, :in => [ true, false ]
belongs_to :changeset
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
def test_create
node_template = Node.new(:latitude => 12.3456,
:longitude => 65.4321,
- :changeset_id => changesets(:normal_user_first_change),
+ :changeset_id => changesets(:normal_user_first_change).id,
:visible => 1,
:version => 1)
assert node_template.save_with_history!