Commit a1dad6bab9a848feb20898bf3026a8a00e8ff14f

Authored by Braulio Bhavamitra
1 parent 816d1df6

rails4: replace :conditions by where

:conditions will replace previous scopes in rails4
Showing 91 changed files with 392 additions and 409 deletions   Show diff stats
app/controllers/admin/admin_panel_controller.rb
@@ -54,7 +54,7 @@ class AdminPanelController < AdminController @@ -54,7 +54,7 @@ class AdminPanelController < AdminController
54 54
55 if request.post? 55 if request.post?
56 env = environment 56 env = environment
57 - folders = params[:folders].map{|fid| Folder.find(:first, :conditions => {:profile_id => env.portal_community, :id => fid})} if params[:folders] 57 + folders = Folder.where :profile_id => env.portal_community, :id => params[:folders] if params[:folders]
58 env.portal_folders = folders 58 env.portal_folders = folders
59 if env.save 59 if env.save
60 session[:notice] = _('Saved the portal folders') 60 session[:notice] = _('Saved the portal folders')
app/controllers/admin/categories_controller.rb
1 class CategoriesController < AdminController 1 class CategoriesController < AdminController
2 2
3 protect 'manage_environment_categories', :environment 3 protect 'manage_environment_categories', :environment
4 - 4 +
5 helper :categories 5 helper :categories
6 6
7 def index 7 def index
8 - @categories = environment.categories.find(:all, :conditions => "parent_id is null AND type is null")  
9 - @regions = environment.regions.find(:all, :conditions => {:parent_id => nil})  
10 - @product_categories = environment.product_categories.find(:all, :conditions => {:parent_id => nil}) 8 + @categories = environment.categories.where("parent_id is null AND type is null")
  9 + @regions = environment.regions.where(:parent_id => nil)
  10 + @product_categories = environment.product_categories.where(:parent_id => nil)
11 end 11 end
12 12
13 def get_children 13 def get_children
app/controllers/admin/environment_role_manager_controller.rb
@@ -2,7 +2,7 @@ class EnvironmentRoleManagerController &lt; AdminController @@ -2,7 +2,7 @@ class EnvironmentRoleManagerController &lt; AdminController
2 protect 'manage_environment_roles', :environment 2 protect 'manage_environment_roles', :environment
3 3
4 def index 4 def index
5 - @admins = Person.find(:all, :conditions => ['role_assignments.resource_type = ?', 'Environment'], :include => :role_assignments ) 5 + @admins = Person.where('role_assignments.resource_type = ?', 'Environment').includes(:role_assignments)
6 end 6 end
7 7
8 def change_roles 8 def change_roles
app/controllers/admin/features_controller.rb
1 class FeaturesController < AdminController 1 class FeaturesController < AdminController
2 protect 'edit_environment_features', :environment 2 protect 'edit_environment_features', :environment
3 - 3 +
4 def index 4 def index
5 @features = Environment.available_features.sort_by{|k,v|v} 5 @features = Environment.available_features.sort_by{|k,v|v}
6 end 6 end
@@ -53,7 +53,7 @@ class FeaturesController &lt; AdminController @@ -53,7 +53,7 @@ class FeaturesController &lt; AdminController
53 53
54 def search_members 54 def search_members
55 arg = params[:q].downcase 55 arg = params[:q].downcase
56 - result = environment.people.find(:all, :conditions => ['LOWER(name) LIKE ? OR identifier LIKE ?', "%#{arg}%", "%#{arg}%"]) 56 + result = environment.people.where('LOWER(name) LIKE ? OR identifier LIKE ?', "%#{arg}%", "%#{arg}%")
57 render :text => prepare_to_token_input(result).to_json 57 render :text => prepare_to_token_input(result).to_json
58 end 58 end
59 59
app/controllers/admin/users_controller.rb
@@ -63,7 +63,7 @@ class UsersController &lt; AdminController @@ -63,7 +63,7 @@ class UsersController &lt; AdminController
63 respond_to do |format| 63 respond_to do |format|
64 format.html 64 format.html
65 format.xml do 65 format.xml do
66 - users = User.find(:all, :conditions => {:environment_id => environment.id}, :include => [:person]) 66 + users = User.where(:environment_id => environment.id).includes(:person)
67 send_data users.to_xml( 67 send_data users.to_xml(
68 :skip_types => true, 68 :skip_types => true,
69 :only => %w[email login created_at updated_at], 69 :only => %w[email login created_at updated_at],
app/controllers/box_organizer_controller.rb
@@ -84,9 +84,9 @@ class BoxOrganizerController &lt; ApplicationController @@ -84,9 +84,9 @@ class BoxOrganizerController &lt; ApplicationController
84 if request.xhr? and params[:query] 84 if request.xhr? and params[:query]
85 search = params[:query] 85 search = params[:query]
86 path_list = if boxes_holder.is_a?(Environment) && boxes_holder.enabled?('use_portal_community') && boxes_holder.portal_community 86 path_list = if boxes_holder.is_a?(Environment) && boxes_holder.enabled?('use_portal_community') && boxes_holder.portal_community
87 - boxes_holder.portal_community.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20).map { |content| "/{portal}/"+content.path } 87 + boxes_holder.portal_community.articles.where("name ILIKE ? OR path ILIKE ?", "%#{search}%", "%#{search}%").limit(20).map { |content| "/{portal}/"+content.path }
88 elsif boxes_holder.is_a?(Profile) 88 elsif boxes_holder.is_a?(Profile)
89 - boxes_holder.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20).map { |content| "/{profile}/"+content.path } 89 + boxes_holder.articles.where("name ILIKE ? OR path ILIKE ?", "%#{search}%", "%#{search}%").limit(20).map { |content| "/{profile}/"+content.path }
90 else 90 else
91 [] 91 []
92 end 92 end
app/controllers/my_profile/cms_controller.rb
@@ -57,16 +57,9 @@ class CmsController &lt; MyProfileController @@ -57,16 +57,9 @@ class CmsController &lt; MyProfileController
57 57
58 def view 58 def view
59 @article = profile.articles.find(params[:id]) 59 @article = profile.articles.find(params[:id])
60 - conditions = []  
61 - if @article.has_posts?  
62 - conditions = ['type != ?', 'RssFeed']  
63 - end  
64 -  
65 - @articles = @article.children.reorder("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC, name").paginate(  
66 - :conditions => conditions,  
67 - :per_page => per_page,  
68 - :page => params[:npage]  
69 - ) 60 + @articles = @article.children.reorder("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC, name")
  61 + @articles = @articles.where type: 'RssFeed' if @article.has_posts?
  62 + @articles = @articles.paginate per_page: per_page, page: params[:npage]
70 end 63 end
71 64
72 def index 65 def index
@@ -390,7 +383,7 @@ class CmsController &lt; MyProfileController @@ -390,7 +383,7 @@ class CmsController &lt; MyProfileController
390 383
391 def search_article_privacy_exceptions 384 def search_article_privacy_exceptions
392 arg = params[:q].downcase 385 arg = params[:q].downcase
393 - result = profile.members.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) 386 + result = profile.members.where('LOWER(name) LIKE ?', "%#{arg}%")
394 render :text => prepare_to_token_input(result).to_json 387 render :text => prepare_to_token_input(result).to_json
395 end 388 end
396 389
app/controllers/my_profile/profile_members_controller.rb
@@ -47,7 +47,7 @@ class ProfileMembersController &lt; MyProfileController @@ -47,7 +47,7 @@ class ProfileMembersController &lt; MyProfileController
47 end 47 end
48 48
49 def remove_role 49 def remove_role
50 - @association = RoleAssignment.find(:all, :conditions => {:id => params[:id], :target_id => profile.id}) 50 + @association = RoleAssignment.where(:id => params[:id], :target_id => profile.id)
51 if @association.destroy 51 if @association.destroy
52 session[:notice] = 'Member succefully unassociated' 52 session[:notice] = 'Member succefully unassociated'
53 else 53 else
@@ -120,7 +120,7 @@ class ProfileMembersController &lt; MyProfileController @@ -120,7 +120,7 @@ class ProfileMembersController &lt; MyProfileController
120 120
121 def search_user 121 def search_user
122 role = Role.find(params[:role]) 122 role = Role.find(params[:role])
123 - render :text => environment.people.find(:all, :conditions => ['LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?', "%#{params['q_'+role.key]}%", "%#{params['q_'+role.key]}%"]). 123 + render :text => environment.people.where('LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?', "%#{params['q_'+role.key]}%", "%#{params['q_'+role.key]}%").
124 select { |person| !profile.members_by_role(role).include?(person) }. 124 select { |person| !profile.members_by_role(role).include?(person) }.
125 map {|person| {:id => person.id, :name => person.name} }. 125 map {|person| {:id => person.id, :name => person.name} }.
126 to_json 126 to_json
app/controllers/my_profile/tasks_controller.rb
@@ -86,7 +86,7 @@ class TasksController &lt; MyProfileController @@ -86,7 +86,7 @@ class TasksController &lt; MyProfileController
86 end 86 end
87 87
88 def ticket_details 88 def ticket_details
89 - @ticket = Ticket.find(:first, :conditions => ['(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]]) 89 + @ticket = Ticket.where('(requestor_id = ? or target_id = ?) and id = ?', profile.id, profile.id, params[:id]).first
90 end 90 end
91 91
92 end 92 end
app/controllers/public/profile_controller.rb
@@ -36,7 +36,7 @@ class ProfileController &lt; PublicController @@ -36,7 +36,7 @@ class ProfileController &lt; PublicController
36 36
37 def tag_feed 37 def tag_feed
38 @tag = params[:id] 38 @tag = params[:id]
39 - tagged = profile.articles.paginate(:per_page => 20, :page => 1, :order => 'published_at DESC', :include => :tags, :conditions => ['tags.name LIKE ?', @tag]) 39 + tagged = profile.articles.paginate(:per_page => 20, :page => 1).order('published_at DESC').includes(:tags).where('tags.name LIKE ?', @tag)
40 feed_writer = FeedWriter.new 40 feed_writer = FeedWriter.new
41 data = feed_writer.write( 41 data = feed_writer.write(
42 tagged, 42 tagged,
@@ -201,7 +201,7 @@ class ProfileController &lt; PublicController @@ -201,7 +201,7 @@ class ProfileController &lt; PublicController
201 201
202 def more_comments 202 def more_comments
203 profile_filter = @profile.person? ? {:user_id => @profile} : {:target_id => @profile} 203 profile_filter = @profile.person? ? {:user_id => @profile} : {:target_id => @profile}
204 - activity = ActionTracker::Record.find(:first, :conditions => {:id => params[:activity]}.merge(profile_filter)) 204 + activity = ActionTracker::Record.where({:id => params[:activity]}.merge profile_filter).first
205 comments_count = activity.comments.count 205 comments_count = activity.comments.count
206 comment_page = (params[:comment_page] || 1).to_i 206 comment_page = (params[:comment_page] || 1).to_i
207 comments_per_page = 5 207 comments_per_page = 5
@@ -221,7 +221,7 @@ class ProfileController &lt; PublicController @@ -221,7 +221,7 @@ class ProfileController &lt; PublicController
221 end 221 end
222 222
223 def more_replies 223 def more_replies
224 - activity = Scrap.find(:first, :conditions => {:id => params[:activity], :receiver_id => @profile, :scrap_id => nil}) 224 + activity = Scrap.where(:id => params[:activity], :receiver_id => @profile, :scrap_id => nil).first
225 comments_count = activity.replies.count 225 comments_count = activity.replies.count
226 comment_page = (params[:comment_page] || 1).to_i 226 comment_page = (params[:comment_page] || 1).to_i
227 comments_per_page = 5 227 comments_per_page = 5
@@ -268,7 +268,7 @@ class ProfileController &lt; PublicController @@ -268,7 +268,7 @@ class ProfileController &lt; PublicController
268 def remove_notification 268 def remove_notification
269 begin 269 begin
270 raise if !can_edit_profile 270 raise if !can_edit_profile
271 - notification = ActionTrackerNotification.find(:first, :conditions => {:profile_id => profile.id, :action_tracker_id => params[:activity_id]}) 271 + notification = ActionTrackerNotification.where(profile_id: profile.id, action_tracker_id: params[:activity_id]).first
272 notification.destroy 272 notification.destroy
273 render :text => _('Notification successfully removed.') 273 render :text => _('Notification successfully removed.')
274 rescue 274 rescue
app/mailers/environment_mailing.rb
1 class EnvironmentMailing < Mailing 1 class EnvironmentMailing < Mailing
2 2
3 def recipients(offset=0, limit=100) 3 def recipients(offset=0, limit=100)
4 - 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 }) 4 + source.people.order(:id).offset(offset).limit(limit)
  5 + .joins("LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)")
  6 + .where("m.person_id" => nil)
5 end 7 end
6 8
7 def each_recipient 9 def each_recipient
app/mailers/organization_mailing.rb
@@ -5,7 +5,9 @@ class OrganizationMailing &lt; Mailing @@ -5,7 +5,9 @@ class OrganizationMailing &lt; Mailing
5 end 5 end
6 6
7 def recipients(offset=0, limit=100) 7 def recipients(offset=0, limit=100)
8 - 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 }) 8 + source.members.order(:id).offset(offset).limit(limit)
  9 + .joins("LEFT OUTER JOIN mailing_sents m ON (m.mailing_id = #{id} AND m.person_id = profiles.id)")
  10 + .where("m.person_id" => nil)
9 end 11 end
10 12
11 def each_recipient 13 def each_recipient
app/models/article.rb
@@ -73,7 +73,7 @@ class Article &lt; ActiveRecord::Base @@ -73,7 +73,7 @@ class Article &lt; ActiveRecord::Base
73 73
74 has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' 74 has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc'
75 75
76 - has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ] 76 + has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false }
77 has_many :categories, :through => :article_categorizations 77 has_many :categories, :through => :article_categorizations
78 78
79 has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization' 79 has_many :article_categorizations_including_virtual, :class_name => 'ArticleCategorization'
@@ -125,15 +125,13 @@ class Article &lt; ActiveRecord::Base @@ -125,15 +125,13 @@ class Article &lt; ActiveRecord::Base
125 125
126 xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list' 126 xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list'
127 127
128 - scope :in_category, lambda { |category|  
129 - {:include => 'categories_including_virtual', :conditions => { 'categories.id' => category.id }} 128 + scope :in_category, -> (category) {
  129 + includes('categories_including_virtual').where('categories.id' => category.id)
130 } 130 }
131 131
132 - scope :by_range, lambda { |range| {  
133 - :conditions => [  
134 - 'articles.published_at BETWEEN :start_date AND :end_date', { :start_date => range.first, :end_date => range.last }  
135 - ]  
136 - }} 132 + scope :by_range, -> (range) {
  133 + where 'articles.published_at BETWEEN :start_date AND :end_date', { start_date: range.first, end_date: range.last }
  134 + }
137 135
138 URL_FORMAT = /\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\Z/ix 136 URL_FORMAT = /\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\Z/ix
139 137
@@ -255,20 +253,21 @@ class Article &lt; ActiveRecord::Base @@ -255,20 +253,21 @@ class Article &lt; ActiveRecord::Base
255 253
256 # retrieves all articles belonging to the given +profile+ that are not 254 # retrieves all articles belonging to the given +profile+ that are not
257 # sub-articles of any other article. 255 # sub-articles of any other article.
258 - scope :top_level_for, lambda { |profile|  
259 - {:conditions => [ 'parent_id is null and profile_id = ?', profile.id ]} 256 + scope :top_level_for, -> {
  257 + where 'parent_id is null and profile_id = ?', profile.id
260 } 258 }
261 259
262 - # :public is reserved on rails 4.1, use is_public instead  
263 - scope :is_public,  
264 - :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ], :joins => [:profile] 260 + scope :is_public, -> {
  261 + joins(:profile).
  262 + where("advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true)
  263 + }
265 264
266 - scope :more_recent,  
267 - :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND  
268 - ((articles.type != ?) OR articles.type is NULL)",  
269 - true, true, true, true, 'RssFeed'  
270 - ],  
271 - :order => 'articles.published_at desc, articles.id desc' 265 + scope :more_recent, -> {
  266 + order('articles.published_at desc, articles.id desc')
  267 + .where("advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND
  268 + ((articles.type != ?) OR articles.type is NULL)",
  269 + true, true, true, true, 'RssFeed')
  270 + }
272 271
273 # retrives the most commented articles, sorted by the comment count (largest 272 # retrives the most commented articles, sorted by the comment count (largest
274 # first) 273 # first)
@@ -276,8 +275,10 @@ class Article &lt; ActiveRecord::Base @@ -276,8 +275,10 @@ class Article &lt; ActiveRecord::Base
276 paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) 275 paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit)
277 end 276 end
278 277
279 - scope :more_popular, :order => 'hits DESC'  
280 - scope :relevant_as_recent, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"] 278 + scope :more_popular, -> { order 'hits DESC' }
  279 + scope :relevant_as_recent, -> {
  280 + where "(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"
  281 + }
