diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb
index 6c2b103..9ecbe6d 100644
--- a/app/controllers/admin/admin_panel_controller.rb
+++ b/app/controllers/admin/admin_panel_controller.rb
@@ -54,7 +54,7 @@ class AdminPanelController < AdminController
if request.post?
env = environment
- folders = params[:folders].map{|fid| Folder.find(:first, :conditions => {:profile_id => env.portal_community, :id => fid})} if params[:folders]
+ folders = Folder.where :profile_id => env.portal_community, :id => params[:folders] if params[:folders]
env.portal_folders = folders
if env.save
session[:notice] = _('Saved the portal folders')
diff --git a/app/controllers/admin/categories_controller.rb b/app/controllers/admin/categories_controller.rb
index 9e24e07..0907c5d 100644
--- a/app/controllers/admin/categories_controller.rb
+++ b/app/controllers/admin/categories_controller.rb
@@ -1,13 +1,13 @@
class CategoriesController < AdminController
protect 'manage_environment_categories', :environment
-
+
helper :categories
def index
- @categories = environment.categories.find(:all, :conditions => "parent_id is null AND type is null")
- @regions = environment.regions.find(:all, :conditions => {:parent_id => nil})
- @product_categories = environment.product_categories.find(:all, :conditions => {:parent_id => nil})
+ @categories = environment.categories.where("parent_id is null AND type is null")
+ @regions = environment.regions.where(:parent_id => nil)
+ @product_categories = environment.product_categories.where(:parent_id => nil)
end
def get_children
diff --git a/app/controllers/admin/environment_role_manager_controller.rb b/app/controllers/admin/environment_role_manager_controller.rb
index fef08a8..67822e5 100644
--- a/app/controllers/admin/environment_role_manager_controller.rb
+++ b/app/controllers/admin/environment_role_manager_controller.rb
@@ -2,7 +2,7 @@ class EnvironmentRoleManagerController < AdminController
protect 'manage_environment_roles', :environment
def index
- @admins = Person.find(:all, :conditions => ['role_assignments.resource_type = ?', 'Environment'], :include => :role_assignments )
+ @admins = Person.where('role_assignments.resource_type = ?', 'Environment').includes(:role_assignments)
end
def change_roles
diff --git a/app/controllers/admin/features_controller.rb b/app/controllers/admin/features_controller.rb
index 4bbe006..4c2afc0 100644
--- a/app/controllers/admin/features_controller.rb
+++ b/app/controllers/admin/features_controller.rb
@@ -1,6 +1,6 @@
class FeaturesController < AdminController
protect 'edit_environment_features', :environment
-
+
def index
@features = Environment.available_features.sort_by{|k,v|v}
end
@@ -53,7 +53,7 @@ class FeaturesController < AdminController
def search_members
arg = params[:q].downcase
- result = environment.people.find(:all, :conditions => ['LOWER(name) LIKE ? OR identifier LIKE ?', "%#{arg}%", "%#{arg}%"])
+ result = environment.people.where('LOWER(name) LIKE ? OR identifier LIKE ?', "%#{arg}%", "%#{arg}%")
render :text => prepare_to_token_input(result).to_json
end
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index b827994..8e1e47c 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -63,7 +63,7 @@ class UsersController < AdminController
respond_to do |format|
format.html
format.xml do
- users = User.find(:all, :conditions => {:environment_id => environment.id}, :include => [:person])
+ users = User.where(:environment_id => environment.id).includes(:person)
send_data users.to_xml(
:skip_types => true,
:only => %w[email login created_at updated_at],
diff --git a/app/controllers/box_organizer_controller.rb b/app/controllers/box_organizer_controller.rb
index eb13d5d..772e18d 100644
--- a/app/controllers/box_organizer_controller.rb
+++ b/app/controllers/box_organizer_controller.rb
@@ -84,9 +84,9 @@ class BoxOrganizerController < ApplicationController
if request.xhr? and params[:query]
search = params[:query]
path_list = if boxes_holder.is_a?(Environment) && boxes_holder.enabled?('use_portal_community') && boxes_holder.portal_community
- boxes_holder.portal_community.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20).map { |content| "/{portal}/"+content.path }
+ boxes_holder.portal_community.articles.where("name ILIKE ? OR path ILIKE ?", "%#{search}%", "%#{search}%").limit(20).map { |content| "/{portal}/"+content.path }
elsif boxes_holder.is_a?(Profile)
- boxes_holder.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20).map { |content| "/{profile}/"+content.path }
+ boxes_holder.articles.where("name ILIKE ? OR path ILIKE ?", "%#{search}%", "%#{search}%").limit(20).map { |content| "/{profile}/"+content.path }
else
[]
end
diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb
index 9ff7a92..7288e07 100644
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -57,16 +57,9 @@ class CmsController < MyProfileController
def view
@article = profile.articles.find(params[:id])
- conditions = []
- if @article.has_posts?
- conditions = ['type != ?', 'RssFeed']
- end
-
- @articles = @article.children.reorder("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC, name").paginate(
- :conditions => conditions,
- :per_page => per_page,
- :page => params[:npage]
- )
+ @articles = @article.children.reorder("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC, name")
+ @articles = @articles.where type: 'RssFeed' if @article.has_posts?
+ @articles = @articles.paginate per_page: per_page, page: params[:npage]
end
def index
@@ -390,7 +383,7 @@ class CmsController < MyProfileController
def search_article_privacy_exceptions
arg = params[:q].downcase
- result = profile.members.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"])
+ result = profile.members.where('LOWER(name) LIKE ?', "%#{arg}%")
render :text => prepare_to_token_input(result).to_json
end
diff --git a/app/controllers/my_profile/profile_members_controller.rb b/app/controllers/my_profile/profile_members_controller.rb
index 26efff7..8fc39be 100644
--- a/app/controllers/my_profile/profile_members_controller.rb
+++ b/app/controllers/my_profile/profile_members_controller.rb
@@ -47,7 +47,7 @@ class ProfileMembersController < MyProfileController
end
def remove_role
- @association = RoleAssignment.find(:all, :conditions => {:id => params[:id], :target_id => profile.id})
+ @association = RoleAssignment.where(:id => params[:id], :target_id => profile.id)
if @association.destroy
session[:notice] = 'Member succefully unassociated'
else
@@ -120,7 +120,7 @@ class ProfileMembersController < MyProfileController
def search_user
role = Role.find(params[:role])
- render :text => environment.people.find(:all, :conditions => ['LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?', "%#{params['q_'+role.key]}%", "%#{params['q_'+role.key]}%"]).
+ render :text => environment.people.where('LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?', "%#{params['q_'+role.key]}%", "%#{params['q_'+role.key]}%").
select { |person| !profile.members_by_role(role).include?(person) }.
map {|person| {:id => person.id, :name => person.name} }.
to_json
diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb
index 78dcee3..976c0cc 100644
--- a/app/controllers/my_profile/tasks_controller.rb
+++ b/app/controllers/my_profile/tasks_controller.rb
@@ -86,7 +86,7 @@ class TasksController < MyProfileController
end
def ticket_details
- @ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]])
+ @ticket = Ticket.where('(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]).first
end
end
diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb
index da07102..77509b1 100644
--- a/app/controllers/public/profile_controller.rb
+++ b/app/controllers/public/profile_controller.rb
@@ -36,7 +36,7 @@ class ProfileController < PublicController
def tag_feed
@tag = params[:id]
- tagged = profile.articles.paginate(:per_page => 20, :page => 1, :order => 'published_at DESC', :include => :tags, :conditions => ['tags.name LIKE ?', @tag])
+ tagged = profile.articles.paginate(:per_page => 20, :page => 1).order('published_at DESC').includes(:tags).where('tags.name LIKE ?', @tag)
feed_writer = FeedWriter.new
data = feed_writer.write(
tagged,
@@ -201,7 +201,7 @@ class ProfileController < PublicController
def more_comments
profile_filter = @profile.person? ? {:user_id => @profile} : {:target_id => @profile}
- activity = ActionTracker::Record.find(:first, :conditions => {:id => params[:activity]}.merge(profile_filter))
+ activity = ActionTracker::Record.where({:id => params[:activity]}.merge profile_filter).first
comments_count = activity.comments.count
comment_page = (params[:comment_page] || 1).to_i
comments_per_page = 5
@@ -221,7 +221,7 @@ class ProfileController < PublicController
end
def more_replies
- activity = Scrap.find(:first, :conditions => {:id => params[:activity], :receiver_id => @profile, :scrap_id => nil})
+ activity = Scrap.where(:id => params[:activity], :receiver_id => @profile, :scrap_id => nil).first
comments_count = activity.replies.count
comment_page = (params[:comment_page] || 1).to_i
comments_per_page = 5
@@ -268,7 +268,7 @@ class ProfileController < PublicController
def remove_notification
begin
raise if !can_edit_profile
- notification = ActionTrackerNotification.find(:first, :conditions => {:profile_id => profile.id, :action_tracker_id => params[:activity_id]})
+ notification = ActionTrackerNotification.where(profile_id: profile.id, action_tracker_id: params[:activity_id]).first
notification.destroy
render :text => _('Notification successfully removed.')
rescue
diff --git a/app/mailers/environment_mailing.rb b/app/mailers/environment_mailing.rb
index 02f4e45..3b16a76 100644
--- a/app/mailers/environment_mailing.rb
+++ b/app/mailers/environment_mailing.rb
@@ -1,7 +1,9 @@
class EnvironmentMailing < Mailing
def recipients(offset=0, limit=100)
- source.people.all(:order => :id, :offset => offset, :limit => limit, :joins => "LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)", :conditions => { "m.person_id" => nil })
+ source.people.order(:id).offset(offset).limit(limit)
+ .joins("LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)")
+ .where("m.person_id" => nil)
end
def each_recipient
diff --git a/app/mailers/organization_mailing.rb b/app/mailers/organization_mailing.rb
index b4704d3..1829a21 100644
--- a/app/mailers/organization_mailing.rb
+++ b/app/mailers/organization_mailing.rb
@@ -5,7 +5,9 @@ class OrganizationMailing < Mailing
end
def recipients(offset=0, limit=100)
- source.members.all(:order => :id, :offset => offset, :limit => limit, :joins => "LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)", :conditions => { "m.person_id" => nil })
+ source.members.order(:id).offset(offset).limit(limit)
+ .joins("LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)")
+ .where("m.person_id" => nil)
end
def each_recipient
diff --git a/app/models/article.rb b/app/models/article.rb
index 6600e89..86e0025 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -73,7 +73,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, :conditions => [ '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'
@@ -125,15 +125,13 @@ class Article < ActiveRecord::Base
xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list'
- scope :in_category, lambda { |category|
- {:include => 'categories_including_virtual', :conditions => { 'categories.id' => category.id }}
+ scope :in_category, -> (category) {
+ includes('categories_including_virtual').where('categories.id' => category.id)
}
- scope :by_range, lambda { |range| {
- :conditions => [
- 'articles.published_at BETWEEN :start_date AND :end_date', { :start_date => range.first, :end_date => range.last }
- ]
- }}
+ scope :by_range, -> (range) {
+ where 'articles.published_at BETWEEN :start_date AND :end_date', { start_date: range.first, end_date: range.last }
+ }
URL_FORMAT = /\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\Z/ix
@@ -255,20 +253,21 @@ 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, lambda { |profile|
- {:conditions => [ 'parent_id is null and profile_id = ?', profile.id ]}
+ scope :top_level_for, -> {
+ where 'parent_id is null and profile_id = ?', profile.id
}
- # :public is reserved on rails 4.1, use is_public instead
- scope :is_public,
- :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ], :joins => [:profile]
+ scope :is_public, -> {
+ joins(:profile).
+ where("advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true)
+ }
- scope :more_recent,
- :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND
- ((articles.type != ?) OR articles.type is NULL)",
- true, true, true, true, 'RssFeed'
- ],
- :order => 'articles.published_at desc, articles.id desc'
+ 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)",
+ true, true, true, true, 'RssFeed')
+ }
# retrives the most commented articles, sorted by the comment count (largest
# first)
@@ -276,8 +275,10 @@ 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, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"]
+ 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"
+ }
def self.recent(limit = nil, extra_conditions = {}, pagination = true)
result = scoped({:conditions => extra_conditions}).
@@ -406,7 +407,7 @@ class Article < ActiveRecord::Base
self.translations.map(&:language)
end
- scope :native_translations, :conditions => { :translation_of_id => nil }
+ scope :native_translations, -> { where :translation_of_id => nil }
def translatable?
false
@@ -461,7 +462,7 @@ class Article < ActiveRecord::Base
elsif self.native_translation.language == locale
self.native_translation
else
- self.native_translation.translations.first(:conditions => { :language => locale })
+ self.native_translation.translations.where(:language => locale).first
end
end
@@ -485,19 +486,19 @@ class Article < ActiveRecord::Base
['TextArticle', 'TextileArticle', 'TinyMceArticle']
end
- scope :published, :conditions => ['articles.published = ?', true]
- scope :folders, lambda {|profile|{:conditions => ['articles.type IN (?)', profile.folder_types] }}
- scope :no_folders, lambda {|profile|{:conditions => ['articles.type NOT IN (?)', profile.folder_types]}}
- scope :galleries, :conditions => [ "articles.type IN ('Gallery')" ]
- scope :images, :conditions => { :is_image => true }
- scope :no_images, :conditions => { :is_image => false }
- scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ]
- scope :files, :conditions => { :type => 'UploadedFile' }
- scope :with_types, lambda { |types| { :conditions => [ '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?)
@@ -619,7 +620,7 @@ class Article < ActiveRecord::Base
]
def self.find_by_old_path(old_path)
- find(:first, :include => :versions, :conditions => ['article_versions.path = ?', old_path], :order => 'article_versions.id desc')
+ self.includes(:versions).where( 'article_versions.path = ?', old_path).order('article_versions.id DESC')
end
def hit
diff --git a/app/models/block.rb b/app/models/block.rb
index a18a5b3..8fbe600 100644
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -20,7 +20,7 @@ class Block < ActiveRecord::Base
acts_as_having_settings
- scope :enabled, :conditions => { :enabled => true }
+ scope :enabled, -> { where :enabled => true }
after_save do |block|
if block.owner.kind_of?(Profile) && block.owner.is_template? && block.mirror?
diff --git a/app/models/blog_archives_block.rb b/app/models/blog_archives_block.rb
index 4368d93..c700d3e 100644
--- a/app/models/blog_archives_block.rb
+++ b/app/models/blog_archives_block.rb
@@ -35,7 +35,7 @@ class BlogArchivesBlock < Block
posts.except(:order).count(:all, :group => 'EXTRACT(YEAR FROM published_at)').sort_by {|year, count| -year.to_i}.each do |year, count|
results << content_tag('li', content_tag('strong', "#{year} (#{count})"))
results << "
<%= _("Last topics") %> |
- <% r = forum.children.find(:all, :order => :updated_at, :conditions => ['type != ?', 'RssFeed']).last(3) %>
+ <% r = forum.children.order(:updated_at).where('type != ?', 'RssFeed').last(3) %>
">
<% r.each do |a| %>
<%= link_to a.title, a.view_url, :class => 'search-forum-sample-item '+icon_for_article(a) %>
diff --git a/app/views/search/_image.html.erb b/app/views/search/_image.html.erb
index b3800c0..dbb3080 100644
--- a/app/views/search/_image.html.erb
+++ b/app/views/search/_image.html.erb
@@ -26,7 +26,7 @@
<% end %>
<% elsif image.is_a? Gallery %>
- <% r = image.children.find(:all, :order => :updated_at, :conditions => ['type = ?', 'UploadedFile']).last(3) %>
+ <% r = image.children.order(updated_at).where('type = ?', 'UploadedFile').last(3) %>
<% if r.length > 0 %>
<% r.each_index do |i| img = r[i] %>
<%= link_to '', img.view_url, :class => "search-image-pic pic-num#{i+1}",
diff --git a/config/initializers/activities_counter_cache.rb b/config/initializers/activities_counter_cache.rb
index b382a8f..3a749a4 100644
--- a/config/initializers/activities_counter_cache.rb
+++ b/config/initializers/activities_counter_cache.rb
@@ -1,6 +1,6 @@
if Delayed::Backend::ActiveRecord::Job.table_exists? &&
Delayed::Backend::ActiveRecord::Job.attribute_names.include?('queue')
- job = Delayed::Backend::ActiveRecord::Job.all :conditions => ['handler LIKE ?', "%ActivitiesCounterCacheJob%"]
+ job = Delayed::Backend::ActiveRecord::Job.where('handler LIKE ?', "%ActivitiesCounterCacheJob%")
if job.blank?
Delayed::Backend::ActiveRecord::Job.enqueue(ActivitiesCounterCacheJob.new, {:priority => -3})
end
diff --git a/db/migrate/059_add_birth_date_to_person.rb b/db/migrate/059_add_birth_date_to_person.rb
index a76bee5..57d615f 100644
--- a/db/migrate/059_add_birth_date_to_person.rb
+++ b/db/migrate/059_add_birth_date_to_person.rb
@@ -37,7 +37,7 @@ class AddBirthDateToPerson < ActiveRecord::Migration
def self.up
add_column :profiles, :birth_date, :date
offset = 0
- while p = Person.find(:first, :conditions => "type = 'Person'", :order => 'id', :offset => offset)
+ while p = Person.where("type = 'Person'").order(:id).offset(offset).first
p.birth_date = ConvertDates.convert(p.data[:birth_date].to_s)
p.save
offset += 1
diff --git a/lib/acts_as_filesystem.rb b/lib/acts_as_filesystem.rb
index 1db6b68..0e729ad 100644
--- a/lib/acts_as_filesystem.rb
+++ b/lib/acts_as_filesystem.rb
@@ -34,7 +34,7 @@ module ActsAsFileSystem
def build_ancestry(parent_id = nil, ancestry = '')
ActiveRecord::Base.transaction do
- self.base_class.all(:conditions => {:parent_id => parent_id}).each do |node|
+ self.base_class.where(parent_id: parent_id).each do |node|
node.update_column :ancestry, ancestry
build_ancestry node.id, (ancestry.empty? ? "#{node.formatted_ancestry_id}" :
@@ -42,7 +42,7 @@ module ActsAsFileSystem
end
end
- #raise "Couldn't reach and set ancestry on every record" if self.base_class.count(:conditions => ['ancestry is null']) != 0
+ #raise "Couldn't reach and set ancestry on every record" if self.base_class.where('ancestry is null').count != 0
end
def has_path?
@@ -89,7 +89,7 @@ module ActsAsFileSystem
["#{self.ancestry_column} LIKE ?", "%#{self.formatted_ancestry_id}%"]
end
def descendents
- self.class.scoped :conditions => descendents_options
+ self.class.where descendents_options
end
# calculates the level of the record in the records hierarchy. Top-level
@@ -147,7 +147,7 @@ module ActsAsFileSystem
@hierarchy = []
if !reload and !recalculate_path and ancestor_ids
- objects = self.class.base_class.all(:conditions => {:id => ancestor_ids})
+ objects = self.class.base_class.where(id: ancestor_ids)
ancestor_ids.each{ |id| @hierarchy << objects.find{ |t| t.id == id } }
@hierarchy << self
else
@@ -170,7 +170,7 @@ module ActsAsFileSystem
result += current_level
ids = current_level.select {|item| item.children_count > 0}.map(&:id)
break if ids.empty?
- current_level = self.class.base_class.find(:all, :conditions => { :parent_id => ids})
+ current_level = self.class.base_class.where(parent_id: ids)
end
block ||= (lambda { |x| x })
result.map(&block)
diff --git a/lib/acts_as_having_image.rb b/lib/acts_as_having_image.rb
index 7c695c7..5e9d056 100644
--- a/lib/acts_as_having_image.rb
+++ b/lib/acts_as_having_image.rb
@@ -3,8 +3,8 @@ module ActsAsHavingImage
module ClassMethods
def acts_as_having_image
belongs_to :image, dependent: :destroy
- scope :with_image, :conditions => [ "#{table_name}.image_id IS NOT NULL" ]
- scope :without_image, :conditions => [ "#{table_name}.image_id IS NULL" ]
+ scope :with_image, -> { where "#{table_name}.image_id IS NOT NULL" }
+ scope :without_image, -> { where "#{table_name}.image_id IS NULL" }
self.send(:include, ActsAsHavingImage)
end
end
@@ -19,4 +19,4 @@ module ActsAsHavingImage
end
-ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods)
\ No newline at end of file
+ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods)
diff --git a/lib/extended_tag.rb b/lib/extended_tag.rb
index eafe8ab..dc9c316 100644
--- a/lib/extended_tag.rb
+++ b/lib/extended_tag.rb
@@ -4,13 +4,13 @@ class ActsAsTaggableOn::Tag
has_many :children, :class_name => 'Tag', :foreign_key => 'parent_id', :dependent => :destroy
-
- @@original_find = self.method(:find)
- # Rename the find method to find_with_pendings that includes all tags in the search regardless if its pending or not
+
+ @@original_find = self.method(:find)
+ # Rename the find method to find_with_pendings that includes all tags in the search regardless if its pending or not
def self.find_with_pendings(*args)
@@original_find.call(*args)
end
-
+
# Redefine the find method to exclude the pending tags from the search not allowing to tag something with an unapproved tag
def self.find(*args)
self.with_scope(:find => { :conditions => ['pending = ?', false] }) do
@@ -20,17 +20,17 @@ class ActsAsTaggableOn::Tag
# Return all the tags that were suggested but not yet approved
def self.find_pendings
- self.find_with_pendings(:all, :conditions => ['pending = ?', true])
+ self.find_with_pendings.where('pending = ?', true)
end
# All the tags that can be a new parent for this tag, that is all but itself and its descendents to avoid loops
def parent_candidates
- ActsAsTaggableOn::Tag.find(:all) - descendents - [self]
+ ActsAsTaggableOn::Tag.all - descendents - [self]
end
-
+
# All tags that have this tag as its one of its ancestors
def descendents
- children.to_a.sum([], &:descendents) + children
+ children.to_a.sum([], &:descendents) + children
end
end
diff --git a/lib/spammable.rb b/lib/spammable.rb
index eff1206..bdd7f27 100644
--- a/lib/spammable.rb
+++ b/lib/spammable.rb
@@ -9,11 +9,11 @@ module Spammable
end
module ClassMethods
- def self.extended (base)
+ def self.extended base
if base.respond_to?(:scope)
base.class_eval do
- scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false]
- scope :spam, :conditions => ['spam = ?', true]
+ scope :without_spam, -> { where 'spam IS NULL OR spam = ?', false }
+ scope :spam, -> { where 'spam = ?', true }
end
end
end
diff --git a/plugins/bsc/controllers/bsc_plugin_admin_controller.rb b/plugins/bsc/controllers/bsc_plugin_admin_controller.rb
index c13366d..31bf0e1 100644
--- a/plugins/bsc/controllers/bsc_plugin_admin_controller.rb
+++ b/plugins/bsc/controllers/bsc_plugin_admin_controller.rb
@@ -28,8 +28,9 @@ class BscPluginAdminController < AdminController
end
def search_enterprise
- render :text => Enterprise.not_validated.find(:all, :conditions => ["type <> 'BscPlugin::Bsc' AND (name LIKE ? OR identifier LIKE ?)", "%#{params[:q]}%", "%#{params[:q]}%"]).
- map {|enterprise| {:id => enterprise.id, :name => enterprise.name} }.
+ render :text => Enterprise.not_validated.
+ where("type <> 'BscPlugin::Bsc' AND (name LIKE ? OR identifier LIKE ?)", "%#{params[:q]}%", "%#{params[:q]}%").
+ map{ |enterprise| {:id => enterprise.id, :name => enterprise.name} }.
to_json
end
diff --git a/plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb b/plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb
index 68d0bca..89b855e 100644
--- a/plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb
+++ b/plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb
@@ -8,7 +8,7 @@ class BscPluginMyprofileController < MyProfileController
end
def search_enterprise
- render :text => environment.enterprises.find(:all, :conditions => ["type <> 'BscPlugin::Bsc' AND (LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?) AND (identifier NOT LIKE ?)", "%#{params[:q]}%", "%#{params[:q]}%", "%_template"]).
+ render :text => environment.enterprises.where("type <> 'BscPlugin::Bsc' AND (LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?) AND (identifier NOT LIKE ?)", "%#{params[:q]}%", "%#{params[:q]}%", "%_template").
select { |enterprise| enterprise.bsc.nil? && !profile.already_requested?(enterprise)}.
map {|enterprise| {:id => enterprise.id, :name => enterprise.name} }.
to_json
@@ -188,7 +188,8 @@ class BscPluginMyprofileController < MyProfileController
end
def search_contract_enterprises
- render :text => profile.enterprises.find(:all, :conditions => ["(LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?)", "%#{params[:enterprises]}%", "%#{params[:enterprises]}%"]).
+ render :text => profile.enterprises.
+ where("(LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?)", "%#{params[:enterprises]}%", "%#{params[:enterprises]}%").
map {|enterprise| {:id => enterprise.id, :name => enterprise.short_name(60)} }.
to_json
end
@@ -199,7 +200,8 @@ class BscPluginMyprofileController < MyProfileController
enterprises = enterprises.blank? ? -1 : enterprises
added_products = (params[:added_products] || []).split(',')
added_products = added_products.blank? ? -1 : added_products
- render :text => Product.find(:all, :conditions => ["LOWER(name) LIKE ? AND profile_id IN (?) AND id NOT IN (?)", "%#{query}%", enterprises, added_products]).
+ render :text => Product.
+ where("LOWER(name) LIKE ? AND profile_id IN (?) AND id NOT IN (?)", "%#{query}%", enterprises, added_products).
map {|product| { :id => product.id,
:name => short_text(product_display_name(product), 60),
:sale_id => params[:sale_id],
diff --git a/plugins/bsc/lib/bsc_plugin/contract.rb b/plugins/bsc/lib/bsc_plugin/contract.rb
index d89cf60..71b44f9 100644
--- a/plugins/bsc/lib/bsc_plugin/contract.rb
+++ b/plugins/bsc/lib/bsc_plugin/contract.rb
@@ -7,8 +7,8 @@ class BscPlugin::Contract < Noosfero::Plugin::ActiveRecord
belongs_to :bsc, :class_name => 'BscPlugin::Bsc'
- named_scope :status, lambda { |status_list| status_list.blank? ? {} : {:conditions => ['status in (?)', status_list]} }
- named_scope :sorted_by, lambda { |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/bsc/lib/bsc_plugin/ext/enterprise.rb b/plugins/bsc/lib/bsc_plugin/ext/enterprise.rb
index 160077c..463c3d5 100644
--- a/plugins/bsc/lib/bsc_plugin/ext/enterprise.rb
+++ b/plugins/bsc/lib/bsc_plugin/ext/enterprise.rb
@@ -8,6 +8,6 @@ class Enterprise
FIELDS << 'enabled'
FIELDS << 'validated'
- named_scope :validated, :conditions => {:validated => true}
- named_scope :not_validated, :conditions => {:validated => false}
+ named_scope :validated, -> { where validated: true }
+ named_scope :not_validated, -> { where validated: false }
end
diff --git a/plugins/comment_classification/lib/comment_classification_plugin/label.rb b/plugins/comment_classification/lib/comment_classification_plugin/label.rb
index 36b9897..32b1674 100644
--- a/plugins/comment_classification/lib/comment_classification_plugin/label.rb
+++ b/plugins/comment_classification/lib/comment_classification_plugin/label.rb
@@ -4,7 +4,7 @@ class CommentClassificationPlugin::Label < Noosfero::Plugin::ActiveRecord
validates_presence_of :name
- scope :enabled, :conditions => { :enabled => true }
+ scope :enabled, -> { where enabled: true }
attr_accessible :name, :enabled, :color
diff --git a/plugins/comment_classification/lib/comment_classification_plugin/status.rb b/plugins/comment_classification/lib/comment_classification_plugin/status.rb
index e7769f9..aa3c34c 100644
--- a/plugins/comment_classification/lib/comment_classification_plugin/status.rb
+++ b/plugins/comment_classification/lib/comment_classification_plugin/status.rb
@@ -6,5 +6,5 @@ class CommentClassificationPlugin::Status < Noosfero::Plugin::ActiveRecord
validates_presence_of :name
- scope :enabled, :conditions => { :enabled => true }
+ scope :enabled, -> { where enabled: true }
end
diff --git a/plugins/comment_group/lib/ext/article.rb b/plugins/comment_group/lib/ext/article.rb
index c532621..6fee4e5 100644
--- a/plugins/comment_group/lib/ext/article.rb
+++ b/plugins/comment_group/lib/ext/article.rb
@@ -2,13 +2,15 @@ require_dependency 'article'
class Article
- has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL']
+ has_many :group_comments, -> {
+ order('created_at asc').where('group_id IS NOT NULL')
+ }, class_name: 'Comment', foreign_key: 'source_id', dependent: :destroy
validate :not_empty_group_comments_removed
def not_empty_group_comments_removed
if body && body_changed?
- groups_with_comments = Comment.find(:all, :select => 'distinct group_id', :conditions => {:source_id => self.id}).map(&:group_id).compact
+ groups_with_comments = Comment.select('DISTINCT group_id').where(source_id: self.id).map(&:group_id).compact
groups = Nokogiri::HTML.fragment(body.to_s).css('.macro').collect{|element| element['data-macro-group_id'].to_i}
errors[:base] << (N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty?
end
diff --git a/plugins/comment_group/lib/ext/comment.rb b/plugins/comment_group/lib/ext/comment.rb
index d1e0df2..52af12f 100644
--- a/plugins/comment_group/lib/ext/comment.rb
+++ b/plugins/comment_group/lib/ext/comment.rb
@@ -2,12 +2,9 @@ require_dependency 'comment'
class Comment
- scope :without_group, :conditions => {:group_id => nil }
+ scope :without_group, -> { where group_id: nil }
- scope :in_group, proc { |group_id| {
- :conditions => ['group_id = ?', group_id]
- }
- }
+ scope :in_group, -> (group_id) { where 'group_id = ?', group_id }
attr_accessible :group_id
diff --git a/plugins/community_track/lib/community_track_plugin/step.rb b/plugins/community_track/lib/community_track_plugin/step.rb
index a390918..8a4cc15 100644
--- a/plugins/community_track/lib/community_track_plugin/step.rb
+++ b/plugins/community_track/lib/community_track_plugin/step.rb
@@ -32,7 +32,7 @@ class CommunityTrackPlugin::Step < Folder
self.start_date ||= Date.today
self.end_date ||= Date.today + 1.day
end
-
+
def set_hidden_position
if hidden
decrement_positions_on_lower_items
@@ -108,7 +108,7 @@ class CommunityTrackPlugin::Step < Folder
end
def tool
- tools.find(:first, :conditions => {:type => tool_type })
+ tools.where(type: tool_type).first
end
end
diff --git a/plugins/custom_forms/lib/custom_forms_plugin/form.rb b/plugins/custom_forms/lib/custom_forms_plugin/form.rb
index 1c92789..eb7ee01 100644
--- a/plugins/custom_forms/lib/custom_forms_plugin/form.rb
+++ b/plugins/custom_forms/lib/custom_forms_plugin/form.rb
@@ -25,9 +25,9 @@ class CustomFormsPlugin::Form < Noosfero::Plugin::ActiveRecord
tasks.each {|task| task.cancel}
end
- scope :from_profile, lambda {|profile| {:conditions => {:profile_id => profile.id}}}
- scope :on_memberships, {:conditions => {:on_membership => true, :for_admission => false}}
- scope :for_admissions, {:conditions => {: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 377f49f..1daafdf 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, lambda {|profile| {:conditions => {: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/display_content/lib/display_content_block.rb b/plugins/display_content/lib/display_content_block.rb
index 10c4e43..138844c 100644
--- a/plugins/display_content/lib/display_content_block.rb
+++ b/plugins/display_content/lib/display_content_block.rb
@@ -114,7 +114,7 @@ class DisplayContentBlock < Block
def articles_of_parent(parent = nil)
return [] if self.holder.nil?
types = VALID_CONTENT + plugins.dispatch(:content_types).map(&:name)
- holder.articles.find(:all, :conditions => {:type => types, :parent_id => (parent.nil? ? nil : parent)})
+ holder.articles.where(type: types, parent_id: if parent.nil? then nil else parent end)
end
def content(args={})
diff --git a/plugins/mark_comment_as_read/lib/mark_comment_as_read_plugin/ext/comment.rb b/plugins/mark_comment_as_read/lib/mark_comment_as_read_plugin/ext/comment.rb
index 15ec814..1152b89 100644
--- a/plugins/mark_comment_as_read/lib/mark_comment_as_read_plugin/ext/comment.rb
+++ b/plugins/mark_comment_as_read/lib/mark_comment_as_read_plugin/ext/comment.rb
@@ -14,11 +14,11 @@ class Comment
end
def marked_as_read?(person)
- person && people.find(:first, :conditions => {:id => person.id})
+ person && people.where(id: person.id).first
end
def self.marked_as_read(person)
- find(:all, :joins => [:read_comments], :conditions => {:author_id => person.id})
+ joins(:read_comments).where(author_id: person.id)
end
end
diff --git a/plugins/oauth_client/lib/oauth_client_plugin/provider.rb b/plugins/oauth_client/lib/oauth_client_plugin/provider.rb
index 70a9892..0b7373f 100644
--- a/plugins/oauth_client/lib/oauth_client_plugin/provider.rb
+++ b/plugins/oauth_client/lib/oauth_client_plugin/provider.rb
@@ -13,7 +13,7 @@ class OauthClientPlugin::Provider < Noosfero::Plugin::ActiveRecord
attr_accessible :name, :environment, :strategy, :client_id, :client_secret, :enabled, :client_options, :image_builder
- scope :enabled, :conditions => {:enabled => true}
+ scope :enabled, -> { where enabled: true }
acts_as_having_image
diff --git a/plugins/people_block/lib/ext/person.rb b/plugins/people_block/lib/ext/person.rb
index 8c6f94b..3a0eed5 100644
--- a/plugins/people_block/lib/ext/person.rb
+++ b/plugins/people_block/lib/ext/person.rb
@@ -2,8 +2,9 @@ require_dependency 'person'
class Person
- scope :with_role, lambda { |role_id|
- { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ["role_assignments.role_id = #{role_id}"] }
+ scope :with_role, -> (role_id) {
+ select('DISTINCT profiles.*').joins(:role_assignments).
+ where("role_assignments.role_id = #{role_id}")
}
end
diff --git a/plugins/recent_content/lib/recent_content_block.rb b/plugins/recent_content/lib/recent_content_block.rb
index c978faa..bb34d07 100644
--- a/plugins/recent_content/lib/recent_content_block.rb
+++ b/plugins/recent_content/lib/recent_content_block.rb
@@ -18,9 +18,8 @@ class RecentContentBlock < Block
end
def articles_of_folder(folder, limit)
- holder.articles.all(:conditions => {:type => VALID_CONTENT, :parent_id => folder.id},
- :order => 'created_at DESC',
- :limit => limit )
+ holder.articles.where(type: VALID_CONTENT, parent_id: folder.id).
+ order('created_at DESC').limit(limit)
end
def holder
@@ -34,12 +33,12 @@ class RecentContentBlock < Block
end
def parents
- selected = self.holder.articles.all(:conditions => {:type => 'Blog'})
+ selected = self.holder.articles.where(type: 'Blog').first
end
def root
unless self.selected_folder.nil?
- holder.articles.where(:id => self.selected_folder).first
+ holder.articles.where(id: self.selected_folder).first
end
end
diff --git a/plugins/relevant_content/lib/ext/article.rb b/plugins/relevant_content/lib/ext/article.rb
index 3de1f50..d64b5ed 100644
--- a/plugins/relevant_content/lib/ext/article.rb
+++ b/plugins/relevant_content/lib/ext/article.rb
@@ -2,7 +2,7 @@ require_dependency 'article'
class Article
- scope :relevant_content, :conditions => ["articles.published = true and (articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL"]
+ scope :relevant_content, -> { where "articles.published = true and (articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL" }
def self.articles_columns
Article.column_names.map {|c| "articles.#{c}"} .join(",")
@@ -10,86 +10,57 @@ class Article
def self.most_accessed(owner, limit = nil)
conditions = owner.kind_of?(Environment) ? ["hits > 0"] : ["profile_id = ? and hits > 0", owner.id]
- result = Article.relevant_content.find(
- :all,
- :order => 'hits desc',
- :limit => limit,
- :conditions => conditions)
+ result = Article.relevant_content.order('hits desc').limit(limit).where(conditions)
result.paginate({:page => 1, :per_page => limit})
end
def self.most_commented_relevant_content(owner, limit)
- conditions = owner.kind_of?(Environment) ? ["comments_count > 0"] : ["profile_id = ? and comments_count > 0", owner.id]
- result = Article.relevant_content.find(
- :all,
- :order => 'comments_count desc',
- :limit => limit,
- :conditions => conditions)
- result.paginate({:page => 1, :per_page => limit})
+ conditions = owner.kind_of?(Environment) ? ["comments_count > 0"] : ["profile_id = ? and comments_count > 0", owner.id]
+ result = Article.relevant_content.all.order('comments_count desc').limit(limit).where(conditions)
+ result.paginate({:page => 1, :per_page => limit})
end
def self.more_positive_votes(owner, limit = nil)
- conditions = owner.kind_of?(Environment) ? {'votes.voteable_type' => 'Article'} : ["profile_id = ? and votes.voteable_type = ? ", owner.id, 'Article']
- result = Article.relevant_content.find(
- :all,
- :order => 'sum(vote) desc',
- :group => 'voteable_id, ' + articles_columns,
- :limit => limit,
- :having => ['sum(vote) > 0'],
- :conditions => conditions,
- :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')
- result.paginate({:page => 1, :per_page => limit})
+ conditions = owner.kind_of?(Environment) ? {'votes.voteable_type' => 'Article'} : ["profile_id = ? and votes.voteable_type = ? ", owner.id, 'Article']
+ result = Article.relevant_content.
+ order('sum(vote) desc').group('voteable_id, ' + articles_columns).
+ limit(limit).having('sum(vote) > 0').
+ where(conditions).joins('INNER JOIN votes ON articles.id = votes.voteable_id')
+ result.paginate({:page => 1, :per_page => limit})
end
def self.more_negative_votes(owner, limit = nil)
- conditions = owner.kind_of?(Environment) ? {'votes.voteable_type' => 'Article'} : ["profile_id = ? and votes.voteable_type = 'Article' ", owner.id]
- result = Article.relevant_content.find(
- :all,
- :order => 'sum(vote) asc',
- :group => 'voteable_id, ' + articles_columns,
- :limit => limit,
- :having => ['sum(vote) < 0'],
- :conditions => conditions,
- :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id'
- )
- result.paginate({:page => 1, :per_page => limit})
+ conditions = owner.kind_of?(Environment) ? {'votes.voteable_type' => 'Article'} : ["profile_id = ? and votes.voteable_type = 'Article' ", owner.id]
+ result = Article.relevant_content.
+ order('sum(vote) asc').group('voteable_id, ' + articles_columns).
+ limit(limit).having('sum(vote) < 0').
+ where(conditions).joins('INNER JOIN votes ON articles.id = votes.voteable_id')
+ result.paginate({:page => 1, :per_page => limit})
end
def self.most_liked(owner, limit = nil)
- conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article' and vote > 0"] : ["votes.voteable_type = 'Article' and vote > 0 and profile_id = ? ", owner.id]
- result = Article.relevant_content.find(
- :all,
- :select => articles_columns,
- :order => 'count(voteable_id) desc',
- :group => 'voteable_id, ' + articles_columns,
- :limit => limit,
- :conditions => conditions,
- :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')
- result.paginate({:page => 1, :per_page => limit})
+ conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article' and vote > 0"] : ["votes.voteable_type = 'Article' and vote > 0 and profile_id = ? ", owner.id]
+ result = Article.relevant_content.
+ select(articles_columns).order('count(voteable_id) desc').
+ group('voteable_id, ' + articles_columns).limit(limit).
+ where(conditions).joins('INNER JOIN votes ON articles.id = votes.voteable_id')
+ result.paginate({:page => 1, :per_page => limit})
end
def self.most_disliked(owner, limit = nil)
- conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article' and vote < 0"] : ["votes.voteable_type = 'Article' and vote < 0 and profile_id = ? ", owner.id]
- result = Article.relevant_content.find(
- :all,
- :order => 'count(voteable_id) desc',
- :group => 'voteable_id, ' + articles_columns,
- :limit => limit,
- :conditions => conditions,
- :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')
- result.paginate({:page => 1, :per_page => limit})
+ conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article' and vote < 0"] : ["votes.voteable_type = 'Article' and vote < 0 and profile_id = ? ", owner.id]
+ result = Article.relevant_content.
+ order('count(voteable_id) desc').group('voteable_id, ' + articles_columns).
+ limit(limit).where(conditions).joins('INNER JOIN votes ON articles.id = votes.voteable_id')
+ result.paginate({:page => 1, :per_page => limit})
end
def self.most_voted(owner, limit = nil)
conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article'"] : ["votes.voteable_type = 'Article' and profile_id = ? ", owner.id]
- result = Article.relevant_content.find(
- :all,
- :select => articles_columns,
- :order => 'count(voteable_id) desc',
- :group => 'voteable_id, ' + articles_columns,
- :limit => limit,
- :conditions => conditions,
- :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')
- result.paginate({:page => 1, :per_page => limit})
+ result = Article.relevant_content.
+ select(articles_columns).order('count(voteable_id) desc').
+ group('voteable_id, ' + articles_columns).limit(limit).
+ where(conditions).joins('INNER JOIN votes ON articles.id = votes.voteable_id')
+ result.paginate({:page => 1, :per_page => limit})
end
end
diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb
index ed7c5fd..8289744 100644
--- a/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb
+++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb
@@ -28,7 +28,7 @@ class ShoppingCartPluginMyprofileController < MyProfileController
end
conditions = [condition] + condition_parameters
- @orders = profile.orders.find(:all, :conditions => conditions)
+ @orders = profile.orders.where(conditions)
@products = {}
@orders.each do |order|
diff --git a/plugins/spaminator/lib/spaminator_plugin/report.rb b/plugins/spaminator/lib/spaminator_plugin/report.rb
index 2ca8eb0..fccde7c 100644
--- a/plugins/spaminator/lib/spaminator_plugin/report.rb
+++ b/plugins/spaminator/lib/spaminator_plugin/report.rb
@@ -7,7 +7,7 @@ class SpaminatorPlugin::Report < Noosfero::Plugin::ActiveRecord
attr_accessible :environment
- scope :from_environment, lambda { |environment| {:conditions => {: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/statistics/lib/statistics_block.rb b/plugins/statistics/lib/statistics_block.rb
index 65d5554..9374341 100644
--- a/plugins/statistics/lib/statistics_block.rb
+++ b/plugins/statistics/lib/statistics_block.rb
@@ -69,7 +69,7 @@ class StatisticsBlock < Block
end
def template_counter_count(template_id)
- owner.communities.visible.count(:conditions => {:template_id => template_id})
+ owner.communities.visible.where(template_id: template_id).count
end
def users
diff --git a/plugins/stoa/lib/ext/person.rb b/plugins/stoa/lib/ext/person.rb
index 4c2de54..9b58f4e 100644
--- a/plugins/stoa/lib/ext/person.rb
+++ b/plugins/stoa/lib/ext/person.rb
@@ -20,7 +20,7 @@ class Person
end
def invitation_task
- Task.pending.find(:first, :conditions => {:code => invitation_code.to_s}) ||
- Task.finished.find(:first, :conditions => {:code => invitation_code.to_s, :target_id => id})
+ Task.pending.where(code: invitation_code.to_s).first or
+ Task.finished.where(code: invitation_code.to_s, target_id: id).first
end
end
diff --git a/plugins/stoa/lib/stoa_plugin.rb b/plugins/stoa/lib/stoa_plugin.rb
index 67dcf06..f65aa62 100644
--- a/plugins/stoa/lib/stoa_plugin.rb
+++ b/plugins/stoa/lib/stoa_plugin.rb
@@ -63,7 +63,7 @@ class StoaPlugin < Noosfero::Plugin
block = proc do
params[:profile_data] ||= {}
params[:profile_data][:invitation_code] = params[:invitation_code]
- invitation = Task.pending.find(:first, :conditions => {:code => params[:invitation_code]})
+ invitation = Task.pending.where(code: params[:invitation_code]).first
if request.post?
if !invitation && !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[params[:confirmation_field]])
# `self` below is evaluated in the context of account_controller
diff --git a/plugins/sub_organizations/controllers/sub_organizations_plugin_myprofile_controller.rb b/plugins/sub_organizations/controllers/sub_organizations_plugin_myprofile_controller.rb
index 637c719..c07c1da 100644
--- a/plugins/sub_organizations/controllers/sub_organizations_plugin_myprofile_controller.rb
+++ b/plugins/sub_organizations/controllers/sub_organizations_plugin_myprofile_controller.rb
@@ -32,11 +32,12 @@ class SubOrganizationsPluginMyprofileController < MyProfileController
end
def search_organization
- render :text => prepare_to_token_input(environment.organizations.find(:all, :conditions =>
- ["(LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?)
+ render :text => prepare_to_token_input(
+ environment.organizations.where(
+ "(LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?)
AND (identifier NOT LIKE ?) AND (id != ?)",
- "%#{params[:q]}%", "%#{params[:q]}%", "%_template", profile.id]).
- select { |organization|
+ "%#{params[:q]}%", "%#{params[:q]}%", "%_template", profile.id).
+ select{ |organization|
Organization.children(organization).blank? &&
!Organization.pending_children(profile).include?(organization)
}).to_json
diff --git a/plugins/sub_organizations/lib/ext/organization.rb b/plugins/sub_organizations/lib/ext/organization.rb
index fae325d..bc92cc9 100644
--- a/plugins/sub_organizations/lib/ext/organization.rb
+++ b/plugins/sub_organizations/lib/ext/organization.rb
@@ -13,26 +13,20 @@ class Organization
FIELDS << 'sub_organizations_plugin_parent_to_be'
- scope :children, lambda { |parent|
- options = {
- :joins => "inner join sub_organizations_plugin_relations as relations on profiles.id=relations.child_id",
- :conditions => ["relations.parent_id = ?", parent.id]
- }
+ 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, lambda { |*children|
- options = {
- :joins => "inner join sub_organizations_plugin_relations as relations on profiles.id=relations.parent_id",
- :conditions => ["relations.child_id in (?)", children.map(&:id)]
- }
+ 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, lambda { |parent|
- options = {
- :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",
- :conditions => ["relations.parent_id = ? AND tasks.status = 1", parent.id]
- }
+ 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)
}
end
diff --git a/plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb b/plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
index 1b8cc5f..6339192 100644
--- a/plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
+++ b/plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
@@ -16,13 +16,13 @@ def edit_visibility
end
folder.save!
redirect_to @back_to
- end
+ end
end
end
def search_article_privacy_exceptions
arg = params[:q].downcase
- result = profile.members.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"])
+ result = profile.members.where('LOWER(name) LIKE ?', "%#{arg}%")
render :text => prepare_to_token_input(result).to_json
end
diff --git a/script/apply-template b/script/apply-template
index b1cdab4..f001dc4 100755
--- a/script/apply-template
+++ b/script/apply-template
@@ -30,7 +30,7 @@ when 'inactive-enterprise'
excluded = [env.inactive_enterprise_template, env.enterprise_template]
template = excluded.first
- while enterprise = Enterprise.find(:first, :conditions => {:enabled => false}, :order => :id, :offset => offset)
+ while enterprise = Enterprise.where(enabled: false).order(:id).offset(offset)
# do nothing with templates
next if excluded.include?(enterprise)
@@ -42,7 +42,7 @@ when 'inactive-enterprise'
offset = offset + 1
end
when 'active-enterprise'
- active_enterprises = Enterprise.find(:all, :conditions => {:enabled => true}) - [env.enterprise_template, env.enterprise_template]
+ active_enterprises = Enterprise.where(enabled: true).all - [env.enterprise_template, env.enterprise_template]
active_enterprises.each do |enterprise|
old_home = enterprise.home_page
enterprise.apply_template(env.enterprise_template)
@@ -53,7 +53,7 @@ when 'community'
excluded = ['espaco', 'anarquismo']
template = env.community_template
offset = 0
- while community = Community.find(:first, :order => :id, :offset => offset)
+ while community = Community.order(:id).offset(offset)
if community != template && !excluded.include?(community.identifier)
report_doing offset, community.name
community.apply_template(template)
diff --git a/script/sample-enterprises b/script/sample-enterprises
index 9552953..d78b0d8 100755
--- a/script/sample-enterprises
+++ b/script/sample-enterprises
@@ -44,7 +44,7 @@ groups.each do |group|
end
done
-EnterpriseActivation.find(:all, :conditions => ['created_at > ?', start_time]).each do |activation|
+EnterpriseActivation.where('created_at > ?', start_time).each do |activation|
enterprise = activation.enterprise
end
diff --git a/script/sample-profiles b/script/sample-profiles
index 316ef06..a2bd106 100755
--- a/script/sample-profiles
+++ b/script/sample-profiles
@@ -104,7 +104,7 @@ save guest
done
print "Activating users: "
-User.all(:conditions => ["login NOT LIKE '%%_template'"]).each do |user|
+User.where("login NOT LIKE '%%_template'").each do |user|
user.activate
print '.'
end
diff --git a/test/unit/article_categorization_test.rb b/test/unit/article_categorization_test.rb
index fa00670..54ea08b 100644
--- a/test/unit/article_categorization_test.rb
+++ b/test/unit/article_categorization_test.rb
@@ -87,7 +87,7 @@ class ArticleCategorizationTest < ActiveSupport::TestCase
ArticleCategorization.add_category_to_article(c2, a)
ArticleCategorization.add_category_to_article(c1, a)
- assert ArticleCategorization.find(:first, :conditions => [ 'category_id = ? and article_id = ? and not virtual', c1.id, a.id ]), 'categorization must be promoted to not virtual'
+ assert ArticleCategorization.where('category_id = ? and article_id = ? and not virtual', c1.id, a.id).first, 'categorization must be promoted to not virtual'
end
private
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index a2cb697..afaa501 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -1006,9 +1006,9 @@ class PersonTest < ActiveSupport::TestCase
p = create_user('test_user').person
c = fast_create(Community, :name => "Foo")
c.add_member(p)
- assert_equal ["Foo"], ActionTracker::Record.last(:conditions => {:verb => 'join_community'}).get_resource_name
+ assert_equal ["Foo"], ActionTracker::Record.where(verb: 'join_community').last.get_resource_name
c.reload.add_moderator(p.reload)
- assert_equal ["Foo"], ActionTracker::Record.last(:conditions => {:verb => 'join_community'}).get_resource_name
+ assert_equal ["Foo"], ActionTracker::Record.where(verb: 'join_community').last.get_resource_name
end
should 'the tracker target be Community when a person joins a community' do
@@ -1016,7 +1016,7 @@ class PersonTest < ActiveSupport::TestCase
p = create_user('test_user').person
c = fast_create(Community, :name => "Foo")
c.add_member(p)
- assert_kind_of Community, ActionTracker::Record.last(:conditions => {:verb => 'join_community'}).target
+ assert_kind_of Community, ActionTracker::Record.where(verb: 'join_community').last.target
end
should 'the community be notified specifically when a person joins a community' do
@@ -1024,7 +1024,7 @@ class PersonTest < ActiveSupport::TestCase
p = create_user('test_user').person
c = fast_create(Community, :name => "Foo")
c.add_member(p)
- assert_not_nil ActionTracker::Record.last(:conditions => {:verb => 'add_member_in_community'})
+ assert_not_nil ActionTracker::Record.where(verb: 'add_member_in_community').last
end
should 'the community specific notification created when a member joins community could not be propagated to members' do
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 2bec4b6..87865d5 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -448,7 +448,7 @@ class ProfileTest < ActiveSupport::TestCase
p1 = create(Profile, :public_profile => true)
p2 = create(Profile, :public_profile => false)
- result = Profile.find(:all, :conditions => {:public_profile => true})
+ result = Profile.where(public_profile: true).all
assert_includes result, p1
assert_not_includes result, p2
end
diff --git a/test/unit/suggest_article_test.rb b/test/unit/suggest_article_test.rb
index d31d13c..3fe2058 100644
--- a/test/unit/suggest_article_test.rb
+++ b/test/unit/suggest_article_test.rb
@@ -81,7 +81,7 @@ class SuggestArticleTest < ActiveSupport::TestCase
t.article[:highlighted] = true
t.perform
- article = TinyMceArticle.last(:conditions => { :name => t.article_name}) # just to be sure
+ article = TinyMceArticle.where(name: t.article_name).last # just to be sure
assert article.highlighted
end
@@ -89,7 +89,7 @@ class SuggestArticleTest < ActiveSupport::TestCase
t = build(SuggestArticle, :target => @profile)
t.perform
- article = TinyMceArticle.last(:conditions => { :name => t.article_name})
+ article = TinyMceArticle.where(name: t.article_name).last
assert_equal false, article.highlighted
end
diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb
index b7e7526..1f40e87 100644
--- a/test/unit/uploaded_file_test.rb
+++ b/test/unit/uploaded_file_test.rb
@@ -229,7 +229,7 @@ class UploadedFileTest < ActiveSupport::TestCase
should 'track action when a published image is uploaded in a gallery' do
p = fast_create(Gallery, :profile_id => @profile.id)
f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile)
- ta = ActionTracker::Record.last(:conditions => { :verb => "upload_image" })
+ ta = ActionTracker::Record.where(verb: "upload_image").last
assert_kind_of String, ta.get_thumbnail_path[0]
assert_equal [f.reload.view_url], ta.get_view_url
assert_equal [p.reload.url], ta.get_parent_url
@@ -240,26 +240,26 @@ class UploadedFileTest < ActiveSupport::TestCase
ActionTracker::Record.delete_all
p = fast_create(Gallery, :profile_id => @profile.id)
f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :parent => p, :profile => @profile)
- assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" })
+ assert_nil ActionTracker::Record.where(verb: "upload_image").last
end
should 'not track action when has no parent' do
f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => nil, :profile => @profile)
- assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" })
+ assert_nil ActionTracker::Record.where(verb: "upload_image").last
end
should 'not track action when is not published' do
ActionTracker::Record.delete_all
p = fast_create(Gallery, :profile_id => @profile.id)
f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile, :published => false)
- assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" })
+ assert_nil ActionTracker::Record.where(verb: "upload_image").last
end
should 'not track action when parent is not gallery' do
ActionTracker::Record.delete_all
p = fast_create(Folder, :profile_id => @profile.id)
f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile)
- assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" })
+ assert_nil ActionTracker::Record.where(verb: "upload_image").last
end
should 'not crash if first paragraph called' do
diff --git a/vendor/plugins/access_control/lib/acts_as_accessor.rb b/vendor/plugins/access_control/lib/acts_as_accessor.rb
index c2f70a6..a86d49d 100644
--- a/vendor/plugins/access_control/lib/acts_as_accessor.rb
+++ b/vendor/plugins/access_control/lib/acts_as_accessor.rb
@@ -15,7 +15,7 @@ module ActsAsAccessor
def define_roles(roles, resource)
roles = [roles] unless roles.kind_of?(Array)
- actual_roles = RoleAssignment.find( :all, :conditions => role_attributes(nil, resource) ).map(&:role)
+ actual_roles = RoleAssignment.where(role_attributes nil, resource).map(&:role)
(roles - actual_roles).each {|r| add_role(r, resource) }
(actual_roles - roles).each {|r| remove_role(r, resource)}
@@ -23,7 +23,7 @@ module ActsAsAccessor
def add_role(role, resource)
attributes = role_attributes(role, resource)
- if RoleAssignment.find(:all, :conditions => attributes).empty?
+ if RoleAssignment.where(attributes).empty?
ra = RoleAssignment.new(attributes)
role_assignments << ra
resource.role_assignments << ra
@@ -35,13 +35,13 @@ module ActsAsAccessor
def remove_role(role, resource)
return unless role
- roles_destroy = RoleAssignment.find(:all, :conditions => role_attributes(role, resource))
+ roles_destroy = RoleAssignment.where(role_attributes role, resource)
return if roles_destroy.empty?
roles_destroy.map(&:destroy).all?
end
def find_roles(res)
- RoleAssignment.find(:all, :conditions => role_attributes(nil, res))
+ RoleAssignment.where(role_attributes nil, res)
end
protected
@@ -55,10 +55,10 @@ module ActsAsAccessor
resource = nil
end
if resource
- attributes[:resource_id] = resource.id
+ attributes[:resource_id] = resource.id
attributes[:resource_type] = resource.class.base_class.name
else
- attributes[:resource_id] = nil
+ attributes[:resource_id] = nil
attributes[:resource_type] = nil
end
attributes
diff --git a/vendor/plugins/access_control/lib/role_assignment.rb b/vendor/plugins/access_control/lib/role_assignment.rb
index 9977265..6453ce0 100644
--- a/vendor/plugins/access_control/lib/role_assignment.rb
+++ b/vendor/plugins/access_control/lib/role_assignment.rb
@@ -7,11 +7,15 @@ class RoleAssignment < ActiveRecord::Base
belongs_to :resource, :polymorphic => true
validates_presence_of :role, :accessor
-
- track_actions :join_community, :after_create, :keep_params => ["resource.name", "resource.url", "resource.profile_custom_icon"], :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource
-
- track_actions :add_member_in_community, :after_create, :if => Proc.new { |x| x.resource.is_a?(Community) && x.accessor.role_assignments.count(:conditions => { :resource_id => x.resource.id, :resource_type => 'Profile' }) == 1 }, :custom_user => :accessor, :custom_target => :resource
-
+
+ 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 },
+ :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 },
+ :custom_user => :accessor, :custom_target => :resource
+
def has_permission?(perm, res)
return false unless role.has_permission?(perm.to_s) && (resource || is_global)
return true if is_global
diff --git a/vendor/plugins/action_tracker/lib/action_tracker.rb b/vendor/plugins/action_tracker/lib/action_tracker.rb
index 41294a5..60e77f3 100644
--- a/vendor/plugins/action_tracker/lib/action_tracker.rb
+++ b/vendor/plugins/action_tracker/lib/action_tracker.rb
@@ -83,7 +83,7 @@ module ActionTracker
module InstanceMethods
def time_spent_doing(verb, conditions = {})
time = 0
- tracked_actions.all(:conditions => conditions.merge({ :verb => verb.to_s })).each do |t|
+ tracked_actions.where(conditions.merge verb: verb.to_s).each do |t|
time += t.updated_at - t.created_at
end
time.to_f
diff --git a/vendor/plugins/action_tracker/lib/action_tracker_model.rb b/vendor/plugins/action_tracker/lib/action_tracker_model.rb
index 586f81b..8ec6c86 100644
--- a/vendor/plugins/action_tracker/lib/action_tracker_model.rb
+++ b/vendor/plugins/action_tracker/lib/action_tracker_model.rb
@@ -24,8 +24,8 @@ module ActionTracker
# In days
RECENT_DELAY = 30
- scope :recent, :conditions => ['created_at >= ?', RECENT_DELAY.days.ago]
- scope :visible, :conditions => { :visible => true }
+ scope :recent, -> { where 'created_at >= ?', RECENT_DELAY.days.ago }
+ scope :visible, -> { where visible: true }
def self.current_user_from_model
u = new
@@ -38,7 +38,7 @@ module ActionTracker
return if u.nil?
target_hash = params[:target].nil? ? {} : {:target_type => params[:target].class.base_class.to_s, :target_id => params[:target].id}
conditions = { :user_id => u.id, :user_type => u.class.base_class.to_s, :verb => params[:verb].to_s }.merge(target_hash)
- l = last :conditions => conditions
+ l = where(conditions).last
( !l.nil? and Time.now - l.updated_at < ActionTrackerConfig.timeout ) ? l.update_attributes(params.merge({ :updated_at => Time.now })) : l = new(params)
l
end
@@ -47,7 +47,7 @@ module ActionTracker
u = params[:user] || current_user_from_model
return if u.nil?
target_hash = params[:target].nil? ? {} : {:target_type => params[:target].class.base_class.to_s, :target_id => params[:target].id}
- l = last :conditions => { :user_id => u.id, :user_type => u.class.base_class.to_s, :verb => params[:verb].to_s }.merge(target_hash)
+ l = where({user_id: u.id, user_type: u.class.base_class.to_s, verb: params[:verb].to_s}.merge target_hash).last
if !l.nil? and Time.now - l.created_at < ActionTrackerConfig.timeout
params[:params].clone.each { |key, value| params[:params][key] = l.params[key].clone.push(value) }
l.update_attributes params
@@ -61,7 +61,7 @@ module ActionTracker
def self.time_spent(conditions = {}) # In seconds
#FIXME Better if it could be completely done in the database, but SQLite does not support difference between two timestamps
time = 0
- all(:conditions => conditions).each { |action| time += action.updated_at - action.created_at }
+ self.where(conditions).each{ |action| time += action.updated_at - action.created_at }
time.to_f
end
diff --git a/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb b/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb
index 65790f9..0e3d298 100644
--- a/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb
+++ b/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb
@@ -159,17 +159,13 @@ module ActiveRecord
# Return the next higher item in the list.
def higher_item
return nil unless in_list?
- acts_as_list_class.find(:first, :conditions =>
- "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}"
- )
+ acts_as_list_class.where("#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}").first
end
# Return the next lower item in the list.
def lower_item
return nil unless in_list?
- acts_as_list_class.find(:first, :conditions =>
- "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}"
- )
+ acts_as_list_class.where("#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}").first
end
# Test if this record is in a list
@@ -200,7 +196,7 @@ module ActiveRecord
def bottom_item(except = nil)
conditions = scope_condition
conditions = "#{conditions} AND #{self.class.primary_key} != #{except.id}" if except
- acts_as_list_class.find(:first, :conditions => conditions, :order => "#{position_column} DESC")
+ acts_as_list_class.where(conditions).order("#{position_column} DESC").first
end
# Forces item to assume the bottom position in the list.
diff --git a/vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb b/vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb
index fccf43c..6f2a31f 100644
--- a/vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb
+++ b/vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb
@@ -1,5 +1,5 @@
# Copyright (c) 2005 Rick Olson
-#
+#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
-#
+#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
-#
+#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -22,7 +22,7 @@ require 'active_support/concern'
module ActiveRecord #:nodoc:
module Acts #:nodoc:
- # Specify this act if you want to save a copy of the row in a versioned table. This assumes there is a
+ # Specify this act if you want to save a copy of the row in a versioned table. This assumes there is a
# versioned table ready and that your model has a version field. This works with optimistic locking if the lock_version
# column is present as well.
#
@@ -56,7 +56,7 @@ module ActiveRecord #:nodoc:
#
# Simple Queries to page between versions
#
- # page.versions.before(version)
+ # page.versions.before(version)
# page.versions.after(version)
#
# Access the previous/next versions from the versioned model itself
@@ -264,7 +264,7 @@ module ActiveRecord #:nodoc:
included do
has_many :versions, self.version_association_options
- before_save :set_new_version
+ #before_save :set_new_version
after_save :save_version
after_save :clear_old_versions
end
@@ -345,7 +345,7 @@ module ActiveRecord #:nodoc:
new_model.send("#{sym}=", orig_model[orig_model.class.inheritance_column]) if orig_model[orig_model.class.inheritance_column]
end
end
-
+
def define_method(object, method)
return if object.methods.include? method
metaclass = class << object; self; end
--
libgit2 0.21.2 |