Fix some rubocop rails style issues

This commit is contained in:
Tom Hughes 2015-02-25 18:49:21 +00:00
parent 2d22ab10f7
commit dbe165bbb3
61 changed files with 336 additions and 348 deletions

View file

@ -4,7 +4,7 @@ class AccessToken < OauthToken
scope :valid, -> { where(:invalidated_at => nil) }
validates_presence_of :user, :secret
validates :user, :secret, :presence => true
before_create :set_authorized_at

View file

@ -15,13 +15,16 @@ class Changeset < ActiveRecord::Base
has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "ChangesetComment"
has_and_belongs_to_many :subscribers, :class_name => "User", :join_table => "changesets_subscribers", :association_foreign_key => "subscriber_id"
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
validates_numericality_of :num_changes, :integer_only => true, :greater_than_or_equal_to => 0
validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :integer_only => true }
validates :user_id, :presence => true,
:numericality => { :integer_only => true }
validates :num_changes, :presence => true,
:numericality => { :integer_only => true,
:greater_than_or_equal_to => 0 }
validates :created_at, :closed_at, :presence => true
validates :min_lat, :max_lat, :min_lon, :max_lat, :allow_nil => true,
:numericality => { :integer_only => true }
before_save :update_closed_at

View file

@ -2,16 +2,14 @@ class ChangesetComment < ActiveRecord::Base
belongs_to :changeset
belongs_to :author, :class_name => "User"
validates_presence_of :id, :on => :update # is it necessary?
validates_uniqueness_of :id
validates_presence_of :changeset
validates_associated :changeset
validates_presence_of :author
validates_associated :author
validates :visible, :inclusion => { :in => [true, false] }
validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :integer_only => true }
validates :changeset, :presence => true, :associated => true
validates :author, :presence => true, :associated => true
validates :visible, :inclusion => [true, false]
# Return the comment text
def body
RichText.new("text", read_attribute(:body))
RichText.new("text", self[:body])
end
end

View file

@ -3,8 +3,7 @@ class ChangesetTag < ActiveRecord::Base
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
validates :changeset, :presence => true, :associated => true
validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
validates :k, :uniqueness => { :scope => :changeset_id }
end

View file