281 282
282 def self.recent(limit = nil, extra_conditions = {}, pagination = true) 283 def self.recent(limit = nil, extra_conditions = {}, pagination = true)
283 result = scoped({:conditions => extra_conditions}). 284 result = scoped({:conditions => extra_conditions}).
@@ -406,7 +407,7 @@ class Article &lt; ActiveRecord::Base @@ -406,7 +407,7 @@ class Article &lt; ActiveRecord::Base
406 self.translations.map(&:language) 407 self.translations.map(&:language)
407 end 408 end
408 409
409 - scope :native_translations, :conditions => { :translation_of_id => nil } 410 + scope :native_translations, -> { where :translation_of_id => nil }
410 411
411 def translatable? 412 def translatable?
412 false 413 false
@@ -461,7 +462,7 @@ class Article &lt; ActiveRecord::Base @@ -461,7 +462,7 @@ class Article &lt; ActiveRecord::Base
461 elsif self.native_translation.language == locale 462 elsif self.native_translation.language == locale
462 self.native_translation 463 self.native_translation
463 else 464 else
464 - self.native_translation.translations.first(:conditions => { :language => locale }) 465 + self.native_translation.translations.where(:language => locale).first
465 end 466 end
466 end 467 end
467 468
@@ -485,19 +486,19 @@ class Article &lt; ActiveRecord::Base @@ -485,19 +486,19 @@ class Article &lt; ActiveRecord::Base
485 ['TextArticle', 'TextileArticle', 'TinyMceArticle'] 486 ['TextArticle', 'TextileArticle', 'TinyMceArticle']
486 end 487 end
487 488
488 - scope :published, :conditions => ['articles.published = ?', true]  
489 - scope :folders, lambda {|profile|{:conditions => ['articles.type IN (?)', profile.folder_types] }}  
490 - scope :no_folders, lambda {|profile|{:conditions => ['articles.type NOT IN (?)', profile.folder_types]}}  
491 - scope :galleries, :conditions => [ "articles.type IN ('Gallery')" ]  
492 - scope :images, :conditions => { :is_image => true }  
493 - scope :no_images, :conditions => { :is_image => false }  
494 - scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ]  
495 - scope :files, :conditions => { :type => 'UploadedFile' }  
496 - scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } 489 + scope :published, -> { where 'articles.published = ?', true }
  490 + scope :folders, -> (profile) { where 'articles.type IN (?)', profile.folder_types }
  491 + scope :no_folders, -> (profile) { where 'articles.type NOT IN (?)', profile.folder_types }
  492 + scope :galleries, -> { where "articles.type IN ('Gallery')" }
  493 + scope :images, -> { where :is_image => true }
  494 + scope :no_images, -> { where :is_image => false }
  495 + scope :text_articles, -> { where 'articles.type IN (?)', text_article_types }
  496 + scope :files, -> { where :type => 'UploadedFile' }
  497 + scope :with_types, -> (types) { where 'articles.type IN (?)', types }
497 498
498 - scope :more_popular, :order => 'hits DESC'  
499 - scope :more_comments, :order => "comments_count DESC"  
500 - scope :more_recent, :order => "created_at DESC" 499 + scope :more_popular, -> { order 'hits DESC' }
  500 + scope :more_comments, -> { order "comments_count DESC" }
  501 + scope :more_recent, -> { order "created_at DESC" }
501 502
502 scope :display_filter, lambda {|user, profile| 503 scope :display_filter, lambda {|user, profile|
503 return published if (user.nil? && profile && profile.public?) 504 return published if (user.nil? && profile && profile.public?)
@@ -619,7 +620,7 @@ class Article &lt; ActiveRecord::Base @@ -619,7 +620,7 @@ class Article &lt; ActiveRecord::Base
619 ] 620 ]
620 621
621 def self.find_by_old_path(old_path) 622 def self.find_by_old_path(old_path)
622 - find(:first, :include => :versions, :conditions => ['article_versions.path = ?', old_path], :order => 'article_versions.id desc') 623 + self.includes(:versions).where( 'article_versions.path = ?', old_path).order('article_versions.id DESC')
623 end 624 end
624 625
625 def hit 626 def hit
app/models/block.rb
@@ -20,7 +20,7 @@ class Block &lt; ActiveRecord::Base @@ -20,7 +20,7 @@ class Block &lt; ActiveRecord::Base
20 20
21 acts_as_having_settings 21 acts_as_having_settings
22 22
23 - scope :enabled, :conditions => { :enabled => true } 23 + scope :enabled, -> { where :enabled => true }
24 24
25 after_save do |block| 25 after_save do |block|
26 if block.owner.kind_of?(Profile) && block.owner.is_template? && block.mirror? 26 if block.owner.kind_of?(Profile) && block.owner.is_template? && block.mirror?
app/models/blog_archives_block.rb
@@ -35,7 +35,7 @@ class BlogArchivesBlock &lt; Block @@ -35,7 +35,7 @@ class BlogArchivesBlock &lt; Block
35 posts.except(:order).count(:all, :group => 'EXTRACT(YEAR FROM published_at)').sort_by {|year, count| -year.to_i}.each do |year, count| 35 posts.except(:order).count(:all, :group => 'EXTRACT(YEAR FROM published_at)').sort_by {|year, count| -year.to_i}.each do |year, count|
36 results << content_tag('li', content_tag('strong', "#{year} (#{count})")) 36 results << content_tag('li', content_tag('strong', "#{year} (#{count})"))
37 results << "<ul class='#{year}-archive'>" 37 results << "<ul class='#{year}-archive'>"
38 - posts.except(:order).count(:all, :conditions => ['EXTRACT(YEAR FROM published_at)=?', year], :group => 'EXTRACT(MONTH FROM published_at)').sort_by {|month, count| -month.to_i}.each do |month, count| 38 + posts.except(:order).where('EXTRACT(YEAR FROM published_at)=?', year).group('EXTRACT(MONTH FROM published_at)').count.sort_by {|month, count| -month.to_i}.each do |month, count|
39 results << content_tag('li', link_to("#{month_name(month.to_i)} (#{count})", owner_blog.url.merge(:year => year, :month => month))) 39 results << content_tag('li', link_to("#{month_name(month.to_i)} (#{count})", owner_blog.url.merge(:year => year, :month => month)))
40 end 40 end
41 results << "</ul>" 41 results << "</ul>"
app/models/box.rb
@@ -7,7 +7,7 @@ class Box &lt; ActiveRecord::Base @@ -7,7 +7,7 @@ class Box &lt; ActiveRecord::Base
7 7
8 include Noosfero::Plugin::HotSpot 8 include Noosfero::Plugin::HotSpot
9 9
10 - scope :with_position, :conditions => ['boxes.position > 0'] 10 + scope :with_position, -> { where 'boxes.position > 0' }
11 11
12 def environment 12 def environment
13 owner ? (owner.kind_of?(Environment) ? owner : owner.environment) : nil 13 owner ? (owner.kind_of?(Environment) ? owner : owner.environment) : nil
app/models/categorization.rb
1 module Categorization 1 module Categorization
2 2
3 def add_category_to_object(category, object) 3 def add_category_to_object(category, object)
4 - if !find(:first, :conditions => {object_id_column => object, :category_id => category} ) 4 + if !self.where(object_id_column => object, :category_id => category).first
5 connection.execute("insert into #{table_name} (category_id, #{object_id_column}) values(#{category.id}, #{object.id})") 5 connection.execute("insert into #{table_name} (category_id, #{object_id_column}) values(#{category.id}, #{object.id})")
6 6
7 c = category.parent 7 c = category.parent
8 - while !c.nil? && !self.find(:first, :conditions => {object_id_column => object, :category_id => c}) 8 + while !c.nil? && !self.where(object_id_column => object, :category_id => c).first
9 connection.execute("insert into #{table_name} (category_id, #{object_id_column}, virtual) values(#{c.id}, #{object.id}, 1>0)") 9 connection.execute("insert into #{table_name} (category_id, #{object_id_column}, virtual) values(#{c.id}, #{object.id}, 1>0)")
10 c = c.parent 10 c = c.parent
11 end 11 end
app/models/category.rb
@@ -14,12 +14,12 @@ class Category &lt; ActiveRecord::Base @@ -14,12 +14,12 @@ class Category &lt; ActiveRecord::Base
14 validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('{fn} is already being used by another category.').fix_i18n 14 validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('{fn} is already being used by another category.').fix_i18n
15 belongs_to :environment 15 belongs_to :environment
16 16
17 - # Finds all top level categories for a given environment.  
18 - scope :top_level_for, lambda { |environment|  
19 - {:conditions => ['parent_id is null and environment_id = ?', environment.id ]} 17 + # Finds all top level categories for a given environment.
  18 + scope :top_level_for, -> (environment) {
  19 + where 'parent_id is null and environment_id = ?', environment.id
20 } 20 }
21 21
22 - scope :on_level, lambda { |parent| {:conditions => {:parent_id => parent}} } 22 + scope :on_level, -> (parent) { where :parent_id => parent }
23 23
24 acts_as_filesystem 24 acts_as_filesystem
25 25
@@ -46,10 +46,10 @@ class Category &lt; ActiveRecord::Base @@ -46,10 +46,10 @@ class Category &lt; ActiveRecord::Base
46 display_color = nil if display_color.blank? 46 display_color = nil if display_color.blank?
47 end 47 end
48 48
49 - scope :from_types, lambda { |types|  
50 - types.select{ |t| t.blank? }.empty? ?  
51 - { :conditions => { :type => types } } :  
52 - { :conditions => [ "type IN (?) OR type IS NULL", types.reject{ |t| t.blank? } ] } 49 + scope :from_types, -> (types) {
  50 + if types.select{ |t| t.blank? }.empty? then
  51 + where(type: types) else
  52 + where("type IN (?) OR type IS NULL", types.reject{ |t| t.blank? }) end
53 } 53 }
54 54
55 def recent_people(limit = 10) 55 def recent_people(limit = 10)
@@ -81,7 +81,7 @@ class Category &lt; ActiveRecord::Base @@ -81,7 +81,7 @@ class Category &lt; ActiveRecord::Base
81 end 81 end
82 82
83 def upcoming_events(limit = 10) 83 def upcoming_events(limit = 10)
84 - self.events.paginate(:conditions => [ 'start_date >= ?', Date.today ], :order => 'start_date', :page => 1, :per_page => limit) 84 + self.events.where('start_date >= ?', Date.today).order('start_date').paginate(:page => 1, :per_page => limit)
85 end 85 end
86 86
87 def display_in_menu? 87 def display_in_menu?
@@ -90,11 +90,11 @@ class Category &lt; ActiveRecord::Base @@ -90,11 +90,11 @@ class Category &lt; ActiveRecord::Base
90 90
91 def children_for_menu 91 def children_for_menu
92 results = [] 92 results = []
93 - pending = children.find(:all, :conditions => { :display_in_menu => true}) 93 + pending = children.where :display_in_menu => true
94 while !pending.empty? 94 while !pending.empty?
95 cat = pending.shift 95 cat = pending.shift
96 results << cat 96 results << cat
97 - pending += cat.children.find(:all, :conditions => { :display_in_menu => true} ) 97 + pending += cat.children.where :display_in_menu => true
98 end 98 end
99 99
100 results 100 results
@@ -102,7 +102,7 @@ class Category &lt; ActiveRecord::Base @@ -102,7 +102,7 @@ class Category &lt; ActiveRecord::Base
102 102
103 def is_leaf_displayable_in_menu? 103 def is_leaf_displayable_in_menu?
104 return false if self.display_in_menu == false 104 return false if self.display_in_menu == false
105 - self.children.find(:all, :conditions => {:display_in_menu => true}).empty? 105 + self.children.where(:display_in_menu => true).empty?
106 end 106 end
107 107
108 def with_color 108 def with_color
app/models/comment.rb
@@ -18,7 +18,7 @@ class Comment &lt; ActiveRecord::Base @@ -18,7 +18,7 @@ class Comment &lt; ActiveRecord::Base
18 has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy 18 has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy
19 belongs_to :reply_of, :class_name => 'Comment', :foreign_key => 'reply_of_id' 19 belongs_to :reply_of, :class_name => 'Comment', :foreign_key => 'reply_of_id'
20 20
21 - scope :without_reply, :conditions => ['reply_of_id IS NULL'] 21 + scope :without_reply, -> { where 'reply_of_id IS NULL' }
22 22
23 # unauthenticated authors: 23 # unauthenticated authors:
24 validates_presence_of :name, :if => (lambda { |record| !record.email.blank? }) 24 validates_presence_of :name, :if => (lambda { |record| !record.email.blank? })
app/models/domain.rb
@@ -37,7 +37,7 @@ class Domain &lt; ActiveRecord::Base @@ -37,7 +37,7 @@ class Domain &lt; ActiveRecord::Base
37 # "www.", but it will be removed before searching. So searching for 37 # "www.", but it will be removed before searching. So searching for
38 # 'www.example.net' is exactly the same as searching for just 'example.net' 38 # 'www.example.net' is exactly the same as searching for just 'example.net'
39 def self.find_by_name(name) 39 def self.find_by_name(name)
40 - self.find(:first, :conditions => [ 'name = ?', self.extract_domain_name(name) ]) 40 + self.where('name = ?', self.extract_domain_name(name)).first
41 end 41 end
42 42
43 # turns the argument (expected to be a String) into a domain name that is 43 # turns the argument (expected to be a String) into a domain name that is
app/models/enterprise.rb
@@ -68,7 +68,7 @@ class Enterprise &lt; Organization @@ -68,7 +68,7 @@ class Enterprise &lt; Organization
68 end 68 end
69 69
70 def highlighted_products_with_image(options = {}) 70 def highlighted_products_with_image(options = {})
71 - Product.find(:all, {:conditions => {:highlighted => true}, :joins => :image}.merge(options)) 71 + Product.where(:highlighted => true).joins(:image)
72 end 72 end
73 73
74 def required_fields 74 def required_fields
app/models/environment.rb
@@ -111,7 +111,7 @@ class Environment &lt; ActiveRecord::Base @@ -111,7 +111,7 @@ class Environment &lt; ActiveRecord::Base
111 def admins 111 def admins
112 admin_role = Environment::Roles.admin(self) 112 admin_role = Environment::Roles.admin(self)
113 return [] if admin_role.blank? 113 return [] if admin_role.blank?
114 - Person.members_of(self).all(:conditions => ['role_assignments.role_id = ?', admin_role.id]) 114 + Person.members_of(self).where 'role_assignments.role_id = ?', admin_role.id
115 end 115 end
116 116
117 # returns the available features for a Environment, in the form of a 117 # returns the available features for a Environment, in the form of a
@@ -222,9 +222,11 @@ class Environment &lt; ActiveRecord::Base @@ -222,9 +222,11 @@ class Environment &lt; ActiveRecord::Base
222 has_many :licenses 222 has_many :licenses
223 223
224 has_many :categories 224 has_many :categories
225 - has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color' 225 + has_many :display_categories, -> {
  226 + order('display_color').where('display_color is not null and parent_id is null')
  227 + }, class_name: 'Category'
