Eliminate deprecated scope and association arguments

This commit is contained in:
Tom Hughes 2013-06-27 00:35:56 +01:00
parent f0feca800d
commit ca30b879f6
12 changed files with 40 additions and 51 deletions

View file

@ -2,7 +2,7 @@ class AccessToken < OauthToken
belongs_to :user
belongs_to :client_application
scope :valid, where(:invalidated_at => nil)
scope :valid, -> { where(:invalidated_at => nil) }
validates_presence_of :user, :secret

View file

@ -2,18 +2,10 @@ class DiaryEntry < ActiveRecord::Base
belongs_to :user, :counter_cache => true
belongs_to :language, :foreign_key => 'language_code'
has_many :comments, :class_name => "DiaryComment",
:include => :user,
:order => "diary_comments.id"
has_many :visible_comments, :class_name => "DiaryComment",
:include => :user,
:conditions => {
:users => { :status => ["active", "confirmed" ] },
:visible => true
},
:order => "diary_comments.id"
has_many :comments, -> { order(:id).preload(:user) }, :class_name => "DiaryComment"
has_many :visible_comments, -> { joins(:user).where(:visible => true, :users => { :status => ["active", "confirmed"] }).order(:id) }, :class_name => "DiaryComment"
scope :visible, where(:visible => true)
scope :visible, -> { where(:visible => true) }
validates_presence_of :title, :body
validates_length_of :title, :within => 1..255

View file

@ -9,7 +9,7 @@ class Node < ActiveRecord::Base
belongs_to :changeset
has_many :old_nodes, :order => :version
has_many :old_nodes, -> { order(:version) }
has_many :way_nodes
has_many :ways, :through => :way_nodes
@ -31,8 +31,8 @@ class Node < ActiveRecord::Base
validate :validate_position
validates_associated :changeset
scope :visible, where(:visible => true)
scope :invisible, where(:visible => false)
scope :visible, -> { where(:visible => true) }
scope :invisible, -> { where(:visible => false) }
# Sanity check the latitude and longitude and add an error if it's broken
def validate_position

View file

@ -1,10 +1,7 @@
class Note < ActiveRecord::Base
include GeoRecord
has_many :comments, :class_name => "NoteComment",
:foreign_key => :note_id,
:order => :created_at,
:conditions => { :visible => true }
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

View file

@ -2,7 +2,7 @@ class OauthToken < ActiveRecord::Base
belongs_to :client_application
belongs_to :user
scope :authorized, where("authorized_at IS NOT NULL and invalidated_at IS NULL")
scope :authorized, -> { where("authorized_at IS NOT NULL and invalidated_at IS NULL") }
validates_uniqueness_of :token
validates_presence_of :client_application, :token

View file

@ -12,7 +12,7 @@ class OldRelation < ActiveRecord::Base
belongs_to :redaction
belongs_to :current_relation, :class_name => "Relation", :foreign_key => "relation_id"
has_many :old_members, :class_name => 'OldRelationMember', :foreign_key => [:relation_id, :version], :order => :sequence_id
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

View file

@ -8,9 +8,9 @@ class Relation < ActiveRecord::Base
belongs_to :changeset
has_many :old_relations, :order => 'version'
has_many :old_relations, -> { order(:version) }
has_many :relation_members, :order => 'sequence_id'
has_many :relation_members, -> { order(:sequence_id) }
has_many :relation_tags
has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
@ -24,11 +24,11 @@ class Relation < ActiveRecord::Base
validates_numericality_of :changeset_id, :version, :integer_only => true
validates_associated :changeset
scope :visible, where(:visible => true)
scope :invisible, where(:visible => false)
scope :nodes, lambda { |*ids| joins(:relation_members).where(:current_relation_members => { :member_type => "Node", :member_id => ids }) }
scope :ways, lambda { |*ids| joins(:relation_members).where(:current_relation_members => { :member_type => "Way", :member_id => ids }) }
scope :relations, lambda { |*ids| joins(:relation_members).where(:current_relation_members => { :member_type => "Relation", :member_id => ids }) }
scope :visible, -> { where(:visible => true) }
scope :invisible, -> { where(:visible => false) }
scope :nodes, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Node", :member_id => ids.flatten }) }
scope :ways, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Way", :member_id => ids.flatten }) }
scope :relations, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Relation", :member_id => ids.flatten }) }
TYPES = ["node", "way", "relation"]

View file

