From: Tom Hughes Date: Sun, 25 Sep 2011 13:42:33 +0000 (+0100) Subject: Rename all ID columns that aren't unique X-Git-Tag: live~6609 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/fc25c3d412829774abf0454e4dcc92e41f47454c Rename all ID columns that aren't unique Having a table with a column called ID that is only part of the primary key really doesn't work as rails likes to treat ID as a special name so it becomes impossible to assign to it or read it. --- diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index ccc1259f7..9c9228a7a 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -413,13 +413,13 @@ class AmfController < ApplicationController amf_handle_error_with_timeout("'getway_old' #{id}, #{timestamp}", 'way',id) do if timestamp == '' # undelete - old_way = OldWay.where(:visible => true, :id => id).order("version DESC").first + old_way = OldWay.where(:visible => true, :way_id => id).order("version DESC").first points = old_way.get_nodes_undelete unless old_way.nil? else begin # revert timestamp = DateTime.strptime(timestamp.to_s, "%d %b %Y, %H:%M:%S") - old_way = OldWay.where("id = ? AND timestamp <= ?", id, timestamp).order("timestamp DESC").first + old_way = OldWay.where("way_id = ? AND timestamp <= ?", id, timestamp).order("timestamp DESC").first unless old_way.nil? points = old_way.get_nodes_revert(timestamp) if !old_way.visible diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index 51d0049a7..ca501fd43 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -177,7 +177,7 @@ class ChangesetController < ApplicationController created << elt.to_xml_node else # get the previous version from the element history - prev_elt = elt.class.where(:id => elt.id, :version => elt.version).first + prev_elt = elt.class.find([elt.id, elt.version]) unless elt.visible # if the element isn't visible then it must have been deleted, so # output the *previous* XML diff --git a/app/controllers/old_node_controller.rb b/app/controllers/old_node_controller.rb index 514e5befe..4a1253034 100644 --- a/app/controllers/old_node_controller.rb +++ b/app/controllers/old_node_controller.rb @@ -18,7 +18,7 @@ class OldNodeController < ApplicationController end def version - if old_node = OldNode.where(:id => params[:id], :version => params[:version]).first + if old_node = OldNode.where(:node_id => params[:id], :version => params[:version]).first response.last_modified = old_node.timestamp doc = OSM::API.new.get_xml_doc diff --git a/app/controllers/old_relation_controller.rb b/app/controllers/old_relation_controller.rb index 0e1950cee..771b322ee 100644 --- a/app/controllers/old_relation_controller.rb +++ b/app/controllers/old_relation_controller.rb @@ -17,7 +17,7 @@ class OldRelationController < ApplicationController end def version - if old_relation = OldRelation.where(:id => params[:id], :version => params[:version]).first + if old_relation = OldRelation.where(:relation_id => params[:id], :version => params[:version]).first response.last_modified = old_relation.timestamp doc = OSM::API.new.get_xml_doc diff --git a/app/controllers/old_way_controller.rb b/app/controllers/old_way_controller.rb index 5ea1a0497..c20212df4 100644 --- a/app/controllers/old_way_controller.rb +++ b/app/controllers/old_way_controller.rb @@ -18,7 +18,7 @@ class OldWayController < ApplicationController end def version - if old_way = OldWay.where(:id => params[:id], :version => params[:version]).first + if old_way = OldWay.where(:way_id => params[:id], :version => params[:version]).first response.last_modified = old_way.timestamp doc = OSM::API.new.get_xml_doc diff --git a/app/controllers/relation_controller.rb b/app/controllers/relation_controller.rb index 0c2cccd11..10328aae4 100644 --- a/app/controllers/relation_controller.rb +++ b/app/controllers/relation_controller.rb @@ -157,7 +157,7 @@ class RelationController < ApplicationController end def relations_for_object(objtype) - relationids = RelationMember.where(:member_type => objtype, :member_id => params[:id]).collect { |ws| ws.id[0] }.uniq + relationids = RelationMember.where(:member_type => objtype, :member_id => params[:id]).collect { |ws| ws.relation_id }.uniq doc = OSM::API.new.get_xml_doc diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 3f6df27f6..d58d91bb3 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -3,7 +3,7 @@ class Changeset < ActiveRecord::Base belongs_to :user - has_many :changeset_tags, :foreign_key => 'id' + has_many :changeset_tags has_many :nodes has_many :ways @@ -177,13 +177,13 @@ class Changeset < ActiveRecord::Base self.save! tags = self.tags - ChangesetTag.delete_all(['id = ?', self.id]) + ChangesetTag.delete_all(:changeset_id => self.id) tags.each do |k,v| tag = ChangesetTag.new + tag.changeset_id = self.id tag.k = k tag.v = v - tag.id = self.id tag.save! end end diff --git a/app/models/changeset_tag.rb b/app/models/changeset_tag.rb index 6a414a0fc..bd0417ab4 100644 --- a/app/models/changeset_tag.rb +++ b/app/models/changeset_tag.rb @@ -1,8 +1,10 @@ class ChangesetTag < ActiveRecord::Base - belongs_to :changeset, :foreign_key => 'id' + set_primary_keys :changeset_id, :k - 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 + belongs_to :changeset + + validates_presence_of :changeset + validates_length_of :k, :maximum => 255, :allow_blank => true + validates_uniqueness_of :k, :scope => :changeset_id + validates_length_of :v, :maximum => 255, :allow_blank => true end diff --git a/app/models/node.rb b/app/models/node.rb index 8f154b473..915188e47 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -8,12 +8,12 @@ class Node < ActiveRecord::Base belongs_to :changeset - has_many :old_nodes, :foreign_key => :id, :order => :version + has_many :old_nodes, :order => :version has_many :way_nodes has_many :ways, :through => :way_nodes - has_many :node_tags, :foreign_key => :id + has_many :node_tags has_many :old_way_nodes has_many :ways_via_history, :class_name=> "Way", :through => :old_way_nodes, :source => :way @@ -289,12 +289,12 @@ class Node < ActiveRecord::Base # Create a NodeTag tags = self.tags - NodeTag.delete_all(['id = ?', self.id]) + NodeTag.delete_all(:node_id => self.id) tags.each do |k,v| tag = NodeTag.new + tag.node_id = self.id tag.k = k tag.v = v - tag.id = self.id tag.save! end diff --git a/app/models/node_tag.rb b/app/models/node_tag.rb index 494260112..6bc1c555e 100644 --- a/app/models/node_tag.rb +++ b/app/models/node_tag.rb @@ -1,10 +1,11 @@ class NodeTag < ActiveRecord::Base set_table_name 'current_node_tags' + set_primary_keys :node_id, :k - belongs_to :node, :foreign_key => 'id' + belongs_to :node - 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 + validates_presence_of :node + validates_length_of :k, :maximum => 255, :allow_blank => true + validates_uniqueness_of :k, :scope => :node_id + validates_length_of :v, :maximum => 255, :allow_blank => true end diff --git a/app/models/old_node.rb b/app/models/old_node.rb index ca179e0e9..f8af91abb 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -3,11 +3,8 @@ class OldNode < ActiveRecord::Base include ConsistencyValidations set_table_name 'nodes' - - # Should probably have the composite primary key set in the model - # however there are some weird bugs happening when you do - #set_primary_keys :id, :version - + set_primary_keys :node_id, :version + validates_presence_of :changeset_id, :timestamp validates_inclusion_of :visible, :in => [ true, false ] validates_numericality_of :latitude, :longitude @@ -28,7 +25,7 @@ class OldNode < ActiveRecord::Base old_node.tags = node.tags old_node.timestamp = node.timestamp old_node.changeset_id = node.changeset_id - old_node.id = node.id + old_node.node_id = node.id old_node.version = node.version return old_node end @@ -41,7 +38,7 @@ class OldNode < ActiveRecord::Base def to_xml_node el1 = XML::Node.new 'node' - el1['id'] = self.id.to_s + el1['id'] = self.node_id.to_s el1['lat'] = self.lat.to_s el1['lon'] = self.lon.to_s el1['changeset'] = self.changeset.id.to_s @@ -69,13 +66,13 @@ class OldNode < ActiveRecord::Base clear_aggregation_cache clear_association_cache #ok from here - @attributes.update(OldNode.where('id = ? AND timestamp = ? AND version = ?', self.id, self.timestamp, self.version).first.instance_variable_get('@attributes')) + @attributes.update(OldNode.where(:node_id => self.node_id, :timestamp => self.timestamp, :version => self.version).first.instance_variable_get('@attributes')) self.tags.each do |k,v| tag = OldNodeTag.new tag.k = k tag.v = v - tag.id = self.id + tag.node_id = self.node_id tag.version = self.version tag.save! end @@ -83,10 +80,10 @@ class OldNode < ActiveRecord::Base def tags unless @tags - @tags = Hash.new - OldNodeTag.where("id = ? AND version = ?", self.id, self.version).each do |tag| - @tags[tag.k] = tag.v - end + @tags = Hash.new + OldNodeTag.where(:node_id => self.node_id, :version => self.version).each do |tag| + @tags[tag.k] = tag.v + end end @tags = Hash.new unless @tags @tags diff --git a/app/models/old_node_tag.rb b/app/models/old_node_tag.rb index dd339ad30..cd5bc4739 100644 --- a/app/models/old_node_tag.rb +++ b/app/models/old_node_tag.rb @@ -1,10 +1,11 @@ class OldNodeTag < ActiveRecord::Base set_table_name 'node_tags' + set_primary_keys :node_id, :version, :k - belongs_to :user + belongs_to :old_node, :foreign_key => [:node_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 + validates_presence_of :old_node + validates_length_of :k, :maximum => 255, :allow_blank => true + validates_uniqueness_of :k, :scope => [:node_id, :version] + validates_length_of :v, :maximum => 255, :allow_blank => true end diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index c83453e25..87771caab 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -2,8 +2,12 @@ class OldRelation < ActiveRecord::Base include ConsistencyValidations set_table_name 'relations' + set_primary_keys :relation_id, :version belongs_to :changeset + + has_many :old_members, :class_name => 'OldRelationMember', :foreign_key => [:relation_id, :version], :order => :sequence_id + has_many :old_tags, :class_name => 'OldRelationTag', :foreign_key => [:relation_id, :version] validates_associated :changeset @@ -12,7 +16,7 @@ class OldRelation < ActiveRecord::Base old_relation.visible = relation.visible old_relation.changeset_id = relation.changeset_id old_relation.timestamp = relation.timestamp - old_relation.id = relation.id + old_relation.relation_id = relation.id old_relation.version = relation.version old_relation.members = relation.members old_relation.tags = relation.tags @@ -25,7 +29,7 @@ class OldRelation < ActiveRecord::Base save! clear_aggregation_cache clear_association_cache - @attributes.update(OldRelation.where('id = ? AND timestamp = ?', self.id, self.timestamp).order("version DESC").first.instance_variable_get('@attributes')) + @attributes.update(OldRelation.where(:relation_id => self.relation_id, :timestamp => self.timestamp).order("version DESC").first.instance_variable_get('@attributes')) # ok, you can touch from here on @@ -33,14 +37,14 @@ class OldRelation < ActiveRecord::Base tag = OldRelationTag.new tag.k = k tag.v = v - tag.id = self.id + tag.relation_id = self.relation_id tag.version = self.version tag.save! end self.members.each_with_index do |m,i| member = OldRelationMember.new - member.id = [self.id, self.version, i] + member.id = [self.relation_id, self.version, i] member.member_type = m[0].classify member.member_id = m[1] member.member_role = m[2] @@ -50,20 +54,20 @@ class OldRelation < ActiveRecord::Base def members unless @members - @members = Array.new - OldRelationMember.where("id = ? AND version = ?", self.id, self.version).order(:sequence_id).each do |m| - @members += [[m.type,m.id,m.role]] - end + @members = Array.new + OldRelationMember.where(:relation_id => self.relation_id, :version => self.version).order(:sequence_id).each do |m| + @members += [[m.type,m.id,m.role]] + end end @members end def tags unless @tags - @tags = Hash.new - OldRelationTag.where("id = ? AND version = ?", self.id, self.version).each do |tag| - @tags[tag.k] = tag.v - end + @tags = Hash.new + OldRelationTag.where(:relation_id => self.relation_id, :version => self.version).each do |tag| + @tags[tag.k] = tag.v + end end @tags = Hash.new unless @tags @tags @@ -77,17 +81,6 @@ class OldRelation < ActiveRecord::Base @tags = t end -# has_many :relation_segments, :class_name => 'OldRelationSegment', :foreign_key => 'id' -# has_many :relation_tags, :class_name => 'OldRelationTag', :foreign_key => 'id' - - def old_members - OldRelationMember.where('id = ? AND version = ?', self.id, self.version).order(:sequence_id) - end - - def old_tags - OldRelationTag.where('id = ? AND version = ?', self.id, self.version) - end - def to_xml doc = OSM::API.new.get_xml_doc doc.root << to_xml_node() @@ -96,7 +89,7 @@ class OldRelation < ActiveRecord::Base def to_xml_node el1 = XML::Node.new 'relation' - el1['id'] = self.id.to_s + el1['id'] = self.relation_id.to_s el1['visible'] = self.visible.to_s el1['timestamp'] = self.timestamp.xmlschema if self.changeset.user.data_public? diff --git a/app/models/old_relation_member.rb b/app/models/old_relation_member.rb index 7bd7442dd..58d7cccfb 100644 --- a/app/models/old_relation_member.rb +++ b/app/models/old_relation_member.rb @@ -1,8 +1,8 @@ class OldRelationMember < ActiveRecord::Base set_table_name 'relation_members' + set_primary_keys :relation_id, :version, :sequence_id - set_primary_keys :id, :version, :sequence_id - belongs_to :relation, :foreign_key=> :id + belongs_to :old_relation, :foreign_key => [:relation_id, :version] # A bit messy, referring to the current tables, should do for the data browser for now belongs_to :member, :polymorphic => true end diff --git a/app/models/old_relation_tag.rb b/app/models/old_relation_tag.rb index 0fcb11326..032a87c77 100644 --- a/app/models/old_relation_tag.rb +++ b/app/models/old_relation_tag.rb @@ -1,10 +1,11 @@ class OldRelationTag < ActiveRecord::Base set_table_name 'relation_tags' + set_primary_keys :relation_id, :version, :k + + belongs_to :old_relation, :foreign_key => [:relation_id, :version] - 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 + validates_presence_of :old_relation + validates_length_of :k, :maximum => 255, :allow_blank => true + validates_uniqueness_of :k, :scope => [:relation_id, :version] + validates_length_of :v, :maximum => 255, :allow_blank => true end diff --git a/app/models/old_way.rb b/app/models/old_way.rb index 85cc64447..c2af4f21c 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -2,9 +2,13 @@ class OldWay < ActiveRecord::Base include ConsistencyValidations set_table_name 'ways' + set_primary_keys :way_id, :version belongs_to :changeset + has_many :old_nodes, :class_name => 'OldWayNode', :foreign_key => [:way_id, :version] + has_many :old_tags, :class_name => 'OldWayTag', :foreign_key => [:way_id, :version] + validates_associated :changeset def self.from_way(way) @@ -12,7 +16,7 @@ class OldWay < ActiveRecord::Base old_way.visible = way.visible old_way.changeset_id = way.changeset_id old_way.timestamp = way.timestamp - old_way.id = way.id + old_way.way_id = way.id old_way.version = way.version old_way.nds = way.nds old_way.tags = way.tags @@ -30,7 +34,7 @@ class OldWay < ActiveRecord::Base save! clear_aggregation_cache clear_association_cache - @attributes.update(OldWay.where('id = ? AND timestamp = ?', self.id, self.timestamp).order("version DESC").first.instance_variable_get('@attributes')) + @attributes.update(OldWay.where(:way_id => self.way_id, :timestamp => self.timestamp).order("version DESC").first.instance_variable_get('@attributes')) # ok, you can touch from here on @@ -38,7 +42,7 @@ class OldWay < ActiveRecord::Base tag = OldWayTag.new tag.k = k tag.v = v - tag.id = self.id + tag.way_id = self.way_id tag.version = self.version tag.save! end @@ -46,7 +50,7 @@ class OldWay < ActiveRecord::Base sequence = 1 self.nds.each do |n| nd = OldWayNode.new - nd.id = [self.id, self.version, sequence] + nd.id = [self.way_id, self.version, sequence] nd.node_id = n nd.save! sequence += 1 @@ -55,20 +59,20 @@ class OldWay < ActiveRecord::Base def nds unless @nds - @nds = Array.new - OldWayNode.where("id = ? AND version = ?", self.id, self.version).order(:sequence_id).each do |nd| - @nds += [nd.node_id] - end + @nds = Array.new + OldWayNode.where(:way_id => self.way_id, :version => self.version).order(:sequence_id).each do |nd| + @nds += [nd.node_id] + end end @nds end def tags unless @tags - @tags = Hash.new - OldWayTag.where("id = ? AND version = ?", self.id, self.version).each do |tag| - @tags[tag.k] = tag.v - end + @tags = Hash.new + OldWayTag.where(:way_id => self.way_id, :version => self.version).each do |tag| + @tags[tag.k] = tag.v + end end @tags = Hash.new unless @tags @tags @@ -82,20 +86,9 @@ class OldWay < ActiveRecord::Base @tags = t end -# has_many :way_nodes, :class_name => 'OldWayNode', :foreign_key => 'id' -# has_many :way_tags, :class_name => 'OldWayTag', :foreign_key => 'id' - - def old_nodes - OldWayNode.where('id = ? AND version = ?', self.id, self.version) - end - - def old_tags - OldWayTag.where('id = ? AND version = ?', self.id, self.version) - end - def to_xml_node el1 = XML::Node.new 'way' - el1['id'] = self.id.to_s + el1['id'] = self.way_id.to_s el1['visible'] = self.visible.to_s el1['timestamp'] = self.timestamp.xmlschema if self.changeset.user.data_public? @@ -139,12 +132,12 @@ class OldWay < ActiveRecord::Base def get_nodes_revert(timestamp) points=[] self.nds.each do |n| - oldnode = OldNode.where('id = ? AND timestamp <= ?', n, timestamp).order("timestamp DESC").first + oldnode = OldNode.where('node_id = ? AND timestamp <= ?', n, timestamp).order("timestamp DESC").first curnode = Node.find(n) id = n; reuse = curnode.visible if oldnode.lat != curnode.lat or oldnode.lon != curnode.lon or oldnode.tags != curnode.tags then # node has changed: if it's in other ways, give it a new id - if curnode.ways-[self.id] then id=-1; reuse=false end + if curnode.ways-[self.node_id] then id=-1; reuse=false end end points << [oldnode.lon, oldnode.lat, id, curnode.version, oldnode.tags_as_hash, reuse] end diff --git a/app/models/old_way_node.rb b/app/models/old_way_node.rb index 6234b85c2..b613be0b4 100644 --- a/app/models/old_way_node.rb +++ b/app/models/old_way_node.rb @@ -1,10 +1,9 @@ class OldWayNode < ActiveRecord::Base set_table_name 'way_nodes' + set_primary_keys :way_id, :version, :sequence_id - set_primary_keys :id, :version, :sequence_id - - belongs_to :way, :foreign_key=> :id - - # A bit messy, referring to current nodes, should do for the data browser for now + belongs_to :old_way, :foreign_key => [:way_id, :version] + # A bit messy, referring to current nodes and ways, should do for the data browser for now belongs_to :node + belongs_to :way end diff --git a/app/models/old_way_tag.rb b/app/models/old_way_tag.rb index 801532dba..9f4adb147 100644 --- a/app/models/old_way_tag.rb +++ b/app/models/old_way_tag.rb @@ -1,10 +1,11 @@ class OldWayTag < ActiveRecord::Base set_table_name 'way_tags' + set_primary_keys :way_id, :version, :k - belongs_to :old_way, :foreign_key => [:id, :version] + belongs_to :old_way, :foreign_key => [:way_id, :version] - validates_presence_of :id - 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 + validates_presence_of :old_way + validates_length_of :k, :maximum => 255, :allow_blank => true + validates_uniqueness_of :k, :scope => [:way_id, :version] + validates_length_of :v, :maximum => 255, :allow_blank => true end diff --git a/app/models/relation.rb b/app/models/relation.rb index d5a6d5dc0..659c4f18a 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -7,10 +7,10 @@ class Relation < ActiveRecord::Base belongs_to :changeset - has_many :old_relations, :foreign_key => 'id', :order => 'version' + has_many :old_relations, :order => 'version' - has_many :relation_members, :foreign_key => 'id', :order => 'sequence_id' - has_many :relation_tags, :foreign_key => 'id' + has_many :relation_members, :order => 'sequence_id' + has_many :relation_tags 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 @@ -348,12 +348,12 @@ class Relation < ActiveRecord::Base # if there are left-over tags then they are new and will have to # be added. tags_changed |= (not tags.empty?) - RelationTag.delete_all(:id => self.id) + RelationTag.delete_all(:relation_id => self.id) self.tags.each do |k,v| tag = RelationTag.new + tag.relation_id = self.id tag.k = k tag.v = v - tag.id = self.id tag.save! end @@ -378,10 +378,11 @@ class Relation < ActiveRecord::Base # members may be in a different order and i don't feel like implementing # a longest common subsequence algorithm to optimise this. members = self.members - RelationMember.delete_all(:id => self.id) + RelationMember.delete_all(:relation_id => self.id) members.each_with_index do |m,i| mem = RelationMember.new - mem.id = [self.id, i] + mem.relation_id = self.id + mem.sequence_id = i mem.member_type = m[0] mem.member_id = m[1] mem.member_role = m[2] diff --git a/app/models/relation_member.rb b/app/models/relation_member.rb index 82cb4cc8d..389e2ce52 100644 --- a/app/models/relation_member.rb +++ b/app/models/relation_member.rb @@ -1,10 +1,9 @@ class RelationMember < ActiveRecord::Base - set_table_name 'current_relation_members' - - set_primary_keys :id, :sequence_id + set_table_name 'current_relation_members' + set_primary_keys :relation_id, :sequence_id + belongs_to :relation belongs_to :member, :polymorphic => true - belongs_to :relation, :foreign_key => :id after_find :set_class_from_type after_initialize :set_class_from_type diff --git a/app/models/relation_tag.rb b/app/models/relation_tag.rb index 812b2ec35..2773d0612 100644 --- a/app/models/relation_tag.rb +++ b/app/models/relation_tag.rb @@ -1,10 +1,11 @@ class RelationTag < ActiveRecord::Base set_table_name 'current_relation_tags' + set_primary_keys :relation_id, :k - belongs_to :relation, :foreign_key => 'id' + belongs_to :relation - 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 + validates_presence_of :relation + validates_length_of :k, :maximum => 255, :allow_blank => true + validates_uniqueness_of :k, :scope => :relation_id + validates_length_of :v, :maximum => 255, :allow_blank => true end diff --git a/app/models/way.rb b/app/models/way.rb index 74fdfed34..b1870fc89 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -7,12 +7,12 @@ class Way < ActiveRecord::Base belongs_to :changeset - has_many :old_ways, :foreign_key => 'id', :order => 'version' + has_many :old_ways, :order => 'version' - has_many :way_nodes, :foreign_key => 'id', :order => 'sequence_id' + has_many :way_nodes, :order => 'sequence_id' has_many :nodes, :through => :way_nodes, :order => 'sequence_id' - has_many :way_tags, :foreign_key => 'id' + has_many :way_tags 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 @@ -320,17 +320,17 @@ class Way < ActiveRecord::Base self.save! tags = self.tags - WayTag.delete_all(['id = ?', self.id]) + WayTag.delete_all(:way_id => self.id) tags.each do |k,v| tag = WayTag.new + tag.way_id = self.id tag.k = k tag.v = v - tag.id = self.id tag.save! end nds = self.nds - WayNode.delete_all(['id = ?', self.id]) + WayNode.delete_all(:way_id => self.id) sequence = 1 nds.each do |n| nd = WayNode.new @@ -358,5 +358,4 @@ class Way < ActiveRecord::Base cs.save! end end - end diff --git a/app/models/way_node.rb b/app/models/way_node.rb index 957016b9d..1a2e6928a 100644 --- a/app/models/way_node.rb +++ b/app/models/way_node.rb @@ -1,8 +1,7 @@ class WayNode < ActiveRecord::Base set_table_name 'current_way_nodes' + set_primary_keys :way_id, :sequence_id - set_primary_keys :id, :sequence_id + belongs_to :way belongs_to :node - - belongs_to :way, :foreign_key => :id end diff --git a/app/models/way_tag.rb b/app/models/way_tag.rb index fa9b43361..f0c5eea8b 100644 --- a/app/models/way_tag.rb +++ b/app/models/way_tag.rb @@ -1,14 +1,11 @@ class WayTag < ActiveRecord::Base set_table_name 'current_way_tags' + set_primary_keys :way_id, :k - # False multipart keys. The following would be a hack: - # set_primary_keys :id, :k, :v - # FIXME add a real multipart key to waytags so that we can do eager loadin - - belongs_to :way, :foreign_key => 'id' + belongs_to :way - 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 + validates_presence_of :way + validates_length_of :k, :maximum => 255, :allow_blank => true + validates_uniqueness_of :k, :scope => :way_id + validates_length_of :v, :maximum => 255, :allow_blank => true end diff --git a/db/migrate/20110925112722_rename_ids.rb b/db/migrate/20110925112722_rename_ids.rb new file mode 100644 index 000000000..9cdbaaa36 --- /dev/null +++ b/db/migrate/20110925112722_rename_ids.rb @@ -0,0 +1,18 @@ +class RenameIds < ActiveRecord::Migration + def change + rename_column :changeset_tags, :id, :changeset_id + rename_column :current_node_tags, :id, :node_id + rename_column :nodes, :id, :node_id + rename_column :node_tags, :id, :node_id + rename_column :current_way_tags, :id, :way_id + rename_column :current_way_nodes, :id, :way_id + rename_column :ways, :id, :way_id + rename_column :way_tags, :id, :way_id + rename_column :way_nodes, :id, :way_id + rename_column :current_relation_tags, :id, :relation_id + rename_column :current_relation_members, :id, :relation_id + rename_column :relations, :id, :relation_id + rename_column :relation_tags, :id, :relation_id + rename_column :relation_members, :id, :relation_id + end +end diff --git a/test/fixtures/changeset_tags.yml b/test/fixtures/changeset_tags.yml index 2292f0dfc..ab5968b87 100644 --- a/test/fixtures/changeset_tags.yml +++ b/test/fixtures/changeset_tags.yml @@ -1,9 +1,9 @@ changeset_1_tag_1: - id: 1 + changeset_id: 1 k: created_by v: test suite yml changeset_2_tag_1: - id: 2 + changeset_id: 2 k: created_by v: test suite yml 2 diff --git a/test/fixtures/current_node_tags.yml b/test/fixtures/current_node_tags.yml index 8d5202e90..5087310e7 100644 --- a/test/fixtures/current_node_tags.yml +++ b/test/fixtures/current_node_tags.yml @@ -1,35 +1,35 @@ t1: - id: 1 + node_id: 1 k: 'testvisible' v: 'yes' t2: - id: 2 + node_id: 2 k: 'testused' v: 'yes' t3: - id: 3 + node_id: 3 k: 'test' v: 'yes' t4: - id: 4 + node_id: 4 k: 'test' v: 'yes' nv_t1: - id: 15 + node_id: 15 k: 'testing' v: 'added in node version 3' nv_t2: - id: 15 + node_id: 15 k: 'testing two' v: 'modified in node version 4' public_v_t1: - id: 16 + node_id: 16 k: 'testvisible' v: 'yes' diff --git a/test/fixtures/current_relation_members.yml b/test/fixtures/current_relation_members.yml index b9703827c..31dccbc22 100644 --- a/test/fixtures/current_relation_members.yml +++ b/test/fixtures/current_relation_members.yml @@ -1,35 +1,35 @@ t1: - id: 1 + relation_id: 1 member_role: "some" member_type: "Way" member_id: 3 t2: - id: 1 + relation_id: 1 member_role: "some" member_type: "Node" member_id: 5 t3: - id: 1 + relation_id: 1 member_role: "some" member_type: "Relation" member_id: 3 t4: - id: 3 + relation_id: 3 member_role: "some" member_type: "Node" member_id: 5 t5: - id: 2 + relation_id: 2 member_role: "some" member_type: "Node" member_id: 5 public_used: - id: 6 + relation_id: 6 member_role: "used by other relation" member_type: "Relation" member_id: 5 diff --git a/test/fixtures/current_relation_tags.yml b/test/fixtures/current_relation_tags.yml index a797a336c..6030b9853 100644 --- a/test/fixtures/current_relation_tags.yml +++ b/test/fixtures/current_relation_tags.yml @@ -1,34 +1,34 @@ t1: - id: 1 + relation_id: 1 k: 'test' v: 'yes' t2: - id: 2 + relation_id: 2 k: 'test' v: 'yes' t3: - id: 3 + relation_id: 3 k: 'test' v: 'yes' mt_1: - id: 4 + relation_id: 4 k: 'tag1' v: 'val1' mt_2: - id: 4 + relation_id: 4 k: 'tag2' v: 'val2' mt_3: - id: 4 + relation_id: 4 k: 'tag3' v: 'val3' mt_4: - id: 4 + relation_id: 4 k: 'tag4' v: 'val4' diff --git a/test/fixtures/current_way_nodes.yml b/test/fixtures/current_way_nodes.yml index ced1a686c..75c4a9981 100644 --- a/test/fixtures/current_way_nodes.yml +++ b/test/fixtures/current_way_nodes.yml @@ -1,29 +1,29 @@ t1: - id: 1 + way_id: 1 node_id: 3 sequence_id: 1 t2: - id: 2 + way_id: 2 node_id: 3 sequence_id: 1 t3: - id: 3 + way_id: 3 node_id: 3 sequence_id: 1 t4: - id: 4 + way_id: 4 node_id: 15 sequence_id: 1 w5_n1: - id: 5 + way_id: 5 node_id: 4 sequence_id: 1 w5_n2: - id: 5 + way_id: 5 node_id: 4 sequence_id: 2 diff --git a/test/fixtures/current_way_tags.yml b/test/fixtures/current_way_tags.yml index c1ef21d57..c2c27414d 100644 --- a/test/fixtures/current_way_tags.yml +++ b/test/fixtures/current_way_tags.yml @@ -1,15 +1,15 @@ t1: - id: 1 + way_id: 1 k: 'test' v: 'yes' t2: - id: 2 + way_id: 2 k: 'test' v: 'yes' t3: - id: 3 + way_id: 3 k: 'test' v: 'yes' diff --git a/test/fixtures/node_tags.yml b/test/fixtures/node_tags.yml index b02291300..6b908aa54 100644 --- a/test/fixtures/node_tags.yml +++ b/test/fixtures/node_tags.yml @@ -1,53 +1,53 @@ t1: - id: 1 + node_id: 1 k: 'testvisible' v: 'yes' version: 1 t2: - id: 3 + node_id: 3 k: 'test' v: 'yes' version: 1 t3: - id: 4 + node_id: 4 k: 'test' v: 'yes' version: 1 nv3_t1: - id: 15 + node_id: 15 k: 'testing' v: 'added in node version 3' version: 3 nv3_t2: - id: 15 + node_id: 15 k: 'testing two' v: 'added in node version 3' version: 3 nv3_t3: - id: 15 + node_id: 15 k: 'testing three' v: 'added in node version 3' version: 3 nv4_t1: - id: 15 + node_id: 15 k: 'testing' v: 'added in node version 3' version: 4 nv4_t2: - id: 15 + node_id: 15 k: 'testing two' v: 'modified in node version 4' version: 4 public_v_t1: - id: 16 + node_id: 16 k: 'testvisible' v: 'yes' version: 1 diff --git a/test/fixtures/nodes.yml b/test/fixtures/nodes.yml index d23a7c014..5125e7146 100644 --- a/test/fixtures/nodes.yml +++ b/test/fixtures/nodes.yml @@ -2,7 +2,7 @@ <% SCALE = 10000000 unless defined?(SCALE) %> visible_node: - id: 1 + node_id: 1 latitude: <%= 1*SCALE %> longitude: <%= 1*SCALE %> changeset_id: 1 @@ -12,7 +12,7 @@ visible_node: timestamp: 2007-01-01 00:00:00 invisible_node: - id: 2 + node_id: 2 latitude: <%= 2*SCALE %> longitude: <%= 2*SCALE %> changeset_id: 1 @@ -22,7 +22,7 @@ invisible_node: timestamp: 2007-01-01 00:00:00 used_node_1: - id: 3 + node_id: 3 latitude: <%= 3*SCALE %> longitude: <%= 3*SCALE %> changeset_id: 2 @@ -32,7 +32,7 @@ used_node_1: timestamp: 2007-01-01 00:00:00 used_node_2: - id: 4 + node_id: 4 latitude: <%= 4*SCALE %> longitude: <%= 4*SCALE %> changeset_id: 1 @@ -42,7 +42,7 @@ used_node_2: timestamp: 2007-01-01 00:00:00 node_used_by_relationship: - id: 5 + node_id: 5 latitude: <%= 5*SCALE %> longitude: <%= 5*SCALE %> changeset_id: 2 @@ -52,7 +52,7 @@ node_used_by_relationship: timestamp: 2007-01-01 00:00:00 node_too_far_north: - id: 6 + node_id: 6 latitude: <%= 90.01*SCALE %> longitude: <%= 6*SCALE %> changeset_id: 5 @@ -62,7 +62,7 @@ node_too_far_north: timestamp: 2007-01-01 00:00:00 node_north_limit: - id: 11 + node_id: 11 latitude: <%= 90*SCALE %> longitude: <%= 11*SCALE %> changeset_id: 5 @@ -72,7 +72,7 @@ node_north_limit: timestamp: 2008-07-08 14:50:00 node_too_far_south: - id: 7 + node_id: 7 latitude: <%= -90.01*SCALE %> longitude: <%= 7*SCALE %> changeset_id: 5 @@ -82,7 +82,7 @@ node_too_far_south: timestamp: 2007-01-01 00:00:00 node_south_limit: - id: 12 + node_id: 12 latitude: <%= -90*SCALE %> longitude: <%= 12*SCALE %> changeset_id: 5 @@ -92,7 +92,7 @@ node_south_limit: timestamp: 2008-07-08 15:02:18 node_too_far_west: - id: 8 + node_id: 8 latitude: <%= 8*SCALE %> longitude: <%= -180.01*SCALE %> changeset_id: 5 @@ -102,7 +102,7 @@ node_too_far_west: timestamp: 2007-01-01 00:00:00 node_west_limit: - id: 13 + node_id: 13 latitude: <%= 13*SCALE %> longitude: <%= -180*SCALE %> changeset_id: 5 @@ -112,7 +112,7 @@ node_west_limit: timestamp: 2008-07-08 15:17:37 node_too_far_east: - id: 9 + node_id: 9 latitude: <%= 9*SCALE %> longitude: <%= 180.01*SCALE %> changeset_id: 5 @@ -122,7 +122,7 @@ node_too_far_east: timestamp: 2007-01-01 00:00:00 node_east_limit: - id: 14 + node_id: 14 latitude: <%= 14*SCALE %> longitude: <%= 180*SCALE %> changeset_id: 5 @@ -132,7 +132,7 @@ node_east_limit: timestamp: 2008-07-08 15:46:16 node_totally_wrong: - id: 10 + node_id: 10 latitude: <%= 200*SCALE %> longitude: <%= 200*SCALE %> changeset_id: 5 @@ -142,7 +142,7 @@ node_totally_wrong: timestamp: 2007-01-01 00:00:00 node_with_versions_v1: - id: 15 + node_id: 15 latitude: <%= 1*SCALE %> longitude: <%= 1*SCALE %> changeset_id: 4 @@ -152,7 +152,7 @@ node_with_versions_v1: timestamp: 2008-01-01 00:01:00 node_with_versions_v2: - id: 15 + node_id: 15 latitude: <%= 2*SCALE %> longitude: <%= 2*SCALE %> changeset_id: 4 @@ -162,7 +162,7 @@ node_with_versions_v2: timestamp: 2008-01-01 00:02:00 node_with_versions_v3: - id: 15 + node_id: 15 latitude: <%= 1*SCALE %> longitude: <%= 1*SCALE %> changeset_id: 4 @@ -172,7 +172,7 @@ node_with_versions_v3: timestamp: 2008-01-01 00:03:00 node_with_versions_v4: - id: 15 + node_id: 15 latitude: <%= 1*SCALE %> longitude: <%= 1*SCALE %> changeset_id: 4 @@ -182,7 +182,7 @@ node_with_versions_v4: timestamp: 2008-01-01 00:04:00 public_visible_node: - id: 16 + node_id: 16 latitude: <%= 1*SCALE %> longitude: <%= 1*SCALE %> changeset_id: 2 diff --git a/test/fixtures/relation_members.yml b/test/fixtures/relation_members.yml index c65deca32..931728dc7 100644 --- a/test/fixtures/relation_members.yml +++ b/test/fixtures/relation_members.yml @@ -1,37 +1,37 @@ t1: - id: 1 + relation_id: 1 member_role: "some" member_type: "Way" member_id: 3 version: 1 t2: - id: 1 + relation_id: 1 member_role: "some" member_type: "Node" member_id: 5 version: 1 t3: - id: 1 + relation_id: 1 member_role: "some" member_type: "Relation" member_id: 3 version: 1 t4: - id: 3 + relation_id: 3 member_role: "some" member_type: "Node" member_id: 5 version: 1 t5: - id: 2 + relation_id: 2 member_role: "some" member_type: "Node" member_id: 5 version: 1 public_used: - id: 6 + relation_id: 6 member_role: "used by other relation" member_type: "Relation" member_id: 5 diff --git a/test/fixtures/relation_tags.yml b/test/fixtures/relation_tags.yml index f7571c301..31b329ed7 100644 --- a/test/fixtures/relation_tags.yml +++ b/test/fixtures/relation_tags.yml @@ -1,41 +1,41 @@ t1: - id: 1 + relation_id: 1 k: 'test' v: 'yes' version: 1 t2: - id: 2 + relation_id: 2 k: 'test' v: 'yes' version: 1 t3: - id: 3 + relation_id: 3 k: 'test' v: 'yes' version: 1 mt_1: - id: 4 + relation_id: 4 k: 'tag1' v: 'val1' version: 1 mt_2: - id: 4 + relation_id: 4 k: 'tag2' v: 'val2' version: 1 mt_3: - id: 4 + relation_id: 4 k: 'tag3' v: 'val3' version: 1 mt_4: - id: 4 + relation_id: 4 k: 'tag4' v: 'val4' version: 1 diff --git a/test/fixtures/relations.yml b/test/fixtures/relations.yml index 3ec80ecae..059528f62 100644 --- a/test/fixtures/relations.yml +++ b/test/fixtures/relations.yml @@ -1,40 +1,40 @@ visible_relation: - id: 1 + relation_id: 1 changeset_id: 1 timestamp: 2007-01-01 00:00:00 visible: true version: 1 invisible_relation: - id: 2 + relation_id: 2 changeset_id: 3 timestamp: 2007-01-01 00:00:00 visible: false version: 1 used_relation: - id: 3 + relation_id: 3 changeset_id: 1 timestamp: 2007-01-01 00:00:00 visible: true version: 1 multi_tag_relation: - id: 4 + relation_id: 4 changeset_id: 4 timestamp: 2009-04-21 09:50:57 visible: true version: 1 public_used_relation: - id: 5 + relation_id: 5 changeset_id: 2 timestamp: 2009-04-22 00:30:03 visible: true version: 1 public_visible_relation: - id: 6 + relation_id: 6 changeset_id: 2 timestamp: 2009-04-22 00:34:12 visible: true diff --git a/test/fixtures/way_nodes.yml b/test/fixtures/way_nodes.yml index 3f7a3dbde..19541d19a 100644 --- a/test/fixtures/way_nodes.yml +++ b/test/fixtures/way_nodes.yml @@ -1,77 +1,77 @@ t1a: - id: 1 + way_id: 1 node_id: 3 sequence_id: 1 version: 1 t2: - id: 2 + way_id: 2 node_id: 3 sequence_id: 1 version: 1 t3: - id: 3 + way_id: 3 node_id: 3 sequence_id: 1 version: 1 w4_v1_n1: - id: 4 + way_id: 4 node_id: 3 sequence_id: 1 version: 1 w4_v1_n2: - id: 4 + way_id: 4 node_id: 4 sequence_id: 2 version: 1 w4_v2_n1: - id: 4 + way_id: 4 node_id: 15 sequence_id: 1 version: 2 w4_v2_n2: - id: 4 + way_id: 4 node_id: 3 sequence_id: 2 version: 2 w4_v2_n3: - id: 4 + way_id: 4 node_id: 4 sequence_id: 3 version: 2 w4_v3_n1: - id: 4 + way_id: 4 node_id: 15 sequence_id: 1 version: 3 w4_v3_n2: - id: 4 + way_id: 4 node_id: 3 sequence_id: 2 version: 3 w4_v4_n1: - id: 4 + way_id: 4 node_id: 15 sequence_id: 1 version: 4 w5_n1: - id: 5 + way_id: 5 node_id: 4 sequence_id: 1 version: 1 w5_n2: - id: 5 + way_id: 5 node_id: 4 sequence_id: 2 version: 1 diff --git a/test/fixtures/way_tags.yml b/test/fixtures/way_tags.yml index 7e671672d..dc727b5f5 100644 --- a/test/fixtures/way_tags.yml +++ b/test/fixtures/way_tags.yml @@ -1,17 +1,17 @@ t1: - id: 1 + way_id: 1 k: 'test' v: 'yes' version: 1 t2: - id: 2 + way_id: 2 k: 'test' v: 'yes' version: 1 t3: - id: 3 + way_id: 3 k: 'test' v: 'yes' version: 1 diff --git a/test/fixtures/ways.yml b/test/fixtures/ways.yml index 090508702..95c001c30 100644 --- a/test/fixtures/ways.yml +++ b/test/fixtures/ways.yml @@ -1,54 +1,54 @@ visible_way: - id: 1 + way_id: 1 changeset_id: 2 timestamp: 2007-01-01 00:00:00 visible: true version: 1 invisible_way: - id: 2 + way_id: 2 changeset_id: 2 timestamp: 2007-01-01 00:00:00 visible: false version: 1 used_way: - id: 3 + way_id: 3 changeset_id: 2 timestamp: 2007-01-01 00:00:00 visible: true version: 1 way_with_versions_v1: - id: 4 + way_id: 4 changeset_id: 4 timestamp: 2008-01-01 00:01:00 visible: true version: 1 way_with_versions_v2: - id: 4 + way_id: 4 changeset_id: 4 timestamp: 2008-01-01 00:02:00 visible: true version: 2 way_with_versions: - id: 4 + way_id: 4 changeset_id: 4 timestamp: 2008-01-01 00:03:00 visible: true version: 3 way_with_versions_v4: - id: 4 + way_id: 4 changeset_id: 4 timestamp: 2008-01-01 00:04:00 visible: true version: 4 way_with_duplicate_nodes: - id: 5 + way_id: 5 changeset_id: 2 timestamp: 2007-01-01 00:00:00 visible: true diff --git a/test/functional/amf_controller_test.rb b/test/functional/amf_controller_test.rb index 1ed8ebf48..8bef10bd1 100644 --- a/test/functional/amf_controller_test.rb +++ b/test/functional/amf_controller_test.rb @@ -208,16 +208,16 @@ class AmfControllerTest < ActionController::TestCase # instead of a version number... # try to get version 1 v1 = ways(:way_with_versions_v1) - { latest => '', - v1 => v1.timestamp.strftime("%d %b %Y, %H:%M:%S") - }.each do |way, t| - amf_content "getway_old", "/1", [way.id, t] + { latest.id => '', + v1.way_id => v1.timestamp.strftime("%d %b %Y, %H:%M:%S") + }.each do |id, t| + amf_content "getway_old", "/1", [id, t] post :amf_read assert_response :success amf_parse_response returned_way = amf_result("/1") assert_equal 0, returned_way[0] - assert_equal way.id, returned_way[2] + assert_equal id, returned_way[2] # API returns the *latest* version, even for old ways... assert_equal latest.version, returned_way[5] end @@ -251,11 +251,11 @@ class AmfControllerTest < ActionController::TestCase v1 = ways(:way_with_versions_v1) # try to get last visible version of non-existent way # try to get specific version of non-existent way - [[nil, ''], - [nil, '1 Jan 1970, 00:00:00'], - [v1, (v1.timestamp - 10).strftime("%d %b %Y, %H:%M:%S")] - ].each do |way, t| - amf_content "getway_old", "/1", [way.nil? ? 0 : way.id, t] + [[0, ''], + [0, '1 Jan 1970, 00:00:00'], + [v1.way_id, (v1.timestamp - 10).strftime("%d %b %Y, %H:%M:%S")] + ].each do |id, t| + amf_content "getway_old", "/1", [id, t] post :amf_read assert_response :success amf_parse_response @@ -398,7 +398,7 @@ class AmfControllerTest < ActionController::TestCase # Finally check that the node that was saved has saved the data correctly # in both the current and history tables # First check the current table - current_node = Node.find(result[3]) + current_node = Node.find(result[3].to_i) assert_in_delta lat, current_node.lat, 0.00001, "The latitude was not retreieved correctly" assert_in_delta lon, current_node.lon, 0.00001, "The longitude was not retreived correctly" assert_equal 0, current_node.tags.size, "There seems to be a tag that has been added to the node" @@ -437,7 +437,7 @@ class AmfControllerTest < ActionController::TestCase # Finally check that the node that was saved has saved the data correctly # in both the current and history tables # First check the current table - current_node = Node.find(result[3]) + current_node = Node.find(result[3].to_i) assert_in_delta lat, current_node.lat, 0.00001, "The latitude was not retreieved correctly" assert_in_delta lon, current_node.lon, 0.00001, "The longitude was not retreived correctly" assert_equal 2, current_node.tags.size, "There seems to be a tag that has been added to the node" @@ -483,7 +483,7 @@ class AmfControllerTest < ActionController::TestCase # Finally check that the node that was saved has saved the data correctly # in both the current and history tables # First check the current table - current_node = Node.find(result[3]) + current_node = Node.find(result[3].to_i) assert_equal 1, current_node.tags.size, "There seems to be a tag that has been added to the node" assert_equal({ "something" => "foo\t\n\rbar" }, current_node.tags, "tags were not fixed correctly") assert_equal result[4], current_node.version, "The version returned, is different to the one returned by the amf" @@ -541,7 +541,7 @@ class AmfControllerTest < ActionController::TestCase assert_equal 3, result.size, result.inspect assert_equal 0, result[0] - new_cs_id = result[2] + new_cs_id = result[2].to_i cs = Changeset.find(new_cs_id) assert_equal "foobar", cs.tags["comment"] diff --git a/test/functional/browse_controller_test.rb b/test/functional/browse_controller_test.rb index 2fa594298..525c879f1 100644 --- a/test/functional/browse_controller_test.rb +++ b/test/functional/browse_controller_test.rb @@ -10,45 +10,45 @@ class BrowseControllerTest < ActionController::TestCase end def test_read_relation - browse_check 'relation', relations(:visible_relation) + browse_check 'relation', relations(:visible_relation).relation_id end def test_read_relation_history - browse_check 'relation_history', relations(:visible_relation) + browse_check 'relation_history', relations(:visible_relation).relation_id end def test_read_way - browse_check 'way', ways(:visible_way) + browse_check 'way', ways(:visible_way).way_id end def test_read_way_history - browse_check 'way_history', ways(:visible_way) + browse_check 'way_history', ways(:visible_way).way_id end def test_read_node - browse_check 'node', nodes(:visible_node) + browse_check 'node', nodes(:visible_node).node_id end def test_read_node_history - browse_check 'node_history', nodes(:visible_node) + browse_check 'node_history', nodes(:visible_node).node_id end def test_read_changeset - browse_check 'changeset', changesets(:normal_user_first_change) + browse_check 'changeset', changesets(:normal_user_first_change).id end # This is a convenience method for most of the above checks # First we check that when we don't have an id, it will correctly return a 404 # then we check that we get the correct 404 when a non-existant id is passed # then we check that it will get a successful response, when we do pass an id - def browse_check(type, fixture) + def browse_check(type, id) get type assert_response :not_found assert_template 'not_found' get type, {:id => -10} # we won't have an id that's negative assert_response :not_found assert_template 'not_found' - get type, {:id => fixture.id} + get type, {:id => id} assert_response :success assert_template type end diff --git a/test/functional/changeset_controller_test.rb b/test/functional/changeset_controller_test.rb index 964e18a12..ef8043340 100644 --- a/test/functional/changeset_controller_test.rb +++ b/test/functional/changeset_controller_test.rb @@ -1282,10 +1282,10 @@ EOF # FIXME needs more assert_select tests assert_select "osmChange[version='#{API_VERSION}'][generator='#{GENERATOR}']" do assert_select "create", :count => 5 - assert_select "create>node[id=#{nodes(:used_node_2).id}][visible=#{nodes(:used_node_2).visible?}][version=#{nodes(:used_node_2).version}]" do + assert_select "create>node[id=#{nodes(:used_node_2).node_id}][visible=#{nodes(:used_node_2).visible?}][version=#{nodes(:used_node_2).version}]" do assert_select "tag[k=#{node_tags(:t3).k}][v=#{node_tags(:t3).v}]" end - assert_select "create>node[id=#{nodes(:visible_node).id}]" + assert_select "create>node[id=#{nodes(:visible_node).node_id}]" end end diff --git a/test/functional/node_controller_test.rb b/test/functional/node_controller_test.rb index 3fc2d83f6..fdefd0896 100644 --- a/test/functional/node_controller_test.rb +++ b/test/functional/node_controller_test.rb @@ -101,7 +101,7 @@ class NodeControllerTest < ActionController::TestCase content("") put :create assert_response :bad_request, "node upload did not return bad_request status" - assert_equal ["NodeTag ", " v: is too long (maximum is 255 characters) (\"#{'x'*256}\")"], @response.body.split(/[0-9]+:/) + assert_equal ["NodeTag ", " v: is too long (maximum is 255 characters) (\"#{'x'*256}\")"], @response.body.split(/[0-9]+,foo:/) end diff --git a/test/functional/old_relation_controller_test.rb b/test/functional/old_relation_controller_test.rb index a52211e2e..54e1cd037 100644 --- a/test/functional/old_relation_controller_test.rb +++ b/test/functional/old_relation_controller_test.rb @@ -9,13 +9,11 @@ class OldRelationControllerTest < ActionController::TestCase # ------------------------------------- def test_history # check that a visible relations is returned properly - get :history, :id => relations(:visible_relation).id + get :history, :id => relations(:visible_relation).relation_id assert_response :success # check chat a non-existent relations is not returned get :history, :id => 0 assert_response :not_found - end - end diff --git a/test/functional/old_way_controller_test.rb b/test/functional/old_way_controller_test.rb index 31da1d2c7..9dd542c52 100644 --- a/test/functional/old_way_controller_test.rb +++ b/test/functional/old_way_controller_test.rb @@ -10,13 +10,13 @@ class OldWayControllerTest < ActionController::TestCase def test_history_visible # check that a visible way is returned properly - get :history, :id => ways(:visible_way).id + get :history, :id => ways(:visible_way).way_id assert_response :success end def test_history_invisible # check that an invisible way's history is returned properly - get :history, :id => ways(:invisible_way).id + get :history, :id => ways(:invisible_way).way_id assert_response :success end diff --git a/test/unit/changeset_tag_test.rb b/test/unit/changeset_tag_test.rb index 4854432c4..2939613c8 100644 --- a/test/unit/changeset_tag_test.rb +++ b/test/unit/changeset_tag_test.rb @@ -11,7 +11,7 @@ class ChangesetTagTest < ActiveSupport::TestCase key = "k" (0..255).each do |i| tag = ChangesetTag.new - tag.id = 1 + tag.changeset_id = 1 tag.k = key*i tag.v = "v" assert tag.valid? @@ -22,7 +22,7 @@ class ChangesetTagTest < ActiveSupport::TestCase val = "v" (0..255).each do |i| tag = ChangesetTag.new - tag.id = 1 + tag.changeset_id = 1 tag.k = "k" tag.v = val*i assert tag.valid? @@ -32,7 +32,7 @@ class ChangesetTagTest < ActiveSupport::TestCase def test_length_key_invalid ["k"*256].each do |k| tag = ChangesetTag.new - tag.id = 1 + tag.changeset_id = 1 tag.k = k tag.v = "v" assert !tag.valid?, "Key #{k} should be too long" @@ -43,7 +43,7 @@ class ChangesetTagTest < ActiveSupport::TestCase def test_length_value_invalid ["v"*256].each do |v| tag = ChangesetTag.new - tag.id = 1 + tag.changeset_id = 1 tag.k = "k" tag.v = v assert !tag.valid?, "Value #{v} should be too long" @@ -54,12 +54,12 @@ class ChangesetTagTest < ActiveSupport::TestCase def test_empty_tag_invalid tag = ChangesetTag.new assert !tag.valid?, "Empty tag should be invalid" - assert tag.errors[:id].any? + assert tag.errors[:changeset].any? end def test_uniqueness tag = ChangesetTag.new - tag.id = changeset_tags(:changeset_1_tag_1).id + tag.changeset_id = changeset_tags(:changeset_1_tag_1).id tag.k = changeset_tags(:changeset_1_tag_1).k tag.v = changeset_tags(:changeset_1_tag_1).v assert tag.new_record? diff --git a/test/unit/node_tag_test.rb b/test/unit/node_tag_test.rb index c4ebd2c6e..2f2631792 100644 --- a/test/unit/node_tag_test.rb +++ b/test/unit/node_tag_test.rb @@ -21,7 +21,7 @@ class NodeTagTest < ActiveSupport::TestCase key = "k" (0..255).each do |i| tag = NodeTag.new - tag.id = current_node_tags(:t1).id + tag.node_id = current_node_tags(:t1).node_id tag.k = key*i tag.v = "v" assert tag.valid? @@ -32,7 +32,7 @@ class NodeTagTest < ActiveSupport::TestCase val = "v" (0..255).each do |i| tag = NodeTag.new - tag.id = current_node_tags(:t1).id + tag.node_id = current_node_tags(:t1).node_id tag.k = "k" tag.v = val*i assert tag.valid? @@ -42,7 +42,7 @@ class NodeTagTest < ActiveSupport::TestCase def test_length_key_invalid ["k"*256].each do |i| tag = NodeTag.new - tag.id = current_node_tags(:t1).id + tag.node_id = current_node_tags(:t1).node_id tag.k = i tag.v = "v" assert !tag.valid?, "Key should be too long" @@ -53,7 +53,7 @@ class NodeTagTest < ActiveSupport::TestCase def test_length_value_invalid ["k"*256].each do |i| tag = NodeTag.new - tag.id = current_node_tags(:t1).id + tag.node_id = current_node_tags(:t1).node_id tag.k = "k" tag.v = i assert !tag.valid?, "Value should be too long" @@ -64,12 +64,12 @@ class NodeTagTest < ActiveSupport::TestCase def test_empty_node_tag_invalid tag = NodeTag.new assert !tag.valid?, "Empty tag should be invalid" - assert tag.errors[:id].any? + assert tag.errors[:node].any? end def test_uniqueness tag = NodeTag.new - tag.id = current_node_tags(:t1).id + tag.node_id = current_node_tags(:t1).node_id tag.k = current_node_tags(:t1).k tag.v = current_node_tags(:t1).v assert tag.new_record? diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index 24300e428..6bfcf7926 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -8,7 +8,7 @@ class NodeTest < ActiveSupport::TestCase end def test_node_too_far_north - invalid_node_test(:node_too_far_north) + invalid_node_test(:node_too_far_north) end def test_node_north_limit @@ -92,8 +92,8 @@ class NodeTest < ActiveSupport::TestCase assert_equal node_template.visible, node.visible assert_equal node_template.timestamp.to_i, node.timestamp.to_i - assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1 - old_node = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ]) + assert_equal OldNode.where(:node_id => node_template.id).count, 1 + old_node = OldNode.where(:node_id => node_template.id).first assert_not_nil old_node assert_equal node_template.latitude, old_node.latitude assert_equal node_template.longitude, old_node.longitude @@ -107,14 +107,14 @@ class NodeTest < ActiveSupport::TestCase node_template = Node.find(current_nodes(:visible_node).id) assert_not_nil node_template - assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1 - old_node_template = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ]) - assert_not_nil old_node_template + assert_equal OldNode.where(:node_id => node_template.id).count, 1 + node = Node.find(node_template.id) + assert_not_nil node node_template.latitude = 12.3456 node_template.longitude = 65.4321 #node_template.tags = "updated=yes" - assert node_template.update_from(old_node_template, users(:normal_user)) + assert node.update_from(node_template, users(:normal_user)) node = Node.find(node_template.id) assert_not_nil node @@ -123,49 +123,43 @@ class NodeTest < ActiveSupport::TestCase assert_equal node_template.changeset_id, node.changeset_id assert_equal node_template.visible, node.visible #assert_equal node_template.tags, node.tags - assert_equal node_template.timestamp.to_i, node.timestamp.to_i - assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 2 - assert_equal OldNode.find(:all, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]).length, 1 - old_node = OldNode.find(:first, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]) + assert_equal OldNode.where(:node_id => node_template.id).count, 2 + old_node = OldNode.where(:node_id => node_template.id, :version => 2).first assert_not_nil old_node assert_equal node_template.latitude, old_node.latitude assert_equal node_template.longitude, old_node.longitude assert_equal node_template.changeset_id, old_node.changeset_id assert_equal node_template.visible, old_node.visible #assert_equal node_template.tags, old_node.tags - assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i end def test_delete node_template = Node.find(current_nodes(:visible_node)) assert_not_nil node_template - assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1 - old_node_template = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ]) - assert_not_nil old_node_template + assert_equal OldNode.where(:node_id => node_template.id).count, 1 + node = Node.find(node_template.id) + assert_not_nil node - assert node_template.delete_with_history!(old_node_template, users(:normal_user)) + assert node.delete_with_history!(node_template, users(:normal_user)) node = Node.find(node_template.id) assert_not_nil node assert_equal node_template.latitude, node.latitude assert_equal node_template.longitude, node.longitude assert_equal node_template.changeset_id, node.changeset_id - assert_equal node_template.visible, node.visible + assert_equal false, node.visible #assert_equal node_template.tags, node.tags - assert_equal node_template.timestamp.to_i, node.timestamp.to_i - assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 2 - assert_equal OldNode.find(:all, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]).length, 1 - old_node = OldNode.find(:first, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]) + assert_equal OldNode.where(:node_id => node_template.id).count, 2 + old_node = OldNode.where(:node_id => node_template.id, :version => 2).first assert_not_nil old_node assert_equal node_template.latitude, old_node.latitude assert_equal node_template.longitude, old_node.longitude assert_equal node_template.changeset_id, old_node.changeset_id - assert_equal node_template.visible, old_node.visible + assert_equal false, old_node.visible #assert_equal node_template.tags, old_node.tags - assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i end def test_from_xml_no_id diff --git a/test/unit/old_node_tag_test.rb b/test/unit/old_node_tag_test.rb index f934ffde1..064b5f198 100644 --- a/test/unit/old_node_tag_test.rb +++ b/test/unit/old_node_tag_test.rb @@ -11,7 +11,7 @@ class OldNodeTest < ActiveSupport::TestCase key = "k" (0..255).each do |i| tag = OldNodeTag.new - tag.id = node_tags(:t1).id + tag.node_id = node_tags(:t1).node_id tag.version = node_tags(:t1).version tag.k = key*i tag.v = "v" @@ -23,7 +23,7 @@ class OldNodeTest < ActiveSupport::TestCase val = "v" (0..255).each do |i| tag = OldNodeTag.new - tag.id = node_tags(:t1).id + tag.node_id = node_tags(:t1).node_id tag.version = node_tags(:t1).version tag.k = "k" tag.v = val*i @@ -34,7 +34,7 @@ class OldNodeTest < ActiveSupport::TestCase def test_length_key_invalid ["k"*256].each do |i| tag = OldNodeTag.new - tag.id = node_tags(:t1).id + tag.node_id = node_tags(:t1).node_id tag.version = node_tags(:t1).version tag.k = i tag.v = "v", "Key should be too long" @@ -46,7 +46,7 @@ class OldNodeTest < ActiveSupport::TestCase def test_length_value_invalid ["k"*256].each do |i| tag = OldNodeTag.new - tag.id = node_tags(:t1).id + tag.node_id = node_tags(:t1).node_id tag.version = node_tags(:t1).version tag.k = "k" tag.v = i @@ -55,16 +55,15 @@ class OldNodeTest < ActiveSupport::TestCase end end - def test_empty_old_node_tag_invalid + def test_empty_tag_invalid tag = OldNodeTag.new assert !tag.valid?, "Empty tag should be invalid" - assert tag.errors[:id].any? - assert tag.errors[:version].any? + assert tag.errors[:old_node].any? end def test_uniqueness tag = OldNodeTag.new - tag.id = node_tags(:t1).id + tag.node_id = node_tags(:t1).node_id tag.version = node_tags(:t1).version tag.k = node_tags(:t1).k tag.v = node_tags(:t1).v diff --git a/test/unit/old_node_test.rb b/test/unit/old_node_test.rb index 10cb23900..e6f3d8035 100644 --- a/test/unit/old_node_test.rb +++ b/test/unit/old_node_test.rb @@ -8,7 +8,7 @@ class OldNodeTest < ActiveSupport::TestCase end def test_node_too_far_north - invalid_node_test(:node_too_far_north) + invalid_node_test(:node_too_far_north) end def test_node_north_limit @@ -48,7 +48,7 @@ class OldNodeTest < ActiveSupport::TestCase # the fixture def valid_node_test(nod) node = nodes(nod) - dbnode = Node.find(node.id) + dbnode = Node.find(node.node_id) assert_equal dbnode.lat, node.latitude.to_f/SCALE assert_equal dbnode.lon, node.longitude.to_f/SCALE assert_equal dbnode.changeset_id, node.changeset_id @@ -64,7 +64,7 @@ class OldNodeTest < ActiveSupport::TestCase # fixture def invalid_node_test(nod) node = nodes(nod) - dbnode = Node.find(node.id) + dbnode = Node.find(node.node_id) assert_equal dbnode.lat, node.latitude.to_f/SCALE assert_equal dbnode.lon, node.longitude.to_f/SCALE assert_equal dbnode.changeset_id, node.changeset_id @@ -74,6 +74,4 @@ class OldNodeTest < ActiveSupport::TestCase #assert_equal node.tile, QuadTile.tile_for_point(nodes(nod).lat, nodes(nod).lon) assert_equal false, node.valid? end - - end diff --git a/test/unit/old_relation_tag_test.rb b/test/unit/old_relation_tag_test.rb index f6ac38428..1d0880822 100644 --- a/test/unit/old_relation_tag_test.rb +++ b/test/unit/old_relation_tag_test.rb @@ -11,7 +11,7 @@ class OldRelationTagTest < ActiveSupport::TestCase key = "k" (0..255).each do |i| tag = OldRelationTag.new - tag.id = relation_tags(:t1).id + tag.relation_id = relation_tags(:t1).relation_id tag.version = 1 tag.k = key*i tag.v = "v" @@ -23,7 +23,7 @@ class OldRelationTagTest < ActiveSupport::TestCase val = "v" (0..255).each do |i| tag = OldRelationTag.new - tag.id = relation_tags(:t1).id + tag.relation_id = relation_tags(:t1).relation_id tag.version = 1 tag.k = "k" tag.v = val*i @@ -34,7 +34,7 @@ class OldRelationTagTest < ActiveSupport::TestCase def test_length_key_invalid ["k"*256].each do |i| tag = OldRelationTag.new - tag.id = relation_tags(:t1).id + tag.relation_id = relation_tags(:t1).relation_id tag.version = 1 tag.k = i tag.v = "v" @@ -46,7 +46,7 @@ class OldRelationTagTest < ActiveSupport::TestCase def test_length_value_invalid ["k"*256].each do |i| tag = OldRelationTag.new - tag.id = relation_tags(:t1).id + tag.relation_id = relation_tags(:t1).relation_id tag.version = 1 tag.k = "k" tag.v = i @@ -55,15 +55,15 @@ class OldRelationTagTest < ActiveSupport::TestCase end end - def test_empty_node_tag_invalid + def test_empty_tag_invalid tag = OldRelationTag.new assert !tag.valid?, "Empty tag should be invalid" - assert tag.errors[:id].any? + assert tag.errors[:old_relation].any? end def test_uniqueness tag = OldRelationTag.new - tag.id = relation_tags(:t1).id + tag.relation_id = relation_tags(:t1).relation_id tag.version = relation_tags(:t1).version tag.k = relation_tags(:t1).k tag.v = relation_tags(:t1).v diff --git a/test/unit/old_way_tag_test.rb b/test/unit/old_way_tag_test.rb index 3282fc473..334e7b86a 100644 --- a/test/unit/old_way_tag_test.rb +++ b/test/unit/old_way_tag_test.rb @@ -11,7 +11,7 @@ class WayTagTest < ActiveSupport::TestCase key = "k" (0..255).each do |i| tag = OldWayTag.new - tag.id = way_tags(:t1).id + tag.way_id = way_tags(:t1).way_id tag.version = 1 tag.k = key*i tag.v = "v" @@ -23,7 +23,7 @@ class WayTagTest < ActiveSupport::TestCase val = "v" (0..255).each do |i| tag = OldWayTag.new - tag.id = way_tags(:t1).id + tag.way_id = way_tags(:t1).way_id tag.version = 1 tag.k = "k" tag.v = val*i @@ -34,7 +34,7 @@ class WayTagTest < ActiveSupport::TestCase def test_length_key_invalid ["k"*256].each do |i| tag = OldWayTag.new - tag.id = way_tags(:t1).id + tag.way_id = way_tags(:t1).way_id tag.version = 1 tag.k = i tag.v = "v" @@ -46,7 +46,7 @@ class WayTagTest < ActiveSupport::TestCase def test_length_value_invalid ["k"*256].each do |i| tag = OldWayTag.new - tag.id = way_tags(:t1).id + tag.way_id = way_tags(:t1).way_id tag.version = 1 tag.k = "k" tag.v = i @@ -55,15 +55,15 @@ class WayTagTest < ActiveSupport::TestCase end end - def test_empty_node_tag_invalid - tag = OldNodeTag.new + def test_empty_tag_invalid + tag = OldWayTag.new assert !tag.valid?, "Empty tag should be invalid" - assert tag.errors[:id].any? + assert tag.errors[:old_way].any? end def test_uniqueness tag = OldWayTag.new - tag.id = way_tags(:t1).id + tag.way_id = way_tags(:t1).way_id tag.version = way_tags(:t1).version tag.k = way_tags(:t1).k tag.v = way_tags(:t1).v diff --git a/test/unit/relation_tag_test.rb b/test/unit/relation_tag_test.rb index 7c703cf27..39a2ff828 100644 --- a/test/unit/relation_tag_test.rb +++ b/test/unit/relation_tag_test.rb @@ -11,7 +11,7 @@ class RelationTagTest < ActiveSupport::TestCase key = "k" (0..255).each do |i| tag = RelationTag.new - tag.id = 1 + tag.relation_id = 1 tag.k = key*i tag.v = "v" assert tag.valid? @@ -22,7 +22,7 @@ class RelationTagTest < ActiveSupport::TestCase val = "v" (0..255).each do |i| tag = RelationTag.new - tag.id = 1 + tag.relation_id = 1 tag.k = "k" tag.v = val*i assert tag.valid? @@ -32,7 +32,7 @@ class RelationTagTest < ActiveSupport::TestCase def test_length_key_invalid ["k"*256].each do |i| tag = RelationTag.new - tag.id = 1 + tag.relation_id = 1 tag.k = i tag.v = "v" assert !tag.valid?, "Key #{i} should be too long" @@ -43,7 +43,7 @@ class RelationTagTest < ActiveSupport::TestCase def test_length_value_invalid ["v"*256].each do |i| tag = RelationTag.new - tag.id = 1 + tag.relation_id = 1 tag.k = "k" tag.v = i assert !tag.valid?, "Value #{i} should be too long" @@ -54,12 +54,12 @@ class RelationTagTest < ActiveSupport::TestCase def test_empty_tag_invalid tag = RelationTag.new assert !tag.valid?, "Empty relation tag should be invalid" - assert tag.errors[:id].any? + assert tag.errors[:relation].any? end def test_uniquness tag = RelationTag.new - tag.id = current_relation_tags(:t1).id + tag.relation_id = current_relation_tags(:t1).relation_id tag.k = current_relation_tags(:t1).k tag.v = current_relation_tags(:t1).v assert tag.new_record? @@ -84,7 +84,7 @@ class RelationTagTest < ActiveSupport::TestCase # assert_equal 0, RelationTag.count(:conditions => ['v=?', v]) # # make sure we select a tag on a relation which has more than one tag - # id = current_relations(:multi_tag_relation).id + # id = current_relations(:multi_tag_relation).relation_id # tag = RelationTag.find(:first, :conditions => ["id = ?", id]) # tag.v = v # tag.save! diff --git a/test/unit/way_node_test.rb b/test/unit/way_node_test.rb index 608d5c5ae..18162b44a 100644 --- a/test/unit/way_node_test.rb +++ b/test/unit/way_node_test.rb @@ -2,9 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper' class WayNodeTest < ActiveSupport::TestCase api_fixtures - + def test_way_nodes_count assert_equal 6, WayNode.count end - end diff --git a/test/unit/way_tag_test.rb b/test/unit/way_tag_test.rb index 5ce088159..b338f9c25 100644 --- a/test/unit/way_tag_test.rb +++ b/test/unit/way_tag_test.rb @@ -11,7 +11,7 @@ class WayTagTest < ActiveSupport::TestCase key = "k" (0..255).each do |i| tag = WayTag.new - tag.id = current_way_tags(:t1).id + tag.way_id = current_way_tags(:t1).way_id tag.k = key*i tag.v = current_way_tags(:t1).v assert tag.valid? @@ -22,7 +22,7 @@ class WayTagTest < ActiveSupport::TestCase val = "v" (0..255).each do |i| tag = WayTag.new - tag.id = current_way_tags(:t1).id + tag.way_id = current_way_tags(:t1).way_id tag.k = "k" tag.v = val*i assert tag.valid? @@ -32,7 +32,7 @@ class WayTagTest < ActiveSupport::TestCase def test_length_key_invalid ["k"*256].each do |i| tag = WayTag.new - tag.id = current_way_tags(:t1).id + tag.way_id = current_way_tags(:t1).way_id tag.k = i tag.v = "v" assert !tag.valid?, "Key #{i} should be too long" @@ -43,7 +43,7 @@ class WayTagTest < ActiveSupport::TestCase def test_length_value_invalid ["v"*256].each do |i| tag = WayTag.new - tag.id = current_way_tags(:t1).id + tag.way_id = current_way_tags(:t1).way_id tag.k = "k" tag.v = i assert !tag.valid?, "Value #{i} should be too long" @@ -54,12 +54,12 @@ class WayTagTest < ActiveSupport::TestCase def test_empty_tag_invalid tag = WayTag.new assert !tag.valid?, "Empty way tag should be invalid" - assert tag.errors[:id].any? + assert tag.errors[:way].any? end def test_uniqueness tag = WayTag.new - tag.id = current_way_tags(:t1).id + tag.way_id = current_way_tags(:t1).way_id tag.k = current_way_tags(:t1).k tag.v = current_way_tags(:t1).v assert tag.new_record?