226 228
227 - has_many :product_categories, :conditions => { :type => 'ProductCategory'} 229 + has_many :product_categories, -> { where type: 'ProductCategory'}
228 has_many :regions 230 has_many :regions
229 has_many :states 231 has_many :states
230 has_many :cities 232 has_many :cities
@@ -672,7 +674,7 @@ class Environment &lt; ActiveRecord::Base @@ -672,7 +674,7 @@ class Environment &lt; ActiveRecord::Base
672 674
673 # the default Environment. 675 # the default Environment.
674 def self.default 676 def self.default
675 - self.find(:first, :conditions => [ 'is_default = ?', true ] ) 677 + self.where('is_default = ?', true).first
676 end 678 end
677 679
678 # returns an array with the top level categories for this environment. 680 # returns an array with the top level categories for this environment.
@@ -853,7 +855,7 @@ class Environment &lt; ActiveRecord::Base @@ -853,7 +855,7 @@ class Environment &lt; ActiveRecord::Base
853 end 855 end
854 856
855 def portal_folders 857 def portal_folders
856 - (settings[:portal_folders] || []).map{|fid| portal_community.articles.find(:first, :conditions => { :id => fid }) }.compact 858 + (settings[:portal_folders] || []).map{|fid| portal_community.articles.where(id: fid).first }.compact
857 end 859 end
858 860
859 def portal_folders=(folders) 861 def portal_folders=(folders)
@@ -940,7 +942,7 @@ class Environment &lt; ActiveRecord::Base @@ -940,7 +942,7 @@ class Environment &lt; ActiveRecord::Base
940 end 942 end
941 943
942 def highlighted_products_with_image(options = {}) 944 def highlighted_products_with_image(options = {})
943 - Product.find(:all, {:conditions => {:highlighted => true, :profile_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) 945 + Product.where(highlighted: true, profile_id: self.enterprises.where(select: :id)).joins(:image)
944 end 946 end
945 947
946 settings_items :home_cache_in_minutes, :type => :integer, :default => 5 948 settings_items :home_cache_in_minutes, :type => :integer, :default => 5
app/models/event.rb
@@ -34,23 +34,20 @@ class Event &lt; Article @@ -34,23 +34,20 @@ class Event &lt; Article
34 end 34 end
35 end 35 end
36 36
37 - scope :by_day, lambda { |date|  
38 - { :conditions => ['start_date = :date AND end_date IS NULL OR (start_date <= :date AND end_date >= :date)', {:date => date}],  
39 - :order => 'start_date ASC'  
40 - } 37 + scope :by_day, -> (date) {
  38 + order('start_date ASC')
  39 + .where('start_date = :date AND end_date IS NULL OR (start_date <= :date AND end_date >= :date)', {:date => date})
41 } 40 }
42 41
43 - scope :next_events_from_month, lambda { |date| 42 + scope :next_events_from_month, -> (date) {
44 date_temp = date.strftime("%Y-%m-%d") 43 date_temp = date.strftime("%Y-%m-%d")
45 - { :conditions => ["start_date >= ?","#{date_temp}"],  
46 - :order => 'start_date ASC'  
47 - } 44 + order('start_date ASC')
  45 + .where("start_date >= ?","#{date_temp}")
48 } 46 }
49 47
50 - scope :by_month, lambda { |date|  
51 - { :conditions => ["EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?",date.year,date.month],  
52 - :order => 'start_date ASC'  
53 - } 48 + scope :by_month, -> (date) {
  49 + order('start_date ASC')
  50 + .where("EXTRACT(YEAR FROM start_date) = ? AND EXTRACT(MONTH FROM start_date) = ?", date.year, date.month)
54 } 51 }
55 52
56 include WhiteListFilter 53 include WhiteListFilter
@@ -71,12 +68,10 @@ class Event &lt; Article @@ -71,12 +68,10 @@ class Event &lt; Article
71 'event' 68 'event'
72 end 69 end
73 70
74 - scope :by_range, lambda { |range| {  
75 - :conditions => [  
76 - 'start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day',  
77 - { :start_day => range.first, :end_day => range.last }  
78 - ]  
79 - }} 71 + scope :by_range, -> (range) {
  72 + where('start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day',
  73 + {:start_day => range.first, :end_day => range.last})
  74 + }
80 75
81 def self.date_range(year, month) 76 def self.date_range(year, month)
82 if year.nil? || month.nil? 77 if year.nil? || month.nil?
app/models/external_feed.rb
@@ -5,9 +5,9 @@ class ExternalFeed &lt; ActiveRecord::Base @@ -5,9 +5,9 @@ class ExternalFeed &lt; ActiveRecord::Base
5 validates_presence_of :address, :if => lambda {|efeed| efeed.enabled} 5 validates_presence_of :address, :if => lambda {|efeed| efeed.enabled}
6 validates_uniqueness_of :blog_id 6 validates_uniqueness_of :blog_id
7 7
8 - scope :enabled, :conditions => { :enabled => true }  
9 - scope :expired, lambda {  
10 - { :conditions => ['(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] } 8 + scope :enabled, -> { where enabled: true }
  9 + scope :expired, -> {
  10 + where '(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval
11 } 11 }
12 12
13 attr_accessible :address, :enabled, :only_once 13 attr_accessible :address, :enabled, :only_once
app/models/feed_reader_block.rb
@@ -27,8 +27,8 @@ class FeedReaderBlock &lt; Block @@ -27,8 +27,8 @@ class FeedReaderBlock &lt; Block
27 settings_items :update_errors, :type => :integer, :default => 0 27 settings_items :update_errors, :type => :integer, :default => 0
28 settings_items :error_message, :type => :string 28 settings_items :error_message, :type => :string
29 29
30 - scope :expired, lambda {  
31 - { :conditions => [ '(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] } 30 + scope :expired, -> {
  31 + where '(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval
32 } 32 }
33 33
34 before_create do |block| 34 before_create do |block|
app/models/folder.rb
@@ -56,10 +56,11 @@ class Folder &lt; Article @@ -56,10 +56,11 @@ class Folder &lt; Article
56 profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id]) 56 profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id])
57 end 57 end
58 58
59 - has_many :images, :class_name => 'Article',  
60 - :foreign_key => 'parent_id',  
61 - :order => 'articles.type, articles.name',  
62 - :conditions => ["articles.type = 'UploadedFile' and articles.content_type in (?) or articles.type in ('Folder','Gallery')", UploadedFile.content_types] 59 + has_many :images, -> {
  60 + order('articles.type, articles.name').
  61 + where("articles.type = 'UploadedFile' and articles.content_type in (?) or articles.type in ('Folder','Gallery')", UploadedFile.content_types)
  62 + }, class_name: 'Article', foreign_key: 'parent_id'
  63 +
63 64
64 def accept_uploads? 65 def accept_uploads?
65 !self.has_posts? || self.gallery? 66 !self.has_posts? || self.gallery?
app/models/input.rb
@@ -13,7 +13,7 @@ class Input &lt; ActiveRecord::Base @@ -13,7 +13,7 @@ class Input &lt; ActiveRecord::Base
13 13
14 belongs_to :unit 14 belongs_to :unit
15 15
16 - scope :relevant_to_price, :conditions => { :relevant_to_price => true } 16 + scope :relevant_to_price, -> { where relevant_to_price: true }
17 17
18 include FloatHelper 18 include FloatHelper
19 19
app/models/invite_friend.rb
@@ -45,7 +45,7 @@ class InviteFriend &lt; Invitation @@ -45,7 +45,7 @@ class InviteFriend &lt; Invitation
45 private 45 private
46 def check_for_invitation_existence 46 def check_for_invitation_existence
47 if friend 47 if friend
48 - friend.tasks.pending.of("InviteFriend").find(:all, :conditions => {:requestor_id => person.id, :target_id => friend.id}).blank? 48 + friend.tasks.pending.of("InviteFriend").where(requestor_id: person.id, target_id: friend.id).blank?
49 end 49 end
50 end 50 end
51 51
app/models/invite_member.rb
@@ -65,7 +65,7 @@ class InviteMember &lt; Invitation @@ -65,7 +65,7 @@ class InviteMember &lt; Invitation
65 private 65 private
66 def check_for_invitation_existence 66 def check_for_invitation_existence
67 if friend 67 if friend
68 - friend.tasks.pending.of("InviteMember").find(:all, :conditions => {:requestor_id => person.id}).select { |t| t.data[:community_id] == community_id }.blank? 68 + friend.tasks.pending.of("InviteMember").where(requestor_id: person.id).select{ |t| t.data[:community_id] == community_id }.blank?
69 end 69 end
70 end 70 end
71 71
app/models/organization.rb
@@ -56,7 +56,7 @@ class Organization &lt; Profile @@ -56,7 +56,7 @@ class Organization &lt; Profile
56 end 56 end
57 57
58 def find_pending_validation(code) 58 def find_pending_validation(code)
59 - validations.pending.find(:first, :conditions => {:code => code}) 59 + validations.pending.where(code: code).first
60 end 60 end
61 61
62 def processed_validations 62 def processed_validations
@@ -64,7 +64,7 @@ class Organization &lt; Profile @@ -64,7 +64,7 @@ class Organization &lt; Profile
64 end 64 end
65 65
66 def find_processed_validation(code) 66 def find_processed_validation(code)
67 - validations.finished.find(:first, :conditions => {:code => code}) 67 + validations.finished.where(code: code).first
68 end 68 end
69 69
70 def is_validation_entity? 70 def is_validation_entity?
@@ -162,7 +162,7 @@ class Organization &lt; Profile @@ -162,7 +162,7 @@ class Organization &lt; Profile
162 end 162 end
163 163
164 def already_request_membership?(person) 164 def already_request_membership?(person)
165 - self.tasks.pending.find_by_requestor_id(person.id, :conditions => { :type => 'AddMember' }) 165 + self.tasks.pending.where(type: 'AddMember', requestor_id: person.id).first
166 end 166 end
167 167
168 def jid(options = {}) 168 def jid(options = {})
app/models/person.rb
@@ -16,27 +16,26 @@ class Person &lt; Profile @@ -16,27 +16,26 @@ class Person &lt; Profile
16 acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} 16 acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)}
17 acts_as_accessor 17 acts_as_accessor
18 18
19 - scope :members_of, lambda { |resources| 19 + scope :members_of, -> (resources) {
20 resources = [resources] if !resources.kind_of?(Array) 20 resources = [resources] if !resources.kind_of?(Array)
21 conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') 21 conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ')
22 - { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => [conditions] } 22 + select('DISTINCT profiles.*').joins(:role_assignments).where([conditions])
23 } 23 }
24 24
25 - scope :not_members_of, lambda { |resources| 25 + scope :not_members_of, -> (resources) {
26 resources = [resources] if !resources.kind_of?(Array) 26 resources = [resources] if !resources.kind_of?(Array)
27 conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') 27 conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ')
28 - { :select => 'DISTINCT profiles.*', :conditions => ['"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] } 28 + 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)
29 } 29 }
30 30
31 - scope :by_role, lambda { |roles| 31 + scope :by_role, -> (roles) {
32 roles = [roles] unless roles.kind_of?(Array) 32 roles = [roles] unless roles.kind_of?(Array)
33 - { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ['role_assignments.role_id IN (?)',  
34 -roles] } 33 + select('DISTINCT profiles.*').joins(:role_assignments).where('role_assignments.role_id IN (?)', roles)
35 } 34 }
36 35
37 - scope :not_friends_of, lambda { |resources| 36 + scope :not_friends_of, -> (resources) {
38 resources = Array(resources) 37 resources = Array(resources)
39 - { :select => 'DISTINCT profiles.*', :conditions => ['"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)] } 38 + 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))
40 } 39 }
41 40
42 def has_permission_with_admin?(permission, resource) 41 def has_permission_with_admin?(permission, resource)
@@ -71,7 +70,9 @@ roles] } @@ -71,7 +70,9 @@ roles] }
71 has_many :friendships, :dependent => :destroy 70 has_many :friendships, :dependent => :destroy
72 has_many :friends, :class_name => 'Person', :through => :friendships 71 has_many :friends, :class_name => 'Person', :through => :friendships
73 72
74 - scope :online, lambda { { :include => :user, :conditions => ["users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes] } } 73 + scope :online, -> {
  74 + includes(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes)
  75 + }
75 76
76 has_many :requested_tasks, :class_name => 'Task', :foreign_key => :requestor_id, :dependent => :destroy 77 has_many :requested_tasks, :class_name => 'Task', :foreign_key => :requestor_id, :dependent => :destroy
77 78
@@ -84,21 +85,31 @@ roles] } @@ -84,21 +85,31 @@ roles] }
84 has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' 85 has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people'
85 has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' 86 has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions'
86 87
87 - has_many :suggested_profiles, :class_name => 'ProfileSuggestion', :foreign_key => :person_id, :order => 'score DESC', :dependent => :destroy  
88 - has_many :suggested_people, :through => :suggested_profiles, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true]  
89 - has_many :suggested_communities, :through => :suggested_profiles, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true] 88 + has_many :suggested_profiles, class_name: 'ProfileSuggestion', foreign_key: :person_id, order: 'score DESC', dependent: :destroy
  89 + has_many :suggested_people, -> {
  90 + where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true
  91 + }, through: :suggested_profiles, source: :suggestion
  92 + has_many :suggested_communities, -> {
  93 + where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true
  94 + }, through: :suggested_profiles, source: :suggestion
90 95
91 - scope :more_popular, :order => 'friends_count DESC' 96 + scope :more_popular, -> { order 'friends_count DESC' }
92 97
93 - scope :abusers, :joins => :abuse_complaints, :conditions => ['tasks.status = 3'], :select => 'DISTINCT profiles.*'  
94 - scope :non_abusers, :joins => "LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'", :conditions => ["tasks.status != 3 OR tasks.id is NULL"], :select => "DISTINCT profiles.*" 98 + scope :abusers, -> {
  99 + joins(:abuse_complaints).where('tasks.status = 3').select('DISTINCT profiles.*')
  100 + }
  101 + scope :non_abusers, -> {
  102 + select("DISTINCT profiles.*").
  103 + joins("LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'").
  104 + where("tasks.status != 3 OR tasks.id is NULL")
  105 + }
95 106
96 - scope :admins, :joins => [:role_assignments => :role], :conditions => ['roles.key = ?', 'environment_administrator' ]  
97 - scope :activated, :joins => :user, :conditions => ['users.activation_code IS NULL AND users.activated_at IS NOT NULL']  
98 - scope :deactivated, :joins => :user, :conditions => ['NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)'] 107 + scope :admins, -> { joins(:role_assignments => :role).where('roles.key = ?', 'environment_administrator') }
  108 + scope :activated, -> { joins(:user).where('users.activation_code IS NULL AND users.activated_at IS NOT NULL') }
  109 + scope :deactivated, -> { joins(:user).where('NOT (users.activation_code IS NULL AND users.activated_at IS NOT NULL)') }
99 110
100 after_destroy do |person| 111 after_destroy do |person|
101 - Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } 112 + Friendship.where(friend_id: person.id).each{ |friendship| friendship.destroy }
102 end 113 end
103 114
104 belongs_to :user, :dependent => :delete 115 belongs_to :user, :dependent => :delete
@@ -156,7 +167,7 @@ roles] } @@ -156,7 +167,7 @@ roles] }
156 end 167 end
157 168
158 def remove_friend(friend) 169 def remove_friend(friend)
159 - Friendship.find(:first, :conditions => {:friend_id => friend, :person_id => id}).destroy 170 + Friendship.where(friend_id: friend, person_id: id).first.destroy
160 end 171 end
161 172
162 FIELDS = %w[ 173 FIELDS = %w[
@@ -267,7 +278,7 @@ roles] } @@ -267,7 +278,7 @@ roles] }
267 end 278 end
268 279
269 validates_each :email, :on => :update do |record,attr,value| 280 validates_each :email, :on => :update do |record,attr,value|
270 - if User.find(:first, :conditions => ['email = ? and id != ? and environment_id = ?', value, record.user.id, record.environment.id]) 281 + if User.where('email = ? and id != ? and environment_id = ?', value, record.user.id, record.environment.id).first
271 record.errors.add(attr, _('{fn} is already used by other user').fix_i18n) 282 record.errors.add(attr, _('{fn} is already used by other user').fix_i18n)
272 end 283 end
273 end 284 end
@@ -379,7 +390,7 @@ roles] } @@ -379,7 +390,7 @@ roles] }
379 def ask_to_join?(community) 390 def ask_to_join?(community)
380 return false if !community.visible? 391 return false if !community.visible?
381 return false if memberships.include?(community) 392 return false if memberships.include?(community)
382 - return false if AddMember.find(:first, :conditions => {:requestor_id => self.id, :target_id => community.id}) 393 + return false if AddMember.where(requestor_id: self.id, target_id: community.id).first
383 !refused_communities.include?(community) 394 !refused_communities.include?(community)
384 end 395 end
385 396
app/models/person_notifier.rb
@@ -28,7 +28,7 @@ class PersonNotifier @@ -28,7 +28,7 @@ class PersonNotifier
28 28
29 def notify 29 def notify
30 if @person.notification_time && @person.notification_time > 0 30 if @person.notification_time && @person.notification_time > 0
31 - notifications = @person.tracked_notifications.find(:all, :conditions => ["created_at > ?", notify_from]) 31 + notifications = @person.tracked_notifications.where("created_at > ?", notify_from)
32 tasks = Task.to(@person).without_spam.pending.where("created_at > ?", notify_from).order_by('created_at', 'asc') 32 tasks = Task.to(@person).without_spam.pending.where("created_at > ?", notify_from).order_by('created_at', 'asc')
33 33
34 Noosfero.with_locale @person.environment.default_language do 34 Noosfero.with_locale @person.environment.default_language do
app/models/product.rb
@@ -47,8 +47,8 @@ class Product &lt; ActiveRecord::Base @@ -47,8 +47,8 @@ class Product &lt; ActiveRecord::Base
47 47
48 scope :more_recent, :order => "created_at DESC" 48 scope :more_recent, :order => "created_at DESC"
49 49
50 - scope :from_category, lambda { |category|  
51 - {:joins => :product_category, :conditions => ['categories.path LIKE ?', "%#{category.slug}%"]} if category 50 + scope :from_category, -> (category) {
  51 + joins(:product_category).where('categories.path LIKE ?', "%#{category.slug}%") if category
52 } 52 }
53 53
54 after_update :save_image 54 after_update :save_image
app/models/product_category.rb
@@ -6,19 +6,19 @@ class ProductCategory &lt; Category @@ -6,19 +6,19 @@ class ProductCategory &lt; Category
6 attr_accessible :name, :parent, :environment 6 attr_accessible :name, :parent, :environment
7 7
8 scope :unique, :select => 'DISTINCT ON (path) categories.*' 8 scope :unique, :select => 'DISTINCT ON (path) categories.*'
9 - scope :by_enterprise, lambda { |enterprise| {  
10 - :joins => :products,  
11 - :conditions => ['products.profile_id = ?', enterprise.id]  
12 - }}  
13 - scope :by_environment, lambda { |environment| {  
14 - :conditions => ['environment_id = ?', environment.id]  
15 - }}  
16 - scope :unique_by_level, lambda { |level| {  
17 - :select => "DISTINCT ON (filtered_category) split_part(path, '/', #{level}) AS filtered_category, categories.*"  
18 - }} 9 + scope :by_enterprise, -> (enterprise) {
  10 + joins(:products).
  11 + where('products.profile_id = ?', enterprise.id)
  12 + }
  13 + scope :by_environment, -> (environment) {
  14 + where 'environment_id = ?', environment.id
  15 + }
  16 + scope :unique_by_level, -> (level) {
  17 + select "DISTINCT ON (filtered_category) split_part(path, '/', #{level}) AS filtered_category, categories.*"
  18 + }