@ -5,10 +5,10 @@ class Trace < ActiveRecord::Base
has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :delete_all
has_many :points, :class_name => 'Tracepoint', :foreign_key => 'gpx_id', :dependent => :delete_all
scope :visible, where(:visible => true)
scope :visible_to, lambda { |u| visible.where("visibility IN ('public', 'identifiable') OR user_id = ?", u) }
scope :public, where(:visibility => ["public", "identifiable"])
scope :tagged, lambda { |t| joins(:tags).where(:gpx_file_tags => { :tag => t }) }
scope :visible, -> { where(:visible => true) }
scope :visible_to, ->(u) { visible.where("visibility IN ('public', 'identifiable') OR user_id = ?", u) }
scope :public, -> { where(:visibility => ["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

View file

@ -1,22 +1,22 @@
class User < ActiveRecord::Base
require 'xml/libxml'
has_many :traces, :conditions => { :visible => true }
has_many :diary_entries, :order => 'created_at DESC'
has_many :diary_comments, :order => 'created_at DESC'
has_many :messages, :foreign_key => :to_user_id, :conditions => { :to_user_visible => true }, :order => 'sent_on DESC', :include => [:sender, :recipient]
has_many :new_messages, :class_name => "Message", :foreign_key => :to_user_id, :conditions => { :to_user_visible => true, :message_read => false }, :order => 'sent_on DESC'
has_many :sent_messages, :class_name => "Message", :foreign_key => :from_user_id, :conditions => { :from_user_visible => true }, :order => 'sent_on DESC', :include => [:sender, :recipient]
has_many :friends, :include => :befriendee, :conditions => "users.status IN ('active', 'confirmed')"
has_many :traces, -> { where(:visible => true) }
has_many :diary_entries, -> { order(:created_at => :desc) }
has_many :diary_comments, -> { order(:created_at => :desc) }
has_many :messages, -> { where(:to_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :foreign_key => :to_user_id
has_many :new_messages, -> { where(:to_user_visible => true, :message_read => false).order(:sent_on => :desc) }, :class_name => "Message", :foreign_key => :to_user_id
has_many :sent_messages, -> { where(:from_user_visible => true).order(:sent_on => :desc).preload(:sender, :recipient) }, :class_name => "Message", :foreign_key => :from_user_id
has_many :friends, -> { joins(:befriendee).where(:users => { :status => ["active", "confirmed"] }) }
has_many :friend_users, :through => :friends, :source => :befriendee
has_many :tokens, :class_name => "UserToken"
has_many :preferences, :class_name => "UserPreference"
has_many :changesets, :order => 'created_at DESC'
has_many :changesets, -> { order(:created_at => :desc) }
has_many :note_comments, :foreign_key => :author_id
has_many :notes, :through => :note_comments
has_many :client_applications
has_many :oauth_tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
has_many :oauth_tokens, -> { order(:authorized_at => :desc).preload(:client_application) }, :class_name => "OauthToken"
has_many :blocks, :class_name => "UserBlock"
has_many :blocks_created, :class_name => "UserBlock", :foreign_key => :creator_id
@ -24,9 +24,9 @@ class User < ActiveRecord::Base
has_many :roles, :class_name => "UserRole"
scope :visible, where(:status => ["pending", "active", "confirmed"])
scope :active, where(:status => ["active", "confirmed"])
scope :public, where(:data_public => true)
scope :visible, -> { where(:status => ["pending", "active", "confirmed"]) }
scope :active, -> { where(:status => ["active", "confirmed"]) }
scope :public, -> { where(:data_public => true) }
validates_presence_of :email, :display_name
validates_confirmation_of :email#, :message => ' addresses must match'

View file

@ -8,10 +8,10 @@ class Way < ActiveRecord::Base
belongs_to :changeset
has_many :old_ways, :order => 'version'
has_many :old_ways, -> { order(:version) }
has_many :way_nodes, :order => 'sequence_id'
has_many :nodes, :through => :way_nodes, :order => 'sequence_id'
has_many :way_nodes, -> { order(:sequence_id) }
has_many :nodes, -> { order("sequence_id") }, :through => :way_nodes
has_many :way_tags
@ -26,8 +26,8 @@ class Way < ActiveRecord::Base
validates_numericality_of :id, :on => :update, :integer_only => true
validates_associated :changeset
scope :visible, where(:visible => true)
scope :invisible, where(:visible => false)
scope :visible, -> { where(:visible => true) }
scope :invisible, -> { where(:visible => false) }
# Read in xml as text and return it's Way object representation
def self.from_xml(xml, create=false)

View file

@ -5,7 +5,7 @@ module GeoRecord
SCALE = 10000000
def self.included(base)
base.scope :bbox, lambda { |bbox| base.where(OSM.sql_for_area(bbox)) }
base.scope :bbox, ->(bbox) { base.where(OSM.sql_for_area(bbox)) }
base.before_save :update_tile
end

View file

@ -4,7 +4,7 @@ module Redactable
def self.included(base)
# this is used to extend activerecord bases, as these aren't
# in scope for the module itself.
base.scope :unredacted, base.where(:redaction_id => nil)
base.scope :unredacted, -> { base.where(:redaction_id => nil) }
end
def redacted?