@ -7,11 +7,10 @@ class ClientApplication < ActiveRecord::Base
has_many :oauth2_verifiers
has_many :oauth_tokens
validates_presence_of :name, :url, :key, :secret
validates_uniqueness_of :key
validates_format_of :url, :with => %r{\Ahttp(s?)://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!\-/]))?}i
validates_format_of :support_url, :with => %r{\Ahttp(s?)://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!\-/]))?}i, :allow_blank => true
validates_format_of :callback_url, :with => %r{\A[a-z][a-z0-9.+-]*://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!\-/]))?}i, :allow_blank => true
validates :key, :presence => true, :uniqueness => true
validates :name, :url, :secret, :presence => true
validates :url, :format => %r{\Ahttp(s?)://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!\-/]))?}i
validates :support_url, :callback_url, :allow_blank => true, :format => %r{\Ahttp(s?)://(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(/|/([\w#!:.?+=&%@!\-/]))?}i
before_validation :generate_keys, :on => :create

View file

@ -2,13 +2,13 @@ class DiaryComment < ActiveRecord::Base
belongs_to :user
belongs_to :diary_entry
validates_presence_of :body
validates_associated :diary_entry
validates :body, :presence => true
validates :diary_entry, :user, :associated => true
after_save :spam_check
def body
RichText.new(read_attribute(:body_format), read_attribute(:body))
RichText.new(self[:body_format], self[:body])
end
def digest

View file

@ -7,19 +7,20 @@ class DiaryEntry < ActiveRecord::Base
scope :visible, -> { where(:visible => true) }
validates_presence_of :title, :body
validates_length_of :title, :within => 1..255
# validates_length_of :language, :within => 2..5, :allow_nil => false
validates_numericality_of :latitude, :allow_nil => true,
:greater_than_or_equal_to => -90, :less_than_or_equal_to => 90
validates_numericality_of :longitude, :allow_nil => true,
:greater_than_or_equal_to => -180, :less_than_or_equal_to => 180
validates_associated :language
validates :title, :body, :presence => true
validates :title, :length => 1..255
validates :latitude, :allow_nil => true,
:numericality => { :greater_than_or_equal_to => -90,
:less_than_or_equal_to => 90 }
validates :longitude, :allow_nil => true,
:numericality => { :greater_than_or_equal_to => -180,
:less_than_or_equal_to => 180 }
validates :language, :user, :associated => true
after_save :spam_check
def body
RichText.new(read_attribute(:body_format), read_attribute(:body))
RichText.new(self[:body_format], self[:body])
end
private

View file

@ -4,10 +4,8 @@ class Message < ActiveRecord::Base
belongs_to :sender, :class_name => "User", :foreign_key => :from_user_id
belongs_to :recipient, :class_name => "User", :foreign_key => :to_user_id
validates_presence_of :title, :body, :sent_on, :sender, :recipient
validates_length_of :title, :within => 1..255
validates_inclusion_of :message_read, :in => [true, false]
validates_as_utf8 :title
validates :title, :presence => true, :utf8 => true, :length => 1..255
validates :body, :sent_on, :sender, :recipient, :presence => true
def self.from_mail(mail, from, to)
if mail.multipart?
@ -33,7 +31,7 @@ class Message < ActiveRecord::Base
end
def body
RichText.new(read_attribute(:body_format), read_attribute(:body))
RichText.new(self[:body_format], self[:body])
end
def digest

View file

@ -23,14 +23,21 @@ 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
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
validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :integer_only => true }
validates :version, :presence => true,
:numericality => { :integer_only => true }
validates :changeset_id, :presence => true,
:numericality => { :integer_only => true }
validates :latitude, :presence => true,
:numericality => { :integer_only => true }
validates :longitude, :presence => true,
:numericality => { :integer_only => true }
validates :timestamp, :presence => true
validates :changeset, :associated => true
validates :visible, :inclusion => [true, false]
validate :validate_position
validates_associated :changeset
scope :visible, -> { where(:visible => true) }
scope :invisible, -> { where(:visible => false) }

View file

@ -4,8 +4,7 @@ class NodeTag < ActiveRecord::Base
belongs_to :node
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
validates :node, :presence => true, :associated => true
validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
validates :k, :uniqueness => { :scope => :node_id }
end

View file

@ -3,12 +3,12 @@ class Note < ActiveRecord::Base
has_many :comments, -> { where(:visible => true).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id
validates_presence_of :id, :on => :update
validates_uniqueness_of :id
validates_numericality_of :latitude, :only_integer => true
validates_numericality_of :longitude, :only_integer => true
validates_presence_of :closed_at if :status == "closed"
validates_inclusion_of :status, :in => %w(open closed hidden)
validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :integer_only => true }
validates :latitude, :longitude, :numericality => { :only_integer => true }
validates :closed_at, :presence => true, :if => proc { :status == "closed" }
validates :status, :inclusion => %w(open closed hidden)
validate :validate_position
scope :visible, -> { where("status != 'hidden'") }

View file

@ -2,17 +2,16 @@ class NoteComment < ActiveRecord::Base
belongs_to :note, :foreign_key => :note_id, :touch => true
belongs_to :author, :class_name => "User", :foreign_key => :author_id
validates_presence_of :id, :on => :update
validates_uniqueness_of :id
validates_presence_of :note_id
validates_associated :note
validates_presence_of :visible
validates_associated :author
validates_inclusion_of :event, :in => %w(opened closed reopened commented hidden)
validates_format_of :body, :with => /\A[^\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff]*\z/
validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :integer_only => true }
validates :note, :presence => true, :associated => true
validates :visible, :inclusion => [true, false]
validates :author, :associated => true
validates :event, :inclusion => %w(opened closed reopened commented hidden)
validates :body, :format => /\A[^\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff]*\z/
# Return the comment text
def body
RichText.new("text", read_attribute(:body))
RichText.new("text", self[:body])
end
end

View file

@ -1,5 +1,6 @@
class Oauth2Verifier < OauthToken
validates_presence_of :user
validates :user, :presence => true, :associated => true
attr_accessor :state
def exchange!(_params = {})

View file

@ -1,8 +1,8 @@
# Simple store of nonces. The OAuth Spec requires that any given pair of nonce and timestamps are unique.
# Thus you can use the same nonce with a different timestamp and viceversa.
class OauthNonce < ActiveRecord::Base
validates_presence_of :nonce, :timestamp
validates_uniqueness_of :nonce, :scope => :timestamp
validates :timestamp, :presence => true
validates :nonce, :presence => true, :uniqueness => { :scope => :timestamp }
# Remembers a nonce and it's associated timestamp. It returns false if it has already been used
def self.remember(nonce, timestamp)

View file

@ -4,8 +4,9 @@ class OauthToken < ActiveRecord::Base
scope :authorized, -> { where("authorized_at IS NOT NULL and invalidated_at IS NULL") }
validates_uniqueness_of :token
validates_presence_of :client_application, :token
validates :token, :presence => true, :uniqueness => true
validates :user, :associated => true
validates :client_application, :presence => true
before_validation :generate_keys, :on => :create

View file

@ -10,11 +10,15 @@ class OldNode < ActiveRecord::Base
# the queries generated by Redactable will use the wrong table name.
include Redactable
validates_presence_of :changeset_id, :timestamp
validates_inclusion_of :visible, :in => [true, false]
validates_numericality_of :latitude, :longitude
validates :changeset, :presence => true, :associated => true
validates :latitude, :presence => true,
:numericality => { :integer_only => true }
validates :longitude, :presence => true,
:numericality => { :integer_only => true }
validates :timestamp, :presence => true
validates :visible, :inclusion => [true, false]
validate :validate_position
validates_associated :changeset
belongs_to :changeset
belongs_to :redaction

View file

@ -4,8 +4,7 @@ class OldNodeTag < ActiveRecord::Base
belongs_to :old_node, :foreign_key => [:node_id, :version]
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
validates :old_node, :presence => true, :associated => true
validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
validates :k, :uniqueness => { :scope => [:node_id, :version] }
end

View file

@ -16,7 +16,9 @@ class OldRelation < ActiveRecord::Base
has_many :old_members, -> { order(:sequence_id) }, :class_name => "OldRelationMember", :foreign_key => [:relation_id, :version]
has_many :old_tags, :class_name => "OldRelationTag", :foreign_key => [:relation_id, :version]
validates_associated :changeset
validates :changeset, :presence => true, :associated => true
validates :timestamp, :presence => true
validates :visible, :inclusion => [true, false]
def self.from_relation(relation)
old_relation = OldRelation.new

View file

@ -4,8 +4,7 @@ class OldRelationTag < ActiveRecord::Base
belongs_to :old_relation, :foreign_key => [:relation_id, :version]
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
validates :old_relation, :presence => true, :associated => true
validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
validates :k, :uniqueness => { :scope => [:relation_id, :version] }
end

View file

@ -16,7 +16,9 @@ class OldWay < ActiveRecord::Base
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
validates :changeset, :presence => true, :associated => true
validates :timestamp, :presence => true
validates :visible, :inclusion => [true, false]
def self.from_way(way)
old_way = OldWay.new

View file

@ -4,8 +4,7 @@ class OldWayTag < ActiveRecord::Base
belongs_to :old_way, :foreign_key => [:way_id, :version]
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
validates :old_way, :presence => true, :associated => true
validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
validates :k, :uniqueness => { :scope => [:way_id, :version] }
end

View file

@ -17,6 +17,6 @@ class Redaction < ActiveRecord::Base
# this method overrides the AR default to provide the rich
# text object for the description field.
def description
RichText.new(read_attribute(:description_format), read_attribute(:description))
RichText.new(self[:description_format], self[:description])
end
end

View file

@ -17,13 +17,15 @@ 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
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
validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :integer_only => true }
validates :version, :presence => true,
:numericality => { :integer_only => true }
validates :changeset_id, :presence => true,
:numericality => { :integer_only => true }
validates :timestamp, :presence => true
validates :changeset, :associated => true
validates :visible, :inclusion => [true, false]
scope :visible, -> { where(:visible => true) }
scope :invisible, -> { where(:visible => false) }

View file

@ -4,8 +4,7 @@ class RelationTag < ActiveRecord::Base
belongs_to :relation
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
validates :relation, :presence => true, :associated => true
validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
validates :k, :uniqueness => { :scope => :relation_id }
end

View file

@ -17,7 +17,7 @@ class RequestToken < OauthToken
params = { :user => user, :client_application => client_application }
# copy the permissions from the authorised request token to the access token
client_application.permissions.each do |p|
params[p] = read_attribute(p)
params[p] = self[p]
end
access_token = AccessToken.create(params)

View file

@ -10,13 +10,11 @@ class Trace < ActiveRecord::Base
scope :visible_to_all, -> { where(:visibility => %w(public identifiable)) }
scope :tagged, ->(t) { joins(:tags).where(:gpx_file_tags => { :tag => t }) }
validates_presence_of :user_id, :name, :timestamp
validates_presence_of :description, :on => :create
validates_length_of :name, :maximum => 255
validates_length_of :description, :maximum => 255
# validates_numericality_of :latitude, :longitude
validates_inclusion_of :inserted, :in => [true, false]
validates_inclusion_of :visibility, :in => %w(private public trackable identifiable)
validates :user, :presence => true, :associated => true
validates :name, :presence => true, :length => 1..255
validates :description, :presence => { :on => :create }, :length => 1..255
validates :timestamp, :presence => true
validates :visibility, :inclusion => %w(private public trackable identifiable)
def destroy
super

View file

@ -3,11 +3,10 @@ class Tracepoint < ActiveRecord::Base
self.table_name = "gps_points"
validates_numericality_of :trackid, :only_integer => true
validates_numericality_of :latitude, :only_integer => true
validates_numericality_of :longitude, :only_integer => true
validates_associated :trace
validates_presence_of :timestamp
validates :trackid, :numericality => { :only_integer => true }
validates :latitude, :longitude, :numericality => { :only_integer => true }
validates :trace, :associated => true
validates :timestamp, :presence => true
belongs_to :trace, :foreign_key => "gpx_id"

View file

@ -1,8 +1,8 @@
class Tracetag < ActiveRecord::Base
self.table_name = "gpx_file_tags"
validates_format_of :tag, :with => /\A[^\/;.,?]*\z/
validates_length_of :tag, :within => 1..255
belongs_to :trace, :foreign_key => "gpx_id"
validates :trace, :presence => true, :associated => true
validates :tag, :length => 1..255, :format => /\A[^\/;.,?]*\z/
end

View file

@ -34,24 +34,27 @@ class User < ActiveRecord::Base
:default_url => "/assets/:class/:attachment/:style.png",
:styles => { :large => "100x100>", :small => "50x50>" }
validates_presence_of :email, :display_name
validates_confirmation_of :email # , :message => ' addresses must match'
validates_confirmation_of :pass_crypt # , :message => ' must match the confirmation password'
validates_uniqueness_of :display_name, :allow_nil => true, :case_sensitive => false, :if => proc { |u| u.display_name_changed? }
validates_uniqueness_of :email, :case_sensitive => false, :if => proc { |u| u.email_changed? }
validates_length_of :pass_crypt, :within => 8..255
validates_length_of :display_name, :within => 3..255, :allow_nil => true
validates :display_name, :presence => true, :allow_nil => true, :length => 3..255,
:exclusion => %w(new terms save confirm confirm-email go_public reset-password forgot-password suspended)
validates :display_name, :if => proc { |u| u.display_name_changed? },
:uniqueness => { :case_sensitive => false }
validates :display_name, :if => proc { |u| u.display_name_changed? },
:format => { :with => /\A[^\x00-\x1f\x7f\ufffe\uffff\/;.,?%#]*\z/ }
validates :display_name, :if => proc { |u| u.display_name_changed? },
:format => { :with => /\A\S/, :message => "has leading whitespace" }
validates :display_name, :if => proc { |u| u.display_name_changed? },
:format => { :with => /\S\z/, :message => "has trailing whitespace" }
validates :email, :presence => true, :confirmation => true
validates :email, :if => proc { |u| u.email_changed? },
:uniqueness => { :case_sensitive => false }
validates :pass_crypt, :confirmation => true, :length => 8..255
validates :home_lat, :home_lon, :allow_nil => true, :numericality => true
validates :home_zoom, :allow_nil => true, :numericality => { :only_integer => true }
validates :preferred_editor, :inclusion => Editors::ALL_EDITORS, :allow_nil => true
validates :image, :attachment_content_type => { :content_type => /\Aimage\/.*\Z/ }
validates_email_format_of :email, :if => proc { |u| u.email_changed? }
validates_email_format_of :new_email, :allow_blank => true, :if => proc { |u| u.new_email_changed? }
validates_format_of :display_name, :with => /\A[^\x00-\x1f\x7f\ufffe\uffff\/;.,?%#]*\z/, :if => proc { |u| u.display_name_changed? }
validates_format_of :display_name, :with => /\A\S/, :message => "has leading whitespace", :if => proc { |u| u.display_name_changed? }
validates_format_of :display_name, :with => /\S\z/, :message => "has trailing whitespace", :if => proc { |u| u.display_name_changed? }
validates_exclusion_of :display_name, :in => %w(new terms save confirm confirm-email go_public reset-password forgot-password suspended)
validates_numericality_of :home_lat, :allow_nil => true
validates_numericality_of :home_lon, :allow_nil => true
validates_numericality_of :home_zoom, :only_integer => true, :allow_nil => true
validates_inclusion_of :preferred_editor, :in => Editors::ALL_EDITORS, :allow_nil => true
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
after_initialize :set_defaults
before_save :encrypt_password
@ -113,15 +116,15 @@ class User < ActiveRecord::Base
end
def description
RichText.new(read_attribute(:description_format), read_attribute(:description))
RichText.new(self[:description_format], self[:description])
end
def languages
attribute_present?(:languages) ? read_attribute(:languages).split(/ *, */) : []
attribute_present?(:languages) ? self[:languages].split(/ *, */) : []
end
def languages=(languages)
write_attribute(:languages, languages.join(","))
self[:languages] = languages.join(",")
end
def preferred_language

View file

@ -16,7 +16,7 @@ class UserBlock < ActiveRecord::Base
##
# return a renderable version of the reason text.
def reason
RichText.new(read_attribute(:reason_format), read_attribute(:reason))
RichText.new(self[:reason_format], self[:reason])
end
##

View file

@ -3,8 +3,8 @@ class UserPreference < ActiveRecord::Base
belongs_to :user
validates_length_of :k, :within => 1..255
validates_length_of :v, :within => 1..255
validates :user, :presence => true, :associated => true
validates :k, :v, :length => 1..255
# Turn this Node in to an XML Node without the <osm> wrapper.
def to_xml_node

View file

@ -3,6 +3,5 @@ class UserRole < ActiveRecord::Base
ALL_ROLES = %w(administrator moderator)
validates_inclusion_of :role, :in => ALL_ROLES
validates_uniqueness_of :role, :scope => :user_id
validates :role, :inclusion => ALL_ROLES, :uniqueness => { :scope => :user_id }
end

View file

@ -19,13 +19,15 @@ 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
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
validates :id, :uniqueness => true, :presence => { :on => :update },
:numericality => { :on => :update, :integer_only => true }
validates :version, :presence => true,
:numericality => { :integer_only => true }
validates :changeset_id, :presence => true,
:numericality => { :integer_only => true }
validates :timestamp, :presence => true
validates :changeset, :associated => true
validates :visible, :inclusion => [true, false]
scope :visible, -> { where(:visible => true) }
scope :invisible, -> { where(:visible => false) }

View file

@ -4,8 +4,7 @@ class WayTag < ActiveRecord::Base
belongs_to :way
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
validates :way, :presence => true, :associated => true
validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
validates :k, :uniqueness => { :scope => :way_id }
end