19 19
20 def all_products 20 def all_products
21 - Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) 21 + Product.where(product_category_id: (all_children << self).map(&:id))
22 end 22 end
23 23
24 def self.menu_categories(top_category, env) 24 def self.menu_categories(top_category, env)
app/models/profile.rb
@@ -48,7 +48,7 @@ class Profile &lt; ActiveRecord::Base @@ -48,7 +48,7 @@ class Profile &lt; ActiveRecord::Base
48 all_roles(env_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? || !r.profile_id.nil?} 48 all_roles(env_id).select{ |r| r.key.match(/^profile_/) unless r.key.blank? || !r.profile_id.nil?}
49 end 49 end
50 def self.all_roles(env_id) 50 def self.all_roles(env_id)
51 - Role.all :conditions => { :environment_id => env_id } 51 + Role.where(environment_id: env_id)
52 end 52 end
53 def self.method_missing(m, *args, &block) 53 def self.method_missing(m, *args, &block)
54 role = find_role(m, args[0]) 54 role = find_role(m, args[0])
@@ -85,20 +85,26 @@ class Profile &lt; ActiveRecord::Base @@ -85,20 +85,26 @@ class Profile &lt; ActiveRecord::Base
85 85
86 include Noosfero::Plugin::HotSpot 86 include Noosfero::Plugin::HotSpot
87 87
88 - scope :memberships_of, lambda { |person| { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ['role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id ] } } 88 + scope :memberships_of, -> (person) {
  89 + select('DISTINCT profiles.*').
  90 + joins(:role_assignments).
  91 + where('role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id)
  92 + }
89 #FIXME: these will work only if the subclass is already loaded 93 #FIXME: these will work only if the subclass is already loaded
90 - scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} }  
91 - scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} }  
92 - scope :templates, lambda { |template_id = nil|  
93 - conditions = {:conditions => {:is_template => true}}  
94 - conditions[:conditions].merge!({:id => template_id}) unless template_id.nil?  
95 - conditions 94 + scope :enterprises, -> {
  95 + where((Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR "))
  96 + }
  97 + scope :communities, -> {
  98 + where((Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR "))
  99 + }
  100 + scope :templates, -> (template_id = nil) {
  101 + if template_id then where id: template_id else where is_template: true end
96 } 102 }
97 103
98 - scope :with_templates, lambda { |templates|  
99 - {:conditions => {:template_id => templates}} 104 + scope :with_templates, -> (templates) {
  105 + where template_id: templates
100 } 106 }
101 - scope :no_templates, {:conditions => {:is_template => false}} 107 + scope :no_templates, -> { where is_template: false }
102 108
103 def members 109 def members
104 scopes = plugins.dispatch_scopes(:organization_members, self) 110 scopes = plugins.dispatch_scopes(:organization_members, self)
@@ -131,10 +137,10 @@ class Profile &lt; ActiveRecord::Base @@ -131,10 +137,10 @@ class Profile &lt; ActiveRecord::Base
131 Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') 137 Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',')
132 end 138 end
133 139
134 - scope :visible, :conditions => { :visible => true, :secret => false }  
135 - scope :disabled, :conditions => { :visible => false }  
136 - scope :is_public, :conditions => { :visible => true, :public_profile => true, :secret => false }  
137 - scope :enabled, :conditions => { :enabled => true } 140 + scope :visible, -> { where visible: true, secret: false }
  141 + scope :disabled, -> { where visible: false }
  142 + scope :is_public, -> { where visible: true, public_profile: true, secret: false }
  143 + scope :enabled, -> { where enabled: true }
138 144
139 # Subclasses must override this method 145 # Subclasses must override this method
140 scope :more_popular 146 scope :more_popular
@@ -234,7 +240,7 @@ class Profile &lt; ActiveRecord::Base @@ -234,7 +240,7 @@ class Profile &lt; ActiveRecord::Base
234 end 240 end
235 end 241 end
236 242
237 - has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ] 243 + has_many :profile_categorizations, -> { where 'categories_profiles.virtual = ?', false }
238 has_many :categories, :through => :profile_categorizations 244 has_many :categories, :through => :profile_categorizations
239 245
240 has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization' 246 has_many :profile_categorizations_including_virtual, :class_name => 'ProfileCategorization'
@@ -461,14 +467,13 @@ class Profile &lt; ActiveRecord::Base @@ -461,14 +467,13 @@ class Profile &lt; ActiveRecord::Base
461 self.articles.recent(limit, options, pagination) 467 self.articles.recent(limit, options, pagination)
462 end 468 end
463 469
464 - def last_articles(limit = 10, options = {})  
465 - options = { :limit => limit,  
466 - :conditions => ["advertise = ? AND published = ? AND  
467 - ((articles.type != ? and articles.type != ? and articles.type != ?) OR  
468 - articles.type is NULL)",  
469 - true, true, 'UploadedFile', 'RssFeed', 'Blog'],  
470 - :order => 'articles.published_at desc, articles.id desc' }.merge(options)  
471 - self.articles.find(:all, options) 470 + def last_articles limit = 10
  471 + self.articles.limit(limit).where(
  472 + "advertise = ? AND published = ? AND
  473 + ((articles.type != ? and articles.type != ? and articles.type != ?) OR
  474 + articles.type is NULL)",
  475 + true, true, 'UploadedFile', 'RssFeed', 'Blog'
  476 + ).order('articles.published_at desc, articles.id desc')
472 end 477 end
473 478
474 class << self 479 class << self
app/models/profile_categorization.rb
@@ -13,7 +13,7 @@ class ProfileCategorization &lt; ActiveRecord::Base @@ -13,7 +13,7 @@ class ProfileCategorization &lt; ActiveRecord::Base
13 end 13 end
14 14
15 def self.remove_region(profile) 15 def self.remove_region(profile)
16 - region = profile.categories.find(:first, :conditions => { :type => [Region, State, City].map(&:name) }) 16 + region = profile.categories.where(type: [Region, State, City].map(&:name)).first
17 if region 17 if region
18 ids = region.hierarchy.map(&:id) 18 ids = region.hierarchy.map(&:id)
19 self.delete_all(:profile_id => profile.id, :category_id => ids) 19 self.delete_all(:profile_id => profile.id, :category_id => ids)
app/models/profile_suggestion.rb
@@ -26,9 +26,9 @@ class ProfileSuggestion &lt; ActiveRecord::Base @@ -26,9 +26,9 @@ class ProfileSuggestion &lt; ActiveRecord::Base
26 end 26 end
27 27
28 validates_uniqueness_of :suggestion_id, :scope => [ :person_id ] 28 validates_uniqueness_of :suggestion_id, :scope => [ :person_id ]
29 - scope :of_person, :conditions => { :suggestion_type => 'Person' }  
30 - scope :of_community, :conditions => { :suggestion_type => 'Community' }  
31 - scope :enabled, :conditions => { :enabled => true } 29 + scope :of_person, -> { where suggestion_type: 'Person' }
  30 + scope :of_community, -> { where suggestion_type: 'Community' }
  31 + scope :enabled, -> { where enabled: true }
32 32
33 # {:category_type => ['category-icon', 'category-label']} 33 # {:category_type => ['category-icon', 'category-label']}
34 CATEGORIES = { 34 CATEGORIES = {
app/models/rss_feed.rb
@@ -69,7 +69,7 @@ class RssFeed &lt; Article @@ -69,7 +69,7 @@ class RssFeed &lt; Article
69 def fetch_articles 69 def fetch_articles
70 if parent && parent.has_posts? 70 if parent && parent.has_posts?
71 language = self.language.blank? ? {} : { :language => self.language } 71 language = self.language.blank? ? {} : { :language => self.language }
72 - return parent.posts.find(:all, :conditions => { :published => true }.merge(language), :limit => self.limit, :order => 'id desc') 72 + return parent.posts.where({published: true}.merge language).limit(self.limit).order('id desc')
73 end 73 end
74 74
75 articles = 75 articles =
app/models/scrap.rb
@@ -13,9 +13,9 @@ class Scrap &lt; ActiveRecord::Base @@ -13,9 +13,9 @@ class Scrap &lt; ActiveRecord::Base
13 has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy 13 has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy
14 belongs_to :root, :class_name => 'Scrap', :foreign_key => 'scrap_id' 14 belongs_to :root, :class_name => 'Scrap', :foreign_key => 'scrap_id'
15 15
16 - scope :all_scraps, lambda {|profile| {:conditions => ["receiver_id = ? OR sender_id = ?", profile, profile], :limit => 30}} 16 + scope :all_scraps, -> (profile) { limit(30).where("receiver_id = ? OR sender_id = ?", profile, profile) }
17 17
18 - scope :not_replies, :conditions => {:scrap_id => nil} 18 + scope :not_replies, -> { where scrap_id: nil }
19 19
20 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 20 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
21 21
app/models/search_term_occurrence.rb
1 class SearchTermOccurrence < ActiveRecord::Base 1 class SearchTermOccurrence < ActiveRecord::Base
  2 +
2 belongs_to :search_term 3 belongs_to :search_term
3 validates_presence_of :search_term 4 validates_presence_of :search_term
4 attr_accessible :search_term, :created_at, :total, :indexed 5 attr_accessible :search_term, :created_at, :total, :indexed
5 6
6 EXPIRATION_TIME = 1.year 7 EXPIRATION_TIME = 1.year
7 8
8 - scope :valid, :conditions => ["search_term_occurrences.created_at > ?", DateTime.now - EXPIRATION_TIME] 9 + scope :valid, -> { where "search_term_occurrences.created_at > ?", DateTime.now - EXPIRATION_TIME }
  10 +
9 end 11 end
app/models/slideshow_block.rb
@@ -13,7 +13,7 @@ class SlideshowBlock &lt; Block @@ -13,7 +13,7 @@ class SlideshowBlock &lt; Block
13 end 13 end
14 14
15 def gallery 15 def gallery
16 - gallery_id ? Gallery.find(:first, :conditions => { :id => gallery_id }) : nil 16 + if gallery_id then Gallery.where(id: gallery_id).first else nil end
17 end 17 end
18 18
19 def public_filename_for(image) 19 def public_filename_for(image)
app/models/task.rb
@@ -236,27 +236,28 @@ class Task &lt; ActiveRecord::Base @@ -236,27 +236,28 @@ class Task &lt; ActiveRecord::Base
236 end 236 end
237 end 237 end
238 238
239 - scope :pending, :conditions => { :status => Task::Status::ACTIVE }  
240 - scope :hidden, :conditions => { :status => Task::Status::HIDDEN }  
241 - scope :finished, :conditions => { :status => Task::Status::FINISHED }  
242 - scope :canceled, :conditions => { :status => Task::Status::CANCELLED }  
243 - scope :closed, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] }  
244 - scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] }  
245 - scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} }  
246 - scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} }  
247 - scope :like, lambda { |field, value| where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value}  
248 - scope :pending_all, lambda { |profile, filter_type, filter_text| 239 + scope :pending, -> { where status: Task::Status::ACTIVE }
  240 + scope :hidden, -> { where status: Task::Status::HIDDEN }
  241 + scope :finished, -> { where status: Task::Status::FINISHED }
  242 + scope :canceled, -> { where status: Task::Status::CANCELLED }
  243 + scope :closed, -> { where status: [Task::Status::CANCELLED, Task::Status::FINISHED] }
  244 + scope :opened, -> { where status: [Task::Status::ACTIVE, Task::Status::HIDDEN] }
  245 + scope :of, -> (type) { where "type LIKE ?", type if type }
  246 + scope :order_by, -> (attribute, ord) { order "#{attribute} #{ord}" }
  247 + scope :like, -> (field, value) { where "LOWER(#{field}) LIKE ?", "%#{value.downcase}%" if value }
  248 + scope :pending_all, -> (profile, filter_type, filter_text) {
249 self.to(profile).without_spam.pending.of(filter_type).like('data', filter_text) 249 self.to(profile).without_spam.pending.of(filter_type).like('data', filter_text)
250 } 250 }
251 251
252 scope :to, lambda { |profile| 252 scope :to, lambda { |profile|
253 environment_condition = nil 253 environment_condition = nil
254 if profile.person? 254 if profile.person?
255 - envs_ids = Environment.find(:all).select{ |env| profile.is_admin?(env) }.map { |env| "target_id = #{env.id}"}.join(' OR ') 255 + envs_ids = Environment.all.select{ |env| profile.is_admin?(env) }.map{ |env| "target_id = #{env.id}"}.join(' OR ')
256 environment_condition = envs_ids.blank? ? nil : "(target_type = 'Environment' AND (#{envs_ids}))" 256 environment_condition = envs_ids.blank? ? nil : "(target_type = 'Environment' AND (#{envs_ids}))"
257 end 257 end
258 profile_condition = "(target_type = 'Profile' AND target_id = #{profile.id})" 258 profile_condition = "(target_type = 'Profile' AND target_id = #{profile.id})"
259 - { :conditions => [environment_condition, profile_condition].compact.join(' OR ') } 259 +
  260 + where [environment_condition, profile_condition].compact.join(' OR ')
260 } 261 }
261 262
262 def self.pending_types_for(profile) 263 def self.pending_types_for(profile)
@@ -319,7 +320,7 @@ class Task &lt; ActiveRecord::Base @@ -319,7 +320,7 @@ class Task &lt; ActiveRecord::Base
319 # 320 #
320 # Can be used in subclasses to find only their instances. 321 # Can be used in subclasses to find only their instances.
321 def find_by_code(code) 322 def find_by_code(code)
322 - self.find(:first, :conditions => { :code => code, :status => Task::Status::ACTIVE }) 323 + self.where(code: code, status: Task::Status::ACTIVE)
323 end 324 end
324 325
325 def per_page 326 def per_page
app/models/user.rb
@@ -111,8 +111,8 @@ class User &lt; ActiveRecord::Base @@ -111,8 +111,8 @@ class User &lt; ActiveRecord::Base
111 # Authenticates a user by their login name or email and unencrypted password. Returns the user or nil. 111 # Authenticates a user by their login name or email and unencrypted password. Returns the user or nil.
112 def self.authenticate(login, password, environment = nil) 112 def self.authenticate(login, password, environment = nil)
113 environment ||= Environment.default 113 environment ||= Environment.default
114 - u = self.first :conditions => ['(login = ? OR email = ?) AND environment_id = ? AND activated_at IS NOT NULL',  
115 - login, login, environment.id] # need to get the salt 114 + u = self.where('(login = ? OR email = ?) AND environment_id = ? AND activated_at IS NOT NULL',
  115 + login, login, environment.id).first # need to get the salt
