diff --git a/app/models/article.rb b/app/models/article.rb index 1b09695..c32c31e 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -74,7 +74,7 @@ class Article < ActiveRecord::Base has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' - has_many :article_categorizations, ->{ where 'articles_categories.virtual = ?', false } + has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false } has_many :categories, :through => :article_categorizations has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization' @@ -126,13 +126,13 @@ class Article < ActiveRecord::Base xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list' - scope :in_category, ->(category) { + scope :in_category, -> category { includes('categories_including_virtual').where('categories.id' => category.id) } include TimeScopes - scope :by_range, ->(range) { + scope :by_range, -> range { where 'articles.published_at BETWEEN :start_date AND :end_date', { start_date: range.first, end_date: range.last } } @@ -256,16 +256,16 @@ class Article < ActiveRecord::Base # retrieves all articles belonging to the given +profile+ that are not # sub-articles of any other article. - scope :top_level_for, ->(profile) { + scope :top_level_for, -> profile { where 'parent_id is null and profile_id = ?', profile.id } - scope :is_public, ->{ + scope :is_public, -> { joins(:profile). where("advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true) } - scope :more_recent, ->{ + scope :more_recent, -> { order('articles.published_at desc, articles.id desc') .where("advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND ((articles.type != ?) OR articles.type is NULL)", @@ -278,8 +278,8 @@ class Article < ActiveRecord::Base paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) end - scope :more_popular, ->{ order 'hits DESC' } - scope :relevant_as_recent, ->{ + scope :more_popular, -> { order 'hits DESC' } + scope :relevant_as_recent, -> { where "(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL" } @@ -410,7 +410,7 @@ class Article < ActiveRecord::Base self.translations.map(&:language) end - scope :native_translations, ->{ where :translation_of_id => nil } + scope :native_translations, -> { where :translation_of_id => nil } def translatable? false @@ -489,19 +489,19 @@ class Article < ActiveRecord::Base ['TextArticle', 'TextileArticle', 'TinyMceArticle'] end - scope :published, ->{ where 'articles.published = ?', true } - scope :folders, ->(profile) { where 'articles.type IN (?)', profile.folder_types } - scope :no_folders, ->(profile) { where 'articles.type NOT IN (?)', profile.folder_types } - scope :galleries, ->{ where "articles.type IN ('Gallery')" } - scope :images, ->{ where :is_image => true } - scope :no_images, ->{ where :is_image => false } - scope :text_articles, ->{ where 'articles.type IN (?)', text_article_types } - scope :files, ->{ where :type => 'UploadedFile' } - scope :with_types, ->(types) { where 'articles.type IN (?)', types } + scope :published, -> { where 'articles.published = ?', true } + scope :folders, -> profile { where 'articles.type IN (?)', profile.folder_types } + scope :no_folders, -> profile { where 'articles.type NOT IN (?)', profile.folder_types } + scope :galleries, -> { where "articles.type IN ('Gallery')" } + scope :images, -> { where :is_image => true } + scope :no_images, -> { where :is_image => false } + scope :text_articles, -> { where 'articles.type IN (?)', text_article_types } + scope :files, -> { where :type => 'UploadedFile' } + scope :with_types, -> types { where 'articles.type IN (?)', types } - scope :more_popular, ->{ order 'hits DESC' } - scope :more_comments, ->{ order "comments_count DESC" } - scope :more_recent, ->{ order "created_at DESC" } + scope :more_popular, -> { order 'hits DESC' } + scope :more_comments, -> { order "comments_count DESC" } + scope :more_recent, -> { order "created_at DESC" } scope :display_filter, lambda {|user, profile| return published if (user.nil? && profile && profile.public?) diff --git a/app/models/category.rb b/app/models/category.rb index 4378dcd..adc91d4 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -15,11 +15,11 @@ class Category < ActiveRecord::Base belongs_to :environment # Finds all top level categories for a given environment. - scope :top_level_for, ->(environment) { + scope :top_level_for, -> environment { where 'parent_id is null and environment_id = ?', environment.id } - scope :on_level, ->(parent) { where :parent_id => parent } + scope :on_level, -> parent { where :parent_id => parent } acts_as_filesystem @@ -46,7 +46,7 @@ class Category < ActiveRecord::Base display_color = nil if display_color.blank? end - scope :from_types, ->(types) { + scope :from_types, -> types { if types.select{ |t| t.blank? }.empty? then where(type: types) else where("type IN (?) OR type IS NULL", types.reject{ |t| t.blank? }) end diff --git a/app/models/event.rb b/app/models/event.rb index 3a65805..e7c4916 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -34,19 +34,19 @@ class Event < Article end end - scope :by_day, ->(date) { + scope :by_day, -> date { where('start_date >= :start_date AND start_date <= :end_date AND end_date IS NULL OR (start_date <= :end_date AND end_date >= :start_date)', start_date: date.beginning_of_day, end_date: date.end_of_day). order('start_date ASC') } - scope :next_events_from_month, ->(date) { + scope :next_events_from_month, -> date { date_temp = date.strftime("%Y-%m-%d") order('start_date ASC') .where("start_date >= ?","#{date_temp}") } - scope :by_month, ->(date) { + scope :by_month, -> date { order('start_date ASC') .where("EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?", date.year, date.month) } @@ -69,7 +69,7 @@ class Event < Article 'event' end - scope :by_range, ->(range) { + scope :by_range, -> range { where('start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day', {:start_day => range.first, :end_day => range.last}) } diff --git a/app/models/person.rb b/app/models/person.rb index e7936f6..53b9218 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -16,24 +16,24 @@ class Person < Profile acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} acts_as_accessor - scope :members_of, ->(resources) { + scope :members_of, -> resources { resources = Array(resources) conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') select('DISTINCT profiles.*').joins(:role_assignments).where([conditions]) } - scope :not_members_of, ->(resources) { + scope :not_members_of, -> resources { resources = Array(resources) conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') select('DISTINCT profiles.*').where('"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "role_assignments" ON "role_assignments"."accessor_id" = "profiles"."id" AND "role_assignments"."accessor_type" = (\'Profile\') WHERE "profiles"."type" IN (\'Person\') AND (%s))' % conditions) } - scope :by_role, ->(roles) { + scope :by_role, -> roles { roles = Array(roles) select('DISTINCT profiles.*').joins(:role_assignments).where('role_assignments.role_id IN (?)', roles) } - scope :not_friends_of, ->(resources) { + scope :not_friends_of, -> resources { resources = Array(resources) select('DISTINCT profiles.*').where('"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "friendships" ON "friendships"."person_id" = "profiles"."id" WHERE "friendships"."friend_id" IN (%s))' % resources.map(&:id)) } @@ -83,7 +83,7 @@ class Person < Profile has_many :friendships, :dependent => :destroy has_many :friends, :class_name => 'Person', :through => :friendships - scope :online, ->{ + scope :online, -> { joins(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes) } @@ -102,27 +102,27 @@ class Person < Profile has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' has_many :suggested_profiles, class_name: 'ProfileSuggestion', foreign_key: :person_id, order: 'score DESC', dependent: :destroy - has_many :suggested_people, ->{ + has_many :suggested_people, -> { where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true }, through: :suggested_profiles, source: :suggestion - has_many :suggested_communities, ->{ + has_many :suggested_communities, -> { where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true }, through: :suggested_profiles, source: :suggestion - scope :more_popular, ->{ order 'friends_count DESC' } + scope :more_popular, -> { order 'friends_count DESC' } - scope :abusers, ->{ + scope :abusers, -> { joins(:abuse_complaints).where('tasks.status = 3').select('DISTINCT profiles.*') } - scope :non_abusers, ->{ + scope :non_abusers, -> { select("DISTINCT profiles.*"). joins("LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'"). where("tasks.status != 3 OR tasks.id is NULL") } - scope :admins, ->{ joins(:role_assignments => :role).where('roles.key = ?', 'environment_administrator') } - scope :activated, ->{ joins(:user).where('users.activation_code IS NULL AND users.activated_at IS NOT NULL') } - scope :deactivated, ->{ joins(:user).where('NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)') } + scope :admins, -> { joins(:role_assignments => :role).where('roles.key = ?', 'environment_administrator') } + scope :activated, -> { joins(:user).where('users.activation_code IS NULL AND users.activated_at IS NOT NULL') } + scope :deactivated, -> { joins(:user).where('NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)') } after_destroy do |person| Friendship.where(friend_id: person.id).each{ |friendship| friendship.destroy } diff --git a/app/models/product.rb b/app/models/product.rb index 559b63d..0d1f1c5 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -52,7 +52,7 @@ class Product < ActiveRecord::Base scope :more_recent, :order => "created_at DESC" - scope :from_category, ->(category) { + scope :from_category, -> category { joins(:product_category).where('categories.path LIKE ?', "%#{category.slug}%") if category } diff --git a/app/models/product_category.rb b/app/models/product_category.rb index 4fcc580..4039b88 100644 --- a/app/models/product_category.rb +++ b/app/models/product_category.rb @@ -6,14 +6,14 @@ class ProductCategory < Category attr_accessible :name, :parent, :environment scope :unique, :select => 'DISTINCT ON (path) categories.*' - scope :by_enterprise, ->(enterprise) { + scope :by_enterprise, -> enterprise { joins(:products). where('products.profile_id = ?', enterprise.id) } - scope :by_environment, ->(environment) { + scope :by_environment, -> environment { where 'environment_id = ?', environment.id } - scope :unique_by_level, ->(level) { + scope :unique_by_level, -> level { select "DISTINCT ON (filtered_category) split_part(path, '/', #{level}) AS filtered_category, categories.*" } diff --git a/app/models/profile.rb b/app/models/profile.rb index b33a558..db54ab4 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -87,28 +87,28 @@ class Profile < ActiveRecord::Base include Noosfero::Plugin::HotSpot - scope :memberships_of, ->(person) { + scope :memberships_of, -> person { select('DISTINCT profiles.*'). joins(:role_assignments). where('role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id) } #FIXME: these will work only if the subclass is already loaded - scope :enterprises, ->{ + scope :enterprises, -> { where((Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")) } - scope :communities, ->{ + scope :communities, -> { where((Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")) } - scope :templates, ->(template_id = nil) { + scope :templates, -> template_id = nil { s = where is_template: true s = s.where id: template_id if template_id s } - scope :with_templates, ->(templates) { + scope :with_templates, -> templates { where template_id: templates } - scope :no_templates, ->{ where is_template: false } + scope :no_templates, -> { where is_template: false } # Returns a scoped object to select profiles in a given location or in a radius # distance from the given location center. @@ -185,10 +185,10 @@ class Profile < ActiveRecord::Base Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') end - scope :visible, ->{ where visible: true, secret: false } - scope :disabled, ->{ where visible: false } - scope :is_public, ->{ where visible: true, public_profile: true, secret: false } - scope :enabled, ->{ where enabled: true } + scope :visible, -> { where visible: true, secret: false } + scope :disabled, -> { where visible: false } + scope :is_public, -> { where visible: true, public_profile: true, secret: false } + scope :enabled, -> { where enabled: true } # Subclasses must override this method scope :more_popular @@ -289,7 +289,7 @@ class Profile < ActiveRecord::Base end end - has_many :profile_categorizations, ->{ where 'categories_profiles.virtual = ?', false } + has_many :profile_categorizations, -> { where 'categories_profiles.virtual = ?', false } has_many :categories, :through => :profile_categorizations has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' diff --git a/app/models/scrap.rb b/app/models/scrap.rb index b644706..cabcc2d 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -18,9 +18,9 @@ class Scrap < ActiveRecord::Base after_create :create_activity after_update :update_activity - scope :all_scraps, ->(profile) { limit(30).where("receiver_id = ? OR sender_id = ?", profile, profile) } + scope :all_scraps, -> profile { limit(30).where("receiver_id = ? OR sender_id = ?", profile, profile) } - scope :not_replies, ->{ where scrap_id: nil } + scope :not_replies, -> { where scrap_id: nil } track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.sender != s.receiver && s.sender != s.top_root.receiver}, :custom_target => :action_tracker_target, :custom_user => :sender diff --git a/app/models/task.rb b/app/models/task.rb index 0e0fe61..cb5dc70 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -281,16 +281,16 @@ class Task < ActiveRecord::Base end end - scope :pending, ->{ where status: Task::Status::ACTIVE } - scope :hidden, ->{ where status: Task::Status::HIDDEN } - scope :finished, ->{ where status: Task::Status::FINISHED } - scope :canceled, ->{ where status: Task::Status::CANCELLED } - scope :closed, ->{ where status: [Task::Status::CANCELLED, Task::Status::FINISHED] } - scope :opened, ->{ where status: [Task::Status::ACTIVE, Task::Status::HIDDEN] } - scope :of, ->(type) { where "type LIKE ?", type if type } - scope :order_by, ->(attribute, ord) { order "#{attribute} #{ord}" } - scope :like, ->(field, value) { where "LOWER(#{field}) LIKE ?", "%#{value.downcase}%" if value } - scope :pending_all, ->(profile, filter_type, filter_text) { + scope :pending, -> { where status: Task::Status::ACTIVE } + scope :hidden, -> { where status: Task::Status::HIDDEN } + scope :finished, -> { where status: Task::Status::FINISHED } + scope :canceled, -> { where status: Task::Status::CANCELLED } + scope :closed, -> { where status: [Task::Status::CANCELLED, Task::Status::FINISHED] } + scope :opened, -> { where status: [Task::Status::ACTIVE, Task::Status::HIDDEN] } + scope :of, -> type { where "type LIKE ?", type if type } + scope :order_by, -> attribute, ord { order "#{attribute} #{ord}" } + scope :like, -> field, value { where "LOWER(#{field}) LIKE ?", "%#{value.downcase}%" if value } + scope :pending_all, -> profile, filter_type, filter_text { self.to(profile).without_spam.pending.of(filter_type).like('data', filter_text) } @@ -364,7 +364,7 @@ class Task < ActiveRecord::Base # specified code AND with status = Task::Status::ACTIVE. # # Can be used in subclasses to find only their instances. - scope :from_code, ->(code) { where code: code, status: Task::Status::ACTIVE } + scope :from_code, -> code { where code: code, status: Task::Status::ACTIVE } class << self diff --git a/plugins/bsc/lib/bsc_plugin/contract.rb b/plugins/bsc/lib/bsc_plugin/contract.rb index 352779f..c7e8270 100644 --- a/plugins/bsc/lib/bsc_plugin/contract.rb +++ b/plugins/bsc/lib/bsc_plugin/contract.rb @@ -8,8 +8,8 @@ class BscPlugin::Contract < ActiveRecord::Base belongs_to :bsc, :class_name => 'BscPlugin::Bsc' - named_scope :status, ->(status_list) { where 'status in (?)', status_list if status_list.present? } - named_scope :sorted_by, ->(sorter, direction) { order "#{sorter} #{direction}" } + named_scope :status, -> status_list { where 'status in (?)', status_list if status_list.present? } + named_scope :sorted_by, -> sorter, direction { order "#{sorter} #{direction}" } before_create do |contract| contract.created_at ||= Time.now.utc diff --git a/plugins/comment_group/lib/ext/comment.rb b/plugins/comment_group/lib/ext/comment.rb index 7e0949e..b29cc5a 100644 --- a/plugins/comment_group/lib/ext/comment.rb +++ b/plugins/comment_group/lib/ext/comment.rb @@ -2,9 +2,9 @@ require_dependency 'comment' class Comment - scope :without_group, ->{ where group_id: nil } + scope :without_group, -> { where group_id: nil } - scope :in_group, ->(group_id) { where 'group_id = ?', group_id } + scope :in_group, -> group_id { where 'group_id = ?', group_id } attr_accessible :group_id diff --git a/plugins/custom_forms/lib/custom_forms_plugin/form.rb b/plugins/custom_forms/lib/custom_forms_plugin/form.rb index 048a769..1d8fb02 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/form.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/form.rb @@ -26,9 +26,9 @@ class CustomFormsPlugin::Form < ActiveRecord::Base tasks.each {|task| task.cancel} end - scope :from_profile, ->(profile) { where profile_id: profile.id } - scope :on_memberships, ->{ where on_membership: true, for_admission: false } - scope :for_admissions, ->{ where for_admission: true } + scope :from_profile, -> profile { where profile_id: profile.id } + scope :on_memberships, -> { where on_membership: true, for_admission: false } + scope :for_admissions, -> { where for_admission: true } =begin scope :accessible_to lambda do |profile| #TODO should verify is profile is associated with the form owner diff --git a/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb b/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb index 4bd591b..e820773 100644 --- a/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb +++ b/plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb @@ -5,7 +5,7 @@ class CustomFormsPlugin::MembershipSurvey < Task include CustomFormsPlugin::Helper - scope :from_profile, ->(profile) { where requestor_id: profile.id } + scope :from_profile, -> profile { where requestor_id: profile.id } def perform form = CustomFormsPlugin::Form.find(form_id) diff --git a/plugins/people_block/lib/ext/person.rb b/plugins/people_block/lib/ext/person.rb index ee82763..03ccddf 100644 --- a/plugins/people_block/lib/ext/person.rb +++ b/plugins/people_block/lib/ext/person.rb @@ -2,7 +2,7 @@ require_dependency 'person' class Person - scope :with_role, ->(role_id) { + scope :with_role, -> role_id { select('DISTINCT profiles.*').joins(:role_assignments). where("role_assignments.role_id = #{role_id}") } diff --git a/plugins/spaminator/lib/spaminator_plugin/report.rb b/plugins/spaminator/lib/spaminator_plugin/report.rb index 4d7c557..ace4acc 100644 --- a/plugins/spaminator/lib/spaminator_plugin/report.rb +++ b/plugins/spaminator/lib/spaminator_plugin/report.rb @@ -8,7 +8,7 @@ class SpaminatorPlugin::Report < ActiveRecord::Base attr_accessible :environment - scope :from_environment, ->(environment) { where :environment_id => environment } + scope :from_environment, -> environment { where :environment_id => environment } after_initialize do |report| report.failed = {:people => [], :comments => []} if report.failed.blank? diff --git a/plugins/sub_organizations/lib/ext/organization.rb b/plugins/sub_organizations/lib/ext/organization.rb index de05761..67975fd 100644 --- a/plugins/sub_organizations/lib/ext/organization.rb +++ b/plugins/sub_organizations/lib/ext/organization.rb @@ -13,17 +13,17 @@ class Organization FIELDS << 'sub_organizations_plugin_parent_to_be' - scope :children, ->(parent) { + scope :children, -> parent { joins("inner join sub_organizations_plugin_relations as relations on profiles.id=relations.child_id"). where("relations.parent_id = ?", parent.id) } - scope :parents, ->(*children) { + scope :parents, -> *children { joins("inner join sub_organizations_plugin_relations as relations on profiles.id=relations.parent_id"). where("relations.child_id in (?)", children.map(&:id)) } - scope :pending_children, ->(parent) { + scope :pending_children, -> parent { select("distinct profiles.*"). joins("inner join sub_organizations_plugin_approve_paternity_relations as relations on profiles.id=relations.child_id inner join tasks on relations.task_id=tasks.id"). where("relations.parent_id = ? AND tasks.status = 1", parent.id) diff --git a/vendor/plugins/access_control/lib/role_assignment.rb b/vendor/plugins/access_control/lib/role_assignment.rb index 44fb9dd..2720811 100644 --- a/vendor/plugins/access_control/lib/role_assignment.rb +++ b/vendor/plugins/access_control/lib/role_assignment.rb @@ -9,11 +9,11 @@ class RoleAssignment < ActiveRecord::Base validates_presence_of :role, :accessor track_actions :join_community, :after_create, :keep_params => ["resource.name", "resource.url", "resource.profile_custom_icon"], - if: ->(x) { x.resource.is_a?(Community) && x.accessor.role_assignments.where(resource_id: x.resource.id, resource_type: 'Profile').count == 1 }, + if: -> x { x.resource.is_a?(Community) && x.accessor.role_assignments.where(resource_id: x.resource.id, resource_type: 'Profile').count == 1 }, :custom_user => :accessor, :custom_target => :resource track_actions :add_member_in_community, :after_create, - if: ->(x) { x.resource.is_a?(Community) && x.accessor.role_assignments.where(resource_id: x.resource.id, resource_type: 'Profile').count == 1 }, + if: -> x { x.resource.is_a?(Community) && x.accessor.role_assignments.where(resource_id: x.resource.id, resource_type: 'Profile').count == 1 }, :custom_user => :accessor, :custom_target => :resource def has_permission?(perm, res) diff --git a/vendor/plugins/kandadaboggu-vote_fu/lib/models/vote.rb b/vendor/plugins/kandadaboggu-vote_fu/lib/models/vote.rb index 253a105..c3f04ba 100644 --- a/vendor/plugins/kandadaboggu-vote_fu/lib/models/vote.rb +++ b/vendor/plugins/kandadaboggu-vote_fu/lib/models/vote.rb @@ -1,15 +1,15 @@ class Vote < ActiveRecord::Base - scope :for_voter, ->(*args) { + scope :for_voter, -> *args { where "voter_id = ? AND voter_type = ?", args.first.id, args.first.class.base_class.name } - scope :for_voteable, ->(*args) { + scope :for_voteable, -> *args { where "voteable_id = ? AND voteable_type = ?", args.first.id, args.first.class.base_class.name } - scope :recent, ->(*args) { + scope :recent, -> *args { where "created_at > ?", (args.first || 2.weeks.ago).to_s(:db) } - scope :descending, ->{ order "created_at DESC" } + scope :descending, -> { order "created_at DESC" } # NOTE: Votes belong to the "voteable" interface, and also to voters belongs_to :voteable, :polymorphic => true -- libgit2 0.21.2