116 u && u.authenticated?(password) ? u : nil 116 u && u.authenticated?(password) ? u : nil
117 end 117 end
118 118
app/views/features/index.html.erb
@@ -44,7 +44,7 @@ Check all the features you want to enable for your environment, uncheck all the @@ -44,7 +44,7 @@ Check all the features you want to enable for your environment, uncheck all the
44 </div> 44 </div>
45 <div class="input"> 45 <div class="input">
46 <div class="info"><%= _('Allow these people to access this environment:') %></div> 46 <div class="info"><%= _('Allow these people to access this environment:') %></div>
47 - <% tokenized_members = prepare_to_token_input(environment.people.find(:all, :conditions => {:id => environment.members_whitelist})) %> 47 + <% tokenized_members = prepare_to_token_input(environment.people.where(id: environment.members_whitelist)) %>
48 <%= token_input_field_tag('environment[members_whitelist]', 'search-members', {:action => 'search_members'}, {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_members}) %> 48 <%= token_input_field_tag('environment[members_whitelist]', 'search-members', {:action => 'search_members'}, {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_members}) %>
49 </div> 49 </div>
50 <hr/> 50 <hr/>
app/views/search/_full_forum.html.erb
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 <tr class="search-forum-items"> 11 <tr class="search-forum-items">
12 <td class="search-field-label"><%= _("Last topics") %></td> 12 <td class="search-field-label"><%= _("Last topics") %></td>
13 13
14 - <% r = forum.children.find(:all, :order => :updated_at, :conditions => ['type != ?', 'RssFeed']).last(3) %> 14 + <% r = forum.children.order(:updated_at).where('type != ?', 'RssFeed').last(3) %>
15 <td class="<%= "search-field-none" if r.empty? %>"> 15 <td class="<%= "search-field-none" if r.empty? %>">
16 <% r.each do |a| %> 16 <% r.each do |a| %>
17 <%= link_to a.title, a.view_url, :class => 'search-forum-sample-item '+icon_for_article(a) %> 17 <%= link_to a.title, a.view_url, :class => 'search-forum-sample-item '+icon_for_article(a) %>
app/views/search/_image.html.erb
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 <% end %> 26 <% end %>
27 <% elsif image.is_a? Gallery %> 27 <% elsif image.is_a? Gallery %>
28 <div class="search-gallery-items"> 28 <div class="search-gallery-items">
29 - <% r = image.children.find(:all, :order => :updated_at, :conditions => ['type = ?', 'UploadedFile']).last(3) %> 29 + <% r = image.children.order(updated_at).where('type = ?', 'UploadedFile').last(3) %>
30 <% if r.length > 0 %> 30 <% if r.length > 0 %>
31 <% r.each_index do |i| img = r[i] %> 31 <% r.each_index do |i| img = r[i] %>
32 <%= link_to '', img.view_url, :class => "search-image-pic pic-num#{i+1}", 32 <%= link_to '', img.view_url, :class => "search-image-pic pic-num#{i+1}",
config/initializers/activities_counter_cache.rb
1 if Delayed::Backend::ActiveRecord::Job.table_exists? && 1 if Delayed::Backend::ActiveRecord::Job.table_exists? &&
2 Delayed::Backend::ActiveRecord::Job.attribute_names.include?('queue') 2 Delayed::Backend::ActiveRecord::Job.attribute_names.include?('queue')
3 - job = Delayed::Backend::ActiveRecord::Job.all :conditions => ['handler LIKE ?', "%ActivitiesCounterCacheJob%"] 3 + job = Delayed::Backend::ActiveRecord::Job.where('handler LIKE ?', "%ActivitiesCounterCacheJob%")
4 if job.blank? 4 if job.blank?
5 Delayed::Backend::ActiveRecord::Job.enqueue(ActivitiesCounterCacheJob.new, {:priority => -3}) 5 Delayed::Backend::ActiveRecord::Job.enqueue(ActivitiesCounterCacheJob.new, {:priority => -3})
6 end 6 end
db/migrate/059_add_birth_date_to_person.rb
@@ -37,7 +37,7 @@ class AddBirthDateToPerson &lt; ActiveRecord::Migration @@ -37,7 +37,7 @@ class AddBirthDateToPerson &lt; ActiveRecord::Migration
37 def self.up 37 def self.up
38 add_column :profiles, :birth_date, :date 38 add_column :profiles, :birth_date, :date
39 offset = 0 39 offset = 0
40 - while p = Person.find(:first, :conditions => "type = 'Person'", :order => 'id', :offset => offset) 40 + while p = Person.where("type = 'Person'").order(:id).offset(offset).first
41 p.birth_date = ConvertDates.convert(p.data[:birth_date].to_s) 41 p.birth_date = ConvertDates.convert(p.data[:birth_date].to_s)
42 p.save 42 p.save
43 offset += 1 43 offset += 1
lib/acts_as_filesystem.rb
@@ -34,7 +34,7 @@ module ActsAsFileSystem @@ -34,7 +34,7 @@ module ActsAsFileSystem
34 34
35 def build_ancestry(parent_id = nil, ancestry = '') 35 def build_ancestry(parent_id = nil, ancestry = '')
36 ActiveRecord::Base.transaction do 36 ActiveRecord::Base.transaction do
37 - self.base_class.all(:conditions => {:parent_id => parent_id}).each do |node| 37 + self.base_class.where(parent_id: parent_id).each do |node|
38 node.update_column :ancestry, ancestry 38 node.update_column :ancestry, ancestry
39 39
40 build_ancestry node.id, (ancestry.empty? ? "#{node.formatted_ancestry_id}" : 40 build_ancestry node.id, (ancestry.empty? ? "#{node.formatted_ancestry_id}" :
@@ -42,7 +42,7 @@ module ActsAsFileSystem @@ -42,7 +42,7 @@ module ActsAsFileSystem
42 end 42 end
43 end 43 end
44 44
45 - #raise "Couldn't reach and set ancestry on every record" if self.base_class.count(:conditions => ['ancestry is null']) != 0 45 + #raise "Couldn't reach and set ancestry on every record" if self.base_class.where('ancestry is null').count != 0
46 end 46 end
47 47
48 def has_path? 48 def has_path?
@@ -89,7 +89,7 @@ module ActsAsFileSystem @@ -89,7 +89,7 @@ module ActsAsFileSystem
89 ["#{self.ancestry_column} LIKE ?", "%#{self.formatted_ancestry_id}%"] 89 ["#{self.ancestry_column} LIKE ?", "%#{self.formatted_ancestry_id}%"]
90 end 90 end
91 def descendents 91 def descendents
92 - self.class.scoped :conditions => descendents_options 92 + self.class.where descendents_options
93 end 93 end
94 94
95 # calculates the level of the record in the records hierarchy. Top-level 95 # calculates the level of the record in the records hierarchy. Top-level
@@ -147,7 +147,7 @@ module ActsAsFileSystem @@ -147,7 +147,7 @@ module ActsAsFileSystem
147 @hierarchy = [] 147 @hierarchy = []
148 148
149 if !reload and !recalculate_path and ancestor_ids 149 if !reload and !recalculate_path and ancestor_ids
150 - objects = self.class.base_class.all(:conditions => {:id => ancestor_ids}) 150 + objects = self.class.base_class.where(id: ancestor_ids)
151 ancestor_ids.each{ |id| @hierarchy << objects.find{ |t| t.id == id } } 151 ancestor_ids.each{ |id| @hierarchy << objects.find{ |t| t.id == id } }
152 @hierarchy << self 152 @hierarchy << self
153 else 153 else
@@ -170,7 +170,7 @@ module ActsAsFileSystem @@ -170,7 +170,7 @@ module ActsAsFileSystem
170 result += current_level 170 result += current_level
171 ids = current_level.select {|item| item.children_count > 0}.map(&:id) 171 ids = current_level.select {|item| item.children_count > 0}.map(&:id)
172 break if ids.empty? 172 break if ids.empty?
173 - current_level = self.class.base_class.find(:all, :conditions => { :parent_id => ids}) 173 + current_level = self.class.base_class.where(parent_id: ids)
174 end 174 end
175 block ||= (lambda { |x| x }) 175 block ||= (lambda { |x| x })
176 result.map(&block) 176 result.map(&block)
lib/acts_as_having_image.rb
@@ -3,8 +3,8 @@ module ActsAsHavingImage @@ -3,8 +3,8 @@ module ActsAsHavingImage
3 module ClassMethods 3 module ClassMethods
4 def acts_as_having_image 4 def acts_as_having_image
5 belongs_to :image, dependent: :destroy 5 belongs_to :image, dependent: :destroy
6 - scope :with_image, :conditions => [ "#{table_name}.image_id IS NOT NULL" ]  
7 - scope :without_image, :conditions => [ "#{table_name}.image_id IS NULL" ] 6 + scope :with_image, -> { where "#{table_name}.image_id IS NOT NULL" }
  7 + scope :without_image, -> { where "#{table_name}.image_id IS NULL" }
8 self.send(:include, ActsAsHavingImage) 8 self.send(:include, ActsAsHavingImage)
9 end 9 end
10 end 10 end
@@ -19,4 +19,4 @@ module ActsAsHavingImage @@ -19,4 +19,4 @@ module ActsAsHavingImage
19 19
20 end 20 end
21 21
22 -ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods)  
23 \ No newline at end of file 22 \ No newline at end of file
  23 +ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods)
lib/extended_tag.rb
@@ -4,13 +4,13 @@ class ActsAsTaggableOn::Tag @@ -4,13 +4,13 @@ class ActsAsTaggableOn::Tag
4 4
5 has_many :children, :class_name => 'Tag', :foreign_key => 'parent_id', :dependent => :destroy 5 has_many :children, :class_name => 'Tag', :foreign_key => 'parent_id', :dependent => :destroy
6 6
7 -  
8 - @@original_find = self.method(:find)  
9 - # Rename the find method to find_with_pendings that includes all tags in the search regardless if its pending or not 7 +
  8 + @@original_find = self.method(:find)
  9 + # Rename the find method to find_with_pendings that includes all tags in the search regardless if its pending or not
10 def self.find_with_pendings(*args) 10 def self.find_with_pendings(*args)
11 @@original_find.call(*args) 11 @@original_find.call(*args)
12 end 12 end
13 - 13 +
14 # Redefine the find method to exclude the pending tags from the search not allowing to tag something with an unapproved tag 14 # Redefine the find method to exclude the pending tags from the search not allowing to tag something with an unapproved tag
15 def self.find(*args) 15 def self.find(*args)
16 self.with_scope(:find => { :conditions => ['pending = ?', false] }) do 16 self.with_scope(:find => { :conditions => ['pending = ?', false] }) do
@@ -20,17 +20,17 @@ class ActsAsTaggableOn::Tag @@ -20,17 +20,17 @@ class ActsAsTaggableOn::Tag
20 20
21 # Return all the tags that were suggested but not yet approved 21 # Return all the tags that were suggested but not yet approved
22 def self.find_pendings 22 def self.find_pendings
23 - self.find_with_pendings(:all, :conditions => ['pending = ?', true]) 23 + self.find_with_pendings.where('pending = ?', true)
24 end 24 end
25 25
26 # All the tags that can be a new parent for this tag, that is all but itself and its descendents to avoid loops 26 # All the tags that can be a new parent for this tag, that is all but itself and its descendents to avoid loops
27 def parent_candidates 27 def parent_candidates
28 - ActsAsTaggableOn::Tag.find(:all) - descendents - [self] 28 + ActsAsTaggableOn::Tag.all - descendents - [self]
29 end 29 end
30 - 30 +
31 # All tags that have this tag as its one of its ancestors 31 # All tags that have this tag as its one of its ancestors
32 def descendents 32 def descendents
33 - children.to_a.sum([], &:descendents) + children 33 + children.to_a.sum([], &:descendents) + children
34 end 34 end
35 35
36 end 36 end
lib/spammable.rb
@@ -9,11 +9,11 @@ module Spammable @@ -9,11 +9,11 @@ module Spammable
9 end 9 end
10 10
11 module ClassMethods 11 module ClassMethods
12 - def self.extended (base) 12 + def self.extended base
13 if base.respond_to?(:scope) 13 if base.respond_to?(:scope)
14 base.class_eval do 14 base.class_eval do
15 - scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false]  
16 - scope :spam, :conditions => ['spam = ?', true] 15 + scope :without_spam, -> { where 'spam IS NULL OR spam = ?', false }
  16 + scope :spam, -> { where 'spam = ?', true }
17 end 17 end
18 end 18 end
19 end 19 end
plugins/bsc/controllers/bsc_plugin_admin_controller.rb
@@ -28,8 +28,9 @@ class BscPluginAdminController &lt; AdminController @@ -28,8 +28,9 @@ class BscPluginAdminController &lt; AdminController
28 end 28 end
29 29
30 def search_enterprise 30 def search_enterprise
31 - render :text => Enterprise.not_validated.find(:all, :conditions => ["type <> 'BscPlugin::Bsc' AND (name LIKE ? OR identifier LIKE ?)", "%#{params[:q]}%", "%#{params[:q]}%"]).  
32 - map {|enterprise| {:id => enterprise.id, :name => enterprise.name} }. 31 + render :text => Enterprise.not_validated.
  32 + where("type <> 'BscPlugin::Bsc' AND (name LIKE ? OR identifier LIKE ?)", "%#{params[:q]}%", "%#{params[:q]}%").
  33 + map{ |enterprise| {:id => enterprise.id, :name => enterprise.name} }.
33 to_json 34 to_json
34 end 35 end
35 36
plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb
@@ -8,7 +8,7 @@ class BscPluginMyprofileController &lt; MyProfileController @@ -8,7 +8,7 @@ class BscPluginMyprofileController &lt; MyProfileController
8 end 8 end
9 9
10 def search_enterprise 10 def search_enterprise
11 - 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"]). 11 + 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").
12 select { |enterprise| enterprise.bsc.nil? && !profile.already_requested?(enterprise)}. 12 select { |enterprise| enterprise.bsc.nil? && !profile.already_requested?(enterprise)}.
13 map {|enterprise| {:id => enterprise.id, :name => enterprise.name} }. 13 map {|enterprise| {:id => enterprise.id, :name => enterprise.name} }.
14 to_json 14 to_json
@@ -188,7 +188,8 @@ class BscPluginMyprofileController &lt; MyProfileController @@ -188,7 +188,8 @@ class BscPluginMyprofileController &lt; MyProfileController
188 end 188 end
189 189
190 def search_contract_enterprises 190 def search_contract_enterprises
191 - render :text => profile.enterprises.find(:all, :conditions => ["(LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?)", "%#{params[:enterprises]}%", "%#{params[:enterprises]}%"]). 191 + render :text => profile.enterprises.
  192 + where("(LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?)", "%#{params[:enterprises]}%", "%#{params[:enterprises]}%").
192 map {|enterprise| {:id => enterprise.id, :name => enterprise.short_name(60)} }. 193 map {|enterprise| {:id => enterprise.id, :name => enterprise.short_name(60)} }.
193 to_json 194 to_json
194 end 195 end
@@ -199,7 +200,8 @@ class BscPluginMyprofileController &lt; MyProfileController @@ -199,7 +200,8 @@ class BscPluginMyprofileController &lt; MyProfileController
199 enterprises = enterprises.blank? ? -1 : enterprises 200 enterprises = enterprises.blank? ? -1 : enterprises
200 added_products = (params[:added_products] || []).split(',') 201 added_products = (params[:added_products] || []).split(',')
201 added_products = added_products.blank? ? -1 : added_products 202 added_products = added_products.blank? ? -1 : added_products
202 - render :text => Product.find(:all, :conditions => ["LOWER(name) LIKE ? AND profile_id IN (?) AND id NOT IN (?)", "%#{query}%", enterprises, added_products]). 203 + render :text => Product.
  204 + where("LOWER(name) LIKE ? AND profile_id IN (?) AND id NOT IN (?)", "%#{query}%", enterprises, added_products).
203 map {|product| { :id => product.id, 205 map {|product| { :id => product.id,
204 :name => short_text(product_display_name(product), 60), 206 :name => short_text(product_display_name(product), 60),
205 :sale_id => params[:sale_id], 207 :sale_id => params[:sale_id],
plugins/bsc/lib/bsc_plugin/contract.rb
@@ -7,8 +7,8 @@ class BscPlugin::Contract &lt; Noosfero::Plugin::ActiveRecord @@ -7,8 +7,8 @@ class BscPlugin::Contract &lt; Noosfero::Plugin::ActiveRecord
7 7
8 belongs_to :bsc, :class_name => 'BscPlugin::Bsc' 8 belongs_to :bsc, :class_name => 'BscPlugin::Bsc'
9 9
10 - named_scope :status, lambda { |status_list| status_list.blank? ? {} : {:conditions => ['status in (?)', status_list]} }  
11 - named_scope :sorted_by, lambda { |sorter, direction| {:order => "#{sorter} #{direction}"} } 10 + named_scope :status, -> (status_list) { where 'status in (?)', status_list if status_list.present? }
  11 + named_scope :sorted_by, -> (sorter, direction) { order "#{sorter} #{direction}" }
12 12
13 before_create do |contract| 13 before_create do |contract|
14 contract.created_at ||= Time.now.utc 14 contract.created_at ||= Time.now.utc
plugins/bsc/lib/bsc_plugin/ext/enterprise.rb
@@ -8,6 +8,6 @@ class Enterprise @@ -8,6 +8,6 @@ class Enterprise
8 FIELDS << 'enabled' 8 FIELDS << 'enabled'
9 FIELDS << 'validated' 9 FIELDS << 'validated'
10 10
11 - named_scope :validated, :conditions => {:validated => true}  
12 - named_scope :not_validated, :conditions => {:validated => false} 11 + named_scope :validated, -> { where validated: true }
  12 + named_scope :not_validated, -> { where validated: false }
13 end 13 end
plugins/comment_classification/lib/comment_classification_plugin/label.rb
@@ -4,7 +4,7 @@ class CommentClassificationPlugin::Label &lt; Noosfero::Plugin::ActiveRecord @@ -4,7 +4,7 @@ class CommentClassificationPlugin::Label &lt; Noosfero::Plugin::ActiveRecord
4 4
5 validates_presence_of :name 5 validates_presence_of :name
6 6
7 - scope :enabled, :conditions => { :enabled => true } 7 + scope :enabled, -> { where enabled: true }
8 8
9 attr_accessible :name, :enabled, :color 9 attr_accessible :name, :enabled, :color
10 10
plugins/comment_classification/lib/comment_classification_plugin/status.rb
@@ -6,5 +6,5 @@ class CommentClassificationPlugin::Status &lt; Noosfero::Plugin::ActiveRecord @@ -6,5 +6,5 @@ class CommentClassificationPlugin::Status &lt; Noosfero::Plugin::ActiveRecord
6 6
7 validates_presence_of :name 7 validates_presence_of :name
8 8
9 - scope :enabled, :conditions => { :enabled => true } 9 + scope :enabled, -> { where enabled: true }
10 end 10 end
plugins/comment_group/lib/ext/article.rb
@@ -2,13 +2,15 @@ require_dependency &#39;article&#39; @@ -2,13 +2,15 @@ require_dependency &#39;article&#39;
2 2
3 class Article 3 class Article
4 4
5 - has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL'] 5 + has_many :group_comments, -> {
  6 + order('created_at asc').where('group_id IS NOT NULL')
  7 + }, class_name: 'Comment', foreign_key: 'source_id', dependent: :destroy
6 8
7 validate :not_empty_group_comments_removed 9 validate :not_empty_group_comments_removed
8 10
9 def not_empty_group_comments_removed 11 def not_empty_group_comments_removed
10 if body && body_changed? 12 if body && body_changed?
11 - groups_with_comments = Comment.find(:all, :select => 'distinct group_id', :conditions => {:source_id => self.id}).map(&:group_id).compact 13 + groups_with_comments = Comment.select('DISTINCT group_id').where(source_id: self.id).map(&:group_id).compact
12 groups = Nokogiri::HTML.fragment(body.to_s).css('.macro').collect{|element| element['data-macro-group_id'].to_i} 14 groups = Nokogiri::HTML.fragment(body.to_s).css('.macro').collect{|element| element['data-macro-group_id'].to_i}
13 errors[:base] << (N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty? 15 errors[:base] << (N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty?
14 end 16 end
plugins/comment_group/lib/ext/comment.rb
@@ -2,12 +2,9 @@ require_dependency &#39;comment&#39; @@ -2,12 +2,9 @@ require_dependency &#39;comment&#39;
2 2
3 class Comment 3 class Comment
4 4
5 - scope :without_group, :conditions => {:group_id => nil } 5 + scope :without_group, -> { where group_id: nil }
6 6
7 - scope :in_group, proc { |group_id| {  
8 - :conditions => ['group_id = ?', group_id]  
9 - }  
10 - } 7 + scope :in_group, -> (group_id) { where 'group_id = ?', group_id }
11 8
12 attr_accessible :group_id 9 attr_accessible :group_id
13 10
plugins/community_track/lib/community_track_plugin/step.rb
@@ -32,7 +32,7 @@ class CommunityTrackPlugin::Step &lt; Folder @@ -32,7 +32,7 @@ class CommunityTrackPlugin::Step &lt; Folder
32 self.start_date ||= Date.today 32 self.start_date ||= Date.today
33 self.end_date ||= Date.today + 1.day 33 self.end_date ||= Date.today + 1.day
34 end 34 end
35 - 35 +
36 def set_hidden_position 36 def set_hidden_position
37 if hidden 37 if hidden
38 decrement_positions_on_lower_items 38 decrement_positions_on_lower_items
@@ -108,7 +108,7 @@ class CommunityTrackPlugin::Step &lt; Folder @@ -108,7 +108,7 @@ class CommunityTrackPlugin::Step &lt; Folder
108 end 108 end
109 109
110 def tool 110 def tool
111 - tools.find(:first, :conditions => {:type => tool_type }) 111 + tools.where(type: tool_type).first
112 end 112 end
113 113
114 end 114 end
plugins/custom_forms/lib/custom_forms_plugin/form.rb
@@ -25,9 +25,9 @@ class CustomFormsPlugin::Form &lt; Noosfero::Plugin::ActiveRecord @@ -25,9 +25,9 @@ class CustomFormsPlugin::Form &lt; Noosfero::Plugin::ActiveRecord
25 tasks.each {|task| task.cancel} 25 tasks.each {|task| task.cancel}
26 end 26 end
27 27
28 - scope :from_profile, lambda {|profile| {:conditions => {:profile_id => profile.id}}}  
29 - scope :on_memberships, {:conditions => {:on_membership => true, :for_admission => false}}  
30 - scope :for_admissions, {:conditions => {:for_admission => true}} 28 + scope :from_profile, -> (profile) { where profile_id: profile.id }
  29 + scope :on_memberships, -> { where on_membership: true, for_admission: false }
  30 + scope :for_admissions, -> { where for_admission: true }
31 =begin 31 =begin
32 scope :accessible_to lambda do |profile| 32 scope :accessible_to lambda do |profile|
33 #TODO should verify is profile is associated with the form owner 33 #TODO should verify is profile is associated with the form owner
plugins/custom_forms/lib/custom_forms_plugin/membership_survey.rb
@@ -5,7 +5,7 @@ class CustomFormsPlugin::MembershipSurvey &lt; Task @@ -5,7 +5,7 @@ class CustomFormsPlugin::MembershipSurvey &lt; Task
5 5
6 include CustomFormsPlugin::Helper 6 include CustomFormsPlugin::Helper
7 7
8 - scope :from_profile, lambda {|profile| {:conditions => {:requestor_id => profile.id}}} 8 + scope :from_profile, -> (profile) { where requestor_id: profile.id }
9 9
10 def perform 10 def perform
11 form = CustomFormsPlugin::Form.find(form_id) 11 form = CustomFormsPlugin::Form.find(form_id)
plugins/display_content/lib/display_content_block.rb
@@ -114,7 +114,7 @@ class DisplayContentBlock &lt; Block @@ -114,7 +114,7 @@ class DisplayContentBlock &lt; Block
114 def articles_of_parent(parent = nil) 114 def articles_of_parent(parent = nil)
115 return [] if self.holder.nil? 115 return [] if self.holder.nil?
116 types = VALID_CONTENT + plugins.dispatch(:content_types).map(&:name) 116 types = VALID_CONTENT + plugins.dispatch(:content_types).map(&:name)
117 - holder.articles.find(:all, :conditions => {:type => types, :parent_id => (parent.nil? ? nil : parent)}) 117 + holder.articles.where(type: types, parent_id: if parent.nil? then nil else parent end)
118 end 118 end
119 119
120 def content(args={}) 120 def content(args={})
plugins/mark_comment_as_read/lib/mark_comment_as_read_plugin/ext/comment.rb
@@ -14,11 +14,11 @@ class Comment @@ -14,11 +14,11 @@ class Comment
14 end 14 end
15 15
16 def marked_as_read?(person) 16 def marked_as_read?(person)
17 - person && people.find(:first, :conditions => {:id => person.id}) 17 + person && people.where(id: person.id).first
18 end 18 end
19 19
20 def self.marked_as_read(person) 20 def self.marked_as_read(person)
21 - find(:all, :joins => [:read_comments], :conditions => {:author_id => person.id}) 21 + joins(:read_comments).where(author_id: person.id)
22 end 22 end
23 23
24 end 24 end
plugins/oauth_client/lib/oauth_client_plugin/provider.rb
@@ -13,7 +13,7 @@ class OauthClientPlugin::Provider &lt; Noosfero::Plugin::ActiveRecord @@ -13,7 +13,7 @@ class OauthClientPlugin::Provider &lt; Noosfero::Plugin::ActiveRecord
13 13
14 attr_accessible :name, :environment, :strategy, :client_id, :client_secret, :enabled, :client_options, :image_builder 14 attr_accessible :name, :environment, :strategy, :client_id, :client_secret, :enabled, :client_options, :image_builder
15 15
16 - scope :enabled, :conditions => {:enabled => true} 16 + scope :enabled, -> { where enabled: true }
17 17
18 acts_as_having_image 18 acts_as_having_image
19 19
plugins/people_block/lib/ext/person.rb
@@ -2,8 +2,9 @@ require_dependency &#39;person&#39; @@ -2,8 +2,9 @@ require_dependency &#39;person&#39;
2 2
3 class Person 3 class Person
4 4
5 - scope :with_role, lambda { |role_id|  
6 - { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ["role_assignments.role_id = #{role_id}"] } 5 + scope :with_role, -> (role_id) {
  6 + select('DISTINCT profiles.*').joins(:role_assignments).
  7 + where("role_assignments.role_id = #{role_id}")
7 } 8 }
8 9
9 end 10 end
plugins/recent_content/lib/recent_content_block.rb
@@ -18,9 +18,8 @@ class RecentContentBlock &lt; Block @@ -18,9 +18,8 @@ class RecentContentBlock &lt; Block
18 end 18 end
19 19
20 def articles_of_folder(folder, limit) 20 def articles_of_folder(folder, limit)
21 - holder.articles.all(:conditions => {:type => VALID_CONTENT, :parent_id => folder.id},  
22 - :order => 'created_at DESC',  
23 - :limit => limit ) 21 + holder.articles.where(type: VALID_CONTENT, parent_id: folder.id).
  22 + order('created_at DESC').limit(limit)
24 end 23 end
25 24
26 def holder 25 def holder
@@ -34,12 +33,12 @@ class RecentContentBlock &lt; Block @@ -34,12 +33,12 @@ class RecentContentBlock &lt; Block
34 end 33 end
35 34
36 def parents 35 def parents
37 - selected = self.holder.articles.all(:conditions => {:type => 'Blog'}) 36 + selected = self.holder.articles.where(type: 'Blog').first
38 end 37 end
39 38
40 def root 39 def root
41 unless self.selected_folder.nil? 40 unless self.selected_folder.nil?
42 - holder.articles.where(:id => self.selected_folder).first 41 + holder.articles.where(id: self.selected_folder).first
43 end 42 end
44 end 43 end
45 44
plugins/relevant_content/lib/ext/article.rb
@@ -2,7 +2,7 @@ require_dependency &#39;article&#39; @@ -2,7 +2,7 @@ require_dependency &#39;article&#39;
2 2
3 class Article 3 class Article
4 4
5 - scope :relevant_content, :conditions => ["articles.published = true and (articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL"] 5 + scope :relevant_content, -> { where "articles.published = true and (articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL" }
6 6
7 def self.articles_columns 7 def self.articles_columns
8 Article.column_names.map {|c| "articles.#{c}"} .join(",") 8 Article.column_names.map {|c| "articles.#{c}"} .join(",")
@@ -10,86 +10,57 @@ class Article @@ -10,86 +10,57 @@ class Article
10 10
11 def self.most_accessed(owner, limit = nil) 11 def self.most_accessed(owner, limit = nil)
12 conditions = owner.kind_of?(Environment) ? ["hits > 0"] : ["profile_id = ? and hits > 0", owner.id] 12 conditions = owner.kind_of?(Environment) ? ["hits > 0"] : ["profile_id = ? and hits > 0", owner.id]
13 - result = Article.relevant_content.find(  
14 - :all,  
15 - :order => 'hits desc',  
16 - :limit => limit,  
17 - :conditions => conditions) 13 + result = Article.relevant_content.order('hits desc').limit(limit).where(conditions)
18 result.paginate({:page => 1, :per_page => limit}) 14 result.paginate({:page => 1, :per_page => limit})
19 end 15 end
20 16
21 def self.most_commented_relevant_content(owner, limit) 17 def self.most_commented_relevant_content(owner, limit)
22 - conditions = owner.kind_of?(Environment) ? ["comments_count > 0"] : ["profile_id = ? and comments_count > 0", owner.id]  
23 - result = Article.relevant_content.find(  
24 - :all,  
25 - :order => 'comments_count desc',  
26 - :limit => limit,  
27 - :conditions => conditions)  
28 - result.paginate({:page => 1, :per_page => limit}) 18 + conditions = owner.kind_of?(Environment) ? ["comments_count > 0"] : ["profile_id = ? and comments_count > 0", owner.id]
  19 + result = Article.relevant_content.all.order('comments_count desc').limit(limit).where(conditions)
  20 + result.paginate({:page => 1, :per_page => limit})
29 end 21 end
30 22
31 def self.more_positive_votes(owner, limit = nil) 23 def self.more_positive_votes(owner, limit = nil)
32 - conditions = owner.kind_of?(Environment) ? {'votes.voteable_type' => 'Article'} : ["profile_id = ? and votes.voteable_type = ? ", owner.id, 'Article']  
33 - result = Article.relevant_content.find(  
34 - :all,  
35 - :order => 'sum(vote) desc',  
36 - :group => 'voteable_id, ' + articles_columns,  
37 - :limit => limit,  
38 - :having => ['sum(vote) > 0'],  
39 - :conditions => conditions,  
40 - :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')  
41 - result.paginate({:page => 1, :per_page => limit}) 24 + conditions = owner.kind_of?(Environment) ? {'votes.voteable_type' => 'Article'} : ["profile_id = ? and votes.voteable_type = ? ", owner.id, 'Article']
  25 + result = Article.relevant_content.
  26 + order('sum(vote) desc').group('voteable_id, ' + articles_columns).
  27 + limit(limit).having('sum(vote) > 0').
  28 + where(conditions).joins('INNER JOIN votes ON articles.id = votes.voteable_id')
  29 + result.paginate({:page => 1, :per_page => limit})
42 end 30 end
43 31
44 def self.more_negative_votes(owner, limit = nil) 32 def self.more_negative_votes(owner, limit = nil)
45 - conditions = owner.kind_of?(Environment) ? {'votes.voteable_type' => 'Article'} : ["profile_id = ? and votes.voteable_type = 'Article' ", owner.id]  
46 - result = Article.relevant_content.find(  
47 - :all,  
48 - :order => 'sum(vote) asc',  
49 - :group => 'voteable_id, ' + articles_columns,  
50 - :limit => limit,  
51 - :having => ['sum(vote) < 0'],  
52 - :conditions => conditions,  
53 - :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id'  
54 - )  
55 - result.paginate({:page => 1, :per_page => limit}) 33 + conditions = owner.kind_of?(Environment) ? {'votes.voteable_type' => 'Article'} : ["profile_id = ? and votes.voteable_type = 'Article' ", owner.id]
  34 + result = Article.relevant_content.
  35 + order('sum(vote) asc').group('voteable_id, ' + articles_columns).
  36 + limit(limit).having('sum(vote) < 0').
  37 + where(conditions).joins('INNER JOIN votes ON articles.id = votes.voteable_id')
  38 + result.paginate({:page => 1, :per_page => limit})
56 end 39 end
57 40
58 def self.most_liked(owner, limit = nil) 41 def self.most_liked(owner, limit = nil)
59 - conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article' and vote > 0"] : ["votes.voteable_type = 'Article' and vote > 0 and profile_id = ? ", owner.id]  
60 - result = Article.relevant_content.find(  
61 - :all,  
62 - :select => articles_columns,  
63 - :order => 'count(voteable_id) desc',  
64 - :group => 'voteable_id, ' + articles_columns,  
65 - :limit => limit,  
66 - :conditions => conditions,  
67 - :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')  
68 - result.paginate({:page => 1, :per_page => limit}) 42 + conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article' and vote > 0"] : ["votes.voteable_type = 'Article' and vote > 0 and profile_id = ? ", owner.id]
  43 + result = Article.relevant_content.
  44 + select(articles_columns).order('count(voteable_id) desc').
  45 + group('voteable_id, ' + articles_columns).limit(limit).
  46 + where(conditions).joins('INNER JOIN votes ON articles.id = votes.voteable_id')
  47 + result.paginate({:page => 1, :per_page => limit})
69 end 48 end
70 49
71 def self.most_disliked(owner, limit = nil) 50 def self.most_disliked(owner, limit = nil)
72 - conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article' and vote < 0"] : ["votes.voteable_type = 'Article' and vote < 0 and profile_id = ? ", owner.id]  
73 - result = Article.relevant_content.find(  
74 - :all,  
75 - :order => 'count(voteable_id) desc',  
76 - :group => 'voteable_id, ' + articles_columns,  
77 - :limit => limit,  
78 - :conditions => conditions,  
79 - :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')  
80 - result.paginate({:page => 1, :per_page => limit}) 51 + conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article' and vote < 0"] : ["votes.voteable_type = 'Article' and vote < 0 and profile_id = ? ", owner.id]
  52 + result = Article.relevant_content.
  53 + order('count(voteable_id) desc').group('voteable_id, ' + articles_columns).
  54 + limit(limit).where(conditions).joins('INNER JOIN votes ON articles.id = votes.voteable_id')
  55 + result.paginate({:page => 1, :per_page => limit})
81 end 56 end
82 57
83 def self.most_voted(owner, limit = nil) 58 def self.most_voted(owner, limit = nil)
84 conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article'"] : ["votes.voteable_type = 'Article' and profile_id = ? ", owner.id] 59 conditions = owner.kind_of?(Environment) ? ["votes.voteable_type = 'Article'"] : ["votes.voteable_type = 'Article' and profile_id = ? ", owner.id]
85 - result = Article.relevant_content.find(  
86 - :all,  
87 - :select => articles_columns,  
88 - :order => 'count(voteable_id) desc',  
89 - :group => 'voteable_id, ' + articles_columns,  
90 - :limit => limit,  
91 - :conditions => conditions,  
92 - :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id')  
93 - result.paginate({:page => 1, :per_page => limit}) 60 + result = Article.relevant_content.
  61 + select(articles_columns).order('count(voteable_id) desc').
  62 + group('voteable_id, ' + articles_columns).limit(limit).
  63 + where(conditions).joins('INNER JOIN votes ON articles.id = votes.voteable_id')
  64 + result.paginate({:page => 1, :per_page => limit})
94 end 65 end
95 end 66 end
plugins/shopping_cart/controllers/shopping_cart_plugin_myprofile_controller.rb
@@ -28,7 +28,7 @@ class ShoppingCartPluginMyprofileController &lt; MyProfileController @@ -28,7 +28,7 @@ class ShoppingCartPluginMyprofileController &lt; MyProfileController
28 end 28 end
29 29
30 conditions = [condition] + condition_parameters 30 conditions = [condition] + condition_parameters
31 - @orders = profile.orders.find(:all, :conditions => conditions) 31 + @orders = profile.orders.where(conditions)
32 32
33 @products = {} 33 @products = {}
34 @orders.each do |order| 34 @orders.each do |order|
plugins/spaminator/lib/spaminator_plugin/report.rb
@@ -7,7 +7,7 @@ class SpaminatorPlugin::Report &lt; Noosfero::Plugin::ActiveRecord @@ -7,7 +7,7 @@ class SpaminatorPlugin::Report &lt; Noosfero::Plugin::ActiveRecord
7 7
8 attr_accessible :environment 8 attr_accessible :environment
9 9
10 - scope :from_environment, lambda { |environment| {:conditions => {:environment_id => environment}}} 10 + scope :from_environment, -> (environment) { where :environment_id => environment }
11 11
12 after_initialize do |report| 12 after_initialize do |report|
13 report.failed = {:people => [], :comments => []} if report.failed.blank? 13 report.failed = {:people => [], :comments => []} if report.failed.blank?
plugins/statistics/lib/statistics_block.rb
@@ -69,7 +69,7 @@ class StatisticsBlock &lt; Block @@ -69,7 +69,7 @@ class StatisticsBlock &lt; Block
69 end 69 end
70 70
71 def template_counter_count(template_id) 71 def template_counter_count(template_id)
72 - owner.communities.visible.count(:conditions => {:template_id => template_id}) 72 + owner.communities.visible.where(template_id: template_id).count
73 end 73 end
74 74
75 def users 75 def users
plugins/stoa/lib/ext/person.rb
@@ -20,7 +20,7 @@ class Person @@ -20,7 +20,7 @@ class Person
20 end 20 end
21 21
22 def invitation_task 22 def invitation_task
23 - Task.pending.find(:first, :conditions => {:code => invitation_code.to_s}) ||  
24 - Task.finished.find(:first, :conditions => {:code => invitation_code.to_s, :target_id => id}) 23 + Task.pending.where(code: invitation_code.to_s).first or
  24 + Task.finished.where(code: invitation_code.to_s, target_id: id).first
25 end 25 end
26 end 26 end
plugins/stoa/lib/stoa_plugin.rb
@@ -63,7 +63,7 @@ class StoaPlugin &lt; Noosfero::Plugin @@ -63,7 +63,7 @@ class StoaPlugin &lt; Noosfero::Plugin
63 block = proc do 63 block = proc do
64 params[:profile_data] ||= {} 64 params[:profile_data] ||= {}
65 params[:profile_data][:invitation_code] = params[:invitation_code] 65 params[:profile_data][:invitation_code] = params[:invitation_code]
66 - invitation = Task.pending.find(:first, :conditions => {:code => params[:invitation_code]}) 66 + invitation = Task.pending.where(code: params[:invitation_code]).first
67 if request.post? 67 if request.post?
68 if !invitation && !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[params[:confirmation_field]]) 68 if !invitation && !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[params[:confirmation_field]])
69 # `self` below is evaluated in the context of account_controller 69 # `self` below is evaluated in the context of account_controller
plugins/sub_organizations/controllers/sub_organizations_plugin_myprofile_controller.rb
@@ -32,11 +32,12 @@ class SubOrganizationsPluginMyprofileController &lt; MyProfileController @@ -32,11 +32,12 @@ class SubOrganizationsPluginMyprofileController &lt; MyProfileController
32 end 32 end
33 33
34 def search_organization 34 def search_organization
35 - render :text => prepare_to_token_input(environment.organizations.find(:all, :conditions =>  
36 - ["(LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?) 35 + render :text => prepare_to_token_input(
  36 + environment.organizations.where(
  37 + "(LOWER(name) LIKE ? OR LOWER(identifier) LIKE ?)
37 AND (identifier NOT LIKE ?) AND (id != ?)", 38 AND (identifier NOT LIKE ?) AND (id != ?)",
38 - "%#{params[:q]}%", "%#{params[:q]}%", "%_template", profile.id]).  
39 - select { |organization| 39 + "%#{params[:q]}%", "%#{params[:q]}%", "%_template", profile.id).
  40 + select{ |organization|
40 Organization.children(organization).blank? && 41 Organization.children(organization).blank? &&
41 !Organization.pending_children(profile).include?(organization) 42 !Organization.pending_children(profile).include?(organization)
42 }).to_json 43 }).to_json
plugins/sub_organizations/lib/ext/organization.rb
@@ -13,26 +13,20 @@ class Organization @@ -13,26 +13,20 @@ class Organization
13 13
14 FIELDS << 'sub_organizations_plugin_parent_to_be' 14 FIELDS << 'sub_organizations_plugin_parent_to_be'
15 15
16 - scope :children, lambda { |parent|  
17 - options = {  
18 - :joins => "inner join sub_organizations_plugin_relations as relations on profiles.id=relations.child_id",  
19 - :conditions => ["relations.parent_id = ?", parent.id]  
20 - } 16 + scope :children, -> (parent) {
  17 + joins("inner join sub_organizations_plugin_relations as relations on profiles.id=relations.child_id").
  18 + where("relations.parent_id = ?", parent.id)
21 } 19 }
22 20
23 - scope :parents, lambda { |*children|  
24 - options = {  
25 - :joins => "inner join sub_organizations_plugin_relations as relations on profiles.id=relations.parent_id",  
26 - :conditions => ["relations.child_id in (?)", children.map(&:id)]  
27 - } 21 + scope :parents, -> (*children) {
  22 + joins("inner join sub_organizations_plugin_relations as relations on profiles.id=relations.parent_id").
  23 + where("relations.child_id in (?)", children.map(&:id))
28 } 24 }
29 25
30 - scope :pending_children, lambda { |parent|  
31 - options = {  
32 - :select => "distinct profiles.*",  
33 - :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",  
34 - :conditions => ["relations.parent_id = ? AND tasks.status = 1", parent.id]  
35 - } 26 + scope :pending_children, -> (parent) {
  27 + select("distinct profiles.*").
  28 + 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").
  29 + where("relations.parent_id = ? AND tasks.status = 1", parent.id)
36 } 30 }
37 31
38 end 32 end
plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
@@ -16,13 +16,13 @@ def edit_visibility @@ -16,13 +16,13 @@ def edit_visibility
16 end 16 end
17 folder.save! 17 folder.save!
18 redirect_to @back_to 18 redirect_to @back_to
19 - end 19 + end
20 end 20 end
21 end 21 end
22 22
23 def search_article_privacy_exceptions 23 def search_article_privacy_exceptions
24 arg = params[:q].downcase 24 arg = params[:q].downcase
25 - result = profile.members.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) 25 + result = profile.members.where('LOWER(name) LIKE ?', "%#{arg}%")
26 render :text => prepare_to_token_input(result).to_json 26 render :text => prepare_to_token_input(result).to_json
27 end 27 end
28 28
script/apply-template
@@ -30,7 +30,7 @@ when &#39;inactive-enterprise&#39; @@ -30,7 +30,7 @@ when &#39;inactive-enterprise&#39;
30 excluded = [env.inactive_enterprise_template, env.enterprise_template] 30 excluded = [env.inactive_enterprise_template, env.enterprise_template]
31 template = excluded.first 31 template = excluded.first
32 32
33 - while enterprise = Enterprise.find(:first, :conditions => {:enabled => false}, :order => :id, :offset => offset) 33 + while enterprise = Enterprise.where(enabled: false).order(:id).offset(offset)
34 # do nothing with templates 34 # do nothing with templates
35 next if excluded.include?(enterprise) 35 next if excluded.include?(enterprise)
36 36
@@ -42,7 +42,7 @@ when &#39;inactive-enterprise&#39; @@ -42,7 +42,7 @@ when &#39;inactive-enterprise&#39;
42 offset = offset + 1 42 offset = offset + 1
43 end 43 end
44 when 'active-enterprise' 44 when 'active-enterprise'
45 - active_enterprises = Enterprise.find(:all, :conditions => {:enabled => true}) - [env.enterprise_template, env.enterprise_template] 45 + active_enterprises = Enterprise.where(enabled: true).all - [env.enterprise_template, env.enterprise_template]
46 active_enterprises.each do |enterprise| 46 active_enterprises.each do |enterprise|
47 old_home = enterprise.home_page 47 old_home = enterprise.home_page
48 enterprise.apply_template(env.enterprise_template) 48 enterprise.apply_template(env.enterprise_template)
@@ -53,7 +53,7 @@ when &#39;community&#39; @@ -53,7 +53,7 @@ when &#39;community&#39;
53 excluded = ['espaco', 'anarquismo'] 53 excluded = ['espaco', 'anarquismo']
54 template = env.community_template 54 template = env.community_template
55 offset = 0 55 offset = 0
56 - while community = Community.find(:first, :order => :id, :offset => offset) 56 + while community = Community.order(:id).offset(offset)
57 if community != template && !excluded.include?(community.identifier) 57 if community != template && !excluded.include?(community.identifier)
58 report_doing offset, community.name 58 report_doing offset, community.name
59 community.apply_template(template) 59 community.apply_template(template)
script/sample-enterprises
@@ -44,7 +44,7 @@ groups.each do |group| @@ -44,7 +44,7 @@ groups.each do |group|
44 end 44 end
45 done 45 done
46 46
47 -EnterpriseActivation.find(:all, :conditions => ['created_at > ?', start_time]).each do |activation| 47 +EnterpriseActivation.where('created_at > ?', start_time).each do |activation|
48 enterprise = activation.enterprise 48 enterprise = activation.enterprise
49 end 49 end
50 50
script/sample-profiles
@@ -104,7 +104,7 @@ save guest @@ -104,7 +104,7 @@ save guest
104 done 104 done
105 105
106 print "Activating users: " 106 print "Activating users: "
107 -User.all(:conditions => ["login NOT LIKE '%%_template'"]).each do |user| 107 +User.where("login NOT LIKE '%%_template'").each do |user|
108 user.activate 108 user.activate
109 print '.' 109 print '.'
110 end 110 end
test/unit/article_categorization_test.rb
@@ -87,7 +87,7 @@ class ArticleCategorizationTest &lt; ActiveSupport::TestCase @@ -87,7 +87,7 @@ class ArticleCategorizationTest &lt; ActiveSupport::TestCase
87 ArticleCategorization.add_category_to_article(c2, a) 87 ArticleCategorization.add_category_to_article(c2, a)
88 ArticleCategorization.add_category_to_article(c1, a) 88 ArticleCategorization.add_category_to_article(c1, a)
89 89
90 - assert ArticleCategorization.find(:first, :conditions => [ 'category_id = ? and article_id = ? and not virtual', c1.id, a.id ]), 'categorization must be promoted to not virtual' 90 + assert ArticleCategorization.where('category_id = ? and article_id = ? and not virtual', c1.id, a.id).first, 'categorization must be promoted to not virtual'
91 end 91 end
92 92
93 private 93 private
test/unit/person_test.rb
@@ -1006,9 +1006,9 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1006,9 +1006,9 @@ class PersonTest &lt; ActiveSupport::TestCase
1006 p = create_user('test_user').person 1006 p = create_user('test_user').person
1007 c = fast_create(Community, :name => "Foo") 1007 c = fast_create(Community, :name => "Foo")
1008 c.add_member(p) 1008 c.add_member(p)
1009 - assert_equal ["Foo"], ActionTracker::Record.last(:conditions => {:verb => 'join_community'}).get_resource_name 1009 + assert_equal ["Foo"], ActionTracker::Record.where(verb: 'join_community').last.get_resource_name
1010 c.reload.add_moderator(p.reload) 1010 c.reload.add_moderator(p.reload)
1011 - assert_equal ["Foo"], ActionTracker::Record.last(:conditions => {:verb => 'join_community'}).get_resource_name 1011 + assert_equal ["Foo"], ActionTracker::Record.where(verb: 'join_community').last.get_resource_name
1012 end 1012 end
1013 1013
1014 should 'the tracker target be Community when a person joins a community' do 1014 should 'the tracker target be Community when a person joins a community' do
@@ -1016,7 +1016,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1016,7 +1016,7 @@ class PersonTest &lt; ActiveSupport::TestCase
1016 p = create_user('test_user').person 1016 p = create_user('test_user').person
1017 c = fast_create(Community, :name => "Foo") 1017 c = fast_create(Community, :name => "Foo")
1018 c.add_member(p) 1018 c.add_member(p)
1019 - assert_kind_of Community, ActionTracker::Record.last(:conditions => {:verb => 'join_community'}).target 1019 + assert_kind_of Community, ActionTracker::Record.where(verb: 'join_community').last.target
1020 end 1020 end
1021 1021
1022 should 'the community be notified specifically when a person joins a community' do 1022 should 'the community be notified specifically when a person joins a community' do
@@ -1024,7 +1024,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1024,7 +1024,7 @@ class PersonTest &lt; ActiveSupport::TestCase
1024 p = create_user('test_user').person 1024 p = create_user('test_user').person
1025 c = fast_create(Community, :name => "Foo") 1025 c = fast_create(Community, :name => "Foo")
1026 c.add_member(p) 1026 c.add_member(p)
1027 - assert_not_nil ActionTracker::Record.last(:conditions => {:verb => 'add_member_in_community'}) 1027 + assert_not_nil ActionTracker::Record.where(verb: 'add_member_in_community').last
1028 end 1028 end
1029 1029
1030 should 'the community specific notification created when a member joins community could not be propagated to members' do 1030 should 'the community specific notification created when a member joins community could not be propagated to members' do
test/unit/profile_test.rb
@@ -448,7 +448,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -448,7 +448,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
448 p1 = create(Profile, :public_profile => true) 448 p1 = create(Profile, :public_profile => true)
449 p2 = create(Profile, :public_profile => false) 449 p2 = create(Profile, :public_profile => false)
450 450
451 - result = Profile.find(:all, :conditions => {:public_profile => true}) 451 + result = Profile.where(public_profile: true).all
452 assert_includes result, p1 452 assert_includes result, p1
453 assert_not_includes result, p2 453 assert_not_includes result, p2
454 end 454 end
test/unit/suggest_article_test.rb
@@ -81,7 +81,7 @@ class SuggestArticleTest &lt; ActiveSupport::TestCase @@ -81,7 +81,7 @@ class SuggestArticleTest &lt; ActiveSupport::TestCase
81 t.article[:highlighted] = true 81 t.article[:highlighted] = true
82 t.perform 82 t.perform
83 83
84 - article = TinyMceArticle.last(:conditions => { :name => t.article_name}) # just to be sure 84 + article = TinyMceArticle.where(name: t.article_name).last # just to be sure
85 assert article.highlighted 85 assert article.highlighted
86 end 86 end
87 87
@@ -89,7 +89,7 @@ class SuggestArticleTest &lt; ActiveSupport::TestCase @@ -89,7 +89,7 @@ class SuggestArticleTest &lt; ActiveSupport::TestCase
89 t = build(SuggestArticle, :target => @profile) 89 t = build(SuggestArticle, :target => @profile)
90 t.perform 90 t.perform
91 91
92 - article = TinyMceArticle.last(:conditions => { :name => t.article_name}) 92 + article = TinyMceArticle.where(name: t.article_name).last
93 assert_equal false, article.highlighted 93 assert_equal false, article.highlighted
94 end 94 end
95 95
test/unit/uploaded_file_test.rb
@@ -229,7 +229,7 @@ class UploadedFileTest &lt; ActiveSupport::TestCase @@ -229,7 +229,7 @@ class UploadedFileTest &lt; ActiveSupport::TestCase
229 should 'track action when a published image is uploaded in a gallery' do 229 should 'track action when a published image is uploaded in a gallery' do
230 p = fast_create(Gallery, :profile_id => @profile.id) 230 p = fast_create(Gallery, :profile_id => @profile.id)
231 f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile) 231 f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile)
232 - ta = ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) 232 + ta = ActionTracker::Record.where(verb: "upload_image").last
233 assert_kind_of String, ta.get_thumbnail_path[0] 233 assert_kind_of String, ta.get_thumbnail_path[0]
234 assert_equal [f.reload.view_url], ta.get_view_url 234 assert_equal [f.reload.view_url], ta.get_view_url
235 assert_equal [p.reload.url], ta.get_parent_url 235 assert_equal [p.reload.url], ta.get_parent_url
@@ -240,26 +240,26 @@ class UploadedFileTest &lt; ActiveSupport::TestCase @@ -240,26 +240,26 @@ class UploadedFileTest &lt; ActiveSupport::TestCase
240 ActionTracker::Record.delete_all 240 ActionTracker::Record.delete_all
241 p = fast_create(Gallery, :profile_id => @profile.id) 241 p = fast_create(Gallery, :profile_id => @profile.id)
242 f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :parent => p, :profile => @profile) 242 f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :parent => p, :profile => @profile)
243 - assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) 243 + assert_nil ActionTracker::Record.where(verb: "upload_image").last
244 end 244 end
245 245
246 should 'not track action when has no parent' do 246 should 'not track action when has no parent' do
247 f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => nil, :profile => @profile) 247 f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => nil, :profile => @profile)
248 - assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) 248 + assert_nil ActionTracker::Record.where(verb: "upload_image").last
249 end 249 end
250 250
251 should 'not track action when is not published' do 251 should 'not track action when is not published' do
252 ActionTracker::Record.delete_all 252 ActionTracker::Record.delete_all
253 p = fast_create(Gallery, :profile_id => @profile.id) 253 p = fast_create(Gallery, :profile_id => @profile.id)
254 f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile, :published => false) 254 f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile, :published => false)
255 - assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) 255 + assert_nil ActionTracker::Record.where(verb: "upload_image").last
256 end 256 end
257 257
258 should 'not track action when parent is not gallery' do 258 should 'not track action when parent is not gallery' do
259 ActionTracker::Record.delete_all 259 ActionTracker::Record.delete_all
260 p = fast_create(Folder, :profile_id => @profile.id) 260 p = fast_create(Folder, :profile_id => @profile.id)
261 f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile) 261 f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile)
262 - assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) 262 + assert_nil ActionTracker::Record.where(verb: "upload_image").last
263 end 263 end
264 264
265 should 'not crash if first paragraph called' do 265 should 'not crash if first paragraph called' do
vendor/plugins/access_control/lib/acts_as_accessor.rb
@@ -15,7 +15,7 @@ module ActsAsAccessor @@ -15,7 +15,7 @@ module ActsAsAccessor
15 15
16 def define_roles(roles, resource) 16 def define_roles(roles, resource)
17 roles = [roles] unless roles.kind_of?(Array) 17 roles = [roles] unless roles.kind_of?(Array)
18 - actual_roles = RoleAssignment.find( :all, :conditions => role_attributes(nil, resource) ).map(&:role) 18 + actual_roles = RoleAssignment.where(role_attributes nil, resource).map(&:role)
19 19
20 (roles - actual_roles).each {|r| add_role(r, resource) } 20 (roles - actual_roles).each {|r| add_role(r, resource) }
21 (actual_roles - roles).each {|r| remove_role(r, resource)} 21 (actual_roles - roles).each {|r| remove_role(r, resource)}
@@ -23,7 +23,7 @@ module ActsAsAccessor @@ -23,7 +23,7 @@ module ActsAsAccessor
23 23
24 def add_role(role, resource) 24 def add_role(role, resource)
25 attributes = role_attributes(role, resource) 25 attributes = role_attributes(role, resource)
26 - if RoleAssignment.find(:all, :conditions => attributes).empty? 26 + if RoleAssignment.where(attributes).empty?
27 ra = RoleAssignment.new(attributes) 27 ra = RoleAssignment.new(attributes)
28 role_assignments << ra 28 role_assignments << ra
29 resource.role_assignments << ra 29 resource.role_assignments << ra
@@ -35,13 +35,13 @@ module ActsAsAccessor @@ -35,13 +35,13 @@ module ActsAsAccessor
35 35
36 def remove_role(role, resource) 36 def remove_role(role, resource)
37 return unless role 37 return unless role
38 - roles_destroy = RoleAssignment.find(:all, :conditions => role_attributes(role, resource)) 38 + roles_destroy = RoleAssignment.where(role_attributes role, resource)
39 return if roles_destroy.empty? 39 return if roles_destroy.empty?
40 roles_destroy.map(&:destroy).all? 40 roles_destroy.map(&:destroy).all?
41 end 41 end
42 42
43 def find_roles(res) 43 def find_roles(res)
44 - RoleAssignment.find(:all, :conditions => role_attributes(nil, res)) 44 + RoleAssignment.where(role_attributes nil, res)
45 end 45 end
46 46
47 protected 47 protected
@@ -55,10 +55,10 @@ module ActsAsAccessor @@ -55,10 +55,10 @@ module ActsAsAccessor
55 resource = nil 55 resource = nil
56 end 56 end
57 if resource 57 if resource
58 - attributes[:resource_id] = resource.id 58 + attributes[:resource_id] = resource.id
59 attributes[:resource_type] = resource.class.base_class.name 59 attributes[:resource_type] = resource.class.base_class.name
60 else 60 else
61 - attributes[:resource_id] = nil 61 + attributes[:resource_id] = nil
62 attributes[:resource_type] = nil 62 attributes[:resource_type] = nil
63 end 63 end
64 attributes 64 attributes
vendor/plugins/access_control/lib/role_assignment.rb
@@ -7,11 +7,15 @@ class RoleAssignment &lt; ActiveRecord::Base @@ -7,11 +7,15 @@ class RoleAssignment &lt; ActiveRecord::Base
7 belongs_to :resource, :polymorphic => true 7 belongs_to :resource, :polymorphic => true
8 8
9 validates_presence_of :role, :accessor 9 validates_presence_of :role, :accessor
10 -  
11 - 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  
12 -  
13 - 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  
14 - 10 +
  11 + track_actions :join_community, :after_create, :keep_params => ["resource.name", "resource.url", "resource.profile_custom_icon"],
  12 + if: -> (x) { x.resource.is_a?(Community) && x.accessor.role_assignments.where(resource_id: x.resource.id, resource_type: 'Profile').count == 1 },
  13 + :custom_user => :accessor, :custom_target => :resource
  14 +
  15 + track_actions :add_member_in_community, :after_create,
  16 + if: -> (x) { x.resource.is_a?(Community) && x.accessor.role_assignments.where(resource_id: x.resource.id, resource_type: 'Profile').count == 1 },
  17 + :custom_user => :accessor, :custom_target => :resource
  18 +
15 def has_permission?(perm, res) 19 def has_permission?(perm, res)
16 return false unless role.has_permission?(perm.to_s) && (resource || is_global) 20 return false unless role.has_permission?(perm.to_s) && (resource || is_global)
17 return true if is_global 21 return true if is_global
vendor/plugins/action_tracker/lib/action_tracker.rb
@@ -83,7 +83,7 @@ module ActionTracker @@ -83,7 +83,7 @@ module ActionTracker
83 module InstanceMethods 83 module InstanceMethods
84 def time_spent_doing(verb, conditions = {}) 84 def time_spent_doing(verb, conditions = {})
85 time = 0 85 time = 0
86 - tracked_actions.all(:conditions => conditions.merge({ :verb => verb.to_s })).each do |t| 86 + tracked_actions.where(conditions.merge verb: verb.to_s).each do |t|
87 time += t.updated_at - t.created_at 87 time += t.updated_at - t.created_at
88 end 88 end
89 time.to_f 89 time.to_f
vendor/plugins/action_tracker/lib/action_tracker_model.rb
@@ -24,8 +24,8 @@ module ActionTracker @@ -24,8 +24,8 @@ module ActionTracker
24 # In days 24 # In days
25 RECENT_DELAY = 30 25 RECENT_DELAY = 30
26 26
27 - scope :recent, :conditions => ['created_at >= ?', RECENT_DELAY.days.ago]  
28 - scope :visible, :conditions => { :visible => true } 27 + scope :recent, -> { where 'created_at >= ?', RECENT_DELAY.days.ago }
  28 + scope :visible, -> { where visible: true }
29 29
30 def self.current_user_from_model 30 def self.current_user_from_model
31 u = new 31 u = new
@@ -38,7 +38,7 @@ module ActionTracker @@ -38,7 +38,7 @@ module ActionTracker
38 return if u.nil? 38 return if u.nil?
39 target_hash = params[:target].nil? ? {} : {:target_type => params[:target].class.base_class.to_s, :target_id => params[:target].id} 39 target_hash = params[:target].nil? ? {} : {:target_type => params[:target].class.base_class.to_s, :target_id => params[:target].id}
40 conditions = { :user_id => u.id, :user_type => u.class.base_class.to_s, :verb => params[:verb].to_s }.merge(target_hash) 40 conditions = { :user_id => u.id, :user_type => u.class.base_class.to_s, :verb => params[:verb].to_s }.merge(target_hash)
41 - l = last :conditions => conditions 41 + l = where(conditions).last
42 ( !l.nil? and Time.now - l.updated_at < ActionTrackerConfig.timeout ) ? l.update_attributes(params.merge({ :updated_at => Time.now })) : l = new(params) 42 ( !l.nil? and Time.now - l.updated_at < ActionTrackerConfig.timeout ) ? l.update_attributes(params.merge({ :updated_at => Time.now })) : l = new(params)
43 l 43 l
44 end 44 end
@@ -47,7 +47,7 @@ module ActionTracker @@ -47,7 +47,7 @@ module ActionTracker
47 u = params[:user] || current_user_from_model 47 u = params[:user] || current_user_from_model
48 return if u.nil? 48 return if u.nil?
49 target_hash = params[:target].nil? ? {} : {:target_type => params[:target].class.base_class.to_s, :target_id => params[:target].id} 49 target_hash = params[:target].nil? ? {} : {:target_type => params[:target].class.base_class.to_s, :target_id => params[:target].id}
50 - l = last :conditions => { :user_id => u.id, :user_type => u.class.base_class.to_s, :verb => params[:verb].to_s }.merge(target_hash) 50 + l = where({user_id: u.id, user_type: u.class.base_class.to_s, verb: params[:verb].to_s}.merge target_hash).last
51 if !l.nil? and Time.now - l.created_at < ActionTrackerConfig.timeout 51 if !l.nil? and Time.now - l.created_at < ActionTrackerConfig.timeout
52 params[:params].clone.each { |key, value| params[:params][key] = l.params[key].clone.push(value) } 52 params[:params].clone.each { |key, value| params[:params][key] = l.params[key].clone.push(value) }
53 l.update_attributes params 53 l.update_attributes params
@@ -61,7 +61,7 @@ module ActionTracker @@ -61,7 +61,7 @@ module ActionTracker
61 def self.time_spent(conditions = {}) # In seconds 61 def self.time_spent(conditions = {}) # In seconds
62 #FIXME Better if it could be completely done in the database, but SQLite does not support difference between two timestamps 62 #FIXME Better if it could be completely done in the database, but SQLite does not support difference between two timestamps
63 time = 0 63 time = 0
64 - all(:conditions => conditions).each { |action| time += action.updated_at - action.created_at } 64 + self.where(conditions).each{ |action| time += action.updated_at - action.created_at }
65 time.to_f 65 time.to_f
66 end 66 end
67 67
vendor/plugins/acts_as_list/lib/active_record/acts/list.rb
@@ -159,17 +159,13 @@ module ActiveRecord @@ -159,17 +159,13 @@ module ActiveRecord
159 # Return the next higher item in the list. 159 # Return the next higher item in the list.
160 def higher_item 160 def higher_item
161 return nil unless in_list? 161 return nil unless in_list?
162 - acts_as_list_class.find(:first, :conditions =>  
163 - "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}"  
164 - ) 162 + acts_as_list_class.where("#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}").first
165 end 163 end
166 164
167 # Return the next lower item in the list. 165 # Return the next lower item in the list.
168 def lower_item 166 def lower_item
169 return nil unless in_list? 167 return nil unless in_list?
170 - acts_as_list_class.find(:first, :conditions =>  
171 - "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}"  
172 - ) 168 + acts_as_list_class.where("#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}").first
173 end 169 end
174 170
175 # Test if this record is in a list 171 # Test if this record is in a list
@@ -200,7 +196,7 @@ module ActiveRecord @@ -200,7 +196,7 @@ module ActiveRecord
200 def bottom_item(except = nil) 196 def bottom_item(except = nil)
201 conditions = scope_condition 197 conditions = scope_condition
202 conditions = "#{conditions} AND #{self.class.primary_key} != #{except.id}" if except 198 conditions = "#{conditions} AND #{self.class.primary_key} != #{except.id}" if except
203 - acts_as_list_class.find(:first, :conditions => conditions, :order => "#{position_column} DESC") 199 + acts_as_list_class.where(conditions).order("#{position_column} DESC").first
204 end 200 end
205 201
206 # Forces item to assume the bottom position in the list. 202 # Forces item to assume the bottom position in the list.
vendor/plugins/acts_as_versioned/lib/acts_as_versioned.rb
1 # Copyright (c) 2005 Rick Olson 1 # Copyright (c) 2005 Rick Olson
2 -# 2 +#
3 # Permission is hereby granted, free of charge, to any person obtaining 3 # Permission is hereby granted, free of charge, to any person obtaining
4 # a copy of this software and associated documentation files (the 4 # a copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including 5 # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@ @@ -7,10 +7,10 @@
7 # distribute, sublicense, and/or sell copies of the Software, and to 7 # distribute, sublicense, and/or sell copies of the Software, and to
8 # permit persons to whom the Software is furnished to do so, subject to 8 # permit persons to whom the Software is furnished to do so, subject to
9 # the following conditions: 9 # the following conditions:
10 -# 10 +#
11 # The above copyright notice and this permission notice shall be 11 # The above copyright notice and this permission notice shall be
12 # included in all copies or substantial portions of the Software. 12 # included in all copies or substantial portions of the Software.
13 -# 13 +#
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 15 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 16 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -22,7 +22,7 @@ require &#39;active_support/concern&#39; @@ -22,7 +22,7 @@ require &#39;active_support/concern&#39;
22 22
23 module ActiveRecord #:nodoc: 23 module ActiveRecord #:nodoc:
24 module Acts #:nodoc: 24 module Acts #:nodoc:
25 - # Specify this act if you want to save a copy of the row in a versioned table. This assumes there is a 25 + # Specify this act if you want to save a copy of the row in a versioned table. This assumes there is a
26 # versioned table ready and that your model has a version field. This works with optimistic locking if the lock_version 26 # versioned table ready and that your model has a version field. This works with optimistic locking if the lock_version
27 # column is present as well. 27 # column is present as well.
28 # 28 #
@@ -56,7 +56,7 @@ module ActiveRecord #:nodoc: @@ -56,7 +56,7 @@ module ActiveRecord #:nodoc:
56 # 56 #
57 # Simple Queries to page between versions 57 # Simple Queries to page between versions
58 # 58 #
59 - # page.versions.before(version) 59 + # page.versions.before(version)
60 # page.versions.after(version) 60 # page.versions.after(version)
61 # 61 #
62 # Access the previous/next versions from the versioned model itself 62 # Access the previous/next versions from the versioned model itself
@@ -264,7 +264,7 @@ module ActiveRecord #:nodoc: @@ -264,7 +264,7 @@ module ActiveRecord #:nodoc:
264 included do 264 included do
265 has_many :versions, self.version_association_options 265 has_many :versions, self.version_association_options
266 266
267 - before_save :set_new_version 267 + #before_save :set_new_version
268 after_save :save_version 268 after_save :save_version
269 after_save :clear_old_versions 269 after_save :clear_old_versions
270 end 270 end
@@ -345,7 +345,7 @@ module ActiveRecord #:nodoc: @@ -345,7 +345,7 @@ module ActiveRecord #:nodoc:
345 new_model.send("#{sym}=", orig_model[orig_model.class.inheritance_column]) if orig_model[orig_model.class.inheritance_column] 345 new_model.send("#{sym}=", orig_model[orig_model.class.inheritance_column]) if orig_model[orig_model.class.inheritance_column]
346 end 346 end
347 end 347 end
348 - 348 +
349 def define_method(object, method) 349 def define_method(object, method)
350 return if object.methods.include? method 350 return if object.methods.include? method
351 metaclass = class << object; self; end 351 metaclass = class << object; self; end