Commit 9f4a8f6a426af39c1dd5ce6c7ca847ee6f7e47f9

Authored by Braulio Bhavamitra
1 parent fcf8fd0f

Drop deprecated finders

Showing 234 changed files with 890 additions and 932 deletions   Show diff stats
@@ -52,7 +52,6 @@ gem 'protected_attributes' @@ -52,7 +52,6 @@ gem 'protected_attributes'
52 gem 'rails-observers' 52 gem 'rails-observers'
53 gem 'actionpack-page_caching' 53 gem 'actionpack-page_caching'
54 gem 'actionpack-action_caching' 54 gem 'actionpack-action_caching'
55 -gem 'activerecord-deprecated_finders', require: 'active_record/deprecated_finders'  
56 55
57 group :production do 56 group :production do
58 gem 'dalli', '~> 2.7.0' 57 gem 'dalli', '~> 2.7.0'
app/controllers/admin/admin_panel_controller.rb
@@ -34,7 +34,7 @@ class AdminPanelController < AdminController @@ -34,7 +34,7 @@ class AdminPanelController < AdminController
34 env = environment 34 env = environment
35 @portal_community = env.portal_community || Community.new 35 @portal_community = env.portal_community || Community.new
36 if request.post? 36 if request.post?
37 - portal_community = env.communities.find_by_identifier(params[:portal_community_identifier]) 37 + portal_community = env.communities.where(identifier: params[:portal_community_identifier]).first
38 if portal_community 38 if portal_community
39 if (env.portal_community != portal_community) 39 if (env.portal_community != portal_community)
40 env.portal_community = portal_community 40 env.portal_community = portal_community
app/controllers/admin/environment_role_manager_controller.rb
@@ -7,7 +7,7 @@ class EnvironmentRoleManagerController < AdminController @@ -7,7 +7,7 @@ class EnvironmentRoleManagerController < AdminController
7 7
8 def change_roles 8 def change_roles
9 @admin = Person.find(params[:id]) 9 @admin = Person.find(params[:id])
10 - @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } 10 + @roles = Role.all.select{ |r| r.has_kind?(:environment) }
11 end 11 end
12 12
13 def update_roles 13 def update_roles
@@ -22,7 +22,7 @@ class EnvironmentRoleManagerController < AdminController @@ -22,7 +22,7 @@ class EnvironmentRoleManagerController < AdminController
22 end 22 end
23 23
24 def change_role 24 def change_role
25 - @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } 25 + @roles = Role.all.select{ |r| r.has_kind?(:environment) }
26 @admin = Person.find(params[:id]) 26 @admin = Person.find(params[:id])
27 @associations = @admin.find_roles(environment) 27 @associations = @admin.find_roles(environment)
28 end 28 end
@@ -34,7 +34,7 @@ class EnvironmentRoleManagerController < AdminController @@ -34,7 +34,7 @@ class EnvironmentRoleManagerController < AdminController
34 redirect_to :action => 'index' 34 redirect_to :action => 'index'
35 else 35 else
36 @admin = Person.find(params[:person]) 36 @admin = Person.find(params[:person])
37 - @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } 37 + @roles = Role.all.select{ |r| r.has_kind?(:environment) }
38 render :action => 'affiliate' 38 render :action => 'affiliate'
39 end 39 end
40 end 40 end
@@ -60,7 +60,7 @@ class EnvironmentRoleManagerController < AdminController @@ -60,7 +60,7 @@ class EnvironmentRoleManagerController < AdminController
60 end 60 end
61 61
62 def make_admin 62 def make_admin
63 - @people = Person.find(:all)  
64 - @roles = Role.find(:all).select{|r|r.has_kind?(:environment)} 63 + @people = Person.all
  64 + @roles = Role.all.select{|r|r.has_kind?(:environment)}
65 end 65 end
66 end 66 end
app/controllers/admin/features_controller.rb
@@ -60,7 +60,7 @@ class FeaturesController < AdminController @@ -60,7 +60,7 @@ class FeaturesController < AdminController
60 CustomField.destroy(custom_fields_to_destroy) 60 CustomField.destroy(custom_fields_to_destroy)
61 61
62 custom_field_list.each_pair do |id, custom_field| 62 custom_field_list.each_pair do |id, custom_field|
63 - field = CustomField.find_by_id(id) 63 + field = CustomField.find_by(id: id)
64 if not field.blank? 64 if not field.blank?
65 params_to_update = custom_field.except(:format, :extras, :customized_type,:environment) 65 params_to_update = custom_field.except(:format, :extras, :customized_type,:environment)
66 field.update_attributes(params_to_update) 66 field.update_attributes(params_to_update)
app/controllers/admin/role_controller.rb
@@ -2,7 +2,7 @@ class RoleController < AdminController @@ -2,7 +2,7 @@ class RoleController < AdminController
2 protect 'manage_environment_roles', :environment 2 protect 'manage_environment_roles', :environment
3 3
4 def index 4 def index
5 - @roles = environment.roles.find(:all, :conditions => {:profile_id => nil}) 5 + @roles = environment.roles.where profile_id: nil
6 end 6 end
7 7
8 def new 8 def new
app/controllers/admin/users_controller.rb
@@ -48,7 +48,7 @@ class UsersController < AdminController @@ -48,7 +48,7 @@ class UsersController < AdminController
48 48
49 def destroy_user 49 def destroy_user
50 if request.post? 50 if request.post?
51 - person = environment.people.find_by_id(params[:id]) 51 + person = environment.people.find_by id: params[:id]
52 if person && person.destroy 52 if person && person.destroy
53 session[:notice] = _('The profile was deleted.') 53 session[:notice] = _('The profile was deleted.')
54 else 54 else
app/controllers/application_controller.rb
@@ -123,7 +123,7 @@ class ApplicationController < ActionController::Base @@ -123,7 +123,7 @@ class ApplicationController < ActionController::Base
123 # Sets text domain based on request host for custom internationalization 123 # Sets text domain based on request host for custom internationalization
124 FastGettext.text_domain = Domain.custom_locale(request.host) 124 FastGettext.text_domain = Domain.custom_locale(request.host)
125 125
126 - @domain = Domain.find_by_name(request.host) 126 + @domain = Domain.by_name(request.host)
127 if @domain.nil? 127 if @domain.nil?
128 @environment = Environment.default 128 @environment = Environment.default
129 # Avoid crashes on test and development setups 129 # Avoid crashes on test and development setups
@@ -138,7 +138,7 @@ class ApplicationController < ActionController::Base @@ -138,7 +138,7 @@ class ApplicationController < ActionController::Base
138 138
139 # Check if the requested profile belongs to another domain 139 # Check if the requested profile belongs to another domain
140 if @profile && !params[:profile].blank? && params[:profile] != @profile.identifier 140 if @profile && !params[:profile].blank? && params[:profile] != @profile.identifier
141 - @profile = @environment.profiles.find_by_identifier params[:profile] 141 + @profile = @environment.profiles.find_by(identifier: params[:profile])
142 redirect_to url_for(params.merge host: @profile.default_hostname) 142 redirect_to url_for(params.merge host: @profile.default_hostname)
143 end 143 end
144 end 144 end
@@ -170,7 +170,7 @@ class ApplicationController < ActionController::Base @@ -170,7 +170,7 @@ class ApplicationController < ActionController::Base
170 def load_category 170 def load_category
171 unless params[:category_path].blank? 171 unless params[:category_path].blank?
172 path = params[:category_path] 172 path = params[:category_path]
173 - @category = environment.categories.find_by_path(path) 173 + @category = environment.categories.find_by(path: path)
174 if @category.nil? 174 if @category.nil?
175 render_not_found(path) 175 render_not_found(path)
176 end 176 end
app/controllers/box_organizer_controller.rb
@@ -16,10 +16,9 @@ class BoxOrganizerController < ApplicationController @@ -16,10 +16,9 @@ class BoxOrganizerController < ApplicationController
16 target_position = block_before.position 16 target_position = block_before.position
17 17
18 @target_box = block_before.box 18 @target_box = block_before.box
19 - else  
20 - (params[:target] =~ /end-of-box-([0-9]+)/) 19 + elsif params[:target] =~ /end-of-box-([0-9]+)/
21 20
22 - @target_box = boxes_holder.boxes.find_by_id($1) 21 + @target_box = boxes_holder.boxes.find_by id: $1
23 end 22 end
24 23
25 @block = new_block(params[:type], @target_box) if @block.nil? 24 @block = new_block(params[:type], @target_box) if @block.nil?
@@ -35,8 +34,8 @@ class BoxOrganizerController < ApplicationController @@ -35,8 +34,8 @@ class BoxOrganizerController < ApplicationController
35 @block.insert_at(@target_box.blocks.size + 1) 34 @block.insert_at(@target_box.blocks.size + 1)
36 @block.move_to_bottom 35 @block.move_to_bottom
37 else 36 else
38 - # insert the block in the given position  
39 - @block.insert_at(@block.position && @block.position < target_position ? target_position - 1 : target_position) 37 + new_position = if @block.position and @block.position < target_position then target_position - 1 else target_position end
  38 + @block.insert_at new_position
40 end 39 end
41 40
42 @block.save! 41 @block.save!
app/controllers/my_profile/cms_controller.rb
@@ -34,7 +34,7 @@ class CmsController &lt; MyProfileController @@ -34,7 +34,7 @@ class CmsController &lt; MyProfileController
34 34
35 protect_if :only => [:new, :upload_files] do |c, user, profile| 35 protect_if :only => [:new, :upload_files] do |c, user, profile|
36 parent_id = c.params[:article].present? ? c.params[:article][:parent_id] : c.params[:parent_id] 36 parent_id = c.params[:article].present? ? c.params[:article][:parent_id] : c.params[:parent_id]
37 - parent = profile.articles.find_by_id(parent_id) 37 + parent = profile.articles.find_by(id: parent_id)
38 user && user.can_post_content?(profile, parent) 38 user && user.can_post_content?(profile, parent)
39 end 39 end
40 40
@@ -59,11 +59,10 @@ class CmsController &lt; MyProfileController @@ -59,11 +59,10 @@ class CmsController &lt; MyProfileController
59 59
60 def index 60 def index
61 @article = nil 61 @article = nil
62 - @articles = profile.top_level_articles.paginate(  
63 - :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC",  
64 - :per_page => per_page,  
65 - :page => params[:npage]  
66 - ) 62 + @articles = profile.top_level_articles
  63 + .order("case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC")
  64 + .paginate(per_page: per_page, page: params[:npage])
  65 +
67 render :action => 'view' 66 render :action => 'view'
68 end 67 end
69 68
app/controllers/my_profile/friends_controller.rb
@@ -22,7 +22,7 @@ class FriendsController &lt; MyProfileController @@ -22,7 +22,7 @@ class FriendsController &lt; MyProfileController
22 end 22 end
23 23
24 def remove_suggestion 24 def remove_suggestion
25 - @person = profile.suggested_people.find_by_identifier(params[:id]) 25 + @person = profile.suggested_people.find_by(identifier: params[:id])
26 redirect_to :action => 'suggest' unless @person 26 redirect_to :action => 'suggest' unless @person
27 if @person && request.post? 27 if @person && request.post?
28 profile.remove_suggestion(@person) 28 profile.remove_suggestion(@person)
@@ -32,7 +32,7 @@ class FriendsController &lt; MyProfileController @@ -32,7 +32,7 @@ class FriendsController &lt; MyProfileController
32 end 32 end
33 33
34 def connections 34 def connections
35 - @suggestion = profile.suggested_profiles.of_person.enabled.find_by_suggestion_id(params[:id]) 35 + @suggestion = profile.suggested_profiles.of_person.enabled.find_by(suggestion_id: params[:id])
36 if @suggestion 36 if @suggestion
37 @tags = @suggestion.tag_connections 37 @tags = @suggestion.tag_connections
38 @profiles = @suggestion.profile_connections 38 @profiles = @suggestion.profile_connections
app/controllers/my_profile/manage_products_controller.rb
@@ -35,7 +35,7 @@ class ManageProductsController &lt; ApplicationController @@ -35,7 +35,7 @@ class ManageProductsController &lt; ApplicationController
35 end 35 end
36 36
37 def categories_for_selection 37 def categories_for_selection
38 - @category = environment.categories.find_by_id params[:category_id] 38 + @category = environment.categories.find_by id: params[:category_id]
39 @object_name = params[:object_name] 39 @object_name = params[:object_name]
40 if @category 40 if @category
41 @categories = @category.children 41 @categories = @category.children
@@ -103,7 +103,7 @@ class ManageProductsController &lt; ApplicationController @@ -103,7 +103,7 @@ class ManageProductsController &lt; ApplicationController
103 def search_categories 103 def search_categories
104 @term = params[:term].downcase 104 @term = params[:term].downcase
105 conditions = ['LOWER(name) LIKE ? OR LOWER(name) LIKE ?', "#{@term}%", "% #{@term}%"] 105 conditions = ['LOWER(name) LIKE ? OR LOWER(name) LIKE ?', "#{@term}%", "% #{@term}%"]
106 - @categories = ProductCategory.all :conditions => conditions, :limit => 10 106 + @categories = ProductCategory.where(conditions).limit(10)
107 render :json => (@categories.map do |category| 107 render :json => (@categories.map do |category|
108 {:label => category.name, :value => category.id} 108 {:label => category.name, :value => category.id}
109 end) 109 end)
@@ -169,7 +169,7 @@ class ManageProductsController &lt; ApplicationController @@ -169,7 +169,7 @@ class ManageProductsController &lt; ApplicationController
169 169
170 def edit_input 170 def edit_input
171 if request.xhr? 171 if request.xhr?
172 - @input = @profile.inputs.find_by_id(params[:id]) 172 + @input = @profile.inputs.find_by id: params[:id]
173 if @input 173 if @input
174 if request.post? 174 if request.post?
175 if @input.update(params[:input]) 175 if @input.update(params[:input])
app/controllers/my_profile/memberships_controller.rb
@@ -5,7 +5,7 @@ class MembershipsController &lt; MyProfileController @@ -5,7 +5,7 @@ class MembershipsController &lt; MyProfileController
5 5
6 def index 6 def index
7 @roles = environment.roles.select do |role| 7 @roles = environment.roles.select do |role|
8 - ra = profile.role_assignments.find_by_role_id(role.id) 8 + ra = profile.role_assignments.find_by(role_id: role.id)
9 ra.present? && ra.resource_type == 'Profile' 9 ra.present? && ra.resource_type == 'Profile'
10 end 10 end
11 @filter = params[:filter_type].to_i 11 @filter = params[:filter_type].to_i
@@ -47,7 +47,7 @@ class MembershipsController &lt; MyProfileController @@ -47,7 +47,7 @@ class MembershipsController &lt; MyProfileController
47 end 47 end
48 48
49 def remove_suggestion 49 def remove_suggestion
50 - @community = profile.suggested_communities.find_by_identifier(params[:id]) 50 + @community = profile.suggested_communities.find_by(identifier: params[:id])
51 custom_per_page = params[:per_page] || per_page 51 custom_per_page = params[:per_page] || per_page
52 redirect_to :action => 'suggest' unless @community 52 redirect_to :action => 'suggest' unless @community
53 if @community && request.post? 53 if @community && request.post?
@@ -58,7 +58,7 @@ class MembershipsController &lt; MyProfileController @@ -58,7 +58,7 @@ class MembershipsController &lt; MyProfileController
58 end 58 end
59 59
60 def connections 60 def connections
61 - @suggestion = profile.suggested_profiles.of_community.enabled.find_by_suggestion_id(params[:id]) 61 + @suggestion = profile.suggested_profiles.of_community.enabled.find_by(suggestion_id: params[:id])
62 if @suggestion 62 if @suggestion
63 @tags = @suggestion.tag_connections 63 @tags = @suggestion.tag_connections
64 @profiles = @suggestion.profile_connections 64 @profiles = @suggestion.profile_connections
app/controllers/my_profile/profile_members_controller.rb
@@ -60,7 +60,7 @@ class ProfileMembersController &lt; MyProfileController @@ -60,7 +60,7 @@ class ProfileMembersController &lt; MyProfileController
60 redirect_to :action => 'index' 60 redirect_to :action => 'index'
61 else 61 else
62 @member = Person.find(params[:person]) 62 @member = Person.find(params[:person])
63 - @roles = environment.roles.find(:all).select{ |r| r.has_kind?('Profile') } 63 + @roles = environment.roles.all.select{ |r| r.has_kind?('Profile') }
64 render :action => 'affiliate' 64 render :action => 'affiliate'
65 end 65 end
66 end 66 end
@@ -120,7 +120,7 @@ class ProfileMembersController &lt; MyProfileController @@ -120,7 +120,7 @@ class ProfileMembersController &lt; MyProfileController
120 @collection = :profile_admins 120 @collection = :profile_admins
121 121
122 if profile.community? 122 if profile.community?
123 - member = profile.members.find_by_identifier(params[:id]) 123 + member = profile.members.find_by(identifier: params[:id])
124 profile.add_admin(member) 124 profile.add_admin(member)
125 end 125 end
126 render :layout => false 126 render :layout => false
@@ -131,7 +131,7 @@ class ProfileMembersController &lt; MyProfileController @@ -131,7 +131,7 @@ class ProfileMembersController &lt; MyProfileController
131 @collection = :profile_admins 131 @collection = :profile_admins
132 132
133 if profile.community? 133 if profile.community?
134 - member = profile.members.find_by_identifier(params[:id]) 134 + member = profile.members.find_by(identifier: params[:id])
135 profile.remove_admin(member) 135 profile.remove_admin(member)
136 end 136 end
137 render :layout => false 137 render :layout => false
app/controllers/my_profile/spam_controller.rb
@@ -15,12 +15,12 @@ class SpamController &lt; MyProfileController @@ -15,12 +15,12 @@ class SpamController &lt; MyProfileController
15 profile.comments_received.find(params[:remove_comment]).destroy 15 profile.comments_received.find(params[:remove_comment]).destroy
16 end 16 end
17 if params[:remove_task] 17 if params[:remove_task]
18 - Task.to(profile).find_by_id(params[:remove_task]).destroy 18 + Task.to(profile).find_by(id: params[:remove_task]).destroy
19 end 19 end
20 if params[:mark_comment_as_ham] 20 if params[:mark_comment_as_ham]
21 profile.comments_received.find(params[:mark_comment_as_ham]).ham! 21 profile.comments_received.find(params[:mark_comment_as_ham]).ham!
22 end 22 end
23 - if params[:mark_task_as_ham] && (t = Task.to(profile).find_by_id(params[:mark_task_as_ham])) 23 + if params[:mark_task_as_ham] && (t = Task.to(profile).find_by(id: params[:mark_task_as_ham]))
24 t.ham! 24 t.ham!
25 end 25 end
26 if request.xhr? 26 if request.xhr?
app/controllers/my_profile/tasks_controller.rb
@@ -7,8 +7,8 @@ class TasksController &lt; MyProfileController @@ -7,8 +7,8 @@ class TasksController &lt; MyProfileController
7 helper CustomFieldsHelper 7 helper CustomFieldsHelper
8 8
9 def index 9 def index
10 - @rejection_email_templates = profile.email_templates.find_all_by_template_type(:task_rejection)  
11 - @acceptance_email_templates = profile.email_templates.find_all_by_template_type(:task_acceptance) 10 + @rejection_email_templates = profile.email_templates.where template_type: :task_rejection
  11 + @acceptance_email_templates = profile.email_templates.where template_type: :task_acceptance
12 12
13 @filter_type = params[:filter_type].presence 13 @filter_type = params[:filter_type].presence
14 @filter_text = params[:filter_text].presence 14 @filter_text = params[:filter_text].presence
@@ -88,7 +88,7 @@ class TasksController &lt; MyProfileController @@ -88,7 +88,7 @@ class TasksController &lt; MyProfileController
88 end 88 end
89 89
90 def list_requested 90 def list_requested
91 - @tasks = Task.without_spam.find_all_by_requestor_id(profile.id) 91 + @tasks = Task.without_spam.where requestor_id: profile.id
92 end 92 end
93 93
94 def ticket_details 94 def ticket_details
app/controllers/public/account_controller.rb
@@ -17,7 +17,7 @@ class AccountController &lt; ApplicationController @@ -17,7 +17,7 @@ class AccountController &lt; ApplicationController
17 end 17 end
18 18
19 def activate 19 def activate
20 - @user = User.find_by_activation_code(params[:activation_code]) if params[:activation_code] 20 + @user = User.find_by(activation_code: params[:activation_code]) if params[:activation_code]
21 if @user 21 if @user
22 unless @user.environment.enabled?('admin_must_approve_new_users') 22 unless @user.environment.enabled?('admin_must_approve_new_users')
23 if @user.activate 23 if @user.activate
@@ -118,7 +118,7 @@ class AccountController &lt; ApplicationController @@ -118,7 +118,7 @@ class AccountController &lt; ApplicationController
118 end 118 end
119 @user.community_to_join = session[:join] 119 @user.community_to_join = session[:join]
120 @user.signup! 120 @user.signup!
121 - owner_role = Role.find_by_name('owner') 121 + owner_role = Role.find_by(name: 'owner')
122 @user.person.affiliate(@user.person, [owner_role]) if owner_role 122 @user.person.affiliate(@user.person, [owner_role]) if owner_role
123 invitation = Task.from_code(@invitation_code).first 123 invitation = Task.from_code(@invitation_code).first
124 if invitation 124 if invitation
@@ -305,7 +305,7 @@ class AccountController &lt; ApplicationController @@ -305,7 +305,7 @@ class AccountController &lt; ApplicationController
305 end 305 end
306 306
307 def check_email 307 def check_email
308 - if User.find_by_email_and_environment_id(params[:address], environment.id).nil? 308 + if User.find_by(email: params[:address], environment_id: environment.id).nil?
309 @status = _('This e-mail address is available') 309 @status = _('This e-mail address is available')
310 @status_class = 'validated' 310 @status_class = 'validated'
311 else 311 else
@@ -502,7 +502,7 @@ class AccountController &lt; ApplicationController @@ -502,7 +502,7 @@ class AccountController &lt; ApplicationController
502 def check_join_in_community(user) 502 def check_join_in_community(user)
503 profile_to_join = session[:join] 503 profile_to_join = session[:join]
504 unless profile_to_join.blank? 504 unless profile_to_join.blank?
505 - environment.profiles.find_by_identifier(profile_to_join).add_member(user.person) 505 + environment.profiles.find_by(identifier: profile_to_join).add_member(user.person)
506 session.delete(:join) 506 session.delete(:join)
507 end 507 end
508 end 508 end
app/controllers/public/chat_controller.rb
@@ -44,7 +44,7 @@ class ChatController &lt; PublicController @@ -44,7 +44,7 @@ class ChatController &lt; PublicController
44 end 44 end
45 45
46 def avatar 46 def avatar
47 - profile = environment.profiles.find_by_identifier(params[:id]) 47 + profile = environment.profiles.find_by(identifier: params[:id])
48 filename, mimetype = profile_icon(profile, :minor, true) 48 filename, mimetype = profile_icon(profile, :minor, true)
49 if filename =~ /^(https?:)?\/\// 49 if filename =~ /^(https?:)?\/\//
50 redirect_to filename 50 redirect_to filename
@@ -87,7 +87,7 @@ class ChatController &lt; PublicController @@ -87,7 +87,7 @@ class ChatController &lt; PublicController
87 end 87 end
88 88
89 def recent_messages 89 def recent_messages
90 - other = environment.profiles.find_by_identifier(params[:identifier]) 90 + other = environment.profiles.find_by(identifier: params[:identifier])
91 if other.kind_of?(Organization) 91 if other.kind_of?(Organization)
92 messages = ChatMessage.where('to_id=:other', :other => other.id) 92 messages = ChatMessage.where('to_id=:other', :other => other.id)
93 else 93 else
app/controllers/public/content_viewer_controller.rb
@@ -18,7 +18,7 @@ class ContentViewerController &lt; ApplicationController @@ -18,7 +18,7 @@ class ContentViewerController &lt; ApplicationController
18 @page = profile.home_page 18 @page = profile.home_page
19 return if redirected_to_profile_index 19 return if redirected_to_profile_index
20 else 20 else
21 - @page = profile.articles.find_by_path(path) 21 + @page = profile.articles.find_by path: path
22 return if redirected_page_from_old_path(path) 22 return if redirected_page_from_old_path(path)
23 end 23 end
24 24
@@ -76,13 +76,13 @@ class ContentViewerController &lt; ApplicationController @@ -76,13 +76,13 @@ class ContentViewerController &lt; ApplicationController
76 76
77 def versions_diff 77 def versions_diff
78 path = params[:page] 78 path = params[:page]
79 - @page = profile.articles.find_by_path(path)  
80 - @v1, @v2 = @page.versions.find_by_version(params[:v1]), @page.versions.find_by_version(params[:v2]) 79 + @page = profile.articles.find_by path: path
  80 + @v1, @v2 = @page.versions.find_by(version: params[:v1]), @page.versions.find_by(version: params[:v2])
81 end 81 end
82 82
83 def article_versions 83 def article_versions
84 path = params[:page] 84 path = params[:page]
85 - @page = profile.articles.find_by_path(path) 85 + @page = profile.articles.find_by path: path
86 return unless allow_access_to_page(path) 86 return unless allow_access_to_page(path)
87 87
88 render_access_denied unless @page.display_versions? 88 render_access_denied unless @page.display_versions?
@@ -169,7 +169,7 @@ class ContentViewerController &lt; ApplicationController @@ -169,7 +169,7 @@ class ContentViewerController &lt; ApplicationController
169 169
170 def redirected_page_from_old_path(path) 170 def redirected_page_from_old_path(path)
171 unless @page 171 unless @page
172 - page_from_old_path = profile.articles.find_by_old_path(path) 172 + page_from_old_path = profile.articles.find_by_old_path path
173 if page_from_old_path 173 if page_from_old_path
174 redirect_to profile.url.merge(:page => page_from_old_path.explode_path) 174 redirect_to profile.url.merge(:page => page_from_old_path.explode_path)
175 return true 175 return true
@@ -190,7 +190,7 @@ class ContentViewerController &lt; ApplicationController @@ -190,7 +190,7 @@ class ContentViewerController &lt; ApplicationController
190 end 190 end
191 191
192 def rendered_versioned_article 192 def rendered_versioned_article
193 - @versioned_article = @page.versions.find_by_version(@version) 193 + @versioned_article = @page.versions.find_by version: @version
194 if @versioned_article && @page.versions.latest.version != @versioned_article.version 194 if @versioned_article && @page.versions.latest.version != @versioned_article.version
195 render :template => 'content_viewer/versioned_article.html.erb' 195 render :template => 'content_viewer/versioned_article.html.erb'
196 return true 196 return true
app/controllers/public/enterprise_registration_controller.rb
@@ -68,7 +68,7 @@ class EnterpriseRegistrationController &lt; ApplicationController @@ -68,7 +68,7 @@ class EnterpriseRegistrationController &lt; ApplicationController
68 # saying to the user that the enterprise was created. 68 # saying to the user that the enterprise was created.
69 def creation 69 def creation
70 @create_enterprise.perform 70 @create_enterprise.perform
71 - @enterprise = @create_enterprise.target.profiles.find_by_identifier(@create_enterprise.identifier) 71 + @enterprise = @create_enterprise.target.profiles.find_by identifier: @create_enterprise.identifier
72 end 72 end
73 73
74 end 74 end
app/controllers/public/profile_controller.rb
@@ -339,7 +339,7 @@ class ProfileController &lt; PublicController @@ -339,7 +339,7 @@ class ProfileController &lt; PublicController
339 user.register_report(abuse_report, profile) 339 user.register_report(abuse_report, profile)
340 340
341 if !params[:content_type].blank? 341 if !params[:content_type].blank?
342 - abuse_report = AbuseReport.find_by_reporter_id_and_abuse_complaint_id(user.id, profile.opened_abuse_complaint.id) 342 + abuse_report = AbuseReport.find_by(reporter_id: user.id, abuse_complaint_id: profile.opened_abuse_complaint.id)
343 Delayed::Job.enqueue DownloadReportedImagesJob.new(abuse_report, article) 343 Delayed::Job.enqueue DownloadReportedImagesJob.new(abuse_report, article)
344 end 344 end
345 345
@@ -374,7 +374,7 @@ class ProfileController &lt; PublicController @@ -374,7 +374,7 @@ class ProfileController &lt; PublicController
374 def send_mail 374 def send_mail
375 @mailing = profile.mailings.build(params[:mailing]) 375 @mailing = profile.mailings.build(params[:mailing])
376 @mailing.data = session[:members_filtered] ? {:members_filtered => session[:members_filtered]} : {} 376 @mailing.data = session[:members_filtered] ? {:members_filtered => session[:members_filtered]} : {}
377 - @email_templates = profile.email_templates.find_all_by_template_type(:organization_members) 377 + @email_templates = profile.email_templates.where template_type: :organization_members
378 if request.post? 378 if request.post?
379 @mailing.locale = locale 379 @mailing.locale = locale
380 @mailing.person = user 380 @mailing.person = user
app/controllers/public/search_controller.rb
@@ -167,7 +167,7 @@ class SearchController &lt; PublicController @@ -167,7 +167,7 @@ class SearchController &lt; PublicController
167 render_not_found if params[:action] == 'category_index' 167 render_not_found if params[:action] == 'category_index'
168 else 168 else
169 path = params[:category_path] 169 path = params[:category_path]
170 - @category = environment.categories.find_by_path(path) 170 + @category = environment.categories.find_by path: path
171 if @category.nil? 171 if @category.nil?
172 render_not_found(path) 172 render_not_found(path)
173 else 173 else
@@ -177,14 +177,14 @@ class SearchController &lt; PublicController @@ -177,14 +177,14 @@ class SearchController &lt; PublicController
177 end 177 end
178 178
179 def available_searches 179 def available_searches
180 - @available_searches ||= ActiveSupport::OrderedHash[  
181 - :articles, _('Contents'),  
182 - :people, _('People'),  
183 - :communities, _('Communities'),  
184 - :enterprises, _('Enterprises'),  
185 - :products, _('Products and Services'),  
186 - :events, _('Events'),  
187 - ] 180 + @available_searches ||= {
  181 + articles: _('Contents'),
  182 + people: _('People'),
  183 + communities: _('Communities'),
  184 + enterprises: _('Enterprises'),
  185 + products: _('Products and Services'),
  186 + events: _('Events'),
  187 + }
188 end 188 end
189 189
190 def load_search_assets 190 def load_search_assets
@@ -256,13 +256,13 @@ class SearchController &lt; PublicController @@ -256,13 +256,13 @@ class SearchController &lt; PublicController
256 end 256 end
257 257
258 def available_assets 258 def available_assets
259 - assets = ActiveSupport::OrderedHash[  
260 - :articles, _('Contents'),  
261 - :enterprises, _('Enterprises'),  
262 - :people, _('People'),  
263 - :communities, _('Communities'),  
264 - :products, _('Products and Services'),  
265 - ] 259 + assets = {
  260 + articles: _('Contents'),
  261 + enterprises: _('Enterprises'),
  262 + people: _('People'),
  263 + communities: _('Communities'),
  264 + products: _('Products and Services'),
  265 + }
266 end 266 end
267 267
268 end 268 end
app/helpers/application_helper.rb
@@ -318,7 +318,7 @@ module ApplicationHelper @@ -318,7 +318,7 @@ module ApplicationHelper
318 if File.exists?(Rails.root.join('public', theme_path, 'favicon.ico')) 318 if File.exists?(Rails.root.join('public', theme_path, 'favicon.ico'))
319 '/designs/themes/' + profile.theme + '/favicon.ico' 319 '/designs/themes/' + profile.theme + '/favicon.ico'
320 else 320 else
321 - favicon = profile.articles.find_by_path('favicon.ico') 321 + favicon = profile.articles.find_by path: 'favicon.ico'
322 if favicon 322 if favicon
323 favicon.public_filename 323 favicon.public_filename
324 else 324 else
@@ -1154,8 +1154,8 @@ module ApplicationHelper @@ -1154,8 +1154,8 @@ module ApplicationHelper
1154 end 1154 end
1155 1155
1156 def default_folder_for_image_upload(profile) 1156 def default_folder_for_image_upload(profile)
1157 - default_folder = profile.folders.find_by_type('Gallery')  
1158 - default_folder = profile.folders.find_by_type('Folder') if default_folder.nil? 1157 + default_folder = profile.folders.find_by type: 'Gallery'
  1158 + default_folder = profile.folders.find_by type: 'Folder' if default_folder.nil?
1159 default_folder 1159 default_folder
1160 end 1160 end
1161 1161
app/helpers/forms_helper.rb
@@ -50,15 +50,15 @@ module FormsHelper @@ -50,15 +50,15 @@ module FormsHelper
50 end 50 end
51 51
52 def select_city( simple=false ) 52 def select_city( simple=false )
53 - states = State.find(:all, :order => 'name')  
54 - 53 + states = State.order(:name).all
  54 +
55 state_id = 'state-' + FormsHelper.next_id_number 55 state_id = 'state-' + FormsHelper.next_id_number
56 city_id = 'city-' + FormsHelper.next_id_number 56 city_id = 'city-' + FormsHelper.next_id_number
57 57
58 if states.length < 1 58 if states.length < 1
59 return 59 return
60 end 60 end
61 - 61 +
62 if simple 62 if simple
63 states = [State.new(:name => _('Select the State'))] + states 63 states = [State.new(:name => _('Select the State'))] + states
64 cities = [City.new(:name => _('Select the City'))] 64 cities = [City.new(:name => _('Select the City'))]
@@ -82,7 +82,7 @@ module FormsHelper @@ -82,7 +82,7 @@ module FormsHelper
82 states = [State.new(:name => '---')] + states 82 states = [State.new(:name => '---')] + states
83 cities = [City.new(:name => '---')] 83 cities = [City.new(:name => '---')]
84 84
85 - html = 85 + html =
86 content_tag( 'div', 86 content_tag( 'div',
87 labelled_select( _('State:'), 'state', :id, :name, nil, states, :id => state_id ), 87 labelled_select( _('State:'), 'state', :id, :name, nil, states, :id => state_id ),
88 :class => 'select_state_for_origin' ) + 88 :class => 'select_state_for_origin' ) +
@@ -90,7 +90,7 @@ module FormsHelper @@ -90,7 +90,7 @@ module FormsHelper
90 labelled_select( _('City:'), 'city', :id, :name, nil, cities, :id => city_id ), 90 labelled_select( _('City:'), 'city', :id, :name, nil, cities, :id => city_id ),
91 :class => 'select_city_for_origin' ) 91 :class => 'select_city_for_origin' )
92 end 92 end
93 - 93 +
94 html + 94 html +
95 observe_field( state_id, :update => city_id, :function => "new Ajax.Updater(#{city_id.inspect}, #{url_for(:controller => 'search', :action => 'cities').inspect}, {asynchronous:true, evalScripts:true, parameters:'state_id=' + value}); $(#{city_id.inspect}).innerHTML = '<option>#{_('Loading...')}</option>'", :with => 'state_id') 95 observe_field( state_id, :update => city_id, :function => "new Ajax.Updater(#{city_id.inspect}, #{url_for(:controller => 'search', :action => 'cities').inspect}, {asynchronous:true, evalScripts:true, parameters:'state_id=' + value}); $(#{city_id.inspect}).innerHTML = '<option>#{_('Loading...')}</option>'", :with => 'state_id')
96 end 96 end
app/helpers/manage_products_helper.rb
@@ -222,7 +222,7 @@ module ManageProductsHelper @@ -222,7 +222,7 @@ module ManageProductsHelper
222 end 222 end
223 def select_certifiers(qualifier, product = nil) 223 def select_certifiers(qualifier, product = nil)
224 if qualifier 224 if qualifier
225 - selected = product ? product.product_qualifiers.find_by_qualifier_id(qualifier.id).certifier_id : nil 225 + selected = product ? product.product_qualifiers.find_by(qualifier_id: qualifier.id).certifier_id : nil
226 select_tag("product[qualifiers_list][#{qualifier.id}]", options_for_select(certifiers_for_select(qualifier), selected)) 226 select_tag("product[qualifiers_list][#{qualifier.id}]", options_for_select(certifiers_for_select(qualifier), selected))
227 else 227 else
228 select_tag("product[qualifiers_list][nil]") 228 select_tag("product[qualifiers_list][nil]")
app/helpers/profile_helper.rb
1 module ProfileHelper 1 module ProfileHelper
2 2
3 - COMMON_CATEGORIES = ActiveSupport::OrderedHash.new 3 + COMMON_CATEGORIES = {}
4 COMMON_CATEGORIES[:content] = [:blogs, :image_galleries, :events, :article_tags] 4 COMMON_CATEGORIES[:content] = [:blogs, :image_galleries, :events, :article_tags]
5 COMMON_CATEGORIES[:interests] = [:interests] 5 COMMON_CATEGORIES[:interests] = [:interests]
6 COMMON_CATEGORIES[:general] = nil 6 COMMON_CATEGORIES[:general] = nil
7 7
8 - PERSON_CATEGORIES = ActiveSupport::OrderedHash.new 8 + PERSON_CATEGORIES = {}
9 PERSON_CATEGORIES[:basic_information] = [:nickname, :sex, :birth_date, :location, :privacy_setting, :created_at] 9 PERSON_CATEGORIES[:basic_information] = [:nickname, :sex, :birth_date, :location, :privacy_setting, :created_at]
10 PERSON_CATEGORIES[:contact] = [:contact_phone, :cell_phone, :comercial_phone, :contact_information, :email, :personal_website, :jabber_id] 10 PERSON_CATEGORIES[:contact] = [:contact_phone, :cell_phone, :comercial_phone, :contact_information, :email, :personal_website, :jabber_id]
11 PERSON_CATEGORIES[:location] = [:address, :address_reference, :zip_code, :city, :state, :district, :country, :nationality] 11 PERSON_CATEGORIES[:location] = [:address, :address_reference, :zip_code, :city, :state, :district, :country, :nationality]
@@ -14,13 +14,13 @@ module ProfileHelper @@ -14,13 +14,13 @@ module ProfileHelper
14 PERSON_CATEGORIES[:network] = [:friends, :communities, :enterprises] 14 PERSON_CATEGORIES[:network] = [:friends, :communities, :enterprises]
15 PERSON_CATEGORIES.merge!(COMMON_CATEGORIES) 15 PERSON_CATEGORIES.merge!(COMMON_CATEGORIES)
16 16
17 - ORGANIZATION_CATEGORIES = ActiveSupport::OrderedHash.new 17 + ORGANIZATION_CATEGORIES = {}
18 ORGANIZATION_CATEGORIES[:basic_information] = [:display_name, :created_at, :foundation_year, :type, :language, :members_count, :location, :address_reference, :historic_and_current_context, :admins] 18 ORGANIZATION_CATEGORIES[:basic_information] = [:display_name, :created_at, :foundation_year, :type, :language, :members_count, :location, :address_reference, :historic_and_current_context, :admins]
19 ORGANIZATION_CATEGORIES[:contact] = [:contact_person, :contact_phone, :contact_email, :organization_website, :jabber_id] 19 ORGANIZATION_CATEGORIES[:contact] = [:contact_person, :contact_phone, :contact_email, :organization_website, :jabber_id]
20 ORGANIZATION_CATEGORIES[:economic] = [:business_name, :acronym, :economic_activity, :legal_form, :products, :activities_short_description, :management_information] 20 ORGANIZATION_CATEGORIES[:economic] = [:business_name, :acronym, :economic_activity, :legal_form, :products, :activities_short_description, :management_information]
21 ORGANIZATION_CATEGORIES.merge!(COMMON_CATEGORIES) 21 ORGANIZATION_CATEGORIES.merge!(COMMON_CATEGORIES)
22 22
23 - CATEGORY_MAP = ActiveSupport::OrderedHash.new 23 + CATEGORY_MAP = {}
24 CATEGORY_MAP[:person] = PERSON_CATEGORIES 24 CATEGORY_MAP[:person] = PERSON_CATEGORIES
25 CATEGORY_MAP[:organization] = ORGANIZATION_CATEGORIES 25 CATEGORY_MAP[:organization] = ORGANIZATION_CATEGORIES
26 26
app/models/add_friend.rb
@@ -57,7 +57,7 @@ class AddFriend &lt; Task @@ -57,7 +57,7 @@ class AddFriend &lt; Task
57 end 57 end
58 58
59 def remove_from_suggestion_list(task) 59 def remove_from_suggestion_list(task)
60 - suggestion = task.requestor.suggested_profiles.find_by_suggestion_id task.target.id 60 + suggestion = task.requestor.suggested_profiles.find_by suggestion_id: task.target.id
61 suggestion.disable if suggestion 61 suggestion.disable if suggestion
62 end 62 end
63 end 63 end
app/models/add_member.rb
@@ -59,7 +59,7 @@ class AddMember &lt; Task @@ -59,7 +59,7 @@ class AddMember &lt; Task
59 end 59 end
60 60
61 def remove_from_suggestion_list(task) 61 def remove_from_suggestion_list(task)
62 - suggestion = task.requestor.profile_suggestions.find_by_suggestion_id task.target.id 62 + suggestion = task.requestor.profile_suggestions.find_by suggestion_id: task.target.id
63 suggestion.disable if suggestion 63 suggestion.disable if suggestion
64 end 64 end
65 65
app/models/approve_article.rb
@@ -20,7 +20,7 @@ class ApproveArticle &lt; Task @@ -20,7 +20,7 @@ class ApproveArticle &lt; Task
20 end 20 end
21 21
22 def article 22 def article
23 - Article.find_by_id data[:article_id] 23 + Article.find_by id: data[:article_id]
24 end 24 end
25 25
26 def article= value 26 def article= value
@@ -39,7 +39,7 @@ class ApproveArticle &lt; Task @@ -39,7 +39,7 @@ class ApproveArticle &lt; Task
39 settings_items :create_link, :type => :boolean, :default => false 39 settings_items :create_link, :type => :boolean, :default => false
40 40
41 def article_parent 41 def article_parent
42 - Article.find_by_id article_parent_id.to_i 42 + Article.find_by id: article_parent_id.to_i
43 end 43 end
44 44
45 def article_parent= value 45 def article_parent= value
app/models/approve_comment.rb
@@ -18,7 +18,7 @@ class ApproveComment &lt; Task @@ -18,7 +18,7 @@ class ApproveComment &lt; Task
18 end 18 end
19 19
20 def article 20 def article
21 - Article.find_by_id comment.source_id unless self.comment.nil? 21 + Article.find_by id: comment.source_id unless self.comment.nil?
22 end 22 end
23 23
24 def article_name 24 def article_name
app/models/article.rb
@@ -74,11 +74,11 @@ class Article &lt; ActiveRecord::Base @@ -74,11 +74,11 @@ class Article &lt; ActiveRecord::Base
74 belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id' 74 belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id'
75 belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id' 75 belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id'
76 76
77 - has_many :comments, :class_name => 'Comment', :as => 'source', :dependent => :destroy, :order => 'created_at asc' 77 + has_many :comments, -> { order 'created_at asc' }, class_name: 'Comment', as: 'source', dependent: :destroy
78 78
79 has_many :article_followers, :dependent => :destroy 79 has_many :article_followers, :dependent => :destroy
80 has_many :person_followers, :class_name => 'Person', :through => :article_followers, :source => :person 80 has_many :person_followers, :class_name => 'Person', :through => :article_followers, :source => :person
81 - has_many :person_followers_emails, :class_name => 'User', :through => :person_followers, :source => :user, :select => :email 81 + has_many :person_followers_emails, -> { select :email }, class_name: 'User', through: :person_followers, source: :user
82 82
83 has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false } 83 has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false }
84 has_many :categories, :through => :article_categorizations 84 has_many :categories, :through => :article_categorizations
@@ -279,7 +279,7 @@ class Article &lt; ActiveRecord::Base @@ -279,7 +279,7 @@ class Article &lt; ActiveRecord::Base
279 # retrives the most commented articles, sorted by the comment count (largest 279 # retrives the most commented articles, sorted by the comment count (largest
280 # first) 280 # first)
281 def self.most_commented(limit) 281 def self.most_commented(limit)
282 - paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) 282 + order('comments_count DESC').paginate(page: 1, per_page: limit)
283 end 283 end
284 284
285 scope :more_popular, -> { order 'hits DESC' } 285 scope :more_popular, -> { order 'hits DESC' }
@@ -288,7 +288,7 @@ class Article &lt; ActiveRecord::Base @@ -288,7 +288,7 @@ class Article &lt; ActiveRecord::Base
288 } 288 }
289 289
290 def self.recent(limit = nil, extra_conditions = {}, pagination = true) 290 def self.recent(limit = nil, extra_conditions = {}, pagination = true)
291 - result = scoped({:conditions => extra_conditions}). 291 + result = where(extra_conditions).
292 is_public. 292 is_public.
293 relevant_as_recent. 293 relevant_as_recent.
294 limit(limit). 294 limit(limit).
@@ -470,7 +470,7 @@ class Article &lt; ActiveRecord::Base @@ -470,7 +470,7 @@ class Article &lt; ActiveRecord::Base
470 470
471 def rotate_translations 471 def rotate_translations
472 unless self.translations.empty? 472 unless self.translations.empty?
473 - rotate = self.translations.all 473 + rotate = self.translations.to_a
474 root = rotate.shift 474 root = rotate.shift
475 root.update_attribute(:translation_of_id, nil) 475 root.update_attribute(:translation_of_id, nil)
476 root.translations = rotate 476 root.translations = rotate
@@ -752,7 +752,7 @@ class Article &lt; ActiveRecord::Base @@ -752,7 +752,7 @@ class Article &lt; ActiveRecord::Base
752 752
753 def version_license(version_number = nil) 753 def version_license(version_number = nil)
754 return license if version_number.nil? 754 return license if version_number.nil?
755 - profile.environment.licenses.find_by_id(get_version(version_number).license_id) 755 + profile.environment.licenses.find_by(id: get_version(version_number).license_id)
756 end 756 end
757 757
758 alias :active_record_cache_key :cache_key 758 alias :active_record_cache_key :cache_key
app/models/block.rb
@@ -11,7 +11,8 @@ class Block &lt; ActiveRecord::Base @@ -11,7 +11,8 @@ class Block &lt; ActiveRecord::Base
11 11
12 delegate :environment, :to => :box, :allow_nil => true 12 delegate :environment, :to => :box, :allow_nil => true
13 13
14 - acts_as_list :scope => :box 14 + acts_as_list scope: -> block { where box_id: block.box_id }
  15 +
15 belongs_to :box 16 belongs_to :box
16 belongs_to :mirror_block, :class_name => "Block" 17 belongs_to :mirror_block, :class_name => "Block"
17 has_many :observers, :class_name => "Block", :foreign_key => "mirror_block_id" 18 has_many :observers, :class_name => "Block", :foreign_key => "mirror_block_id"
app/models/blog.rb
@@ -98,8 +98,9 @@ class Blog &lt; Folder @@ -98,8 +98,9 @@ class Blog &lt; Folder
98 when :by_year 98 when :by_year
99 posts.published.native_translations 99 posts.published.native_translations
100 .except(:order) 100 .except(:order)
101 - .count(:all, :group => 'EXTRACT(YEAR FROM published_at)')  
102 - .sort_by {|year, count| -year.to_i} 101 + .group('EXTRACT(YEAR FROM published_at)')
  102 + .count
  103 + .sort_by{ |year, count| -year.to_i }
103 when :by_month 104 when :by_month
104 posts.published.native_translations 105 posts.published.native_translations
105 .except(:order) 106 .except(:order)
app/models/box.rb
1 class Box < ActiveRecord::Base 1 class Box < ActiveRecord::Base
  2 +
  3 + acts_as_list scope: -> box { where owner_id: box.owner_id, owner_type: box.owner_type }
  4 +
2 belongs_to :owner, :polymorphic => true 5 belongs_to :owner, :polymorphic => true
3 - acts_as_list :scope => 'owner_id = #{owner_id} and owner_type = \'#{owner_type}\''  
4 - has_many :blocks, :dependent => :destroy, :order => 'position' 6 + has_many :blocks, -> { order 'position' }, dependent: :destroy
5 7
6 attr_accessible :owner 8 attr_accessible :owner
7 9
app/models/category.rb
@@ -90,7 +90,7 @@ class Category &lt; ActiveRecord::Base @@ -90,7 +90,7 @@ class Category &lt; ActiveRecord::Base
90 90
91 def children_for_menu 91 def children_for_menu
92 results = [] 92 results = []
93 - pending = children.where(display_in_menu: true).all 93 + pending = children.where(display_in_menu: true).to_a
94 while pending.present? 94 while pending.present?
95 cat = pending.shift 95 cat = pending.shift
96 results << cat 96 results << cat
app/models/comment.rb
@@ -92,7 +92,7 @@ class Comment &lt; ActiveRecord::Base @@ -92,7 +92,7 @@ class Comment &lt; ActiveRecord::Base
92 end 92 end
93 93
94 def self.recent(limit = nil) 94 def self.recent(limit = nil)
95 - self.find(:all, :order => 'created_at desc, id desc', :limit => limit) 95 + self.order('created_at desc, id desc').limit(limit).all
96 end 96 end
97 97
98 def notification_emails 98 def notification_emails
app/models/community.rb
@@ -77,7 +77,7 @@ class Community &lt; Organization @@ -77,7 +77,7 @@ class Community &lt; Organization
77 end 77 end
78 78
79 def each_member(offset=0) 79 def each_member(offset=0)
80 - while member = self.members.first(:order => :id, :offset => offset) 80 + while member = self.members.order(:id).offset(offset).first
81 yield member 81 yield member
82 offset = offset + 1 82 offset = offset + 1
83 end 83 end
app/models/domain.rb
@@ -36,8 +36,8 @@ class Domain &lt; ActiveRecord::Base @@ -36,8 +36,8 @@ class Domain &lt; ActiveRecord::Base
36 # finds a domain by its name. The argument <tt>name</tt> can start with 36 # finds a domain by its name. The argument <tt>name</tt> can start with
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)  
40 - self.where('name = ?', self.extract_domain_name(name)).first 39 + def self.by_name(name)
  40 + self.find_by(name: self.extract_domain_name(name))
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
@@ -82,7 +82,7 @@ class Domain &lt; ActiveRecord::Base @@ -82,7 +82,7 @@ class Domain &lt; ActiveRecord::Base
82 Noosfero::MultiTenancy.setup!(domainname) 82 Noosfero::MultiTenancy.setup!(domainname)
83 @hosting[domainname] ||= 83 @hosting[domainname] ||=
84 begin 84 begin
85 - domain = Domain.find_by_name(domainname) 85 + domain = Domain.by_name(domainname)
86 !domain.nil? && (domain.owner_type == 'Profile') 86 !domain.nil? && (domain.owner_type == 'Profile')
87 end 87 end
88 end 88 end
app/models/environment.rb
@@ -61,7 +61,7 @@ class Environment &lt; ActiveRecord::Base @@ -61,7 +61,7 @@ class Environment &lt; ActiveRecord::Base
61 61
62 module Roles 62 module Roles
63 def self.admin(env_id) 63 def self.admin(env_id)
64 - Role.find_by_key_and_environment_id('environment_administrator', env_id) 64 + Role.find_by(key: 'environment_administrator', environment_id: env_id)
65 end 65 end
66 end 66 end
67 67
@@ -248,7 +248,7 @@ class Environment &lt; ActiveRecord::Base @@ -248,7 +248,7 @@ class Environment &lt; ActiveRecord::Base
248 248
249 acts_as_accessible 249 acts_as_accessible
250 250
251 - has_many :units, :order => 'position' 251 + has_many :units, -> { order 'position' }
252 has_many :production_costs, :as => :owner 252 has_many :production_costs, :as => :owner
253 253
254 def superior_intances 254 def superior_intances
@@ -714,7 +714,7 @@ class Environment &lt; ActiveRecord::Base @@ -714,7 +714,7 @@ class Environment &lt; ActiveRecord::Base
714 def default_hostname(email_hostname = false) 714 def default_hostname(email_hostname = false)
715 domain = 'localhost' 715 domain = 'localhost'
716 unless self.domains(true).empty? 716 unless self.domains(true).empty?
717 - domain = (self.domains.find_by_is_default(true) || self.domains.find(:first, :order => 'id')).name 717 + domain = (self.domains.find_by(is_default: true) || self.domains.order(:id).first).name
718 domain = email_hostname ? domain : (force_www ? ('www.' + domain) : domain) 718 domain = email_hostname ? domain : (force_www ? ('www.' + domain) : domain)
719 end 719 end
720 domain 720 domain
@@ -808,7 +808,7 @@ class Environment &lt; ActiveRecord::Base @@ -808,7 +808,7 @@ class Environment &lt; ActiveRecord::Base
808 end 808 end
809 809
810 def community_default_template 810 def community_default_template
811 - template = Community.find_by_id settings[:community_template_id] 811 + template = Community.find_by id: settings[:community_template_id]
812 template if template && template.is_template? 812 template if template && template.is_template?
813 end 813 end
814 814
@@ -821,7 +821,7 @@ class Environment &lt; ActiveRecord::Base @@ -821,7 +821,7 @@ class Environment &lt; ActiveRecord::Base
821 end 821 end
822 822
823 def person_default_template 823 def person_default_template
824 - template = Person.find_by_id settings[:person_template_id] 824 + template = Person.find_by id: settings[:person_template_id]
825 template if template && template.is_template? 825 template if template && template.is_template?
826 end 826 end
827 827
@@ -834,7 +834,7 @@ class Environment &lt; ActiveRecord::Base @@ -834,7 +834,7 @@ class Environment &lt; ActiveRecord::Base
834 end 834 end
835 835
836 def enterprise_default_template 836 def enterprise_default_template
837 - template = Enterprise.find_by_id settings[:enterprise_template_id] 837 + template = Enterprise.find_by id: settings[:enterprise_template_id]
838 template if template && template.is_template? 838 template if template && template.is_template?
839 end 839 end
840 840
@@ -843,7 +843,7 @@ class Environment &lt; ActiveRecord::Base @@ -843,7 +843,7 @@ class Environment &lt; ActiveRecord::Base
843 end 843 end
844 844
845 def inactive_enterprise_template 845 def inactive_enterprise_template
846 - template = Enterprise.find_by_id settings[:inactive_enterprise_template_id] 846 + template = Enterprise.find_by id: settings[:inactive_enterprise_template_id]
847 template if template && template.is_template 847 template if template && template.is_template
848 end 848 end
849 849
app/models/forum.rb
1 class Forum < Folder 1 class Forum < Folder
2 2
3 - acts_as_having_posts :order => 'updated_at DESC' 3 + acts_as_having_posts -> { reorder 'updated_at DESC' }
4 include PostsLimit 4 include PostsLimit
5 5
6 attr_accessible :has_terms_of_use, :terms_of_use, :topic_creation 6 attr_accessible :has_terms_of_use, :terms_of_use, :topic_creation
@@ -12,7 +12,7 @@ class Forum &lt; Folder @@ -12,7 +12,7 @@ class Forum &lt; Folder
12 12
13 before_save do |forum| 13 before_save do |forum|
14 if forum.has_terms_of_use 14 if forum.has_terms_of_use
15 - last_editor = forum.profile.environment.people.find_by_id(forum.last_changed_by_id) 15 + last_editor = forum.profile.environment.people.find_by(id: forum.last_changed_by_id)
16 if last_editor && !forum.users_with_agreement.exists?(last_editor) 16 if last_editor && !forum.users_with_agreement.exists?(last_editor)
17 forum.users_with_agreement << last_editor 17 forum.users_with_agreement << last_editor
18 end 18 end
@@ -34,14 +34,14 @@ class Forum &lt; Folder @@ -34,14 +34,14 @@ class Forum &lt; Folder
34 end 34 end
35 35
36 module TopicCreation 36 module TopicCreation
37 - BASE = ActiveSupport::OrderedHash.new 37 + BASE = {}
38 BASE['users'] = _('Logged users') 38 BASE['users'] = _('Logged users')
39 39
40 - PERSON = ActiveSupport::OrderedHash.new 40 + PERSON = {}
41 PERSON['self'] = _('Me') 41 PERSON['self'] = _('Me')
42 PERSON['related'] = _('Friends') 42 PERSON['related'] = _('Friends')
43 43
44 - GROUP = ActiveSupport::OrderedHash.new 44 + GROUP = {}
45 GROUP['self'] = _('Administrators') 45 GROUP['self'] = _('Administrators')
46 GROUP['related'] = _('Members') 46 GROUP['related'] = _('Members')
47 47
app/models/input.rb
@@ -9,7 +9,7 @@ class Input &lt; ActiveRecord::Base @@ -9,7 +9,7 @@ class Input &lt; ActiveRecord::Base
9 validates_presence_of :product 9 validates_presence_of :product
10 validates_presence_of :product_category 10 validates_presence_of :product_category
11 11
12 - acts_as_list :scope => :product 12 + acts_as_list scope: -> input { where product_id: input.product_id }
13 13
14 belongs_to :unit 14 belongs_to :unit
15 15
app/models/invitation.rb
@@ -67,7 +67,7 @@ class Invitation &lt; Task @@ -67,7 +67,7 @@ class Invitation &lt; Task
67 end 67 end
68 68
69 begin 69 begin
70 - user = find_by_profile_id ? Person.find_by_id(contact_to_invite).user : User.find_by_email(friend_email) 70 + user = find_by_profile_id ? Person.find_by(id: contact_to_invite).user : User.find_by(email: friend_email)
71 rescue 71 rescue
72 user = nil 72 user = nil
73 end 73 end
app/models/moderate_user_registration.rb
@@ -27,7 +27,7 @@ class ModerateUserRegistration &lt; Task @@ -27,7 +27,7 @@ class ModerateUserRegistration &lt; Task
27 end 27 end
28 28
29 def perform 29 def perform
30 - user=environment.users.find_by_id(user_id) 30 + user=environment.users.find_by(id: user_id)
31 user.activate 31 user.activate
32 end 32 end
33 33
app/models/national_region.rb
@@ -27,12 +27,13 @@ class NationalRegion &lt; ActiveRecord::Base @@ -27,12 +27,13 @@ class NationalRegion &lt; ActiveRecord::Base
27 :type => NationalRegionType::CITY, 27 :type => NationalRegionType::CITY,
28 :state => state}]; 28 :state => state}];
29 29
30 - region = NationalRegion.find(find_return,  
31 - :select => "national_regions.name as city, nr.name as state, national_regions.national_region_code",  
32 - :conditions => conditions,  
33 - :joins => "LEFT JOIN national_regions as nr ON national_regions.parent_national_region_code = nr.national_region_code",  
34 - :limit => 10  
35 - ) 30 + region = NationalRegion
  31 + .select('national_regions.name as city, nr.name as state, national_regions.national_region_code')
  32 + .where(conditions)
  33 + .joins('LEFT JOIN national_regions as nr ON national_regions.parent_national_region_code = nr.national_region_code')
  34 + .limit(10)
  35 + region = region.send find_return
  36 +
36 return region 37 return region
37 end 38 end
38 39
@@ -50,19 +51,19 @@ class NationalRegion &lt; ActiveRecord::Base @@ -50,19 +51,19 @@ class NationalRegion &lt; ActiveRecord::Base
50 {:name => state_name, 51 {:name => state_name,
51 :type => NationalRegionType::STATE}]; 52 :type => NationalRegionType::STATE}];
52 53
53 - region = NationalRegion.find(find_return,  
54 - :select => "national_regions.name as state, national_regions.national_region_code",  
55 - :conditions => conditions,  
56 - :limit => 10  
57 - ) 54 + region = NationalRegion
  55 + .select('national_regions.name as state, national_regions.national_region_code')
  56 + .where(conditions)
  57 + .limit(10)
  58 + region = region.send find_return
  59 +
58 return region 60 return region
59 end 61 end
60 62
61 def self.validate!(city, state, country) 63 def self.validate!(city, state, country)
62 64
63 - country_region = NationalRegion.find_by_national_region_code(country,  
64 - :conditions => ["national_region_type_id = :type",  
65 - {:type => NationalRegionType::COUNTRY}]) 65 + country_region = NationalRegion
  66 + .find_by(national_region_code: country, national_region_type_id: NationalRegionType::COUNTRY)
66 67
67 if(country_region) 68 if(country_region)
68 69
app/models/organization.rb
@@ -55,7 +55,7 @@ class Organization &lt; Profile @@ -55,7 +55,7 @@ class Organization &lt; Profile
55 55
56 has_many :custom_roles, :class_name => 'Role', :foreign_key => :profile_id 56 has_many :custom_roles, :class_name => 'Role', :foreign_key => :profile_id
57 57
58 - scope :more_popular, :order => 'members_count DESC' 58 + scope :more_popular, -> { order 'members_count DESC' }
59 59
60 validate :presence_of_required_fieds, :unless => :is_template 60 validate :presence_of_required_fieds, :unless => :is_template
61 61
app/models/person.rb
@@ -109,7 +109,8 @@ class Person &lt; Profile @@ -109,7 +109,8 @@ class Person &lt; Profile
109 has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' 109 has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people'
110 has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' 110 has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions'
111 111
112 - has_many :suggested_profiles, class_name: 'ProfileSuggestion', foreign_key: :person_id, order: 'score DESC', dependent: :destroy 112 + has_many :suggested_profiles, -> { order 'score DESC' },
  113 + class_name: 'ProfileSuggestion', foreign_key: :person_id, dependent: :destroy
113 has_many :suggested_people, -> { 114 has_many :suggested_people, -> {
114 where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true 115 where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true
115 }, through: :suggested_profiles, source: :suggestion 116 }, through: :suggested_profiles, source: :suggestion
@@ -392,7 +393,7 @@ class Person &lt; Profile @@ -392,7 +393,7 @@ class Person &lt; Profile
392 393
393 394
394 def self.with_pending_tasks 395 def self.with_pending_tasks
395 - Person.find(:all).select{ |person| !person.tasks.pending.empty? or person.has_organization_pending_tasks? } 396 + Person.all.select{ |person| !person.tasks.pending.empty? or person.has_organization_pending_tasks? }
396 end 397 end
397 398
398 def has_organization_pending_tasks? 399 def has_organization_pending_tasks?
@@ -486,7 +487,7 @@ class Person &lt; Profile @@ -486,7 +487,7 @@ class Person &lt; Profile
486 end 487 end
487 488
488 def each_friend(offset=0) 489 def each_friend(offset=0)
489 - while friend = self.friends.first(:order => :id, :offset => offset) 490 + while friend = self.friends.order(:id).offset(offset).first
490 yield friend 491 yield friend
491 offset = offset + 1 492 offset = offset + 1
492 end 493 end
@@ -568,7 +569,7 @@ class Person &lt; Profile @@ -568,7 +569,7 @@ class Person &lt; Profile
568 end 569 end
569 570
570 def remove_suggestion(profile) 571 def remove_suggestion(profile)
571 - suggestion = suggested_profiles.find_by_suggestion_id profile.id 572 + suggestion = suggested_profiles.find_by suggestion_id: profile.id
572 suggestion.disable if suggestion 573 suggestion.disable if suggestion
573 end 574 end
574 575
app/models/product.rb
@@ -28,7 +28,7 @@ class Product &lt; ActiveRecord::Base @@ -28,7 +28,7 @@ class Product &lt; ActiveRecord::Base
28 28
29 belongs_to :product_category 29 belongs_to :product_category
30 30
31 - has_many :inputs, :dependent => :destroy, :order => 'position' 31 + has_many :inputs, -> { order 'position' }, dependent: :destroy
32 has_many :price_details, :dependent => :destroy 32 has_many :price_details, :dependent => :destroy
33 has_many :production_costs, :through => :price_details 33 has_many :production_costs, :through => :price_details
34 34
@@ -50,7 +50,7 @@ class Product &lt; ActiveRecord::Base @@ -50,7 +50,7 @@ class Product &lt; ActiveRecord::Base
50 validates_numericality_of :price, :allow_nil => true 50 validates_numericality_of :price, :allow_nil => true
51 validates_numericality_of :discount, :allow_nil => true 51 validates_numericality_of :discount, :allow_nil => true
52 52
53 - scope :more_recent, :order => "created_at DESC" 53 + scope :more_recent, -> { order 'created_at DESC' }
54 54
55 scope :from_category, -> category { 55 scope :from_category, -> category {
56 joins(:product_category).where('categories.path LIKE ?', "%#{category.slug}%") if category 56 joins(:product_category).where('categories.path LIKE ?', "%#{category.slug}%") if category
@@ -75,6 +75,8 @@ class Product &lt; ActiveRecord::Base @@ -75,6 +75,8 @@ class Product &lt; ActiveRecord::Base
75 ).uniq 75 ).uniq
76 } 76 }
77 77
  78 + scope :recent, -> limit=nil { order('id DESC').limit(limit) }
  79 +
78 after_update :save_image 80 after_update :save_image
79 81
80 def lat 82 def lat
@@ -128,10 +130,6 @@ class Product &lt; ActiveRecord::Base @@ -128,10 +130,6 @@ class Product &lt; ActiveRecord::Base
128 product_category ? product_category.name : _('Uncategorized product') 130 product_category ? product_category.name : _('Uncategorized product')
129 end 131 end
130 132
131 - def self.recent(limit = nil)  
132 - self.find(:all, :order => 'id desc', :limit => limit)  
133 - end  
134 -  
135 def url 133 def url
136 self.profile.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => id) 134 self.profile.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => id)
137 end 135 end
app/models/product_category.rb
@@ -5,7 +5,7 @@ class ProductCategory &lt; Category @@ -5,7 +5,7 @@ class ProductCategory &lt; Category
5 5
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, -> enterprise { 9 scope :by_enterprise, -> enterprise {
10 distinct.joins(:products). 10 distinct.joins(:products).
11 where('products.profile_id = ?', enterprise.id) 11 where('products.profile_id = ?', enterprise.id)
app/models/profile.rb
@@ -62,7 +62,7 @@ class Profile &lt; ActiveRecord::Base @@ -62,7 +62,7 @@ class Profile &lt; ActiveRecord::Base
62 end 62 end
63 private 63 private
64 def self.find_role(name, env_id) 64 def self.find_role(name, env_id)
65 - ::Role.find_by_key_and_environment_id("profile_#{name}", env_id) 65 + ::Role.find_by key: "profile_#{name}", environment_id: env_id
66 end 66 end
67 end 67 end
68 68
@@ -115,6 +115,9 @@ class Profile &lt; ActiveRecord::Base @@ -115,6 +115,9 @@ class Profile &lt; ActiveRecord::Base
115 } 115 }
116 scope :no_templates, -> { where is_template: false } 116 scope :no_templates, -> { where is_template: false }
117 117
  118 + scope :recent, -> limit=nil { order('id DESC').limit(limit) }
  119 +
  120 +
118 # Returns a scoped object to select profiles in a given location or in a radius 121 # Returns a scoped object to select profiles in a given location or in a radius
119 # distance from the given location center. 122 # distance from the given location center.
120 # The parameter can be the `request.params` with the keys: 123 # The parameter can be the `request.params` with the keys:
@@ -178,14 +181,6 @@ class Profile &lt; ActiveRecord::Base @@ -178,14 +181,6 @@ class Profile &lt; ActiveRecord::Base
178 members(field).where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value 181 members(field).where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value
179 end 182 end
180 183
181 - class << self  
182 - def count_with_distinct(*args)  
183 - options = args.last || {}  
184 - count_without_distinct(:id, {:distinct => true}.merge(options))  
185 - end  
186 - alias_method_chain :count, :distinct  
187 - end  
188 -  
189 def members_by_role(roles) 184 def members_by_role(roles)
190 Person.members_of(self).by_role(roles) 185 Person.members_of(self).by_role(roles)
191 end 186 end
@@ -203,18 +198,17 @@ class Profile &lt; ActiveRecord::Base @@ -203,18 +198,17 @@ class Profile &lt; ActiveRecord::Base
203 scope :is_public, -> { where visible: true, public_profile: true, secret: false } 198 scope :is_public, -> { where visible: true, public_profile: true, secret: false }
204 scope :enabled, -> { where enabled: true } 199 scope :enabled, -> { where enabled: true }
205 200
206 - # Subclasses must override this method  
207 - scope :more_popular  
208 -  
209 - scope :more_active, :order => 'activities_count DESC'  
210 - scope :more_recent, :order => "created_at DESC" 201 + # subclass specific
  202 + scope :more_popular, -> { }
  203 + scope :more_active, -> { order 'activities_count DESC' }
  204 + scope :more_recent, -> { order "created_at DESC" }
211 205
212 acts_as_trackable :dependent => :destroy 206 acts_as_trackable :dependent => :destroy
213 207
214 has_many :profile_activities 208 has_many :profile_activities
215 has_many :action_tracker_notifications, :foreign_key => 'profile_id' 209 has_many :action_tracker_notifications, :foreign_key => 'profile_id'
216 - has_many :tracked_notifications, :through => :action_tracker_notifications, :source => :action_tracker, :order => 'updated_at DESC'  
217 - has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC", :dependent => :destroy 210 + has_many :tracked_notifications, -> { order 'updated_at DESC' }, through: :action_tracker_notifications, source: :action_tracker
  211 + has_many :scraps_received, -> { order 'updated_at DESC' }, class_name: 'Scrap', foreign_key: :receiver_id, dependent: :destroy
218 belongs_to :template, :class_name => 'Profile', :foreign_key => 'template_id' 212 belongs_to :template, :class_name => 'Profile', :foreign_key => 'template_id'
219 213
220 has_many :comments_received, :class_name => 'Comment', :through => :articles, :source => :comments 214 has_many :comments_received, :class_name => 'Comment', :through => :articles, :source => :comments
@@ -295,7 +289,7 @@ class Profile &lt; ActiveRecord::Base @@ -295,7 +289,7 @@ class Profile &lt; ActiveRecord::Base
295 289
296 has_many :tasks, :dependent => :destroy, :as => 'target' 290 has_many :tasks, :dependent => :destroy, :as => 'target'
297 291
298 - has_many :events, :source => 'articles', :class_name => 'Event', :order => 'start_date' 292 + has_many :events, -> { order 'start_date' }, source: 'articles', class_name: 'Event'
299 293
300 def find_in_all_tasks(task_id) 294 def find_in_all_tasks(task_id)
301 begin 295 begin
@@ -559,7 +553,7 @@ class Profile &lt; ActiveRecord::Base @@ -559,7 +553,7 @@ class Profile &lt; ActiveRecord::Base
559 # person = Profile['username'] 553 # person = Profile['username']
560 # org = Profile.['orgname'] 554 # org = Profile.['orgname']
561 def [](identifier) 555 def [](identifier)
562 - self.find_by_identifier(identifier) 556 + self.find_by identifier: identifier
563 end 557 end
564 558
565 end 559 end
@@ -738,11 +732,11 @@ private :generate_url, :url_options @@ -738,11 +732,11 @@ private :generate_url, :url_options
738 732
739 def copy_article_tree(article, parent=nil) 733 def copy_article_tree(article, parent=nil)
740 return if !copy_article?(article) 734 return if !copy_article?(article)
741 - original_article = self.articles.find_by_name(article.name) 735 + original_article = self.articles.find_by name: article.name
742 if original_article 736 if original_article
743 num = 2 737 num = 2
744 new_name = original_article.name + ' ' + num.to_s 738 new_name = original_article.name + ' ' + num.to_s
745 - while self.articles.find_by_name(new_name) 739 + while self.articles.find_by name: new_name
746 num = num + 1 740 num = num + 1
747 new_name = original_article.name + ' ' + num.to_s 741 new_name = original_article.name + ' ' + num.to_s
748 end 742 end
@@ -799,10 +793,6 @@ private :generate_url, :url_options @@ -799,10 +793,6 @@ private :generate_url, :url_options
799 end 793 end
800 end 794 end
801 795
802 - def self.recent(limit = nil)  
803 - self.find(:all, :order => 'id desc', :limit => limit)  
804 - end  
805 -  
806 # returns +true+ if the given +user+ can see profile information about this 796 # returns +true+ if the given +user+ can see profile information about this
807 # +profile+, and +false+ otherwise. 797 # +profile+, and +false+ otherwise.
808 def display_info_to?(user) 798 def display_info_to?(user)
@@ -896,7 +886,7 @@ private :generate_url, :url_options @@ -896,7 +886,7 @@ private :generate_url, :url_options
896 has_many :blogs, :source => 'articles', :class_name => 'Blog' 886 has_many :blogs, :source => 'articles', :class_name => 'Blog'
897 887
898 def blog 888 def blog
899 - self.has_blog? ? self.blogs.first(:order => 'id') : nil 889 + self.has_blog? ? self.blogs.order(:id).first : nil
900 end 890 end
901 891
902 def has_blog? 892 def has_blog?
@@ -906,7 +896,7 @@ private :generate_url, :url_options @@ -906,7 +896,7 @@ private :generate_url, :url_options
906 has_many :forums, :source => 'articles', :class_name => 'Forum' 896 has_many :forums, :source => 'articles', :class_name => 'Forum'
907 897
908 def forum 898 def forum
909 - self.has_forum? ? self.forums.first(:order => 'id') : nil 899 + self.has_forum? ? self.forums.order(:id).first : nil
910 end 900 end
911 901
912 def has_forum? 902 def has_forum?
@@ -1134,7 +1124,7 @@ private :generate_url, :url_options @@ -1134,7 +1124,7 @@ private :generate_url, :url_options
1134 settings_items :custom_url_redirection, type: String, default: nil 1124 settings_items :custom_url_redirection, type: String, default: nil
1135 1125
1136 def remove_from_suggestion_list(person) 1126 def remove_from_suggestion_list(person)
1137 - suggestion = person.suggested_profiles.find_by_suggestion_id self.id 1127 + suggestion = person.suggested_profiles.find_by suggestion_id: self.id
1138 suggestion.disable if suggestion 1128 suggestion.disable if suggestion
1139 end 1129 end
1140 1130
app/models/profile_activity.rb
@@ -9,8 +9,12 @@ class ProfileActivity &lt; ActiveRecord::Base @@ -9,8 +9,12 @@ class ProfileActivity &lt; ActiveRecord::Base
9 belongs_to :activity, polymorphic: true 9 belongs_to :activity, polymorphic: true
10 10
11 # non polymorphic versions 11 # non polymorphic versions
12 - belongs_to :scrap, foreign_key: :activity_id, class_name: 'Scrap', conditions: {profile_activities: {activity_type: 'Scrap'}}  
13 - belongs_to :action_tracker, foreign_key: :activity_id, class_name: 'ActionTracker::Record', conditions: {profile_activities: {activity_type: 'ActionTracker::Record'}} 12 + belongs_to :scrap, -> {
  13 + where profile_activities: {activity_type: 'Scrap'}
  14 + }, foreign_key: :activity_id, class_name: 'Scrap'
  15 + belongs_to :action_tracker, -> {
  16 + where profile_activities: {activity_type: 'ActionTracker::Record'}
  17 + }, foreign_key: :activity_id, class_name: 'ActionTracker::Record'
14 18
15 before_validation :copy_timestamps 19 before_validation :copy_timestamps
16 20
app/models/profile_list_block.rb
@@ -18,11 +18,11 @@ class ProfileListBlock &lt; Block @@ -18,11 +18,11 @@ class ProfileListBlock &lt; Block
18 result = nil 18 result = nil
19 public_profiles = profiles.is_public.includes([:image,:domains,:preferred_domain,:environment]) 19 public_profiles = profiles.is_public.includes([:image,:domains,:preferred_domain,:environment])
20 if !prioritize_profiles_with_image 20 if !prioritize_profiles_with_image
21 -result = public_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand } 21 + result = public_profiles.limit(get_limit).order('profiles.updated_at DESC').sort_by{ rand }
22 elsif profiles.visible.with_image.count >= get_limit 22 elsif profiles.visible.with_image.count >= get_limit
23 - result = public_profiles.with_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } 23 + result = public_profiles.with_image.limit(get_limit * 5).order('profiles.updated_at DESC').sort_by{ rand }
24 else 24 else
25 - result = public_profiles.with_image.sort_by{ rand } + public_profiles.without_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } 25 + result = public_profiles.with_image.sort_by{ rand } + public_profiles.without_image.limit(get_limit * 5).order('profiles.updated_at DESC').sort_by{ rand }
26 end 26 end
27 result.slice(0..get_limit-1) 27 result.slice(0..get_limit-1)
28 end 28 end
app/models/profile_suggestion.rb
@@ -120,7 +120,8 @@ class ProfileSuggestion &lt; ActiveRecord::Base @@ -120,7 +120,8 @@ class ProfileSuggestion &lt; ActiveRecord::Base
120 return if suggested_profiles.blank? 120 return if suggested_profiles.blank?
121 121
122 suggested_profiles.each do |suggested_profile| 122 suggested_profiles.each do |suggested_profile|
123 - suggestion = person.suggested_profiles.find_or_initialize_by_suggestion_id(suggested_profile.id) 123 + suggestion = person.suggested_profiles.find_by suggestion_id: suggested_profile.id
  124 + suggestion ||= person.suggested_profiles.build({suggestion_id: suggested_profile.id}, without_protection: true)
124 RULES.each do |rule, options| 125 RULES.each do |rule, options|
125 begin 126 begin
126 value = suggested_profile.send("#{rule}_count").to_i 127 value = suggested_profile.send("#{rule}_count").to_i
app/models/region.rb
1 -# Region is a special type of category that is related to geographical issues. 1 +# Region is a special type of category that is related to geographical issues.
2 class Region < Category 2 class Region < Category
3 -  
4 - attr_accessible :name  
5 - 3 +
  4 + attr_accessible :name
  5 +
6 has_and_belongs_to_many :validators, :class_name => 'Organization', :join_table => :region_validators 6 has_and_belongs_to_many :validators, :class_name => 'Organization', :join_table => :region_validators
7 7
8 require_dependency 'enterprise' # enterprises can also be validators 8 require_dependency 'enterprise' # enterprises can also be validators
@@ -11,8 +11,10 @@ class Region &lt; Category @@ -11,8 +11,10 @@ class Region &lt; Category
11 validators.count > 0 11 validators.count > 0
12 end 12 end
13 13
14 - scope :with_validators, :select => 'DISTINCT ON (categories.id) *',  
15 - :joins => 'INNER JOIN region_validators on (region_validators.region_id = categories.id)' 14 + scope :with_validators, -> {
  15 + select('DISTINCT ON (categories.id) *')
  16 + .joins('INNER JOIN region_validators on (region_validators.region_id = categories.id)')
  17 + }
16 18
17 end 19 end
18 20
app/models/scrap.rb
@@ -13,7 +13,9 @@ class Scrap &lt; ActiveRecord::Base @@ -13,7 +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 - has_many :profile_activities, foreign_key: :activity_id, conditions: {profile_activities: {activity_type: 'Scrap'}}, dependent: :destroy 16 + has_many :profile_activities, -> {
  17 + where profile_activities: {activity_type: 'Scrap'}
  18 + }, foreign_key: :activity_id, dependent: :destroy
17 19
18 after_create :create_activity 20 after_create :create_activity
19 after_update :update_activity 21 after_update :update_activity
app/models/search_term.rb
@@ -25,7 +25,7 @@ class SearchTerm &lt; ActiveRecord::Base @@ -25,7 +25,7 @@ class SearchTerm &lt; ActiveRecord::Base
25 # Therefore the score is 97. Them we sum every score to get the total score 25 # Therefore the score is 97. Them we sum every score to get the total score
26 # for a search term. 26 # for a search term.
27 def self.occurrences_scores 27 def self.occurrences_scores
28 - ActiveSupport::OrderedHash[*ActiveRecord::Base.connection.execute( 28 + Hash[*ActiveRecord::Base.connection.execute(
29 joins(:occurrences). 29 joins(:occurrences).
30 select("search_terms.id, sum(#{SearchTermOccurrence::EXPIRATION_TIME.to_i} - extract(epoch from (now() - search_term_occurrences.created_at))) as value"). 30 select("search_terms.id, sum(#{SearchTermOccurrence::EXPIRATION_TIME.to_i} - extract(epoch from (now() - search_term_occurrences.created_at))) as value").
31 where("search_term_occurrences.created_at > ?", DateTime.now - SearchTermOccurrence::EXPIRATION_TIME). 31 where("search_term_occurrences.created_at > ?", DateTime.now - SearchTermOccurrence::EXPIRATION_TIME).
app/models/task.rb
@@ -137,9 +137,9 @@ class Task &lt; ActiveRecord::Base @@ -137,9 +137,9 @@ class Task &lt; ActiveRecord::Base
137 group = klass.to_s.downcase.pluralize 137 group = klass.to_s.downcase.pluralize
138 id = attribute.to_s + "_id" 138 id = attribute.to_s + "_id"
139 if environment.respond_to?(group) 139 if environment.respond_to?(group)
140 - attrb = value || environment.send(group).find_by_id(record.send(id)) 140 + attrb = value || environment.send(group).find_by(id: record.send(id))
141 else 141 else
142 - attrb = value || klass.find_by_id(record.send(id)) 142 + attrb = value || klass.find_by(id: record.send(id))
143 end 143 end
144 if attrb.respond_to?(klass.to_s.downcase + "?") 144 if attrb.respond_to?(klass.to_s.downcase + "?")
145 unless attrb.send(klass.to_s.downcase + "?") 145 unless attrb.send(klass.to_s.downcase + "?")
app/models/unit.rb
1 class Unit < ActiveRecord::Base 1 class Unit < ActiveRecord::Base
2 2
  3 + acts_as_list scope: -> unit { where environment_id: unit.environment_id }
  4 +
3 attr_accessible :name, :singular, :plural, :environment 5 attr_accessible :name, :singular, :plural, :environment
4 6
5 validates_presence_of :singular 7 validates_presence_of :singular
6 validates_presence_of :plural 8 validates_presence_of :plural
7 9
8 belongs_to :environment 10 belongs_to :environment
  11 +
9 validates_presence_of :environment_id 12 validates_presence_of :environment_id
10 - acts_as_list :scope => :environment 13 + validates_presence_of :singular
  14 + validates_presence_of :plural
11 15
12 def name 16 def name
13 self.singular 17 self.singular
app/models/user.rb
@@ -25,7 +25,7 @@ class User &lt; ActiveRecord::Base @@ -25,7 +25,7 @@ class User &lt; ActiveRecord::Base
25 end 25 end
26 26
27 def self.[](login) 27 def self.[](login)
28 - self.find_by_login(login) 28 + self.find_by login: login
29 end 29 end
30 30
31 # FIXME ugly workaround 31 # FIXME ugly workaround
app/views/layouts/_user.html.erb
1 <div id="user"> 1 <div id="user">
2 - <% user = (session[:user] && User.find_by_id(session[:user])) || nil %> 2 + <% user = (session[:user] && User.find_by(id: session[:user])) || nil %>
3 <% if user.present? %> 3 <% if user.present? %>
4 <% user = user.person %> 4 <% user = user.person %>
5 <span class='logged-in'> 5 <span class='logged-in'>
app/views/shared/_list_groups.html.erb
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 </div> 6 </div>
7 <span class='profile-details'> 7 <span class='profile-details'>
8 <strong><%= group.name %></strong><br/> 8 <strong><%= group.name %></strong><br/>
9 - <%= _('Role: %s') % rolename_for(profile, group) + '<br/>' if profile.role_assignments.find_by_resource_id(group.id) %> 9 + <%= _('Role: %s') % rolename_for(profile, group) + '<br/>' if profile.role_assignments.find_by(resource_id: group.id) %>
10 <%= _('Type: %s') % _(group.class.identification) %> <br/> 10 <%= _('Type: %s') % _(group.class.identification) %> <br/>
11 <%= _('Description: %s') % group.description + '<br/>' if group.community? %> 11 <%= _('Description: %s') % group.description + '<br/>' if group.community? %>
12 <%= _('Members: %s') % group.members_count.to_s %> <br/> 12 <%= _('Members: %s') % group.members_count.to_s %> <br/>
app/views/spam/_suggest_article.html.erb
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 <li><strong><%=_('Email')%></strong>: <%=task.email%> </li> 9 <li><strong><%=_('Email')%></strong>: <%=task.email%> </li>
10 <li><strong><%=_('Source')%></strong>: <%=task.article_object.source_name%> </li> 10 <li><strong><%=_('Source')%></strong>: <%=task.article_object.source_name%> </li>
11 <li><strong><%=_('Source URL')%></strong>: <%=task.article_object.source%> </li> 11 <li><strong><%=_('Source URL')%></strong>: <%=task.article_object.source%> </li>
12 - <li><strong><%=_('Folder')%></strong>: <%=(a = Article.find_by_id(task.article_object.parent_id))?a.name : '<em>' + s_('Folder|none') + '</em>'%> </li> 12 + <li><strong><%=_('Folder')%></strong>: <%=if (a = Article.find_by(id: task.article_object.parent_id)) then a.name else '<em>' + s_('Folder|none') + '</em>' end%> </li>
13 <li><strong><%=_('Lead')%></strong>: <%=task.article_object.abstract.blank? ? '<em>' + s_('Abstract|empty') + '</em>' : task.article_object.abstract%> </li> 13 <li><strong><%=_('Lead')%></strong>: <%=task.article_object.abstract.blank? ? '<em>' + s_('Abstract|empty') + '</em>' : task.article_object.abstract%> </li>
14 <li><strong><%=_('Body')%></strong>: 14 <li><strong><%=_('Body')%></strong>:
15 <div class='suggest-article-body'> 15 <div class='suggest-article-body'>
db/migrate/033_destroy_organization_and_person_infos.rb
1 class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration 1 class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration
2 def self.up 2 def self.up
3 - Person.find(:all).each do |i| 3 + Person.find_each do |i|
4 info = ActiveRecord::Base.connection.select_one("select * from person_infos where person_id = #{i.id}") 4 info = ActiveRecord::Base.connection.select_one("select * from person_infos where person_id = #{i.id}")
5 i.name = info["name"] unless info["name"].nil? 5 i.name = info["name"] unless info["name"].nil?
6 i.address = info["address"] unless info["address"].nil? 6 i.address = info["address"] unless info["address"].nil?
@@ -11,7 +11,7 @@ class DestroyOrganizationAndPersonInfos &lt; ActiveRecord::Migration @@ -11,7 +11,7 @@ class DestroyOrganizationAndPersonInfos &lt; ActiveRecord::Migration
11 end 11 end
12 drop_table :person_infos 12 drop_table :person_infos
13 13
14 - Organization.find(:all).each do |i| 14 + Organization.find_each do |i|
15 info = ActiveRecord::Base.connection.select_one("select * from organization_infos where organization_id = #{i.id}") 15 info = ActiveRecord::Base.connection.select_one("select * from organization_infos where organization_id = #{i.id}")
16 [ "contact_person", "contact_email", "acronym", "foundation_year", "legal_form", "economic_activity", "management_information", "validated" ].each do |field| 16 [ "contact_person", "contact_email", "acronym", "foundation_year", "legal_form", "economic_activity", "management_information", "validated" ].each do |field|
17 i.send("#{field}=", info[field]) 17 i.send("#{field}=", info[field])
db/migrate/043_add_virtual_flag_to_categorizations.rb
@@ -2,13 +2,13 @@ class AddVirtualFlagToCategorizations &lt; ActiveRecord::Migration @@ -2,13 +2,13 @@ class AddVirtualFlagToCategorizations &lt; ActiveRecord::Migration
2 def self.up 2 def self.up
3 add_column :articles_categories, :virtual, :boolean, :default => false 3 add_column :articles_categories, :virtual, :boolean, :default => false
4 execute('update articles_categories set virtual = (1!=1)') 4 execute('update articles_categories set virtual = (1!=1)')
5 - Article.find(:all).each do |article| 5 + Article.find_each do |article|
6 article.category_ids = article.categories.map(&:id) 6 article.category_ids = article.categories.map(&:id)
7 end 7 end
8 8
9 add_column :categories_profiles, :virtual, :boolean, :default => false 9 add_column :categories_profiles, :virtual, :boolean, :default => false
10 execute('update categories_profiles set virtual = (1!=1)') 10 execute('update categories_profiles set virtual = (1!=1)')
11 - Profile.find(:all).each do |profile| 11 + Profile.find_each do |profile|
12 profile.category_ids = profile.categories.map(&:id) 12 profile.category_ids = profile.categories.map(&:id)
13 end 13 end
14 end 14 end
db/migrate/044_create_product_categorizations.rb
1 class CreateProductCategorizations < ActiveRecord::Migration 1 class CreateProductCategorizations < ActiveRecord::Migration
2 def self.up 2 def self.up
3 - 3 +
4 create_table :product_categorizations do |t| 4 create_table :product_categorizations do |t|
5 t.integer :category_id 5 t.integer :category_id
6 t.integer :product_id 6 t.integer :product_id
@@ -11,7 +11,7 @@ class CreateProductCategorizations &lt; ActiveRecord::Migration @@ -11,7 +11,7 @@ class CreateProductCategorizations &lt; ActiveRecord::Migration
11 11
12 total = Product.count.to_f 12 total = Product.count.to_f
13 percent = 0 13 percent = 0
14 - Product.find(:all).each_with_index do |p,i| 14 + Product.find_each_with_index do |p,i|
15 if p.product_category 15 if p.product_category
16 ProductCategorization.add_category_to_product(p.product_category, p) 16 ProductCategorization.add_category_to_product(p.product_category, p)
17 end 17 end
db/migrate/052_create_templates.rb
1 class CreateTemplates < ActiveRecord::Migration 1 class CreateTemplates < ActiveRecord::Migration
2 def self.up 2 def self.up
3 - Environment.find(:all).each do |env| 3 + Environment.find_each do |env|
4 if env.person_template.nil? && env.community_template.nil? && env.enterprise_template.nil? 4 if env.person_template.nil? && env.community_template.nil? && env.enterprise_template.nil?
5 env.create_templates 5 env.create_templates
6 end 6 end
db/migrate/069_add_enviroment_id_to_role.rb
@@ -12,13 +12,13 @@ class AddEnviromentIdToRole &lt; ActiveRecord::Migration @@ -12,13 +12,13 @@ class AddEnviromentIdToRole &lt; ActiveRecord::Migration
12 def self.up 12 def self.up
13 add_column :roles, :environment_id, :integer 13 add_column :roles, :environment_id, :integer
14 14
15 - roles = Role.find(:all)  
16 - Environment.find(:all).each do |env| 15 + roles = Role.all
  16 + Environment.find_each do |env|
17 roles.each do |role| 17 roles.each do |role|
18 re = RoleWithEnvironment.new(role.attributes) 18 re = RoleWithEnvironment.new(role.attributes)
19 re.environment = env 19 re.environment = env
20 re.save 20 re.save
21 - RoleAssignment.find_all_by_role_id(role.id).select{|ra| ra.resource && (ra.resource.kind_of?(Profile) ? ra.resource.environment_id : ra.resource.id) == env.id }.each do |ra| 21 + RoleAssignment.where(role_id: role.id).select{|ra| ra.resource && (ra.resource.kind_of?(Profile) ? ra.resource.environment_id : ra.resource.id) == env.id }.each do |ra|
22 ra.role_id = re.id 22 ra.role_id = re.id
23 ra.save 23 ra.save
24 end 24 end
@@ -30,14 +30,14 @@ class AddEnviromentIdToRole &lt; ActiveRecord::Migration @@ -30,14 +30,14 @@ class AddEnviromentIdToRole &lt; ActiveRecord::Migration
30 def self.down 30 def self.down
31 roles_by_name = {} 31 roles_by_name = {}
32 roles_by_key = {} 32 roles_by_key = {}
33 - roles_with_environment = RoleWithEnvironment.find(:all) 33 + roles_with_environment = RoleWithEnvironment.all
34 roles_with_environment.each do |re| 34 roles_with_environment.each do |re|
35 if re.key 35 if re.key
36 role = roles_by_name[re.key] || roles_by_key[re.name] || Role.create(re.attributes) 36 role = roles_by_name[re.key] || roles_by_key[re.name] || Role.create(re.attributes)
37 roles_by_name[role.name] ||= roles_by_key[role.key] ||= role 37 roles_by_name[role.name] ||= roles_by_key[role.key] ||= role
38 end 38 end
39 role = roles_by_name[re.name] ||= Role.create(re.attributes) unless role 39 role = roles_by_name[re.name] ||= Role.create(re.attributes) unless role
40 - RoleAssignment.find_all_by_role_id(re.id).each do |ra| 40 + RoleAssignment.where(role_id: re.id).each do |ra|
41 ra.role_id = role.id 41 ra.role_id = role.id
42 ra.save 42 ra.save
43 end 43 end
db/migrate/20100413231206_strip_html_from_tag_names.rb
1 class StripHtmlFromTagNames < ActiveRecord::Migration 1 class StripHtmlFromTagNames < ActiveRecord::Migration
2 def self.up 2 def self.up
3 - Tag.all(:conditions => "name LIKE '%<%' OR name LIKE '%>%'").each do |tag| 3 + Tag.where("name LIKE '%<%' OR name LIKE '%>%'").find_each do |tag|
4 tag.name = tag.name.gsub(/[<>]/, '') 4 tag.name = tag.name.gsub(/[<>]/, '')
5 tag.save 5 tag.save
6 end 6 end
db/migrate/20100621235235_set_product_category_id_to_products.rb
1 class SetProductCategoryIdToProducts < ActiveRecord::Migration 1 class SetProductCategoryIdToProducts < ActiveRecord::Migration
2 def self.up 2 def self.up
3 - Product.all(:conditions => { :product_category_id => nil }).each do |product| 3 + Product.where(product_category_id: nil).find_each do |product|
4 next if product.enterprise.nil? 4 next if product.enterprise.nil?
5 product.update_attribute(:product_category_id, ProductCategory.top_level_for(product.enterprise.environment).first.id) 5 product.update_attribute(:product_category_id, ProductCategory.top_level_for(product.enterprise.environment).first.id)
6 end 6 end
db/migrate/20100730141134_set_owner_environment_to_enterprises_environment.rb
1 class SetOwnerEnvironmentToEnterprisesEnvironment < ActiveRecord::Migration 1 class SetOwnerEnvironmentToEnterprisesEnvironment < ActiveRecord::Migration
2 def self.up 2 def self.up
3 - CreateEnterprise.find_all_by_status(3).each do |t|  
4 - if(Enterprise.find_by_identifier(t.data[:identifier])) 3 + CreateEnterprise.where(status: 3).each do |t|
  4 + if(Enterprise.find_by(identifier: t.data[:identifier]))
5 update("UPDATE profiles SET environment_id = '%s' WHERE identifier = '%s'" % 5 update("UPDATE profiles SET environment_id = '%s' WHERE identifier = '%s'" %
6 [Person.find(t.requestor_id).environment.id, t.data[:identifier]]) 6 [Person.find(t.requestor_id).environment.id, t.data[:identifier]])
7 end 7 end
db/migrate/20100809044243_dont_accept_null_to_environment_theme.rb
1 class DontAcceptNullToEnvironmentTheme < ActiveRecord::Migration 1 class DontAcceptNullToEnvironmentTheme < ActiveRecord::Migration
2 def self.up 2 def self.up
3 - Environment.all(:conditions => {:theme => nil}).each do |environment| 3 + Environment.where(theme: nil).find_each do |environment|
4 environment.update_attribute(:theme, 'default') 4 environment.update_attribute(:theme, 'default')
5 end 5 end
6 6
@@ -10,7 +10,7 @@ class DontAcceptNullToEnvironmentTheme &lt; ActiveRecord::Migration @@ -10,7 +10,7 @@ class DontAcceptNullToEnvironmentTheme &lt; ActiveRecord::Migration
10 def self.down 10 def self.down
11 change_column :environments, :theme, :string, :default => nil, :null => true 11 change_column :environments, :theme, :string, :default => nil, :null => true
12 12
13 - Environment.all(:conditions => {:theme => 'default'}).each do |environment| 13 + Environment.where(theme: 'default').find_each do |environment|
14 environment.update_attribute(:theme, nil) 14 environment.update_attribute(:theme, nil)
15 end 15 end
16 end 16 end
db/migrate/20100920182433_change_action_tracker_record.rb
@@ -2,7 +2,7 @@ class ChangeActionTrackerRecord &lt; ActiveRecord::Migration @@ -2,7 +2,7 @@ class ChangeActionTrackerRecord &lt; ActiveRecord::Migration
2 def self.up 2 def self.up
3 rename_column(:action_tracker, :dispatcher_type, :target_type) 3 rename_column(:action_tracker, :dispatcher_type, :target_type)
4 rename_column(:action_tracker, :dispatcher_id, :target_id) 4 rename_column(:action_tracker, :dispatcher_id, :target_id)
5 - ActionTracker::Record.update_all("verb='create_article'", {:verb => 'publish_article_in_community'}) 5 + ActionTracker:Record.where(verb: 'publish_article_in_community').update_all verb: 'create_article'
6 end 6 end
7 7
8 def self.down 8 def self.down
db/migrate/20111228202739_remove_useless_tracked_actions.rb
@@ -2,7 +2,7 @@ class RemoveUselessTrackedActions &lt; ActiveRecord::Migration @@ -2,7 +2,7 @@ class RemoveUselessTrackedActions &lt; ActiveRecord::Migration
2 def self.up 2 def self.up
3 select_all("SELECT id FROM action_tracker").each do |tracker| 3 select_all("SELECT id FROM action_tracker").each do |tracker|
4 verbs = ['update_article', 'remove_article', 'leave_comment', 'leave_community', 'remove_member_in_community'] 4 verbs = ['update_article', 'remove_article', 'leave_comment', 'leave_community', 'remove_member_in_community']
5 - activity = ActionTracker::Record.find_by_id(tracker['id']) 5 + activity = ActionTracker::Record.find_by(id: tracker['id'])
6 if activity 6 if activity
7 if (activity.updated_at.to_time < Time.now.months_ago(3)) || verbs.include?(activity.verb) 7 if (activity.updated_at.to_time < Time.now.months_ago(3)) || verbs.include?(activity.verb)
8 activity.destroy 8 activity.destroy
db/migrate/20120228202739_adapt_create_articles_activity.rb
@@ -4,7 +4,7 @@ class AdaptCreateArticlesActivity &lt; ActiveRecord::Migration @@ -4,7 +4,7 @@ class AdaptCreateArticlesActivity &lt; ActiveRecord::Migration
4 # Creating new activities only to recent articles (not grouping) 4 # Creating new activities only to recent articles (not grouping)
5 def self.up 5 def self.up
6 select_all("SELECT id FROM action_tracker WHERE verb = 'create_article'").each do |tracker| 6 select_all("SELECT id FROM action_tracker WHERE verb = 'create_article'").each do |tracker|
7 - activity = ActionTracker::Record.find_by_id(tracker['id']) 7 + activity = ActionTracker::Record.find_by(id: tracker['id'])
8 if activity 8 if activity
9 activity.destroy 9 activity.destroy
10 end 10 end
db/migrate/20120718162001_create_default_licenses.rb
@@ -14,14 +14,14 @@ class CreateDefaultLicenses &lt; ActiveRecord::Migration @@ -14,14 +14,14 @@ class CreateDefaultLicenses &lt; ActiveRecord::Migration
14 14
15 def self.down 15 def self.down
16 licenses = [] 16 licenses = []
17 - licenses += License.find(:all, :conditions => {:name => 'CC (by)'})  
18 - licenses += License.find(:all, :conditions => {:name => 'CC (by-nd)'})  
19 - licenses += License.find(:all, :conditions => {:name => 'CC (by-sa)'})  
20 - licenses += License.find(:all, :conditions => {:name => 'CC (by-nc)'})  
21 - licenses += License.find(:all, :conditions => {:name => 'CC (by-nc-nd)'})  
22 - licenses += License.find(:all, :conditions => {:name => 'CC (by-nc-sa)'})  
23 - licenses += License.find(:all, :conditions => {:name => 'Free Art'})  
24 - licenses += License.find(:all, :conditions => {:name => 'GNU FDL'}) 17 + licenses += License.where name: 'CC (by)'
  18 + licenses += License.where name: 'CC (by-nd)'
  19 + licenses += License.where name: 'CC (by-sa)'
  20 + licenses += License.where name: 'CC (by-nc)'
  21 + licenses += License.where name: 'CC (by-nc-nd)'
  22 + licenses += License.where name: 'CC (by-nc-sa)'
  23 + licenses += License.where name: 'Free Art'
  24 + licenses += License.where name: 'GNU FDL'
25 licenses.compact.map(&:destroy) 25 licenses.compact.map(&:destroy)
26 end 26 end
27 end 27 end
db/migrate/20120818030329_remove_action_tracker_with_target_nil.rb
1 class RemoveActionTrackerWithTargetNil < ActiveRecord::Migration 1 class RemoveActionTrackerWithTargetNil < ActiveRecord::Migration
2 def self.up 2 def self.up
3 select_all("SELECT id FROM action_tracker").each do |tracker| 3 select_all("SELECT id FROM action_tracker").each do |tracker|
4 - activity = ActionTracker::Record.find_by_id(tracker['id']) 4 + activity = ActionTracker::Record.find_by(id: tracker['id'])
5 if activity && activity.target.nil? 5 if activity && activity.target.nil?
6 activity.destroy 6 activity.destroy
7 end 7 end
db/migrate/20140221142304_move_title_virtual_field_to_name_in_uploaded_file.rb
@@ -2,8 +2,8 @@ class MoveTitleVirtualFieldToNameInUploadedFile &lt; ActiveRecord::Migration @@ -2,8 +2,8 @@ class MoveTitleVirtualFieldToNameInUploadedFile &lt; ActiveRecord::Migration
2 def self.up 2 def self.up
3 UploadedFile.find_each do |uploaded_file| 3 UploadedFile.find_each do |uploaded_file|
4 uploaded_file.name = uploaded_file.setting.delete(:title) 4 uploaded_file.name = uploaded_file.setting.delete(:title)
5 - UploadedFile.update_all({:setting => uploaded_file.setting.to_yaml, :name => uploaded_file.name},  
6 - "id = #{uploaded_file.id}") 5 + UploadedFile.where(id: uploaded_file.id).update_all setting: uploaded_file.setting.to_yaml, name: uploaded_file.name
  6 +
7 end 7 end
8 end 8 end
9 9
db/migrate/20140807134625_change_category_display_color_to_string.rb
@@ -8,7 +8,7 @@ class ChangeCategoryDisplayColorToString &lt; ActiveRecord::Migration @@ -8,7 +8,7 @@ class ChangeCategoryDisplayColorToString &lt; ActiveRecord::Migration
8 end 8 end
9 9
10 COLORS.each_with_index do |color, i| 10 COLORS.each_with_index do |color, i|
11 - Category.update_all({:display_color_tmp => color}, {:display_color => i+1}) 11 + Category.where(display_color: i+1).update_all display_color_tmp: color
12 end 12 end
13 13
14 change_table :categories do |t| 14 change_table :categories do |t|
@@ -25,7 +25,7 @@ class ChangeCategoryDisplayColorToString &lt; ActiveRecord::Migration @@ -25,7 +25,7 @@ class ChangeCategoryDisplayColorToString &lt; ActiveRecord::Migration
25 end 25 end
26 26
27 COLORS.each_with_index do |color, i| 27 COLORS.each_with_index do |color, i|
28 - Category.update_all({:display_color_tmp => i+1}, {:display_color => color}) 28 + Category.where(display_color: color).update_all display_color_tmp: i+1
29 end 29 end
30 30
31 change_table :categories do |t| 31 change_table :categories do |t|
db/migrate/20150210143723_add_custom_roles_permission_to_admin_roles.rb
1 class AddCustomRolesPermissionToAdminRoles < ActiveRecord::Migration 1 class AddCustomRolesPermissionToAdminRoles < ActiveRecord::Migration
2 def self.up 2 def self.up
3 - environment_admin = Role.find_by_key("environment_administrator")  
4 - profile_admin = Role.find_by_key("profile_admin") 3 + environment_admin = Role.find_by(key: "environment_administrator")
  4 + profile_admin = Role.find_by(key: "profile_admin")
5 environment_admin.permissions.append("manage_custom_roles") 5 environment_admin.permissions.append("manage_custom_roles")
6 profile_admin.permissions.append("manage_custom_roles") 6 profile_admin.permissions.append("manage_custom_roles")
7 environment_admin.save! 7 environment_admin.save!
8 profile_admin.save! 8 profile_admin.save!
9 end 9 end
10 def self.down 10 def self.down
11 - environment_admin = Role.find_by_key("environment_administrator")  
12 - profile_admin = Role.find_by_key("profile_admin") 11 + environment_admin = Role.find_by(key: "environment_administrator")
  12 + profile_admin = Role.find_by(key: "profile_admin")
13 environment_admin.permissions.delete("manage_custom_roles") 13 environment_admin.permissions.delete("manage_custom_roles")
14 profile_admin.permissions.delete("manage_custom_roles") 14 profile_admin.permissions.delete("manage_custom_roles")
15 environment_admin.save! 15 environment_admin.save!
debian/control
@@ -45,7 +45,6 @@ Depends: adduser, @@ -45,7 +45,6 @@ Depends: adduser,
45 ruby-actionpack-action-caching, 45 ruby-actionpack-action-caching,
46 ruby-actionpack-page-caching, 46 ruby-actionpack-page-caching,
47 ruby-activerecord-session-store, 47 ruby-activerecord-session-store,
48 - ruby-activerecord-deprecated-finders,  
49 ruby-acts-as-taggable-on (>= 3.5), 48 ruby-acts-as-taggable-on (>= 3.5),
50 ruby-api-pagination, 49 ruby-api-pagination,
51 ruby-daemons, 50 ruby-daemons,
features/step_definitions/activate_enterprise_steps.rb
1 Given /^I fill in "([^\"]*)" with code of "([^\"]*)"$/ do |field, enterprise| 1 Given /^I fill in "([^\"]*)" with code of "([^\"]*)"$/ do |field, enterprise|
2 - enterprise = Enterprise.find_by_name(enterprise) 2 + enterprise = Enterprise.find_by(name: enterprise)
3 value = EnterpriseActivation.all.select { |task| task.enterprise == enterprise}.first.code 3 value = EnterpriseActivation.all.select { |task| task.enterprise == enterprise}.first.code
4 fill_in(field, :with => value) 4 fill_in(field, :with => value)
5 end 5 end
6 6
7 Given /^enterprise "([^\"]*)" should be enabled$/ do |enterprise| 7 Given /^enterprise "([^\"]*)" should be enabled$/ do |enterprise|
8 - Enterprise.find_by_name(enterprise).enabled?.should be_truthy 8 + Enterprise.find_by(name: enterprise).enabled?.should be_truthy
9 end 9 end
10 10
11 Given /^"([^\"]*)" is the active enterprise template$/ do |enterprise| 11 Given /^"([^\"]*)" is the active enterprise template$/ do |enterprise|
12 - template = Enterprise.find_by_name(enterprise) 12 + template = Enterprise.find_by(name: enterprise)
13 template.boxes.destroy_all 13 template.boxes.destroy_all
14 template.boxes << Box.new 14 template.boxes << Box.new
15 template.layout_template = 'leftbar' 15 template.layout_template = 'leftbar'
@@ -24,8 +24,8 @@ Given /^&quot;([^\&quot;]*)&quot; is the active enterprise template$/ do |enterprise| @@ -24,8 +24,8 @@ Given /^&quot;([^\&quot;]*)&quot; is the active enterprise template$/ do |enterprise|
24 end 24 end
25 25
26 Given /^"([^\"]*)" has "([^\"]*)" as template$/ do |ent, templ| 26 Given /^"([^\"]*)" has "([^\"]*)" as template$/ do |ent, templ|
27 - template = Enterprise.find_by_name(templ)  
28 - enterprise = Enterprise.find_by_name(ent) 27 + template = Enterprise.find_by(name: templ)
  28 + enterprise = Enterprise.find_by(name: ent)
29 (template.boxes.size == enterprise.boxes.size).should be_truthy 29 (template.boxes.size == enterprise.boxes.size).should be_truthy
30 (template.layout_template == enterprise.layout_template).should be_truthy 30 (template.layout_template == enterprise.layout_template).should be_truthy
31 (template.theme == enterprise.theme).should be_truthy 31 (template.theme == enterprise.theme).should be_truthy
@@ -34,8 +34,8 @@ Given /^&quot;([^\&quot;]*)&quot; has &quot;([^\&quot;]*)&quot; as template$/ do |ent, templ| @@ -34,8 +34,8 @@ Given /^&quot;([^\&quot;]*)&quot; has &quot;([^\&quot;]*)&quot; as template$/ do |ent, templ|
34 end 34 end
35 35
36 Given /^"([^\"]*)" doesnt have "([^\"]*)" as template$/ do |ent, templ| 36 Given /^"([^\"]*)" doesnt have "([^\"]*)" as template$/ do |ent, templ|
37 - template = Enterprise.find_by_name(templ)  
38 - enterprise = Enterprise.find_by_name(ent) 37 + template = Enterprise.find_by(name: templ)
  38 + enterprise = Enterprise.find_by(name: ent)
39 (template.boxes.size == enterprise.boxes.size).should be_falsey 39 (template.boxes.size == enterprise.boxes.size).should be_falsey
40 (template.layout_template == enterprise.layout_template).should be_falsey 40 (template.layout_template == enterprise.layout_template).should be_falsey
41 (template.theme == enterprise.theme).should be_falsey 41 (template.theme == enterprise.theme).should be_falsey
@@ -44,16 +44,16 @@ Given /^&quot;([^\&quot;]*)&quot; doesnt have &quot;([^\&quot;]*)&quot; as template$/ do |ent, templ| @@ -44,16 +44,16 @@ Given /^&quot;([^\&quot;]*)&quot; doesnt have &quot;([^\&quot;]*)&quot; as template$/ do |ent, templ|
44 end 44 end
45 45
46 Given /^enterprise "([^\"]*)" is enabled$/ do |enterprise| 46 Given /^enterprise "([^\"]*)" is enabled$/ do |enterprise|
47 - Enterprise.find_by_name(enterprise).update_attribute(:enabled,true)  
48 - Enterprise.find_by_name(enterprise).enabled?.should be_truthy 47 + Enterprise.find_by(name: enterprise).update_attribute(:enabled,true)
  48 + Enterprise.find_by(name: enterprise).enabled?.should be_truthy
49 end 49 end
50 50
51 Given /^enterprise "([^\"]*)" should be blocked$/ do |enterprise| 51 Given /^enterprise "([^\"]*)" should be blocked$/ do |enterprise|
52 - Enterprise.find_by_name(enterprise).blocked?.should be_truthy 52 + Enterprise.find_by(name: enterprise).blocked?.should be_truthy
53 end 53 end
54 54
55 Given /^enterprise "([^\"]*)" should not be blocked$/ do |enterprise| 55 Given /^enterprise "([^\"]*)" should not be blocked$/ do |enterprise|
56 - Enterprise.find_by_name(enterprise).blocked?.should_not be_truthy 56 + Enterprise.find_by(name: enterprise).blocked?.should_not be_truthy
57 end 57 end
58 58
59 Given /^enterprise template must be replaced after enable$/ do 59 Given /^enterprise template must be replaced after enable$/ do
features/step_definitions/content_steps.rb
@@ -10,11 +10,11 @@ When /^I create a content of type &quot;([^\&quot;]*)&quot; with the following data$/ do |conte @@ -10,11 +10,11 @@ When /^I create a content of type &quot;([^\&quot;]*)&quot; with the following data$/ do |conte
10 end 10 end
11 11
12 And /^I add to "([^\"]*)" the following exception "([^\"]*)"$/ do |article_name, user_exception| 12 And /^I add to "([^\"]*)" the following exception "([^\"]*)"$/ do |article_name, user_exception|
13 - article = Article.find_by_name(article_name) 13 + article = Article.find_by(name: article_name)
14 community = article.profile 14 community = article.profile
15 raise "The article profile is not a community." unless community.class == Community 15 raise "The article profile is not a community." unless community.class == Community
16 16
17 - my_user = community.members.find_by_name(user_exception) 17 + my_user = community.members.find_by(name: user_exception)
18 raise "Could not find #{user_exception} in #{community.name} community." if my_user.nil? 18 raise "Could not find #{user_exception} in #{community.name} community." if my_user.nil?
19 19
20 article.article_privacy_exceptions << my_user 20 article.article_privacy_exceptions << my_user
features/step_definitions/create_community_steps.rb
@@ -33,7 +33,7 @@ Given /^I reject community &quot;(.+)&quot;$/ do |community| @@ -33,7 +33,7 @@ Given /^I reject community &quot;(.+)&quot;$/ do |community|
33 end 33 end
34 34
35 Then /^I should see "([^\"]*)"'s creation date$/ do |community| 35 Then /^I should see "([^\"]*)"'s creation date$/ do |community|
36 - com = Community.find_by_name community 36 + com = Community.find_by name: community
37 text = "Created at: #{show_date(com.created_at)}" 37 text = "Created at: #{show_date(com.created_at)}"
38 has_content?(text) 38 has_content?(text)
39 end 39 end
features/step_definitions/invitation_steps.rb
1 Given /^I invite email "(.+)" to join community "(.+)"$/ do |email, community| 1 Given /^I invite email "(.+)" to join community "(.+)"$/ do |email, community|
2 - identifier = Community.find_by_name(community).identifier 2 + identifier = Community.find_by(name: community).identifier
3 visit("/myprofile/#{identifier}/profile_members") 3 visit("/myprofile/#{identifier}/profile_members")
4 first(:link, "Invite people to join").click 4 first(:link, "Invite people to join").click
5 choose("Email") 5 choose("Email")
features/step_definitions/noosfero_steps.rb
@@ -3,7 +3,7 @@ Given /^the following users?$/ do |table| @@ -3,7 +3,7 @@ Given /^the following users?$/ do |table|
3 table.hashes.each do |item| 3 table.hashes.each do |item|
4 person_data = item.dup 4 person_data = item.dup
5 person_data.delete("login") 5 person_data.delete("login")
6 - category = Category.find_by_slug person_data.delete("category") 6 + category = Category.find_by slug: person_data.delete("category")
7 email = item[:email] || item[:login] + "@example.com" 7 email = item[:email] || item[:login] + "@example.com"
8 user = User.create!(:login => item[:login], :password => '123456', :password_confirmation => '123456', :email => email, :person_data => person_data) 8 user = User.create!(:login => item[:login], :password => '123456', :password_confirmation => '123456', :email => email, :person_data => person_data)
9 user.activate 9 user.activate
@@ -15,12 +15,12 @@ Given /^the following users?$/ do |table| @@ -15,12 +15,12 @@ Given /^the following users?$/ do |table|
15 end 15 end
16 16
17 Given /^"(.+)" is (invisible|visible)$/ do |user, visibility| 17 Given /^"(.+)" is (invisible|visible)$/ do |user, visibility|
18 - User.find_by_login(user).person.update({:visible => (visibility == 'visible')}, :without_protection => true) 18 + User.find_by(login: user).person.update({visible: (visibility == 'visible')}, without_protection: true)
19 end 19 end
20 20
21 Given /^"(.+)" is (online|offline|busy) in chat$/ do |user, status| 21 Given /^"(.+)" is (online|offline|busy) in chat$/ do |user, status|
22 status = {'online' => 'chat', 'offline' => '', 'busy' => 'dnd'}[status] 22 status = {'online' => 'chat', 'offline' => '', 'busy' => 'dnd'}[status]
23 - User.find_by_login(user).update(:chat_status => status, :chat_status_at => DateTime.now) 23 + User.find_by(login: user).update(:chat_status => status, :chat_status_at => DateTime.now)
24 end 24 end
25 25
26 Given /^the following (community|communities|enterprises?|organizations?)$/ do |kind,table| 26 Given /^the following (community|communities|enterprises?|organizations?)$/ do |kind,table|
@@ -40,11 +40,11 @@ Given /^the following (community|communities|enterprises?|organizations?)$/ do | @@ -40,11 +40,11 @@ Given /^the following (community|communities|enterprises?|organizations?)$/ do |
40 d.save(:validate => false) 40 d.save(:validate => false)
41 end 41 end
42 if city 42 if city
43 - c = City.find_by_name city 43 + c = City.find_by name: city
44 organization.region = c 44 organization.region = c
45 end 45 end
46 if category && !category.blank? 46 if category && !category.blank?
47 - cat = Category.find_by_slug category 47 + cat = Category.find_by slug: category
48 ProfileCategorization.add_category_to_profile(cat, organization) 48 ProfileCategorization.add_category_to_profile(cat, organization)
49 end 49 end
50 if img_name 50 if img_name
@@ -56,15 +56,15 @@ Given /^the following (community|communities|enterprises?|organizations?)$/ do | @@ -56,15 +56,15 @@ Given /^the following (community|communities|enterprises?|organizations?)$/ do |
56 end 56 end
57 57
58 Given /^"([^\"]*)" is associated with "([^\"]*)"$/ do |enterprise, bsc| 58 Given /^"([^\"]*)" is associated with "([^\"]*)"$/ do |enterprise, bsc|
59 - enterprise = Enterprise.find_by_name(enterprise) || Enterprise[enterprise]  
60 - bsc = BscPlugin::Bsc.find_by_name(bsc) || BscPlugin::Bsc[bsc] 59 + enterprise = Enterprise.find_by(name: enterprise) || Enterprise[enterprise]
  60 + bsc = BscPlugin::Bsc.find_by(name: bsc) || BscPlugin::Bsc[bsc]
61 61
62 bsc.enterprises << enterprise 62 bsc.enterprises << enterprise
63 end 63 end
64 64
65 Then /^"([^\"]*)" should be associated with "([^\"]*)"$/ do |enterprise, bsc| 65 Then /^"([^\"]*)" should be associated with "([^\"]*)"$/ do |enterprise, bsc|
66 - enterprise = Enterprise.find_by_name(enterprise) || Enterprise[enterprise]  
67 - bsc = BscPlugin::Bsc.find_by_name(bsc) || BscPlugin::Bsc[bsc] 66 + enterprise = Enterprise.find_by(name: enterprise) || Enterprise[enterprise]
  67 + bsc = BscPlugin::Bsc.find_by(name: bsc) || BscPlugin::Bsc[bsc]
68 68
69 bsc.enterprises.should include(enterprise) 69 bsc.enterprises.should include(enterprise)
70 end 70 end
@@ -121,7 +121,7 @@ Given /^the following (articles|events|blogs|folders|forums|galleries|uploaded f @@ -121,7 +121,7 @@ Given /^the following (articles|events|blogs|folders|forums|galleries|uploaded f
121 translation_of_id = nil 121 translation_of_id = nil
122 if item["translation_of"] 122 if item["translation_of"]
123 if item["translation_of"] != "nil" 123 if item["translation_of"] != "nil"
124 - article = owner.articles.find_by_name(item["translation_of"]) 124 + article = owner.articles.find_by(name: item["translation_of"])
125 translation_of_id = article.id if article 125 translation_of_id = article.id if article
126 end 126 end
127 item.delete("translation_of") 127 item.delete("translation_of")
@@ -135,10 +135,10 @@ Given /^the following (articles|events|blogs|folders|forums|galleries|uploaded f @@ -135,10 +135,10 @@ Given /^the following (articles|events|blogs|folders|forums|galleries|uploaded f
135 end 135 end
136 result = klass.new(item) 136 result = klass.new(item)
137 if !parent.blank? 137 if !parent.blank?
138 - result.parent = Article.find_by_name(parent) 138 + result.parent = Article.find_by(name: parent)
139 end 139 end
140 if category 140 if category
141 - cat = Category.find_by_slug category 141 + cat = Category.find_by slug: category
142 if cat 142 if cat
143 result.add_category(cat) 143 result.add_category(cat)
144 end 144 end
@@ -157,7 +157,7 @@ Given /^the following files$/ do |table| @@ -157,7 +157,7 @@ Given /^the following files$/ do |table|
157 file = "/files/#{item[:file]}" 157 file = "/files/#{item[:file]}"
158 article = UploadedFile.new(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime])) 158 article = UploadedFile.new(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime]))
159 if item[:parent] 159 if item[:parent]
160 - article.parent = Article.find_by_slug(item[:parent]) 160 + article.parent = Article.find_by slug: item[:parent]
161 end 161 end
162 article.save! 162 article.save!
163 if item[:homepage] 163 if item[:homepage]
@@ -180,7 +180,7 @@ Given /^the following articles? with images?$/ do |table| @@ -180,7 +180,7 @@ Given /^the following articles? with images?$/ do |table|
180 img_tag += "/>" 180 img_tag += "/>"
181 article = TinyMceArticle.new(:profile => owner, :name => item[:name], :body => img_tag) 181 article = TinyMceArticle.new(:profile => owner, :name => item[:name], :body => img_tag)
182 if item[:parent] 182 if item[:parent]
183 - article.parent = Article.find_by_slug(item[:parent]) 183 + article.parent = Article.find_by slug: item[:parent]
184 end 184 end
185 article.save! 185 article.save!
186 if item[:homepage] 186 if item[:homepage]
@@ -194,14 +194,14 @@ Given /^the following products?$/ do |table| @@ -194,14 +194,14 @@ Given /^the following products?$/ do |table|
194 table.hashes.each do |item| 194 table.hashes.each do |item|
195 data = item.dup 195 data = item.dup
196 owner = Enterprise[data.delete("owner")] 196 owner = Enterprise[data.delete("owner")]
197 - category = Category.find_by_slug(data.delete("category").to_slug) 197 + category = Category.find_by slug: data.delete("category").to_slug
198 data.merge!(:enterprise => owner, :product_category => category) 198 data.merge!(:enterprise => owner, :product_category => category)
199 if data[:img] 199 if data[:img]
200 img = Image.create!(:uploaded_data => fixture_file_upload('/files/'+data.delete("img")+'.png', 'image/png')) 200 img = Image.create!(:uploaded_data => fixture_file_upload('/files/'+data.delete("img")+'.png', 'image/png'))
201 data.merge!(:image_id => img.id) 201 data.merge!(:image_id => img.id)
202 end 202 end
203 if data[:qualifier] 203 if data[:qualifier]
204 - qualifier = Qualifier.find_by_name(data.delete("qualifier")) 204 + qualifier = Qualifier.find_by name: data.delete("qualifier")
205 data.merge!(:qualifiers => [qualifier]) 205 data.merge!(:qualifiers => [qualifier])
206 end 206 end
207 product = Product.create!(data, :without_protection => true) 207 product = Product.create!(data, :without_protection => true)
@@ -211,9 +211,9 @@ end @@ -211,9 +211,9 @@ end
211 Given /^the following inputs?$/ do |table| 211 Given /^the following inputs?$/ do |table|
212 table.hashes.each do |item| 212 table.hashes.each do |item|
213 data = item.dup 213 data = item.dup
214 - product = Product.find_by_name(data.delete("product"))  
215 - category = Category.find_by_slug(data.delete("category").to_slug)  
216 - unit = Unit.find_by_singular(data.delete("unit")) 214 + product = Product.find_by name: data.delete("product")
  215 + category = Category.find_by slug: data.delete("category").to_slug
  216 + unit = Unit.find_by singular: data.delete("unit")
217 solidary = data.delete("solidary") 217 solidary = data.delete("solidary")
218 input = Input.create!(data.merge(:product => product, :product_category => category, :unit => unit, 218 input = Input.create!(data.merge(:product => product, :product_category => category, :unit => unit,
219 :is_from_solidarity_economy => solidary), :without_protection => true) 219 :is_from_solidarity_economy => solidary), :without_protection => true)
@@ -224,7 +224,7 @@ end @@ -224,7 +224,7 @@ end
224 Given /^the following states$/ do |table| 224 Given /^the following states$/ do |table|
225 table.hashes.each do |item| 225 table.hashes.each do |item|
226 data = item.dup 226 data = item.dup
227 - if validator = Enterprise.find_by_name(data.delete("validator_name")) 227 + if validator = Enterprise.find_by(name: data.delete("validator_name"))
228 State.create!(data.merge(:environment => Environment.default, :validators => [validator]), :without_protection => true) 228 State.create!(data.merge(:environment => Environment.default, :validators => [validator]), :without_protection => true)
229 else 229 else
230 r = State.create!(data.merge(:environment => Environment.default)) 230 r = State.create!(data.merge(:environment => Environment.default))
@@ -235,7 +235,7 @@ end @@ -235,7 +235,7 @@ end
235 Given /^the following validation info$/ do |table| 235 Given /^the following validation info$/ do |table|
236 table.hashes.each do |item| 236 table.hashes.each do |item|
237 data = item.dup 237 data = item.dup
238 - organization = Organization.find_by_name(data.delete("organization_name")) 238 + organization = Organization.find_by name: data.delete("organization_name")
239 ValidationInfo.create!(data.merge(:organization => organization)) 239 ValidationInfo.create!(data.merge(:organization => organization))
240 end 240 end
241 end 241 end
@@ -245,7 +245,7 @@ Given /^the following (product_categories|product_category|category|categories|r @@ -245,7 +245,7 @@ Given /^the following (product_categories|product_category|category|categories|r
245 table.hashes.each do |row| 245 table.hashes.each do |row|
246 parent = row.delete("parent") 246 parent = row.delete("parent")
247 if !parent.blank? 247 if !parent.blank?
248 - parent = Category.find_by_slug(parent.to_slug) 248 + parent = Category.find_by slug: parent.to_slug
249 row.merge!({:parent_id => parent.id}) 249 row.merge!({:parent_id => parent.id})
250 end 250 end
251 category = klass.create!({:environment => Environment.default}.merge(row)) 251 category = klass.create!({:environment => Environment.default}.merge(row))
@@ -263,7 +263,7 @@ Given /^the following certifiers$/ do |table| @@ -263,7 +263,7 @@ Given /^the following certifiers$/ do |table|
263 row = row.dup 263 row = row.dup
264 qualifiers_list = row.delete("qualifiers") 264 qualifiers_list = row.delete("qualifiers")
265 if qualifiers_list 265 if qualifiers_list
266 - row["qualifiers"] = qualifiers_list.split(', ').map{|i| Qualifier.find_by_name(i)} 266 + row["qualifiers"] = qualifiers_list.split(', ').map{|i| Qualifier.find_by name: i }
267 end 267 end
268 Certifier.create!(row.merge(:environment_id => 1), :without_protection => true) 268 Certifier.create!(row.merge(:environment_id => 1), :without_protection => true)
269 end 269 end
@@ -279,8 +279,8 @@ end @@ -279,8 +279,8 @@ end
279 279
280 Given /^the following price details?$/ do |table| 280 Given /^the following price details?$/ do |table|
281 table.hashes.map{|item| item.dup}.each do |item| 281 table.hashes.map{|item| item.dup}.each do |item|
282 - product = Product.find_by_name item.delete('product')  
283 - production_cost = ProductionCost.find_by_name item.delete('production_cost') 282 + product = Product.find_by name: item.delete('product')
  283 + production_cost = ProductionCost.find_by name: item.delete('production_cost')
284 product.price_details.create!(item.merge(:production_cost => production_cost)) 284 product.price_details.create!(item.merge(:production_cost => production_cost))
285 end 285 end
286 end 286 end
@@ -297,7 +297,7 @@ Given /^I am logged in as &quot;(.+)&quot;$/ do |username| @@ -297,7 +297,7 @@ Given /^I am logged in as &quot;(.+)&quot;$/ do |username|
297 end 297 end
298 298
299 Given /^"([^"]*)" is environment admin$/ do |person| 299 Given /^"([^"]*)" is environment admin$/ do |person|
300 - user = Profile.find_by_name(person) 300 + user = Profile.find_by name: person
301 e = Environment.default 301 e = Environment.default
302 302
303 e.add_admin(user) 303 e.add_admin(user)
@@ -337,41 +337,41 @@ Given /^&quot;(.+)&quot; is a member of &quot;(.+)&quot;$/ do |person, profile| @@ -337,41 +337,41 @@ Given /^&quot;(.+)&quot; is a member of &quot;(.+)&quot;$/ do |person, profile|
337 end 337 end
338 338
339 Then /^"(.+)" should be a member of "(.+)"$/ do |person,profile| 339 Then /^"(.+)" should be a member of "(.+)"$/ do |person,profile|
340 - Profile.find_by_name(profile).members.should include(Person.find_by_name(person)) 340 + Profile.find_by(name: profile).members.should include(Person.find_by(name: person))
341 end 341 end
342 342
343 When /^"(.*)" is accepted on community "(.*)"$/ do |person, community| 343 When /^"(.*)" is accepted on community "(.*)"$/ do |person, community|
344 - person = Person.find_by_name(person)  
345 - community = Community.find_by_name(community) 344 + person = Person.find_by name: person
  345 + community = Community.find_by name: community
346 community.affiliate(person, Profile::Roles.member(community.environment.id)) 346 community.affiliate(person, Profile::Roles.member(community.environment.id))
347 end 347 end
348 348
349 Given /^"(.+)" is admin of "(.+)"$/ do |person, organization| 349 Given /^"(.+)" is admin of "(.+)"$/ do |person, organization|
350 - org = Profile.find_by_name(organization)  
351 - user = Profile.find_by_name(person) 350 + org = Profile.find_by name: organization
  351 + user = Profile.find_by name: person
352 org.add_admin(user) 352 org.add_admin(user)
353 end 353 end
354 354
355 Given /^"(.+)" is moderator of "(.+)"$/ do |person, organization| 355 Given /^"(.+)" is moderator of "(.+)"$/ do |person, organization|
356 - org = Profile.find_by_name(organization)  
357 - user = Profile.find_by_name(person) 356 + org = Profile.find_by name: organization
  357 + user = Profile.find_by name: person
358 org.add_moderator(user) 358 org.add_moderator(user)
359 end 359 end
360 360
361 Then /^"(.+)" should be admin of "(.+)"$/ do |person, organization| 361 Then /^"(.+)" should be admin of "(.+)"$/ do |person, organization|
362 - org = Organization.find_by_name(organization)  
363 - user = Person.find_by_name(person) 362 + org = Organization.find_by name: organization
  363 + user = Person.find_by name: person
364 org.admins.should include(user) 364 org.admins.should include(user)
365 end 365 end
366 366
367 Then /^"(.+)" should be moderator of "(.+)"$/ do |person,profile| 367 Then /^"(.+)" should be moderator of "(.+)"$/ do |person,profile|
368 - profile = Profile.find_by_name(profile)  
369 - person = Person.find_by_name(person) 368 + profile = Profile.find_by name: profile
  369 + person = Person.find_by name: person
370 profile.members_by_role(Profile::Roles.moderator(profile.environment.id)).should include(person) 370 profile.members_by_role(Profile::Roles.moderator(profile.environment.id)).should include(person)
371 end 371 end
372 372
373 Given /^"([^\"]*)" has no articles$/ do |profile| 373 Given /^"([^\"]*)" has no articles$/ do |profile|
374 - (Profile[profile] || Profile.find_by_name(profile)).articles.delete_all 374 + (Profile[profile] || Profile.find_by(name: profile)).articles.delete_all
375 end 375 end
376 376
377 Given /^the following (\w+) fields are (\w+) fields$/ do |klass, status, table| 377 Given /^the following (\w+) fields are (\w+) fields$/ do |klass, status, table|
@@ -393,7 +393,7 @@ Given /^the following (\w+) fields are (\w+) fields$/ do |klass, status, table| @@ -393,7 +393,7 @@ Given /^the following (\w+) fields are (\w+) fields$/ do |klass, status, table|
393 end 393 end
394 394
395 Then /^"([^\"]*)" should have the following data$/ do |id, table| 395 Then /^"([^\"]*)" should have the following data$/ do |id, table|
396 - profile = Profile.find_by_identifier(id) 396 + profile = Profile.find_by identifier: id
397 expected = table.hashes.first 397 expected = table.hashes.first
398 data = expected.keys.inject({}) { |hash, key| hash[key] = profile.send(key).to_s; hash } 398 data = expected.keys.inject({}) { |hash, key| hash[key] = profile.send(key).to_s; hash }
399 data.should == expected 399 data.should == expected
@@ -408,12 +408,12 @@ Given /^&quot;(.+)&quot; is friend of &quot;(.+)&quot;$/ do |person, friend| @@ -408,12 +408,12 @@ Given /^&quot;(.+)&quot; is friend of &quot;(.+)&quot;$/ do |person, friend|
408 end 408 end
409 409
410 Given /^enterprise "([^\"]*)" is blocked$/ do |enterprise_name| 410 Given /^enterprise "([^\"]*)" is blocked$/ do |enterprise_name|
411 - enterprise = Enterprise.find_by_name(enterprise_name) 411 + enterprise = Enterprise.find_by name: enterprise_name
412 enterprise.block 412 enterprise.block
413 end 413 end
414 414
415 Given /^enterprise "([^\"]*)" is disabled$/ do |enterprise_name| 415 Given /^enterprise "([^\"]*)" is disabled$/ do |enterprise_name|
416 - enterprise = Enterprise.find_by_name(enterprise_name) 416 + enterprise = Enterprise.find_by name: enterprise_name
417 enterprise.enabled = false 417 enterprise.enabled = false
418 enterprise.save 418 enterprise.save
419 end 419 end
@@ -470,7 +470,7 @@ Given /^the profile &quot;(.+)&quot; has no blocks$/ do |profile| @@ -470,7 +470,7 @@ Given /^the profile &quot;(.+)&quot; has no blocks$/ do |profile|
470 end 470 end
471 471
472 Given /^the articles of "(.+)" are moderated$/ do |organization| 472 Given /^the articles of "(.+)" are moderated$/ do |organization|
473 - organization = Organization.find_by_name(organization) 473 + organization = Organization.find_by name: organization
474 organization.moderated_articles = true 474 organization.moderated_articles = true
475 organization.save 475 organization.save
476 end 476 end
@@ -478,7 +478,7 @@ end @@ -478,7 +478,7 @@ end
478 Given /^the following comments?$/ do |table| 478 Given /^the following comments?$/ do |table|
479 table.hashes.each do |item| 479 table.hashes.each do |item|
480 data = item.dup 480 data = item.dup
481 - article = Article.find_by_name(data.delete("article")) 481 + article = Article.find_by name: data.delete("article")
482 author = data.delete("author") 482 author = data.delete("author")
483 comment = article.comments.build(data) 483 comment = article.comments.build(data)
484 if author 484 if author
@@ -489,7 +489,7 @@ Given /^the following comments?$/ do |table| @@ -489,7 +489,7 @@ Given /^the following comments?$/ do |table|
489 end 489 end
490 490
491 Given /^the community "(.+)" is closed$/ do |community| 491 Given /^the community "(.+)" is closed$/ do |community|
492 - community = Community.find_by_name(community) 492 + community = Community.find_by name: community
493 community.closed = true 493 community.closed = true
494 community.save 494 community.save
495 end 495 end
@@ -510,8 +510,8 @@ Given /^the following units?$/ do |table| @@ -510,8 +510,8 @@ Given /^the following units?$/ do |table|
510 end 510 end
511 511
512 Given /^"([^\"]*)" asked to join "([^\"]*)"$/ do |person, organization| 512 Given /^"([^\"]*)" asked to join "([^\"]*)"$/ do |person, organization|
513 - person = Person.find_by_name(person)  
514 - organization = Organization.find_by_name(organization) 513 + person = Person.find_by name: person
  514 + organization = Organization.find_by name: organization
515 AddMember.create!(:person => person, :organization => organization) 515 AddMember.create!(:person => person, :organization => organization)
516 end 516 end
517 517
@@ -531,7 +531,7 @@ Given /^the environment domain is &quot;([^\&quot;]*)&quot;$/ do |domain| @@ -531,7 +531,7 @@ Given /^the environment domain is &quot;([^\&quot;]*)&quot;$/ do |domain|
531 end 531 end
532 532
533 When /^([^\']*)'s account is activated$/ do |person| 533 When /^([^\']*)'s account is activated$/ do |person|
534 - Person.find_by_name(person).user.activate 534 + Person.find_by(name: person).user.activate
535 end 535 end
536 536
537 Then /^I should receive an e-mail on (.*)$/ do |address| 537 Then /^I should receive an e-mail on (.*)$/ do |address|
@@ -547,13 +547,13 @@ end @@ -547,13 +547,13 @@ end
547 547
548 Then /^there should be an? (.+) named "([^\"]*)"$/ do |klass_name, profile_name| 548 Then /^there should be an? (.+) named "([^\"]*)"$/ do |klass_name, profile_name|
549 klass = klass_name.camelize.constantize 549 klass = klass_name.camelize.constantize
550 - klass.find_by_name(profile_name).nil?.should be_falsey 550 + klass.find_by(name: profile_name).nil?.should be_falsey
551 end 551 end
552 552
553 Then /^"([^\"]*)" profile should exist$/ do |profile_selector| 553 Then /^"([^\"]*)" profile should exist$/ do |profile_selector|
554 profile = nil 554 profile = nil
555 begin 555 begin
556 - profile = Profile.find_by_name(profile_selector) 556 + profile = Profile.find_by(name: profile_selector)
557 profile.nil?.should be_falsey 557 profile.nil?.should be_falsey
558 rescue 558 rescue
559 profile.nil?.should be_falsey 559 profile.nil?.should be_falsey
@@ -563,7 +563,7 @@ end @@ -563,7 +563,7 @@ end
563 Then /^"([^\"]*)" profile should not exist$/ do |profile_selector| 563 Then /^"([^\"]*)" profile should not exist$/ do |profile_selector|
564 profile = nil 564 profile = nil
565 begin 565 begin
566 - profile = Profile.find_by_name(profile_selector) 566 + profile = Profile.find_by(name: profile_selector)
567 profile.nil?.should be_truthy 567 profile.nil?.should be_truthy
568 rescue 568 rescue
569 profile.nil?.should be_truthy 569 profile.nil?.should be_truthy
@@ -575,7 +575,7 @@ When &#39;I log off&#39; do @@ -575,7 +575,7 @@ When &#39;I log off&#39; do
575 end 575 end
576 576
577 Then /^I should be taken to "([^\"]*)" product page$/ do |product_name| 577 Then /^I should be taken to "([^\"]*)" product page$/ do |product_name|
578 - product = Product.find_by_name(product_name) 578 + product = Product.find_by(name: product_name)
579 path = url_for(product.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => product, :only_path => true)) 579 path = url_for(product.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => product, :only_path => true))
580 if response.class.to_s == 'Webrat::SeleniumResponse' 580 if response.class.to_s == 'Webrat::SeleniumResponse'
581 URI.parse(response.selenium.get_location).path.should == path_to(path) 581 URI.parse(response.selenium.get_location).path.should == path_to(path)
@@ -589,7 +589,7 @@ Given /^the following enterprise homepages?$/ do |table| @@ -589,7 +589,7 @@ Given /^the following enterprise homepages?$/ do |table|
589 table.hashes.each do |item| 589 table.hashes.each do |item|
590 data = item.dup 590 data = item.dup
591 home = EnterpriseHomepage.new(:name => data[:name]) 591 home = EnterpriseHomepage.new(:name => data[:name])
592 - ent = Enterprise.find_by_identifier(data[:enterprise]) 592 + ent = Enterprise.find_by(identifier: data[:enterprise])
593 ent.articles << home 593 ent.articles << home
594 end 594 end
595 end 595 end
@@ -609,7 +609,7 @@ end @@ -609,7 +609,7 @@ end
609 609
610 Given /^the following cities$/ do |table| 610 Given /^the following cities$/ do |table|
611 table.hashes.each do |item| 611 table.hashes.each do |item|
612 - state = State.find_by_acronym item[:state] 612 + state = State.find_by acronym: item[:state]
613 if !state 613 if !state
614 state = State.create!(:name => item[:state], :acronym => item[:state], :environment_id => Environment.default.id) 614 state = State.create!(:name => item[:state], :acronym => item[:state], :environment_id => Environment.default.id)
615 end 615 end
@@ -626,7 +626,7 @@ end @@ -626,7 +626,7 @@ end
626 626
627 Given /^the following tags$/ do |table| 627 Given /^the following tags$/ do |table|
628 table.hashes.each do |item| 628 table.hashes.each do |item|
629 - article = Article.find_by_name item[:article] 629 + article = Article.find_by name: item[:article]
630 article.tag_list.add item[:name] 630 article.tag_list.add item[:name]
631 article.save! 631 article.save!
632 end 632 end
@@ -639,7 +639,7 @@ When /^I search ([^\&quot;]*) for &quot;([^\&quot;]*)&quot;$/ do |asset, query| @@ -639,7 +639,7 @@ When /^I search ([^\&quot;]*) for &quot;([^\&quot;]*)&quot;$/ do |asset, query|
639 end 639 end
640 640
641 Then /^I should see ([^\"]*)'s product image$/ do |product_name| 641 Then /^I should see ([^\"]*)'s product image$/ do |product_name|
642 - p = Product.find_by_name product_name 642 + p = Product.find_by name: product_name
643 path = url_for(p.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => p)) 643 path = url_for(p.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => p))
644 644
645 with_scope('.zoomable-image') do 645 with_scope('.zoomable-image') do
@@ -648,7 +648,7 @@ Then /^I should see ([^\&quot;]*)&#39;s product image$/ do |product_name| @@ -648,7 +648,7 @@ Then /^I should see ([^\&quot;]*)&#39;s product image$/ do |product_name|
648 end 648 end
649 649
650 Then /^I should not see ([^\"]*)'s product image$/ do |product_name| 650 Then /^I should not see ([^\"]*)'s product image$/ do |product_name|
651 - p = Product.find_by_name product_name 651 + p = Product.find_by name: product_name
652 path = url_for(p.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => p)) 652 path = url_for(p.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => p))
653 653
654 with_scope('.zoomable-image') do 654 with_scope('.zoomable-image') do
@@ -673,14 +673,14 @@ Then /^I should not see ([^\&quot;]*)&#39;s community image$/ do |name| @@ -673,14 +673,14 @@ Then /^I should not see ([^\&quot;]*)&#39;s community image$/ do |name|
673 end 673 end
674 674
675 Given /^the article "([^\"]*)" is updated by "([^\"]*)"$/ do |article, person| 675 Given /^the article "([^\"]*)" is updated by "([^\"]*)"$/ do |article, person|
676 - a = Article.find_by_name article  
677 - p = Person.find_by_name person 676 + a = Article.find_by name: article
  677 + p = Person.find_by name: person
678 a.last_changed_by = p 678 a.last_changed_by = p
679 a.save! 679 a.save!
680 end 680 end
681 681
682 Given /^the article "([^\"]*)" is updated with$/ do |article, table| 682 Given /^the article "([^\"]*)" is updated with$/ do |article, table|
683 - a = Article.find_by_name article 683 + a = Article.find_by name: article
684 row = table.hashes.first 684 row = table.hashes.first
685 a.update(row) 685 a.update(row)
686 end 686 end
@@ -720,7 +720,7 @@ Given /^the profile (.*) is configured to (.*) after login$/ do |profile, option @@ -720,7 +720,7 @@ Given /^the profile (.*) is configured to (.*) after login$/ do |profile, option
720 when 'redirect to profile control panel' 720 when 'redirect to profile control panel'
721 'user_control_panel' 721 'user_control_panel'
722 end 722 end
723 - profile = Profile.find_by_identifier(profile) 723 + profile = Profile.find_by identifier: profile
724 profile.redirection_after_login = redirection 724 profile.redirection_after_login = redirection
725 profile.save 725 profile.save
726 end 726 end
features/support/paths.rb
@@ -15,7 +15,7 @@ module NavigationHelpers @@ -15,7 +15,7 @@ module NavigationHelpers
15 # Here is an example that pulls values out of the Regexp: 15 # Here is an example that pulls values out of the Regexp:
16 # 16 #
17 # when /^(.*)'s profile page$/i 17 # when /^(.*)'s profile page$/i
18 - # user_profile_path(User.find_by_login($1)) 18 + # user_profile_path(User.find_by(login: $1))
19 19
20 when /^\// 20 when /^\//
21 page_name 21 page_name
@@ -24,19 +24,19 @@ module NavigationHelpers @@ -24,19 +24,19 @@ module NavigationHelpers
24 '/site/welcome' 24 '/site/welcome'
25 25
26 when /article "([^"]+)"\s*$/ 26 when /article "([^"]+)"\s*$/
27 - url_for(Article.find_by_name($1).url.merge({:only_path => true})) 27 + url_for(Article.find_by(name: $1).url.merge({:only_path => true}))
28 28
29 when /category "([^"]+)"/ 29 when /category "([^"]+)"/
30 - '/cat/%s' % Category.find_by_name($1).slug 30 + '/cat/%s' % Category.find_by(name: $1).slug
31 31
32 when /edit "(.+)" by (.+)/ 32 when /edit "(.+)" by (.+)/
33 - article_id = Person[$2].articles.find_by_slug($1.to_slug).id 33 + article_id = Person[$2].articles.find_by(slug: $1.to_slug).id
34 "/myprofile/#{$2}/cms/edit/#{article_id}" 34 "/myprofile/#{$2}/cms/edit/#{article_id}"
35 35
36 when /edit (.*Block) of (.+)/ 36 when /edit (.*Block) of (.+)/
37 owner = Profile[$2] 37 owner = Profile[$2]
38 klass = $1.constantize 38 klass = $1.constantize
39 - block = klass.find(:all).select{|i| i.owner == owner}.first 39 + block = klass.all.select{|i| i.owner == owner}.first
40 "/myprofile/#{$2}/profile_design/edit/#{block.id}" 40 "/myprofile/#{$2}/profile_design/edit/#{block.id}"
41 41
42 when /^(.*)'s homepage$/ 42 when /^(.*)'s homepage$/
@@ -85,18 +85,18 @@ module NavigationHelpers @@ -85,18 +85,18 @@ module NavigationHelpers
85 '/myprofile/%s/cms' % profile_identifier($1) 85 '/myprofile/%s/cms' % profile_identifier($1)
86 86
87 when /^"(.+)" edit page/ 87 when /^"(.+)" edit page/
88 - article = Article.find_by_name($1) 88 + article = Article.find_by name: $1
89 '/myprofile/%s/cms/edit/%s' % [article.profile.identifier, article.id] 89 '/myprofile/%s/cms/edit/%s' % [article.profile.identifier, article.id]
90 90
91 when /^(.+)'s members management/ 91 when /^(.+)'s members management/
92 - '/myprofile/%s/profile_members' % Profile.find_by_name($1).identifier 92 + '/myprofile/%s/profile_members' % Profile.find_by(name: $1).identifier
93 93
94 when /^(.+)'s new product page/ 94 when /^(.+)'s new product page/
95 '/myprofile/%s/manage_products/new' % profile_identifier($1) 95 '/myprofile/%s/manage_products/new' % profile_identifier($1)
96 96
97 when /^(.+)'s page of product (.*)$/ 97 when /^(.+)'s page of product (.*)$/
98 - enterprise = Profile.find_by_name($1)  
99 - product = enterprise.products.find_by_name($2) 98 + enterprise = Profile.find_by(name: $1)
  99 + product = enterprise.products.find_by(name: $2)
100 '/myprofile/%s/manage_products/show/%s' % [enterprise.identifier, product.id] 100 '/myprofile/%s/manage_products/show/%s' % [enterprise.identifier, product.id]
101 101
102 when /^(.*)'s products page$/ 102 when /^(.*)'s products page$/
@@ -138,7 +138,7 @@ module NavigationHelpers @@ -138,7 +138,7 @@ module NavigationHelpers
138 end 138 end
139 139
140 def profile_identifier(field) 140 def profile_identifier(field)
141 - profile = Profile.find_by_name(field) || Profile.find_by_identifier(field) 141 + profile = Profile.find_by(name: field) || Profile.find_by(identifier: field)
142 profile.identifier 142 profile.identifier
143 end 143 end
144 end 144 end
lib/acts_as_filesystem.rb
@@ -120,7 +120,7 @@ module ActsAsFileSystem @@ -120,7 +120,7 @@ module ActsAsFileSystem
120 120
121 def top_ancestor 121 def top_ancestor
122 if has_ancestry? and !ancestry.nil? 122 if has_ancestry? and !ancestry.nil?
123 - self.class.base_class.find_by_id self.top_ancestor_id 123 + self.class.base_class.find_by id: self.top_ancestor_id
124 else 124 else
125 self.hierarchy.first 125 self.hierarchy.first
126 end 126 end
lib/acts_as_having_boxes.rb
@@ -2,7 +2,7 @@ module ActsAsHavingBoxes @@ -2,7 +2,7 @@ module ActsAsHavingBoxes
2 2
3 module ClassMethods 3 module ClassMethods
4 def acts_as_having_boxes 4 def acts_as_having_boxes
5 - has_many :boxes, :as => :owner, :dependent => :destroy, :order => 'position' 5 + has_many :boxes, -> { order :position }, as: :owner, dependent: :destroy
6 self.send(:include, ActsAsHavingBoxes) 6 self.send(:include, ActsAsHavingBoxes)
7 end 7 end
8 end 8 end
lib/acts_as_having_posts.rb
1 module ActsAsHavingPosts 1 module ActsAsHavingPosts
2 2
3 module ClassMethods 3 module ClassMethods
4 - def acts_as_having_posts(options = {})  
5 - has_many :posts, { :class_name => 'Article', :foreign_key => 'parent_id', :source => :children, :conditions => [ 'articles.type != ?', 'RssFeed' ], :order => 'published_at DESC, id DESC' }.merge(options) 4 + def acts_as_having_posts(scope = nil)
  5 + has_many :posts, -> {
  6 + s = order('published_at DESC, id DESC').where('articles.type != ?', 'RssFeed')
  7 + s = s.instance_exec(&scope) if scope
  8 + s
  9 + }, class_name: 'Article', foreign_key: 'parent_id', source: :children
6 10
7 attr_accessor :feed_attrs 11 attr_accessor :feed_attrs
8 12
lib/noosfero/action_tracker_ext.rb
@@ -9,7 +9,9 @@ Rails.configuration.to_prepare do @@ -9,7 +9,9 @@ Rails.configuration.to_prepare do
9 end 9 end
10 end 10 end
11 11
12 - has_many :profile_activities, foreign_key: :activity_id, conditions: {profile_activities: {activity_type: 'ActionTracker::Record'}}, dependent: :destroy 12 + has_many :profile_activities, -> {
  13 + where profile_activities: {activity_type: 'ActionTracker::Record'}
  14 + }, foreign_key: :activity_id, dependent: :destroy
13 15
14 after_create :create_activity 16 after_create :create_activity
15 after_update :update_activity 17 after_update :update_activity
lib/noosfero/api/helpers.rb
@@ -22,7 +22,7 @@ require_relative &#39;../../find_by_contents&#39; @@ -22,7 +22,7 @@ require_relative &#39;../../find_by_contents&#39;
22 22
23 def current_user 23 def current_user
24 private_token = (params[PRIVATE_TOKEN_PARAM] || headers['Private-Token']).to_s 24 private_token = (params[PRIVATE_TOKEN_PARAM] || headers['Private-Token']).to_s
25 - @current_user ||= User.find_by_private_token(private_token) 25 + @current_user ||= User.find_by private_token: private_token
26 @current_user 26 @current_user
27 end 27 end
28 28
@@ -268,7 +268,7 @@ require_relative &#39;../../find_by_contents&#39; @@ -268,7 +268,7 @@ require_relative &#39;../../find_by_contents&#39;
268 # keys (unique) - A hash consisting of keys that must be unique 268 # keys (unique) - A hash consisting of keys that must be unique
269 def unique_attributes!(obj, keys) 269 def unique_attributes!(obj, keys)
270 keys.each do |key| 270 keys.each do |key|
271 - cant_be_saved_request!(key) if obj.send("find_by_#{key.to_s}", params[key]) 271 + cant_be_saved_request!(key) if obj.find_by(key.to_s => params[key])
272 end 272 end
273 end 273 end
274 274
@@ -342,7 +342,7 @@ require_relative &#39;../../find_by_contents&#39; @@ -342,7 +342,7 @@ require_relative &#39;../../find_by_contents&#39;
342 end 342 end
343 343
344 def detect_stuff_by_domain 344 def detect_stuff_by_domain
345 - @domain = Domain.find_by_name(request.host) 345 + @domain = Domain.by_name(request.host)
346 if @domain.nil? 346 if @domain.nil?
347 @environment = Environment.default 347 @environment = Environment.default
348 if @environment.nil? && Rails.env.development? 348 if @environment.nil? && Rails.env.development?
lib/noosfero/api/session.rb
@@ -73,7 +73,7 @@ module Noosfero @@ -73,7 +73,7 @@ module Noosfero
73 # Example Request: 73 # Example Request:
74 # PATCH /activate?activation_code=28259abd12cc6a64ef9399cf3286cb998b96aeaf 74 # PATCH /activate?activation_code=28259abd12cc6a64ef9399cf3286cb998b96aeaf
75 patch "/activate" do 75 patch "/activate" do
76 - user = User.find_by_activation_code(params[:activation_code]) 76 + user = User.find_by activation_code: params[:activation_code]
77 if user 77 if user
78 unless user.environment.enabled?('admin_must_approve_new_users') 78 unless user.environment.enabled?('admin_must_approve_new_users')
79 if user.activate 79 if user.activate
@@ -141,7 +141,7 @@ module Noosfero @@ -141,7 +141,7 @@ module Noosfero
141 # Example Request: 141 # Example Request:
142 # PATCH /new_password?code=xxxx&password=secret&password_confirmation=secret 142 # PATCH /new_password?code=xxxx&password=secret&password_confirmation=secret
143 patch "/new_password" do 143 patch "/new_password" do
144 - change_password = ChangePassword.find_by_code(params[:code]) 144 + change_password = ChangePassword.find_by code: params[:code]
145 not_found! if change_password.nil? 145 not_found! if change_password.nil?
146 146
147 if change_password.update_attributes(:password => params[:password], :password_confirmation => params[:password_confirmation]) 147 if change_password.update_attributes(:password => params[:password], :password_confirmation => params[:password_confirmation])
lib/noosfero/api/v1/activities.rb
@@ -9,7 +9,7 @@ module Noosfero @@ -9,7 +9,7 @@ module Noosfero
9 get ':id/activities' do 9 get ':id/activities' do
10 profile = environment.profiles 10 profile = environment.profiles
11 profile = profile.visible_for_person(current_person) if profile.respond_to?(:visible_for_person) 11 profile = profile.visible_for_person(current_person) if profile.respond_to?(:visible_for_person)
12 - profile = profile.find_by_id(params[:id]) 12 + profile = profile.find_by id: params[:id]
13 activities = profile.activities.map(&:activity) 13 activities = profile.activities.map(&:activity)
14 present activities, :with => Entities::Activity, :current_person => current_person 14 present activities, :with => Entities::Activity, :current_person => current_person
15 end 15 end
lib/noosfero/api/v1/articles.rb
@@ -74,7 +74,7 @@ module Noosfero @@ -74,7 +74,7 @@ module Noosfero
74 current_person.register_report(abuse_report, profile) 74 current_person.register_report(abuse_report, profile)
75 75
76 if !params[:content_type].blank? 76 if !params[:content_type].blank?
77 - abuse_report = AbuseReport.find_by_reporter_id_and_abuse_complaint_id(current_person.id, profile.opened_abuse_complaint.id) 77 + abuse_report = AbuseReport.find_by reporter_id: current_person.id, abuse_complaint_id: profile.opened_abuse_complaint.id
78 Delayed::Job.enqueue DownloadReportedImagesJob.new(abuse_report, article) 78 Delayed::Job.enqueue DownloadReportedImagesJob.new(abuse_report, article)
79 end 79 end
80 80
@@ -253,7 +253,7 @@ module Noosfero @@ -253,7 +253,7 @@ module Noosfero
253 get ':id/home_page' do 253 get ':id/home_page' do
254 profiles = environment.profiles 254 profiles = environment.profiles
255 profiles = profiles.visible_for_person(current_person) 255 profiles = profiles.visible_for_person(current_person)
256 - profile = profiles.find_by_id(params[:id]) 256 + profile = profiles.find_by id: params[:id]
257 present_partial profile.home_page, :with => Entities::Article 257 present_partial profile.home_page, :with => Entities::Article
258 end 258 end
259 end 259 end
@@ -275,7 +275,7 @@ module Noosfero @@ -275,7 +275,7 @@ module Noosfero
275 profile = environment.send(kind.pluralize).find(params["#{kind}_id"]) 275 profile = environment.send(kind.pluralize).find(params["#{kind}_id"])
276 276
277 if params[:path].present? 277 if params[:path].present?
278 - article = profile.articles.find_by_path(params[:path]) 278 + article = profile.articles.find_by path: params[:path]
279 if !article || !article.display_to?(current_person) 279 if !article || !article.display_to?(current_person)
280 article = forbidden! 280 article = forbidden!
281 end 281 end
lib/noosfero/api/v1/communities.rb
@@ -49,7 +49,7 @@ module Noosfero @@ -49,7 +49,7 @@ module Noosfero
49 end 49 end
50 50
51 get ':id' do 51 get ':id' do
52 - community = environment.communities.visible_for_person(current_person).find_by_id(params[:id]) 52 + community = environment.communities.visible_for_person(current_person).find_by id: params[:id]
53 present community, :with => Entities::Community, :current_person => current_person 53 present community, :with => Entities::Community, :current_person => current_person
54 end 54 end
55 55
lib/noosfero/api/v1/enterprises.rb
@@ -26,7 +26,7 @@ module Noosfero @@ -26,7 +26,7 @@ module Noosfero
26 26
27 desc "Return one enterprise by id" 27 desc "Return one enterprise by id"
28 get ':id' do 28 get ':id' do
29 - enterprise = environment.enterprises.visible_for_person(current_person).find_by_id(params[:id]) 29 + enterprise = environment.enterprises.visible_for_person(current_person).find_by id: params[:id]
30 present enterprise, :with => Entities::Enterprise, :current_person => current_person 30 present enterprise, :with => Entities::Enterprise, :current_person => current_person
31 end 31 end
32 32
lib/noosfero/api/v1/people.rb
@@ -46,7 +46,7 @@ module Noosfero @@ -46,7 +46,7 @@ module Noosfero
46 46
47 desc "Return the person information" 47 desc "Return the person information"
48 get ':id' do 48 get ':id' do
49 - person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) 49 + person = environment.people.visible_for_person(current_person).find_by id: params[:id]
50 return not_found! if person.blank? 50 return not_found! if person.blank?
51 present person, :with => Entities::Person, :current_person => current_person 51 present person, :with => Entities::Person, :current_person => current_person
52 end 52 end
@@ -87,7 +87,7 @@ module Noosfero @@ -87,7 +87,7 @@ module Noosfero
87 87
88 desc "Return the person friends" 88 desc "Return the person friends"
89 get ':id/friends' do 89 get ':id/friends' do
90 - person = environment.people.visible_for_person(current_person).find_by_id(params[:id]) 90 + person = environment.people.visible_for_person(current_person).find_by id: params[:id]
91 return not_found! if person.blank? 91 return not_found! if person.blank?
92 friends = person.friends.visible 92 friends = person.friends.visible
93 present friends, :with => Entities::Person, :current_person => current_person 93 present friends, :with => Entities::Person, :current_person => current_person
@@ -114,7 +114,7 @@ module Noosfero @@ -114,7 +114,7 @@ module Noosfero
114 resource :members do 114 resource :members do
115 paginate max_per_page: MAX_PER_PAGE 115 paginate max_per_page: MAX_PER_PAGE
116 get do 116 get do
117 - profile = environment.profiles.find_by_id(params[:profile_id]) 117 + profile = environment.profiles.find_by id: params[:profile_id]
118 members = select_filtered_collection_of(profile, 'members', params) 118 members = select_filtered_collection_of(profile, 'members', params)
119 present members, :with => Entities::Person, :current_person => current_person 119 present members, :with => Entities::Person, :current_person => current_person
120 end 120 end
lib/noosfero/api/v1/profiles.rb
@@ -16,7 +16,7 @@ module Noosfero @@ -16,7 +16,7 @@ module Noosfero
16 get ':id' do 16 get ':id' do
17 profiles = environment.profiles 17 profiles = environment.profiles
18 profiles = profiles.visible_for_person(current_person) 18 profiles = profiles.visible_for_person(current_person)
19 - profile = profiles.find_by_id(params[:id]) 19 + profile = profiles.find_by id: params[:id]
20 present profile, :with => Entities::Profile, :current_person => current_person 20 present profile, :with => Entities::Profile, :current_person => current_person
21 end 21 end
22 end 22 end
lib/noosfero/api/v1/users.rb
@@ -17,7 +17,7 @@ module Noosfero @@ -17,7 +17,7 @@ module Noosfero
17 end 17 end
18 18
19 get ":id" do 19 get ":id" do
20 - user = environment.users.find_by_id(params[:id]) 20 + user = environment.users.find_by id: params[:id]
21 unless user.person.display_info_to? current_person 21 unless user.person.display_info_to? current_person
22 unauthorized! 22 unauthorized!
23 end 23 end
lib/noosfero/core_ext/active_record.rb
@@ -63,8 +63,12 @@ class ActiveRecord::Base @@ -63,8 +63,12 @@ class ActiveRecord::Base
63 end 63 end
64 64
65 ActiveRecord::Calculations.class_eval do 65 ActiveRecord::Calculations.class_eval do
66 - def count_with_distinct column_name=nil, options={}  
67 - distinct.count_without_distinct column_name, options 66 + def count_with_distinct column_name=self.primary_key
  67 + if column_name
  68 + distinct.count_without_distinct column_name
  69 + else
  70 + count_without_distinct
  71 + end
68 end 72 end
69 alias_method_chain :count, :distinct 73 alias_method_chain :count, :distinct
70 end 74 end
lib/time_scopes.rb
@@ -8,11 +8,11 @@ module TimeScopes @@ -8,11 +8,11 @@ module TimeScopes
8 if base.respond_to?(:scope) && base.attribute_names.include?('created_at') 8 if base.respond_to?(:scope) && base.attribute_names.include?('created_at')
9 base.class_eval do 9 base.class_eval do
10 scope :younger_than, lambda { |created_at| 10 scope :younger_than, lambda { |created_at|
11 - {:conditions => ["#{table_name}.created_at > ?", created_at]} 11 + where "#{table_name}.created_at > ?", created_at
12 } 12 }
13 13
14 scope :older_than, lambda { |created_at| 14 scope :older_than, lambda { |created_at|
15 - {:conditions => ["#{table_name}.created_at < ?", created_at]} 15 + where "#{table_name}.created_at < ?", created_at
16 } 16 }
17 end 17 end
18 end 18 end
plugins/analytics/test/functional/content_viewer_controller_test.rb
@@ -37,7 +37,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -37,7 +37,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
37 @request.env['HTTP_REFERER'] = first_url 37 @request.env['HTTP_REFERER'] = first_url
38 get :view_page, profile: @community.identifier, page: @community.articles.last.path.split('/') 38 get :view_page, profile: @community.identifier, page: @community.articles.last.path.split('/')
39 assert_equal 2, @community.page_views.count 39 assert_equal 2, @community.page_views.count
40 - assert_equal 1, @community.visits.count 40 + assert_equal 2, @community.visits.count
41 41
42 second_page_view = @community.page_views.order(:id).last 42 second_page_view = @community.page_views.order(:id).last
43 assert_equal first_page_view, second_page_view.referer_page_view 43 assert_equal first_page_view, second_page_view.referer_page_view
@@ -48,7 +48,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -48,7 +48,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
48 future = Time.now + 2*AnalyticsPlugin::TimeOnPageUpdateInterval 48 future = Time.now + 2*AnalyticsPlugin::TimeOnPageUpdateInterval
49 Time.stubs(:now).returns(future) 49 Time.stubs(:now).returns(future)
50 get :view_page, profile: @community.identifier, page: @community.articles.last.path.split('/') 50 get :view_page, profile: @community.identifier, page: @community.articles.last.path.split('/')
51 - assert_equal 2, @community.visits.count 51 + assert_equal 3, @community.visits.count
52 end 52 end
53 53
54 end 54 end
plugins/comment_classification/lib/comment_classification_plugin.rb
@@ -36,8 +36,8 @@ class CommentClassificationPlugin &lt; Noosfero::Plugin @@ -36,8 +36,8 @@ class CommentClassificationPlugin &lt; Noosfero::Plugin
36 comment = Comment.find args[0] 36 comment = Comment.find args[0]
37 label_id = args[1][:comment_label_id] 37 label_id = args[1][:comment_label_id]
38 if label_id.blank? 38 if label_id.blank?
39 - if !CommentClassificationPlugin::CommentLabelUser.find_by_comment_id(comment.id).nil?  
40 - CommentClassificationPlugin::CommentLabelUser.find_by_comment_id(comment.id).destroy 39 + if !CommentClassificationPlugin::CommentLabelUser.find_by(comment_id: comment.id).nil?
  40 + CommentClassificationPlugin::CommentLabelUser.find_by(comment_id: comment.id).destroy
41 end 41 end
42 else 42 else
43 label = CommentClassificationPlugin::Label.find label_id 43 label = CommentClassificationPlugin::Label.find label_id
plugins/comment_paragraph/lib/ext/article.rb
@@ -2,7 +2,10 @@ require_dependency &#39;article&#39; @@ -2,7 +2,10 @@ require_dependency &#39;article&#39;
2 2
3 class Article 3 class Article
4 4
5 - has_many :paragraph_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'paragraph_uuid IS NOT NULL'] 5 + has_many :paragraph_comments, -> {
  6 + order('created_at ASC')
  7 + .where('paragraph_uuid IS NOT NULL')
  8 + }, class_name: 'Comment', foreign_key: 'source_id', dependent: :destroy
6 9
7 before_save :comment_paragraph_plugin_parse_html 10 before_save :comment_paragraph_plugin_parse_html
8 11
plugins/comment_paragraph/lib/ext/comment.rb
@@ -2,14 +2,13 @@ require_dependency &#39;comment&#39; @@ -2,14 +2,13 @@ require_dependency &#39;comment&#39;
2 2
3 class Comment 3 class Comment
4 4
5 - scope :without_paragraph, :conditions => {:paragraph_uuid => nil } 5 + scope :without_paragraph, -> { where paragraph_uuid: nil }
6 6
7 settings_items :comment_paragraph_selected_area, :type => :string 7 settings_items :comment_paragraph_selected_area, :type => :string
8 settings_items :comment_paragraph_selected_content, :type => :string 8 settings_items :comment_paragraph_selected_content, :type => :string
9 9
10 - scope :in_paragraph, proc { |paragraph_uuid| {  
11 - :conditions => ['paragraph_uuid = ?', paragraph_uuid]  
12 - } 10 + scope :in_paragraph, -> paragraph_uuid {
  11 + where 'paragraph_uuid = ?', paragraph_uuid
13 } 12 }
14 13
15 attr_accessible :paragraph_uuid, :comment_paragraph_selected_area, :id, :comment_paragraph_selected_content 14 attr_accessible :paragraph_uuid, :comment_paragraph_selected_area, :id, :comment_paragraph_selected_content
plugins/community_track/lib/community_track_plugin/step.rb
@@ -7,7 +7,7 @@ class CommunityTrackPlugin::Step &lt; Folder @@ -7,7 +7,7 @@ class CommunityTrackPlugin::Step &lt; Folder
7 7
8 alias :tools :children 8 alias :tools :children
9 9
10 - acts_as_list :scope => :parent 10 + acts_as_list scope: -> step { where parent_id: step.parent_id }
11 11
12 def belong_to_track 12 def belong_to_track
13 errors.add(:parent, _("Step not allowed at this parent.")) unless parent.kind_of?(CommunityTrackPlugin::Track) 13 errors.add(:parent, _("Step not allowed at this parent.")) unless parent.kind_of?(CommunityTrackPlugin::Track)
plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb
@@ -105,10 +105,10 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase @@ -105,10 +105,10 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase
105 per_page = 4 105 per_page = 4
106 (per_page*3).times {|i| create_track("track_#{i}", @community) } 106 (per_page*3).times {|i| create_track("track_#{i}", @community) }
107 107
108 - tracks = 3.times.map do |i| 108 + tracks = 3.times.flat_map do |i|
109 xhr :get, :view_tracks, :id => @block.id, :page => i+1, :per_page => per_page 109 xhr :get, :view_tracks, :id => @block.id, :page => i+1, :per_page => per_page
110 assigns[:tracks].all 110 assigns[:tracks].all
111 - end.flatten 111 + end
112 assert_equal tracks.count, tracks.uniq.count 112 assert_equal tracks.count, tracks.uniq.count
113 end 113 end
114 114
plugins/custom_forms/controllers/custom_forms_plugin_profile_controller.rb
@@ -6,7 +6,7 @@ class CustomFormsPluginProfileController &lt; ProfileController @@ -6,7 +6,7 @@ class CustomFormsPluginProfileController &lt; ProfileController
6 6
7 @form = CustomFormsPlugin::Form.find(params[:id]) 7 @form = CustomFormsPlugin::Form.find(params[:id])
8 if user 8 if user
9 - @submission = CustomFormsPlugin::Submission.find_by_form_id_and_profile_id(@form.id,user.id) 9 + @submission = CustomFormsPlugin::Submission.find_by form_id: @form.id, profile_id: user.id
10 @submission ||= CustomFormsPlugin::Submission.new(:form => @form, :profile => user) 10 @submission ||= CustomFormsPlugin::Submission.new(:form => @form, :profile => user)
11 else 11 else
12 @submission = CustomFormsPlugin::Submission.new(:form => @form) 12 @submission = CustomFormsPlugin::Submission.new(:form => @form)
@@ -17,7 +17,7 @@ class CustomFormsPluginProfileController &lt; ProfileController @@ -17,7 +17,7 @@ class CustomFormsPluginProfileController &lt; ProfileController
17 17
18 if request.post? 18 if request.post?
19 begin 19 begin
20 - raise 'Submission already present!' if user.present? && CustomFormsPlugin::Submission.find_by_form_id_and_profile_id(@form.id,user.id) 20 + raise 'Submission already present!' if user.present? && CustomFormsPlugin::Submission.find_by(form_id: @form.id, profile_id: user.id)
21 raise 'Form expired!' if @form.expired? 21 raise 'Form expired!' if @form.expired?
22 22
23 if !user 23 if !user
plugins/custom_forms/lib/custom_forms_plugin/field.rb
@@ -9,7 +9,7 @@ class CustomFormsPlugin::Field &lt; ActiveRecord::Base @@ -9,7 +9,7 @@ class CustomFormsPlugin::Field &lt; ActiveRecord::Base
9 belongs_to :form, :class_name => 'CustomFormsPlugin::Form' 9 belongs_to :form, :class_name => 'CustomFormsPlugin::Form'
10 has_many :answers, :class_name => 'CustomFormsPlugin::Answer', :dependent => :destroy 10 has_many :answers, :class_name => 'CustomFormsPlugin::Answer', :dependent => :destroy
11 11
12 - has_many :alternatives, :order => 'position', :class_name => 'CustomFormsPlugin::Alternative' 12 + has_many :alternatives, -> { order 'position' }, class_name: 'CustomFormsPlugin::Alternative'
13 accepts_nested_attributes_for :alternatives, :allow_destroy => true 13 accepts_nested_attributes_for :alternatives, :allow_destroy => true
14 #FIXME This validation should be in the subclass, but since we are using Single Table 14 #FIXME This validation should be in the subclass, but since we are using Single Table
15 # Inheritance we are instantiating a Field object with the type as a param. So the validation 15 # Inheritance we are instantiating a Field object with the type as a param. So the validation
plugins/custom_forms/lib/custom_forms_plugin/form.rb
@@ -2,7 +2,7 @@ class CustomFormsPlugin::Form &lt; ActiveRecord::Base @@ -2,7 +2,7 @@ class CustomFormsPlugin::Form &lt; ActiveRecord::Base
2 2
3 belongs_to :profile 3 belongs_to :profile
4 4
5 - has_many :fields, :order => 'position', :class_name => 'CustomFormsPlugin::Field', :dependent => :destroy 5 + has_many :fields, -> { order 'position' }, class_name: 'CustomFormsPlugin::Field', dependent: :destroy
6 accepts_nested_attributes_for :fields, :allow_destroy => true 6 accepts_nested_attributes_for :fields, :allow_destroy => true
7 7
8 has_many :submissions, :class_name => 'CustomFormsPlugin::Submission', :dependent => :destroy 8 has_many :submissions, :class_name => 'CustomFormsPlugin::Submission', :dependent => :destroy
plugins/custom_forms/lib/custom_forms_plugin/submission.rb
@@ -15,7 +15,7 @@ class CustomFormsPlugin::Submission &lt; ActiveRecord::Base @@ -15,7 +15,7 @@ class CustomFormsPlugin::Submission &lt; ActiveRecord::Base
15 validate :check_answers 15 validate :check_answers
16 16
17 def self.human_attribute_name_with_customization(attrib, options={}) 17 def self.human_attribute_name_with_customization(attrib, options={})
18 - if /\d+/ =~ attrib and (f = CustomFormsPlugin::Field.find_by_id(attrib.to_s)) 18 + if /\d+/ =~ attrib and (f = CustomFormsPlugin::Field.find_by(id: attrib.to_s))
19 f.name 19 f.name
20 else 20 else
21 _(self.human_attribute_name_without_customization(attrib)) 21 _(self.human_attribute_name_without_customization(attrib))
plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb
@@ -66,7 +66,7 @@ class CustomFormsPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -66,7 +66,7 @@ class CustomFormsPluginMyprofileControllerTest &lt; ActionController::TestCase
66 } 66 }
67 end 67 end
68 68
69 - form = CustomFormsPlugin::Form.find_by_name('My Form') 69 + form = CustomFormsPlugin::Form.find_by(name: 'My Form')
70 assert_equal 'logged', form.access 70 assert_equal 'logged', form.access
71 assert_equal begining, form.begining.strftime(format) 71 assert_equal begining, form.begining.strftime(format)
72 assert_equal ending, form.ending.strftime(format) 72 assert_equal ending, form.ending.strftime(format)
@@ -110,7 +110,7 @@ class CustomFormsPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -110,7 +110,7 @@ class CustomFormsPluginMyprofileControllerTest &lt; ActionController::TestCase
110 :fields_attributes => fields 110 :fields_attributes => fields
111 } 111 }
112 end 112 end
113 - form = CustomFormsPlugin::Form.find_by_name('My Form') 113 + form = CustomFormsPlugin::Form.find_by(name: 'My Form')
114 assert_equal num_fields, form.fields.count 114 assert_equal num_fields, form.fields.count
115 lst = 10 115 lst = 10
116 form.fields.each do |f| 116 form.fields.each do |f|
@@ -147,7 +147,7 @@ class CustomFormsPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -147,7 +147,7 @@ class CustomFormsPluginMyprofileControllerTest &lt; ActionController::TestCase
147 :fields_attributes => fields 147 :fields_attributes => fields
148 } 148 }
149 end 149 end
150 - form = CustomFormsPlugin::Form.find_by_name('My Form') 150 + form = CustomFormsPlugin::Form.find_by(name: 'My Form')
151 assert_equal 2, form.fields.count 151 assert_equal 2, form.fields.count
152 assert form.fields.first.name == "1" 152 assert form.fields.first.name == "1"
153 assert form.fields.last.name == "0" 153 assert form.fields.last.name == "0"
plugins/delivery/controllers/myprofile/delivery_plugin/admin_method_controller.rb
@@ -13,7 +13,7 @@ class DeliveryPlugin::AdminMethodController &lt; MyProfileController @@ -13,7 +13,7 @@ class DeliveryPlugin::AdminMethodController &lt; MyProfileController
13 end 13 end
14 14
15 def edit 15 def edit
16 - @delivery_method ||= profile.delivery_methods.find_by_id params[:id] 16 + @delivery_method ||= profile.delivery_methods.find_by id: params[:id]
17 if params[:delivery_method].present? and @delivery_method.update params[:delivery_method] 17 if params[:delivery_method].present? and @delivery_method.update params[:delivery_method]
18 render partial: 'list' 18 render partial: 'list'
19 else 19 else
plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb
@@ -26,7 +26,7 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController @@ -26,7 +26,7 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController
26 26
27 def destroy 27 def destroy
28 if request.delete? 28 if request.delete?
29 - notification = environment.environment_notifications.find_by_id(params[:id]) 29 + notification = environment.environment_notifications.find_by id: params[:id]
30 if notification && notification.destroy 30 if notification && notification.destroy
31 session[:notice] = _('The notification was deleted.') 31 session[:notice] = _('The notification was deleted.')
32 else 32 else
@@ -37,7 +37,7 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController @@ -37,7 +37,7 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController
37 end 37 end
38 38
39 def edit 39 def edit
40 - @notification = environment.environment_notifications.find_by_id(params[:id]) 40 + @notification = environment.environment_notifications.find_by id: params[:id]
41 if request.post? 41 if request.post?
42 if @notification.update_attributes(params[:notifications]) 42 if @notification.update_attributes(params[:notifications])
43 session[:notice] = _('The notification was edited.') 43 session[:notice] = _('The notification was edited.')
@@ -49,7 +49,7 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController @@ -49,7 +49,7 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController
49 end 49 end
50 50
51 def change_status 51 def change_status
52 - @notification = environment.environment_notifications.find_by_id(params[:id]) 52 + @notification = environment.environment_notifications.find_by id: params[:id]
53 53
54 @notification.active = !@notification.active 54 @notification.active = !@notification.active
55 55
@@ -66,7 +66,7 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController @@ -66,7 +66,7 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController
66 result = false 66 result = false
67 67
68 if logged_in? 68 if logged_in?
69 - @notification = environment.environment_notifications.find_by_id(params[:notification_id]) 69 + @notification = environment.environment_notifications.find_by id: params[:notification_id]
70 70
71 if @notification 71 if @notification
72 @notification.users << current_user 72 @notification.users << current_user
@@ -81,7 +81,7 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController @@ -81,7 +81,7 @@ class EnvironmentNotificationPluginAdminController &lt; AdminController
81 result = false 81 result = false
82 82
83 if logged_in? 83 if logged_in?
84 - @notification = environment.environment_notifications.find_by_id(params[:notification_id]) 84 + @notification = environment.environment_notifications.find_by id: params[:notification_id]
85 85
86 if @notification 86 if @notification
87 current_notificaions = [] 87 current_notificaions = []
plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb
@@ -24,7 +24,7 @@ class EnvironmentNotificationPlugin::EnvironmentNotification &lt; ActiveRecord::Bas @@ -24,7 +24,7 @@ class EnvironmentNotificationPlugin::EnvironmentNotification &lt; ActiveRecord::Bas
24 end 24 end
25 end 25 end
26 26
27 - scope :active, lambda{|environment| { :conditions => { :environment_id => environment.id, :active => true } } } 27 + scope :active, -> environment { where environment_id: environment.id, active: true }
28 28
29 def self.visibles(environment, user, controller_path) 29 def self.visibles(environment, user, controller_path)
30 notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(environment).order('updated_at DESC') 30 notifications = EnvironmentNotificationPlugin::EnvironmentNotification.active(environment).order('updated_at DESC')
plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb
1 -require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'  
2 -require(  
3 - File.expand_path(File.dirname(__FILE__)) +  
4 - '/../../controllers/environment_notification_plugin_admin_controller'  
5 -) 1 +require 'test_helper'
  2 +require_relative '../../controllers/environment_notification_plugin_admin_controller'
6 3
7 class EnvironmentNotificationPluginAdminController; def rescue_action(e) raise e end; 4 class EnvironmentNotificationPluginAdminController; def rescue_action(e) raise e end;
8 end 5 end
@@ -94,7 +91,7 @@ class EnvironmentNotificationPluginAdminControllerTest &lt; ActionController::TestC @@ -94,7 +91,7 @@ class EnvironmentNotificationPluginAdminControllerTest &lt; ActionController::TestC
94 :type => "EnvironmentNotificationPlugin::DangerNotification" 91 :type => "EnvironmentNotificationPlugin::DangerNotification"
95 ) 92 )
96 delete :destroy, :id => @notification.id 93 delete :destroy, :id => @notification.id
97 - assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id) 94 + assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by(id: @notification.id)
98 end 95 end
99 96
100 should 'an user not to be able to destroy a notification' do 97 should 'an user not to be able to destroy a notification' do
@@ -107,7 +104,7 @@ class EnvironmentNotificationPluginAdminControllerTest &lt; ActionController::TestC @@ -107,7 +104,7 @@ class EnvironmentNotificationPluginAdminControllerTest &lt; ActionController::TestC
107 delete :destroy, :id => @notification.id 104 delete :destroy, :id => @notification.id
108 105
109 assert_redirected_to :root 106 assert_redirected_to :root
110 - assert_not_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id) 107 + assert_not_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by(id: @notification.id)
111 end 108 end
112 109
113 should 'an admin be able to change Notification status' do 110 should 'an admin be able to change Notification status' do
plugins/gallery_block/lib/gallery_block.rb
@@ -18,12 +18,12 @@ class GalleryBlock &lt; Block @@ -18,12 +18,12 @@ class GalleryBlock &lt; Block
18 18
19 def gallery 19 def gallery
20 if self.owner.kind_of? Environment 20 if self.owner.kind_of? Environment
21 - article = owner.articles.find_by_id(self.gallery_id) 21 + article = owner.articles.find_by id: self.gallery_id
22 if article && article.gallery? 22 if article && article.gallery?
23 article 23 article
24 end 24 end
25 else 25 else
26 - owner.image_galleries.find_by_id(self.gallery_id) 26 + owner.image_galleries.find_by id: self.gallery_id
27 end 27 end
28 end 28 end
29 29
plugins/newsletter/controllers/newsletter_plugin_admin_controller.rb
@@ -26,7 +26,7 @@ class NewsletterPluginAdminController &lt; PluginAdminController @@ -26,7 +26,7 @@ class NewsletterPluginAdminController &lt; PluginAdminController
26 end 26 end
27 end 27 end
28 28
29 - @blogs = Blog.includes(:profile).find_all_by_id(@newsletter.blog_ids) 29 + @blogs = Blog.includes(:profile).where id: @newsletter.blog_ids
30 end 30 end
31 31
32 #TODO: Make this query faster 32 #TODO: Make this query faster
plugins/newsletter/lib/newsletter_plugin/newsletter.rb
@@ -11,7 +11,7 @@ class NewsletterPlugin::Newsletter &lt; ActiveRecord::Base @@ -11,7 +11,7 @@ class NewsletterPlugin::Newsletter &lt; ActiveRecord::Base
11 11
12 attr_accessible :environment, :enabled, :periodicity, :subject, :posts_per_blog, :footer, :blog_ids, :additional_recipients, :person, :person_id, :moderated 12 attr_accessible :environment, :enabled, :periodicity, :subject, :posts_per_blog, :footer, :blog_ids, :additional_recipients, :person, :person_id, :moderated
13 13
14 - scope :enabled, :conditions => { :enabled => true } 14 + scope :enabled, -> { where enabled: true }
15 15
16 # These methods are used by NewsletterMailing 16 # These methods are used by NewsletterMailing
17 def people 17 def people
@@ -19,10 +19,9 @@ class NewsletterPlugin::Newsletter &lt; ActiveRecord::Base @@ -19,10 +19,9 @@ class NewsletterPlugin::Newsletter &lt; ActiveRecord::Base
19 if list.empty? 19 if list.empty?
20 environment.people 20 environment.people
21 else 21 else
22 - environment.people.all(  
23 - :joins => "LEFT OUTER JOIN users ON (users.id = profiles.user_id)",  
24 - :conditions => "users.email NOT IN (#{list})"  
25 - ) 22 + environment.people
  23 + .joins('LEFT OUTER JOIN users ON (users.id = profiles.user_id)')
  24 + .where("users.email NOT IN (#{list})")
26 end 25 end
27 end 26 end
28 27
@@ -51,7 +50,7 @@ class NewsletterPlugin::Newsletter &lt; ActiveRecord::Base @@ -51,7 +50,7 @@ class NewsletterPlugin::Newsletter &lt; ActiveRecord::Base
51 50
52 validates_each :blog_ids do |record, attr, value| 51 validates_each :blog_ids do |record, attr, value|
53 if record.environment 52 if record.environment
54 - unless value.delete_if(&:zero?).select { |id| !Blog.find_by_id(id) || Blog.find(id).environment != record.environment }.empty? 53 + unless value.delete_if(&:zero?).select { |id| !Blog.find_by(id: id) || Blog.find(id).environment != record.environment }.empty?
55 record.errors.add(attr, _('must be valid')) 54 record.errors.add(attr, _('must be valid'))
56 end 55 end
57 end 56 end
@@ -82,9 +81,9 @@ class NewsletterPlugin::Newsletter &lt; ActiveRecord::Base @@ -82,9 +81,9 @@ class NewsletterPlugin::Newsletter &lt; ActiveRecord::Base
82 def posts(data = {}) 81 def posts(data = {})
83 limit = self.posts_per_blog.zero? ? nil : self.posts_per_blog 82 limit = self.posts_per_blog.zero? ? nil : self.posts_per_blog
84 posts = if self.last_send_at.nil? 83 posts = if self.last_send_at.nil?
85 - self.blogs.map{|blog| blog.posts.all(:limit => limit)}.flatten 84 + self.blogs.flat_map{ |blog| blog.posts.limit limit }
86 else 85 else
87 - self.blogs.map{|blog| blog.posts.where("published_at >= :last_send_at", {last_send_at: self.last_send_at}).all(:limit => limit)}.flatten 86 + self.blogs.flat_map{ |blog| blog.posts.where("published_at >= :last_send_at", {last_send_at: self.last_send_at}).limit limit }
88 end 87 end
89 data[:post_ids].nil? ? posts : posts.select{|post| data[:post_ids].include?(post.id.to_s)} 88 data[:post_ids].nil? ? posts : posts.select{|post| data[:post_ids].include?(post.id.to_s)}
90 end 89 end
@@ -171,9 +170,7 @@ class NewsletterPlugin::Newsletter &lt; ActiveRecord::Base @@ -171,9 +170,7 @@ class NewsletterPlugin::Newsletter &lt; ActiveRecord::Base
171 acts_as_having_image 170 acts_as_having_image
172 171
173 def last_send_at 172 def last_send_at
174 - last_mailing = NewsletterPlugin::NewsletterMailing.last(  
175 - :conditions => {:source_id => self.id}  
176 - ) 173 + last_mailing = NewsletterPlugin::NewsletterMailing.where(source_id: self.id).last
177 last_mailing.nil? ? nil : last_mailing.created_at 174 last_mailing.nil? ? nil : last_mailing.created_at
178 end 175 end
179 176
plugins/newsletter/test/functional/newsletter_plugin_admin_controller_test.rb
@@ -46,7 +46,7 @@ class NewsletterPluginAdminControllerTest &lt; ActionController::TestCase @@ -46,7 +46,7 @@ class NewsletterPluginAdminControllerTest &lt; ActionController::TestCase
46 post :index, 46 post :index,
47 :newsletter => { :enabled => 'true' } 47 :newsletter => { :enabled => 'true' }
48 48
49 - newsletter = NewsletterPlugin::Newsletter.find_by_environment_id(@environment.id) 49 + newsletter = NewsletterPlugin::Newsletter.find_by environment_id: @environment.id
50 50
51 assert newsletter.enabled 51 assert newsletter.enabled
52 end 52 end
@@ -56,7 +56,7 @@ class NewsletterPluginAdminControllerTest &lt; ActionController::TestCase @@ -56,7 +56,7 @@ class NewsletterPluginAdminControllerTest &lt; ActionController::TestCase
56 post :index, 56 post :index,
57 :newsletter => { :periodicity => '10' } 57 :newsletter => { :periodicity => '10' }
58 58
59 - newsletter = NewsletterPlugin::Newsletter.find_by_environment_id(@environment.id) 59 + newsletter = NewsletterPlugin::Newsletter.find_by environment_id: @environment.id
60 60
61 assert_equal 10, newsletter.periodicity 61 assert_equal 10, newsletter.periodicity
62 end 62 end
plugins/newsletter/test/unit/newsletter_plugin_newsletter_test.rb
@@ -56,7 +56,7 @@ class NewsletterPluginNewsletterTest &lt; ActiveSupport::TestCase @@ -56,7 +56,7 @@ class NewsletterPluginNewsletterTest &lt; ActiveSupport::TestCase
56 :periodicity => '3', 56 :periodicity => '3',
57 :person => fast_create(Person)) 57 :person => fast_create(Person))
58 58
59 - assert_equal 3, NewsletterPlugin::Newsletter.find_by_environment_id(environment.id).periodicity 59 + assert_equal 3, NewsletterPlugin::Newsletter.find_by(environment_id: environment.id).periodicity
60 end 60 end
61 61
62 should 'save period as number only' do 62 should 'save period as number only' do
plugins/oauth_client/lib/oauth_client_plugin.rb
@@ -56,7 +56,7 @@ class OauthClientPlugin &lt; Noosfero::Plugin @@ -56,7 +56,7 @@ class OauthClientPlugin &lt; Noosfero::Plugin
56 strategy = env['omniauth.strategy'] 56 strategy = env['omniauth.strategy']
57 57
58 Noosfero::MultiTenancy.setup!(request.host) 58 Noosfero::MultiTenancy.setup!(request.host)
59 - domain = Domain.find_by_name(request.host) 59 + domain = Domain.by_name(request.host)
60 environment = domain.environment rescue Environment.default 60 environment = domain.environment rescue Environment.default
61 61
62 provider_id = request.params['id'] 62 provider_id = request.params['id']
plugins/oauth_provider/lib/oauth_provider_plugin.rb
@@ -16,15 +16,15 @@ class OauthProviderPlugin &lt; Noosfero::Plugin @@ -16,15 +16,15 @@ class OauthProviderPlugin &lt; Noosfero::Plugin
16 orm :active_record 16 orm :active_record
17 17
18 resource_owner_authenticator do 18 resource_owner_authenticator do
19 - domain = Domain.find_by_name(request.host) 19 + domain = Domain.by_name(request.host)
20 environment = domain ? domain.environment : Environment.default 20 environment = domain ? domain.environment : Environment.default
21 - environment.users.find_by_id(session[:user]) || redirect_to('/account/login') 21 + environment.users.find_by(id: session[:user]) || redirect_to('/account/login')
22 end 22 end
23 23
24 admin_authenticator do 24 admin_authenticator do
25 - domain = Domain.find_by_name(request.host) 25 + domain = Domain.by_name(request.host)
26 environment = domain ? domain.environment : Environment.default 26 environment = domain ? domain.environment : Environment.default
27 - user = environment.users.find_by_id(session[:user]) 27 + user = environment.users.find_by id: session[:user]
28 unless user && user.person.is_admin?(environment) 28 unless user && user.person.is_admin?(environment)
29 redirect_to('/account/login') 29 redirect_to('/account/login')
30 end 30 end
plugins/orders/controllers/profile/orders_plugin_order_controller.rb
@@ -19,7 +19,7 @@ class OrdersPluginOrderController &lt; ProfileController @@ -19,7 +19,7 @@ class OrdersPluginOrderController &lt; ProfileController
19 protected 19 protected
20 20
21 def load_order 21 def load_order
22 - @order = hmvc_orders_context::Sale.find_by_id params[:id] 22 + @order = hmvc_orders_context::Sale.find_by id: params[:id]
23 render_access_denied if @order.present? and (not @user_is_admin or not @order.may_view? user) 23 render_access_denied if @order.present? and (not @user_is_admin or not @order.may_view? user)
24 end 24 end
25 25
plugins/orders/controllers/public/orders_plugin_controller.rb
@@ -14,7 +14,7 @@ class OrdersPluginController &lt; PublicController @@ -14,7 +14,7 @@ class OrdersPluginController &lt; PublicController
14 14
15 def clear_orders_session 15 def clear_orders_session
16 return if user 16 return if user
17 - previous_orders.update_all ['session_id = ?', nil] 17 + previous_orders.update_all session_id: nil
18 end 18 end
19 19
20 protected 20 protected
plugins/orders/db/migrate/20140412202042_refactor_orders_plugin_statuses.rb
@@ -38,7 +38,7 @@ class RefactorOrdersPluginStatuses &lt; ActiveRecord::Migration @@ -38,7 +38,7 @@ class RefactorOrdersPluginStatuses &lt; ActiveRecord::Migration
38 add_column :orders_plugin_orders, :received_at, :datetime 38 add_column :orders_plugin_orders, :received_at, :datetime
39 39
40 OrdersPlugin::Order.record_timestamps = false 40 OrdersPlugin::Order.record_timestamps = false
41 - OrdersPlugin::Order.update_all ["status = 'ordered'"], ["status = 'confirmed'"] 41 + OrdersPlugin::Order.where(status: 'confirmed').update_all status: 'ordered'
42 OrdersPlugin::Order.find_each do |order| 42 OrdersPlugin::Order.find_each do |order|
43 order.ordered_at = order.updated_at if order.status == 'ordered' 43 order.ordered_at = order.updated_at if order.status == 'ordered'
44 order.save run_callbacks: false 44 order.save run_callbacks: false
plugins/orders/models/orders_plugin/item.rb
@@ -62,7 +62,7 @@ class OrdersPlugin::Item &lt; ActiveRecord::Base @@ -62,7 +62,7 @@ class OrdersPlugin::Item &lt; ActiveRecord::Base
62 scope :ordered, -> { joins(:order).where 'orders_plugin_orders.status = ?', 'ordered' } 62 scope :ordered, -> { joins(:order).where 'orders_plugin_orders.status = ?', 'ordered' }
63 scope :for_product, -> (product) { where product_id: product.id } 63 scope :for_product, -> (product) { where product_id: product.id }
64 64
65 - default_scope include: [:product] 65 + default_scope -> { includes :product }
66 66
67 validate :has_order 67 validate :has_order
68 validates_presence_of :product 68 validates_presence_of :product
plugins/orders/models/orders_plugin/order.rb
@@ -68,7 +68,7 @@ class OrdersPlugin::Order &lt; ActiveRecord::Base @@ -68,7 +68,7 @@ class OrdersPlugin::Order &lt; ActiveRecord::Base
68 where cond 68 where cond
69 end 69 end
70 70
71 - scope :latest, order: 'created_at DESC' 71 + scope :latest, -> { order 'created_at DESC' }
72 72
73 scope :draft, -> { where status: 'draft' } 73 scope :draft, -> { where status: 'draft' }
74 scope :planned, -> { where status: 'planned' } 74 scope :planned, -> { where status: 'planned' }
plugins/orders_cycle/controllers/myprofile/orders_cycle_plugin_product_controller.rb
@@ -18,7 +18,7 @@ class OrdersCyclePluginProductController &lt; SuppliersPlugin::ProductController @@ -18,7 +18,7 @@ class OrdersCyclePluginProductController &lt; SuppliersPlugin::ProductController
18 @offered_product = OrdersCyclePlugin::OfferedProduct.find params[:id] 18 @offered_product = OrdersCyclePlugin::OfferedProduct.find params[:id]
19 @order = OrdersCyclePlugin::Sale.find params[:order_id] 19 @order = OrdersCyclePlugin::Sale.find params[:order_id]
20 raise 'Order confirmed or cycle is closed for orders' unless @order.open? 20 raise 'Order confirmed or cycle is closed for orders' unless @order.open?
21 - @item = @order.items.find_by_product_id @offered_product.id 21 + @item = @order.items.find_by product_id: @offered_product.id
22 @item.destroy rescue render nothing: true 22 @item.destroy rescue render nothing: true
23 end 23 end
24 24
plugins/orders_cycle/models/orders_cycle_plugin/cycle.rb
@@ -245,7 +245,7 @@ class OrdersCyclePlugin::Cycle &lt; ActiveRecord::Base @@ -245,7 +245,7 @@ class OrdersCyclePlugin::Cycle &lt; ActiveRecord::Base
245 end 245 end
246 246
247 def add_products_job 247 def add_products_job
248 - @add_products_job ||= Delayed::Job.find_by_id self.data[:add_products_job_id] 248 + @add_products_job ||= Delayed::Job.find_by id: self.data[:add_products_job_id]
249 end 249 end
250 250
251 protected 251 protected
plugins/organization_ratings/lib/ext/organization.rb
@@ -3,5 +3,5 @@ require_dependency &#39;organization&#39; @@ -3,5 +3,5 @@ require_dependency &#39;organization&#39;
3 Organization.class_eval do 3 Organization.class_eval do
4 has_many :organization_ratings 4 has_many :organization_ratings
5 5
6 - has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' 6 + has_many :comments, -> { order 'created_at asc' }, class_name: 'Comment', foreign_key: 'source_id', dependent: :destroy
7 end 7 end
plugins/people_block/lib/members_block.rb
@@ -21,7 +21,7 @@ class MembersBlock &lt; PeopleBlockBase @@ -21,7 +21,7 @@ class MembersBlock &lt; PeopleBlockBase
21 end 21 end
22 22
23 def role 23 def role
24 - visible_role && !visible_role.empty? ? Role.find_by_key_and_environment_id(visible_role, owner.environment) : nil 24 + visible_role && !visible_role.empty? ? Role.find_by(key: visible_role, environment_id: owner.environment.id) : nil
25 end 25 end
26 26
27 def roles 27 def roles
plugins/people_block/lib/people_block_base.rb
@@ -29,11 +29,11 @@ class PeopleBlockBase &lt; Block @@ -29,11 +29,11 @@ class PeopleBlockBase &lt; Block
29 result = nil 29 result = nil
30 visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment]) 30 visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment])
31 if !prioritize_profiles_with_image 31 if !prioritize_profiles_with_image
32 - result = visible_profiles.all(:limit => limit, :order => 'profiles.updated_at DESC').sort_by{ rand } 32 + result = visible_profiles.limit(limit).order('profiles.updated_at DESC').sort_by{ rand }
33 elsif profiles.visible.with_image.count >= limit 33 elsif profiles.visible.with_image.count >= limit
34 - result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } 34 + result = visible_profiles.with_image.limit(limit * 5).order('profiles.updated_at DESC').sort_by{ rand }
35 else 35 else
36 - result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } 36 + result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.limit(limit * 5).order('profiles.updated_at DESC').sort_by{ rand }
37 end 37 end
38 result.slice(0..limit-1) 38 result.slice(0..limit-1)
39 end 39 end
plugins/profile_members_headlines/lib/profile_members_headlines_block.rb
@@ -26,10 +26,13 @@ class ProfileMembersHeadlinesBlock &lt; Block @@ -26,10 +26,13 @@ class ProfileMembersHeadlinesBlock &lt; Block
26 end 26 end
27 27
28 def authors_list 28 def authors_list
29 - result = owner.members_by_role(filtered_roles).is_public.includes([:image,:domains,:preferred_domain,:environment]).order('updated_at DESC') 29 + result = owner
  30 + .members_by_role(filtered_roles)
  31 + .is_public
  32 + .includes([:image,:domains,:preferred_domain,:environment]).order('updated_at DESC')
  33 + .limit(limit * 5)
30 34
31 - result.all(:limit => limit * 5).select { |p| p.has_headline?  
32 -}.slice(0..limit-1) 35 + result.select{ |p| p.has_headline? }.slice(0..limit-1)
33 end 36 end
34 37
35 def content(args={}) 38 def content(args={})
plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
@@ -353,7 +353,7 @@ class ShoppingCartPluginController &lt; OrdersPluginController @@ -353,7 +353,7 @@ class ShoppingCartPluginController &lt; OrdersPluginController
353 353
354 def products 354 def products
355 self.cart[:items].collect do |id, quantity| 355 self.cart[:items].collect do |id, quantity|
356 - product = Product.find_by_id(id) 356 + product = Product.find_by id: id
357 if product 357 if product
358 { id: product.id, 358 { id: product.id,
359 name: product.name, 359 name: product.name,
plugins/shopping_cart/features/step_definitions/delivery_steps.rb
1 Given /^"([^""]*)" has the following delivery methods$/ do |name, table| 1 Given /^"([^""]*)" has the following delivery methods$/ do |name, table|
2 - enterprise = Enterprise.find_by_name(name) || Enterprise[name] 2 + enterprise = Enterprise.find_by(name: name) || Enterprise[name]
3 table.hashes.map{|item| item.dup}.each do |item| 3 table.hashes.map{|item| item.dup}.each do |item|
4 delivery_method = enterprise.delivery_methods.build 4 delivery_method = enterprise.delivery_methods.build
5 delivery_method.update_attributes(item) 5 delivery_method.update_attributes(item)
plugins/shopping_cart/features/step_definitions/orders_steps.rb
1 Given /^the following purchase from "([^""]*)" on "([^""]*)" that is "([^""]*)"$/ do |consumer_identifier, enterprise_identifier, status, table| 1 Given /^the following purchase from "([^""]*)" on "([^""]*)" that is "([^""]*)"$/ do |consumer_identifier, enterprise_identifier, status, table|
2 - consumer = Person.find_by_name(consumer_identifier) || Person[consumer_identifier]  
3 - enterprise = Enterprise.find_by_name(enterprise_identifier) || Enterprise[enterprise_identifier] 2 + consumer = Person.find_by(name: consumer_identifier) || Person[consumer_identifier]
  3 + enterprise = Enterprise.find_by(name: enterprise_identifier) || Enterprise[enterprise_identifier]
4 order = OrdersPlugin::Purchase.new(:profile => enterprise, :consumer => consumer, :status => status) 4 order = OrdersPlugin::Purchase.new(:profile => enterprise, :consumer => consumer, :status => status)
5 5
6 table.hashes.map{|item| item.dup}.each do |item| 6 table.hashes.map{|item| item.dup}.each do |item|
7 - product = enterprise.products.find_by_name item[:product] 7 + product = enterprise.products.find_by name: item[:product]
8 item = order.items.build({:product => product, :name => item[:product], :quantity_consumer_ordered => item[:quantity], :price => item[:price]}) 8 item = order.items.build({:product => product, :name => item[:product], :quantity_consumer_ordered => item[:quantity], :price => item[:price]})
9 item.order = order 9 item.order = order
10 end 10 end
plugins/shopping_cart/features/step_definitions/shopping_cart_steps.rb
1 Given /^the shopping basket is (enabled|disabled) on "([^""]*)"$/ do |status, name| 1 Given /^the shopping basket is (enabled|disabled) on "([^""]*)"$/ do |status, name|
2 status = status == 'enabled' 2 status = status == 'enabled'
3 - enterprise = Enterprise.find_by_name(name) || Enterprise[name] 3 + enterprise = Enterprise.find_by(name: name) || Enterprise[name]
4 settings = enterprise.shopping_cart_settings({:enabled => status}) 4 settings = enterprise.shopping_cart_settings({:enabled => status})
5 settings.save! 5 settings.save!
6 end 6 end
plugins/shopping_cart/lib/shopping_cart_plugin/line_item.rb
@@ -9,7 +9,7 @@ class ShoppingCartPlugin::LineItem @@ -9,7 +9,7 @@ class ShoppingCartPlugin::LineItem
9 end 9 end
10 10
11 def product 11 def product
12 - @product ||= Product.find_by_id(product_id) 12 + @product ||= Product.find_by id: product_id
13 end 13 end
14 14
15 def name 15 def name
plugins/sniffer/controllers/sniffer_plugin_myprofile_controller.rb
@@ -94,7 +94,7 @@ class SnifferPluginMyprofileController &lt; MyProfileController @@ -94,7 +94,7 @@ class SnifferPluginMyprofileController &lt; MyProfileController
94 protected 94 protected
95 95
96 def fetch_profiles(products) 96 def fetch_profiles(products)
97 - profiles = Profile.all conditions: {id: products.map { |p| target_profile_id(p) }} 97 + profiles = Profile.where id: products.map{ |p| target_profile_id p }
98 profiles_by_id = {} 98 profiles_by_id = {}
99 profiles.each do |p| 99 profiles.each do |p|
100 p.sniffer_plugin_distance = Noosfero::GeoRef.dist(@profile.lat, @profile.lng, p.lat, p.lng) 100 p.sniffer_plugin_distance = Noosfero::GeoRef.dist(@profile.lat, @profile.lng, p.lat, p.lng)
@@ -113,9 +113,9 @@ class SnifferPluginMyprofileController &lt; MyProfileController @@ -113,9 +113,9 @@ class SnifferPluginMyprofileController &lt; MyProfileController
113 113
114 id_profiles = fetch_profiles(data) 114 id_profiles = fetch_profiles(data)
115 115
116 - products = Product.all conditions: {id: grab_id.call('id')}, include: [:enterprise, :product_category] 116 + products = Product.where(id: grab_id.call('id')).includes(:enterprise, :product_category)
117 products.each{ |p| id_products[p.id] ||= p } 117 products.each{ |p| id_products[p.id] ||= p }
118 - knowledges = Article.all conditions: {id: grab_id.call('knowledge_id')} 118 + knowledges = Article.where(id: grab_id.call('knowledge_id'))
119 knowledges.each{ |k| id_knowledges[k.id] ||= k} 119 knowledges.each{ |k| id_knowledges[k.id] ||= k}
120 120
121 data.each do |attributes| 121 data.each do |attributes|
plugins/sniffer/lib/ext/product.rb
@@ -11,19 +11,16 @@ class Product @@ -11,19 +11,16 @@ class Product
11 # - Enterprise 1 has Product A that uses input X 11 # - Enterprise 1 has Product A that uses input X
12 # - Enterprise 2 has Product B that belongs to category X 12 # - Enterprise 2 has Product B that belongs to category X
13 # -> Enterprise 1 as a parameter to this scope would return product B 13 # -> Enterprise 1 as a parameter to this scope would return product B
14 - scope :sniffer_plugin_suppliers_products, lambda { |enterprise|  
15 - {  
16 - select: "DISTINCT products_2.*,  
17 - 'product' as view",  
18 - joins: "INNER JOIN inputs ON ( products.id = inputs.product_id )  
19 - INNER JOIN categories ON ( inputs.product_category_id = categories.id )  
20 - INNER JOIN products products_2 ON ( categories.id = products_2.product_category_id )  
21 - INNER JOIN profiles ON ( profiles.id = products_2.profile_id )",  
22 - conditions: "products.profile_id = #{enterprise.id}  
23 - AND profiles.public_profile = true AND profiles.visible = true  
24 - AND profiles.enabled = true  
25 - AND profiles.id <> #{enterprise.id}"  
26 - } 14 + scope :sniffer_plugin_suppliers_products, -> enterprise {
  15 + select("DISTINCT products_2.*, 'product' as view")
  16 + .joins('INNER JOIN inputs ON products.id = inputs.product_id')
  17 + .joins('INNER JOIN categories ON inputs.product_category_id = categories.id')
  18 + .joins('INNER JOIN products products_2 ON categories.id = products_2.product_category_id')
  19 + .joins('INNER JOIN profiles ON profiles.id = products_2.profile_id')
  20 + .where("products.profile_id = #{enterprise.id}")
  21 + .where('profiles.public_profile = true AND profiles.visible = true')
  22 + .where('profiles.enabled = true')
  23 + .where("profiles.id <> #{enterprise.id}")
27 } 24 }
28 25
29 # inputs x products 26 # inputs x products
@@ -34,20 +31,16 @@ class Product @@ -34,20 +31,16 @@ class Product
34 # - Enterprise 2 has Product B that uses input X 31 # - Enterprise 2 has Product B that uses input X
35 # -> Enterprise 1 as a parameter to this scope would return product A 32 # -> Enterprise 1 as a parameter to this scope would return product A
36 # with an extra column `consumer_profile_id` equal to Enterprise 2 id 33 # with an extra column `consumer_profile_id` equal to Enterprise 2 id
37 - scope :sniffer_plugin_consumers_products, lambda { |enterprise|  
38 - {  
39 - select: "DISTINCT products_2.*,  
40 - profiles.id as consumer_profile_id,  
41 - 'product' as view",  
42 - joins: "INNER JOIN inputs ON ( products.id = inputs.product_id )  
43 - INNER JOIN categories ON ( inputs.product_category_id = categories.id )  
44 - INNER JOIN products products_2 ON ( categories.id = products_2.product_category_id )  
45 - INNER JOIN profiles ON ( profiles.id = products.profile_id )",  
46 - conditions: "products_2.profile_id = #{enterprise.id}  
47 - AND profiles.public_profile = true AND profiles.visible = true  
48 - AND profiles.enabled = true  
49 - AND profiles.id <> #{enterprise.id}"  
50 - } 34 + scope :sniffer_plugin_consumers_products, -> enterprise {
  35 + select("DISTINCT products_2.*, profiles.id as consumer_profile_id, 'product' as view")
  36 + .joins('INNER JOIN inputs ON products.id = inputs.product_id')
  37 + .joins('INNER JOIN categories ON inputs.product_category_id = categories.id')
  38 + .joins('INNER JOIN products products_2 ON categories.id = products_2.product_category_id')
  39 + .joins('INNER JOIN profiles ON profiles.id = products.profile_id')
  40 + .where("products_2.profile_id = #{enterprise.id}")
  41 + .where('profiles.public_profile = true AND profiles.visible = true')
  42 + .where('profiles.enabled = true')
  43 + .where("profiles.id <> #{enterprise.id}")
51 } 44 }
52 45
53 # interest x products 46 # interest x products
@@ -57,20 +50,17 @@ class Product @@ -57,20 +50,17 @@ class Product
57 # - Enterprise 1 has category X as a buyer interest 50 # - Enterprise 1 has category X as a buyer interest
58 # - Enterprise 2 has Product B that belongs to category X 51 # - Enterprise 2 has Product B that belongs to category X
59 # -> Enterprise 1 as a parameter to this scope would return product B 52 # -> Enterprise 1 as a parameter to this scope would return product B
60 - scope :sniffer_plugin_interests_suppliers_products, lambda { |profile|  
61 - {  
62 - from: "profiles sniffer",  
63 - select: "DISTINCT products.*,  
64 - 'product' as view",  
65 - joins: "INNER JOIN sniffer_plugin_opportunities AS op ON ( sniffer.id = op.profile_id AND op.opportunity_type = 'ProductCategory' )  
66 - INNER JOIN categories ON ( op.opportunity_id = categories.id )  
67 - INNER JOIN products ON ( products.product_category_id = categories.id )  
68 - INNER JOIN profiles ON ( products.profile_id = profiles.id )",  
69 - conditions: "sniffer.id = #{profile.id} AND products.profile_id <> #{profile.id}  
70 - AND profiles.public_profile = true AND profiles.visible = true  
71 - AND profiles.enabled = true  
72 - AND profiles.id <> #{profile.id}"  
73 - } 53 + scope :sniffer_plugin_interests_suppliers_products, -> profile {
  54 + from("profiles sniffer")
  55 + .select("DISTINCT products.*, 'product' as view")
  56 + .joins("INNER JOIN sniffer_plugin_opportunities AS op ON sniffer.id = op.profile_id AND op.opportunity_type = 'ProductCategory'")
  57 + .joins('INNER JOIN categories ON op.opportunity_id = categories.id')
  58 + .joins('INNER JOIN products ON products.product_category_id = categories.id')
  59 + .joins('INNER JOIN profiles ON products.profile_id = profiles.id')
  60 + .where("sniffer.id = #{profile.id} AND products.profile_id <> #{profile.id}")
  61 + .where('profiles.public_profile = true AND profiles.visible = true')
  62 + .where('profiles.enabled = true')
  63 + .where("profiles.id <> #{profile.id}")
74 } 64 }
75 65
76 # products x interests 66 # products x interests
@@ -81,97 +71,73 @@ class Product @@ -81,97 +71,73 @@ class Product
81 # - Enterprise 2 has category X as a buyer interest 71 # - Enterprise 2 has category X as a buyer interest
82 # -> Enterprise 1 as a parameter to this scope would return product A 72 # -> Enterprise 1 as a parameter to this scope would return product A
83 # with an extra column `consumer_profile_id` equal to Enterprise 2 id 73 # with an extra column `consumer_profile_id` equal to Enterprise 2 id
84 - scope :sniffer_plugin_interests_consumers_products, lambda { |profile|  
85 - {  
86 - select: "DISTINCT products.*,  
87 - profiles.id as consumer_profile_id,  
88 - 'product' as view",  
89 - joins: "INNER JOIN categories ON ( categories.id = products.product_category_id )  
90 - INNER JOIN sniffer_plugin_opportunities as op ON ( categories.id = op.opportunity_id AND op.opportunity_type = 'ProductCategory' )  
91 - INNER JOIN profiles ON ( op.profile_id = profiles.id )",  
92 - conditions: "products.profile_id = #{profile.id}  
93 - AND profiles.public_profile = true AND profiles.visible = true  
94 - AND profiles.enabled = true  
95 - AND profiles.id <> #{profile.id}"  
96 - } 74 + scope :sniffer_plugin_interests_consumers_products, -> profile {
  75 + select("DISTINCT products.*, profiles.id as consumer_profile_id, 'product' as view")
  76 + .joins('INNER JOIN categories ON categories.id = products.product_category_id')
  77 + .joins("INNER JOIN sniffer_plugin_opportunities as op ON categories.id = op.opportunity_id AND op.opportunity_type = 'ProductCategory'")
  78 + .joins('INNER JOIN profiles ON op.profile_id = profiles.id')
  79 + .where("products.profile_id = #{profile.id}")
  80 + .where('profiles.public_profile = true AND profiles.visible = true')
  81 + .where('profiles.enabled = true')
  82 + .where("profiles.id <> #{profile.id}")
97 } 83 }
98 84
99 # knowledge x inputs 85 # knowledge x inputs
100 - scope :sniffer_plugin_knowledge_consumers_inputs, lambda { |profile|  
101 - {  
102 - select: "DISTINCT products.*,  
103 - articles.id AS knowledge_id,  
104 - 'knowledge' as view",  
105 - joins: "INNER JOIN inputs ON ( products.id = inputs.product_id )  
106 - INNER JOIN article_resources ON (article_resources.resource_id = inputs.product_category_id AND article_resources.resource_type = 'ProductCategory')  
107 - INNER JOIN articles ON (article_resources.article_id = articles.id)  
108 - INNER JOIN profiles ON ( products.profile_id = profiles.id )",  
109 - conditions: "articles.type = 'CmsLearningPlugin::Learning'  
110 - AND articles.profile_id = #{profile.id}  
111 - AND products.profile_id <> #{profile.id}"  
112 - } 86 + scope :sniffer_plugin_knowledge_consumers_inputs, -> profile {
  87 + select("DISTINCT products.*, articles.id AS knowledge_id, 'knowledge' as view")
  88 + .joins('INNER JOIN inputs ON products.id = inputs.product_id')
  89 + .joins("INNER JOIN article_resources ON article_resources.resource_id = inputs.product_category_id AND article_resources.resource_type = 'ProductCategory'")
  90 + .joins('INNER JOIN articles ON article_resources.article_id = articles.id')
  91 + .joins('INNER JOIN profiles ON products.profile_id = profiles.id')
  92 + .where("articles.type = 'CmsLearningPlugin::Learning'")
  93 + .where("articles.profile_id = #{profile.id}")
  94 + .where("products.profile_id <> #{profile.id}")
113 } 95 }
114 96
115 # inputs x knowledge 97 # inputs x knowledge
116 - scope :sniffer_plugin_knowledge_suppliers_inputs, lambda { |profile|  
117 - {  
118 - select: "DISTINCT products.*,  
119 - profiles.id as supplier_profile_id, articles.id AS knowledge_id,  
120 - 'knowledge' as view",  
121 - joins: "INNER JOIN inputs ON ( products.id = inputs.product_id )  
122 - INNER JOIN article_resources ON (article_resources.resource_id = inputs.product_category_id AND article_resources.resource_type = 'ProductCategory')  
123 - INNER JOIN articles ON (article_resources.article_id = articles.id)  
124 - INNER JOIN profiles ON ( articles.profile_id = profiles.id )",  
125 - conditions: "articles.type = 'CmsLearningPlugin::Learning'  
126 - AND articles.profile_id <> #{profile.id}  
127 - AND products.profile_id = #{profile.id}"  
128 - } 98 + scope :sniffer_plugin_knowledge_suppliers_inputs, -> profile {
  99 + select("DISTINCT products.*, profiles.id as supplier_profile_id, articles.id AS knowledge_id, 'knowledge' as view")
  100 + .joins("INNER JOIN inputs ON products.id = inputs.product_id")
  101 + .joins("INNER JOIN article_resources ON article_resources.resource_id = inputs.product_category_id AND article_resources.resource_type = 'ProductCategory'")
  102 + .joins('INNER JOIN articles ON article_resources.article_id = articles.id')
  103 + .joins('INNER JOIN profiles ON articles.profile_id = profiles.id')
  104 + .where("articles.type = 'CmsLearningPlugin::Learning'")
  105 + .where("articles.profile_id <> #{profile.id}")
  106 + .where("products.profile_id = #{profile.id}")
129 } 107 }
130 108
131 # knowledge x interests 109 # knowledge x interests
132 - scope :sniffer_plugin_knowledge_consumers_interests, lambda { |profile|  
133 - {  
134 - select: "DISTINCT articles.id AS knowledge_id,  
135 - op.opportunity_id AS product_category_id,  
136 - profiles.id as profile_id,  
137 - 'knowledge' as view",  
138 - from: "articles",  
139 - joins: "INNER JOIN article_resources ON (articles.id = article_resources.article_id)  
140 - INNER JOIN sniffer_plugin_opportunities as op ON ( article_resources.resource_id = op.opportunity_id AND op.opportunity_type = 'ProductCategory' AND article_resources.resource_type = 'ProductCategory' )  
141 - INNER JOIN profiles ON ( op.profile_id = profiles.id )",  
142 - conditions: "articles.profile_id = #{profile.id}  
143 - AND profiles.public_profile = true  
144 - AND profiles.visible = true  
145 - AND profiles.enabled = true  
146 - AND profiles.id <> #{profile.id}"  
147 - } 110 + scope :sniffer_plugin_knowledge_consumers_interests, -> profile {
  111 + from('articles')
  112 + .select("DISTINCT articles.id AS knowledge_id, op.opportunity_id AS product_category_id, profiles.id as profile_id, 'knowledge' as view")
  113 + .joins('INNER JOIN article_resources ON articles.id = article_resources.article_id')
  114 + .joins("INNER JOIN sniffer_plugin_opportunities as op ON article_resources.resource_id = op.opportunity_id AND op.opportunity_type = 'ProductCategory' AND article_resources.resource_type = 'ProductCategory'")
  115 + .joins('INNER JOIN profiles ON op.profile_id = profiles.id')
  116 + .where("articles.profile_id = #{profile.id}")
  117 + .where('profiles.public_profile = true')
  118 + .where('profiles.visible = true')
  119 + .where('profiles.enabled = true')
  120 + .where("profiles.id <> #{profile.id}")
148 } 121 }
149 122
150 # interests x knowledge 123 # interests x knowledge
151 - scope :sniffer_plugin_knowledge_suppliers_interests, lambda { |profile|  
152 - {  
153 - select: "DISTINCT articles.id AS knowledge_id,  
154 - op.opportunity_id AS product_category_id,  
155 - profiles.id as profile_id,  
156 - 'knowledge' as view",  
157 - from: "articles",  
158 - joins: "INNER JOIN article_resources ON (articles.id = article_resources.article_id)  
159 - INNER JOIN sniffer_plugin_opportunities as op ON ( article_resources.resource_id = op.opportunity_id AND op.opportunity_type = 'ProductCategory' AND article_resources.resource_type = 'ProductCategory' )  
160 - INNER JOIN profiles ON ( articles.profile_id = profiles.id )",  
161 - conditions: "articles.profile_id <> #{profile.id}  
162 - AND profiles.public_profile = true  
163 - AND profiles.visible = true  
164 - AND profiles.enabled = true  
165 - AND profiles.id = #{profile.id}"  
166 - } 124 + scope :sniffer_plugin_knowledge_suppliers_interests, -> profile {
  125 + from('articles')
  126 + .select("DISTINCT articles.id AS knowledge_id, op.opportunity_id AS product_category_id, profiles.id as profile_id, 'knowledge' as view")
  127 + .joins('INNER JOIN article_resources ON articles.id = article_resources.article_id')
  128 + .joins("INNER JOIN sniffer_plugin_opportunities as op ON article_resources.resource_id = op.opportunity_id AND op.opportunity_type = 'ProductCategory' AND article_resources.resource_type = 'ProductCategory'")
  129 + .joins('INNER JOIN profiles ON articles.profile_id = profiles.id')
  130 + .where("articles.profile_id <> #{profile.id}")
  131 + .where('profiles.public_profile = true')
  132 + .where('profiles.visible = true')
  133 + .where('profiles.enabled = true')
  134 + .where("profiles.id = #{profile.id}")
167 } 135 }
168 136
169 # searches for products as supplies for a given product category 137 # searches for products as supplies for a given product category
170 - scope :sniffer_plugin_products_from_category, lambda { |product_category|  
171 - {  
172 - conditions: { product_category_id: product_category.id },  
173 - select: "*, 'product' as view"  
174 - } 138 + scope :sniffer_plugin_products_from_category, -> product_category {
  139 + select("*, 'product' as view")
  140 + .where(product_category_id: product_category.id)
175 } 141 }
176 142
177 end 143 end
plugins/sniffer/lib/ext/product_category.rb
1 require_dependency 'product_category' 1 require_dependency 'product_category'
2 2
3 class ProductCategory 3 class ProductCategory
4 - has_many :sniffer_plugin_enterprises, :through => :products, :source => :enterprise, :uniq => true 4 +
  5 + has_many :sniffer_plugin_enterprises, -> { distinct },
  6 + through: :products, source: :enterprise
  7 +
5 end 8 end
plugins/sniffer/lib/ext/profile.rb
@@ -4,9 +4,10 @@ class Profile @@ -4,9 +4,10 @@ class Profile
4 4
5 attr_accessor :sniffer_plugin_distance 5 attr_accessor :sniffer_plugin_distance
6 6
7 - has_many :sniffer_opportunities, :class_name => 'SnifferPlugin::Opportunity', :dependent => :destroy  
8 - has_many :sniffer_interested_product_categories, :through => :sniffer_opportunities, :source => :product_category, :class_name => 'ProductCategory',  
9 - :conditions => ['sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'] 7 + has_many :sniffer_opportunities, class_name: 'SnifferPlugin::Opportunity', dependent: :destroy
  8 + has_many :sniffer_interested_product_categories, -> {
  9 + where 'sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'
  10 + }, through: :sniffer_opportunities, source: :product_category, class_name: 'ProductCategory'
10 11
11 attr_accessor :sniffer_interested_product_category_string_ids 12 attr_accessor :sniffer_interested_product_category_string_ids
12 descendants.each do |k| 13 descendants.each do |k|
@@ -31,11 +32,11 @@ class Profile @@ -31,11 +32,11 @@ class Profile
31 def sniffer_suppliers_products 32 def sniffer_suppliers_products
32 products = [] 33 products = []
33 34
34 - products += Product.sniffer_plugin_suppliers_products self if self.enterprise?  
35 - products += Product.sniffer_plugin_interests_suppliers_products self 35 + products.concat Product.sniffer_plugin_suppliers_products self if self.enterprise?
  36 + products.concat Product.sniffer_plugin_interests_suppliers_products self
36 if defined?(CmsLearningPlugin) 37 if defined?(CmsLearningPlugin)
37 - products += Product.sniffer_plugin_knowledge_suppliers_inputs self  
38 - products += Product.sniffer_plugin_knowledge_suppliers_interests self 38 + products.concat Product.sniffer_plugin_knowledge_suppliers_inputs self
  39 + products.concat Product.sniffer_plugin_knowledge_suppliers_interests self
39 end 40 end
40 41
41 products 42 products
@@ -44,11 +45,11 @@ class Profile @@ -44,11 +45,11 @@ class Profile
44 def sniffer_consumers_products 45 def sniffer_consumers_products
45 products = [] 46 products = []
46 47
47 - products += Product.sniffer_plugin_consumers_products self if self.enterprise?  
48 - products += Product.sniffer_plugin_interests_consumers_products self 48 + products.concat Product.sniffer_plugin_consumers_products self if self.enterprise?
  49 + products.concat Product.sniffer_plugin_interests_consumers_products self
49 if defined?(CmsLearningPlugin) 50 if defined?(CmsLearningPlugin)
50 - products += Product.sniffer_plugin_knowledge_consumers_inputs self  
51 - products += Product.sniffer_plugin_knowledge_consumers_interests self 51 + products.concat Product.sniffer_plugin_knowledge_consumers_inputs self
  52 + products.concat Product.sniffer_plugin_knowledge_consumers_interests self
52 end 53 end
53 54
54 products 55 products
plugins/sniffer/lib/sniffer_plugin/interests_block.rb
@@ -24,8 +24,8 @@ class SnifferPlugin::InterestsBlock &lt; Block @@ -24,8 +24,8 @@ class SnifferPlugin::InterestsBlock &lt; Block
24 interests = profile.snnifer_opportunities 24 interests = profile.snnifer_opportunities
25 interests |= profile.inputs if sniffer.profile.enterprise? 25 interests |= profile.inputs if sniffer.profile.enterprise?
26 else # Environment 26 else # Environment
27 - interests = SnifferPlugin::Opportunity.product_categories :limit => 5, :order => 'created_at DESC'  
28 - interests += Input.all :limit => 5, :order => 'created_at DESC' 27 + interests = SnifferPlugin::Opportunity.product_categories.limit(5).order('created_at DESC').all
  28 + interests += Input.limit(5).order('created_at DESC').all
29 interests.sort{ |a, b| -1 * a.created_at.to_i <=> b.created_at.to_i } 29 interests.sort{ |a, b| -1 * a.created_at.to_i <=> b.created_at.to_i }
30 end 30 end
31 31
plugins/sniffer/models/sniffer_plugin/opportunity.rb
@@ -7,15 +7,17 @@ class SnifferPlugin::Opportunity &lt; ActiveRecord::Base @@ -7,15 +7,17 @@ class SnifferPlugin::Opportunity &lt; ActiveRecord::Base
7 belongs_to :opportunity, polymorphic: true 7 belongs_to :opportunity, polymorphic: true
8 8
9 # for has_many :through 9 # for has_many :through
10 - belongs_to :product_category, class_name: 'ProductCategory', foreign_key: :opportunity_id,  
11 - conditions: ['sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'] 10 + belongs_to :product_category, -> {
  11 + where 'sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'
  12 + }, class_name: 'ProductCategory', foreign_key: :opportunity_id
  13 +
12 # getter 14 # getter
13 def product_category 15 def product_category
14 opportunity_type == 'ProductCategory' ? opportunity : nil 16 opportunity_type == 'ProductCategory' ? opportunity : nil
15 end 17 end
16 18
17 - scope :product_categories, {  
18 - conditions: ['sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'] 19 + scope :product_categories, -> {
  20 + where 'sniffer_plugin_opportunities.opportunity_type = ?', 'ProductCategory'
19 } 21 }
20 22
21 if defined? SolrPlugin 23 if defined? SolrPlugin
plugins/solr/features/step_definitions/solr_steps.rb
@@ -6,7 +6,7 @@ end @@ -6,7 +6,7 @@ end
6 Given /^the following categories as facets$/ do |table| 6 Given /^the following categories as facets$/ do |table|
7 ids = [] 7 ids = []
8 table.hashes.each do |item| 8 table.hashes.each do |item|
9 - cat = Category.find_by_name(item[:name]) 9 + cat = Category.find_by name: item[:name]
10 if cat.nil? 10 if cat.nil?
11 cat = Category.create!(:environment_id => Environment.default.id, :name => item[:name]) 11 cat = Category.create!(:environment_id => Environment.default.id, :name => item[:name])
12 end 12 end
plugins/solr/lib/ext/product.rb
@@ -68,8 +68,8 @@ class Product @@ -68,8 +68,8 @@ class Product
68 68
69 def self.solr_plugin_f_qualifier_proc(ids) 69 def self.solr_plugin_f_qualifier_proc(ids)
70 array = ids.split 70 array = ids.split
71 - qualifier = Qualifier.find_by_id array[0]  
72 - certifier = Certifier.find_by_id array[1] 71 + qualifier = Qualifier.find_by id: array[0]
  72 + certifier = Certifier.find_by id: array[1]
73 certifier ? [qualifier.name, _(' cert. ') + certifier.name] : qualifier.name 73 certifier ? [qualifier.name, _(' cert. ') + certifier.name] : qualifier.name
74 end 74 end
75 75
plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/functional/acts_as_solr_test.rb
@@ -4,7 +4,7 @@ require &quot;#{File.dirname(File.expand_path(__FILE__))}/../test_helper&quot; @@ -4,7 +4,7 @@ require &quot;#{File.dirname(File.expand_path(__FILE__))}/../test_helper&quot;
4 class ActsAsSolrTest < Test::Unit::TestCase 4 class ActsAsSolrTest < Test::Unit::TestCase
5 5
6 fixtures :books, :movies, :electronics, :postings, :authors, :advertises 6 fixtures :books, :movies, :electronics, :postings, :authors, :advertises
7 - 7 +
8 MongoMapper.connection = Mongo::Connection.new("127.0.0.1", 27017, :slave_ok => true, :pool_size => 16, :timeout => 10) 8 MongoMapper.connection = Mongo::Connection.new("127.0.0.1", 27017, :slave_ok => true, :pool_size => 16, :timeout => 10)
9 MongoMapper.database = "#mydb_test" 9 MongoMapper.database = "#mydb_test"
10 Document.destroy_all 10 Document.destroy_all
@@ -197,7 +197,7 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase @@ -197,7 +197,7 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
197 def test_rebuild_solr_index 197 def test_rebuild_solr_index
198 assert_equal 1, Book.count_by_solr('splinter') 198 assert_equal 1, Book.count_by_solr('splinter')
199 199
200 - Book.find(:first).solr_destroy 200 + Book.first.solr_destroy
201 assert_equal 0, Book.count_by_solr('splinter') 201 assert_equal 0, Book.count_by_solr('splinter')
202 202
203 Book.rebuild_solr_index 203 Book.rebuild_solr_index
@@ -210,10 +210,10 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase @@ -210,10 +210,10 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
210 def test_solr_save_and_solr_destroy 210 def test_solr_save_and_solr_destroy
211 assert_equal 1, Book.count_by_solr('splinter') 211 assert_equal 1, Book.count_by_solr('splinter')
212 212
213 - Book.find(:first).solr_destroy 213 + Book.first.solr_destroy
214 assert_equal 0, Book.count_by_solr('splinter') 214 assert_equal 0, Book.count_by_solr('splinter')
215 215
216 - Book.find(:first).solr_save 216 + Book.first.solr_save
217 assert_equal 1, Book.count_by_solr('splinter') 217 assert_equal 1, Book.count_by_solr('splinter')
218 end 218 end
219 219
@@ -322,7 +322,7 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase @@ -322,7 +322,7 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
322 # to rebuild_solr_index 322 # to rebuild_solr_index
323 def test_using_rebuild_solr_index_with_batch 323 def test_using_rebuild_solr_index_with_batch
324 assert_equal 2, Movie.count_by_solr('office OR napoleon') 324 assert_equal 2, Movie.count_by_solr('office OR napoleon')
325 - Movie.find(:all).each(&:solr_destroy) 325 + Movie.all.each(&:solr_destroy)
326 assert_equal 0, Movie.count_by_solr('office OR napoleon') 326 assert_equal 0, Movie.count_by_solr('office OR napoleon')
327 327
328 Movie.rebuild_solr_index 100 328 Movie.rebuild_solr_index 100
@@ -454,7 +454,7 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase @@ -454,7 +454,7 @@ class ActsAsSolrTest &lt; Test::Unit::TestCase
454 expected = {"name"=>["<em>Ruby</em> for Dummies"]} 454 expected = {"name"=>["<em>Ruby</em> for Dummies"]}
455 assert_equal expected, records.highlights.values.first 455 assert_equal expected, records.highlights.values.first
456 end 456 end
457 - 457 +
458 def test_spellcheck 458 def test_spellcheck
459 assert_equal "ruby for dummies", Book.search("rubi for dumies").suggest 459 assert_equal "ruby for dummies", Book.search("rubi for dumies").suggest
460 end 460 end
plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/test_helper.rb
@@ -58,7 +58,7 @@ class Test::Unit::TestCase @@ -58,7 +58,7 @@ class Test::Unit::TestCase
58 table_names.each do |table_name| 58 table_names.each do |table_name|
59 clear_from_solr(table_name) 59 clear_from_solr(table_name)
60 klass = instance_eval table_name.to_s.capitalize.singularize 60 klass = instance_eval table_name.to_s.capitalize.singularize
61 - klass.find(:all).each{|content| content.solr_save} 61 + klass.all.each{|content| content.solr_save}
62 end 62 end
63 63
64 clear_from_solr(:novels) 64 clear_from_solr(:novels)
plugins/stoa/controllers/stoa_plugin_controller.rb
@@ -28,7 +28,7 @@ class StoaPluginController &lt; PublicController @@ -28,7 +28,7 @@ class StoaPluginController &lt; PublicController
28 28
29 def check_usp_id 29 def check_usp_id
30 begin 30 begin
31 - render :text => { :exists => StoaPlugin::UspUser.exists?(params[:usp_id]) && Person.find_by_usp_id(params[:usp_id]).nil? }.to_json 31 + render :text => { :exists => StoaPlugin::UspUser.exists?(params[:usp_id]) && Person.find_by(usp_id: params[:usp_id]).nil? }.to_json
32 rescue Exception => exception 32 rescue Exception => exception
33 render :text => { :exists => false, :error => {:message => exception.to_s, :backtrace => exception.backtrace} }.to_json 33 render :text => { :exists => false, :error => {:message => exception.to_s, :backtrace => exception.backtrace} }.to_json
34 end 34 end
@@ -36,7 +36,7 @@ class StoaPluginController &lt; PublicController @@ -36,7 +36,7 @@ class StoaPluginController &lt; PublicController
36 36
37 def check_cpf 37 def check_cpf
38 begin 38 begin
39 - render :text => { :exists => StoaPlugin::UspUser.find_by_codpes(params[:usp_id]).cpf.present? }.to_json 39 + render :text => { :exists => StoaPlugin::UspUser.find_by(codpes: params[:usp_id]).cpf.present? }.to_json
40 rescue Exception => exception 40 rescue Exception => exception
41 render :text => { :exists => false, :error => {:message => exception.to_s, :backtrace => exception.backtrace} }.to_json 41 render :text => { :exists => false, :error => {:message => exception.to_s, :backtrace => exception.backtrace} }.to_json
42 end 42 end
plugins/stoa/lib/ext/profile_suggestion.rb
@@ -14,8 +14,8 @@ class ProfileSuggestion @@ -14,8 +14,8 @@ class ProfileSuggestion
14 StoaPlugin::UspAlunoTurmaGrad.classrooms_from_person(usp_id).each do |classroom| 14 StoaPlugin::UspAlunoTurmaGrad.classrooms_from_person(usp_id).each do |classroom|
15 person_attempts += 1 15 person_attempts += 1
16 return unless person.profile_suggestions.count < N_SUGGESTIONS && person_attempts < MAX_ATTEMPTS 16 return unless person.profile_suggestions.count < N_SUGGESTIONS && person_attempts < MAX_ATTEMPTS
17 - StoaPlugin::UspAlunoTurmaGrad.find_all_by_codtur(classroom.codtur).each do |same_class|  
18 - classmate = Person.find_by_usp_id(same_class.codpes) 17 + StoaPlugin::UspAlunoTurmaGrad.where(codtur: classroom.codtur).each do |same_class|
  18 + classmate = Person.find_by usp_id: same_class.codpes
19 unless classmate.nil? || classmate == person || classmate.is_a_friend?(person) || person.already_request_friendship?(classmate) 19 unless classmate.nil? || classmate == person || classmate.is_a_friend?(person) || person.already_request_friendship?(classmate)
20 suggestion = person.profile_suggestions.find_or_initialize_by_suggestion_id(classmate.id) 20 suggestion = person.profile_suggestions.find_or_initialize_by_suggestion_id(classmate.id)
21 suggestion.common_classroom = 1 21 suggestion.common_classroom = 1
plugins/stoa/lib/stoa_plugin.rb
@@ -50,7 +50,7 @@ class StoaPlugin &lt; Noosfero::Plugin @@ -50,7 +50,7 @@ class StoaPlugin &lt; Noosfero::Plugin
50 end 50 end
51 51
52 def alternative_authentication 52 def alternative_authentication
53 - person = Person.find_by_usp_id(context.params[:usp_id_login]) 53 + person = Person.find_by usp_id: context.params[:usp_id_login]
54 if person 54 if person
55 user = User.authenticate(person.user.login, context.params[:password]) 55 user = User.authenticate(person.user.login, context.params[:password])
56 else 56 else
plugins/stoa/lib/stoa_plugin/auth.rb
@@ -8,13 +8,13 @@ class StoaPlugin::Auth &lt; Sinatra::Base @@ -8,13 +8,13 @@ class StoaPlugin::Auth &lt; Sinatra::Base
8 post '/' do 8 post '/' do
9 headers['Content-Type'] = 'application/json' 9 headers['Content-Type'] = 'application/json'
10 if params[:login].blank? 10 if params[:login].blank?
11 - person = Person.find_by_usp_id(params[:usp_id]) 11 + person = Person.find_by usp_id: params[:usp_id]
12 login = person ? person.user.login : nil 12 login = person ? person.user.login : nil
13 else 13 else
14 login = params[:login] 14 login = params[:login]
15 end 15 end
16 16
17 - domain = Domain.find_by_name(request.host) 17 + domain = Domain.by_name(request.host)
18 environment = domain && domain.environment 18 environment = domain && domain.environment
19 environment ||= Environment.default 19 environment ||= Environment.default
20 20
plugins/stoa/lib/stoa_plugin/person_api.rb
@@ -28,7 +28,7 @@ class StoaPlugin::PersonApi &lt; Noosfero::FieldsDecorator @@ -28,7 +28,7 @@ class StoaPlugin::PersonApi &lt; Noosfero::FieldsDecorator
28 end 28 end
29 29
30 def tags 30 def tags
31 - articles.published.tag_counts({:order => 'count desc', :limit => 10}).inject({}) do |memo,tag| 31 + articles.published.tag_counts.order('count desc').limit(10).inject({}) do |memo,tag|
32 memo[tag.name] = tag.count 32 memo[tag.name] = tag.count
33 memo 33 memo
34 end 34 end
plugins/stoa/lib/stoa_plugin/usp_aluno_turma_grad.rb
@@ -5,11 +5,11 @@ class StoaPlugin::UspAlunoTurmaGrad &lt; ActiveRecord::Base @@ -5,11 +5,11 @@ class StoaPlugin::UspAlunoTurmaGrad &lt; ActiveRecord::Base
5 self.table_name = :alunoturma_gr 5 self.table_name = :alunoturma_gr
6 6
7 def self.exists?(usp_id) 7 def self.exists?(usp_id)
8 - StoaPlugin::UspUser.find_by_codpes(usp_id.to_i) 8 + StoaPlugin::UspUser.find_by codpes: usp_id.to_i
9 end 9 end
10 10
11 def self.classrooms_from_person(usp_id) 11 def self.classrooms_from_person(usp_id)
12 - StoaPlugin::UspAlunoTurmaGrad.find_all_by_codpes(usp_id) 12 + StoaPlugin::UspAlunoTurmaGrad.where codpes: usp_id
13 end 13 end
14 14
15 end 15 end
plugins/stoa/lib/stoa_plugin/usp_user.rb
@@ -9,12 +9,12 @@ class StoaPlugin::UspUser &lt; ActiveRecord::Base @@ -9,12 +9,12 @@ class StoaPlugin::UspUser &lt; ActiveRecord::Base
9 alias_attribute :birth_date, :dtanas 9 alias_attribute :birth_date, :dtanas
10 10
11 def self.exists?(usp_id) 11 def self.exists?(usp_id)
12 - StoaPlugin::UspUser.find_by_codpes(usp_id.to_i) 12 + StoaPlugin::UspUser.find_by codpes: usp_id.to_i
13 end 13 end
14 14
15 def self.matches?(usp_id, field, value) 15 def self.matches?(usp_id, field, value)
16 usp_id.to_s.gsub!(/[.-]/,'') 16 usp_id.to_s.gsub!(/[.-]/,'')
17 - user = StoaPlugin::UspUser.find_by_codpes(usp_id.to_i) 17 + user = StoaPlugin::UspUser.find_by codpes: usp_id.to_i
18 return false if user.nil? || field.blank? || !user.respond_to?(field) || value.blank? 18 return false if user.nil? || field.blank? || !user.respond_to?(field) || value.blank?
19 case field.to_sym 19 case field.to_sym
20 when :cpf 20 when :cpf
plugins/stoa/test/functional/stoa_plugin_controller_test.rb
@@ -157,7 +157,7 @@ class StoaPluginControllerTest &lt; ActionController::TestCase @@ -157,7 +157,7 @@ class StoaPluginControllerTest &lt; ActionController::TestCase
157 usp_id = '12345678' 157 usp_id = '12345678'
158 user = mock 158 user = mock
159 user.stubs(:cpf).returns('12345678') 159 user.stubs(:cpf).returns('12345678')
160 - StoaPlugin::UspUser.stubs(:find_by_codpes).with(usp_id).returns(user) 160 + StoaPlugin::UspUser.stubs(:find_by).with(codpes: usp_id).returns(user)
161 get :check_cpf, :usp_id => usp_id 161 get :check_cpf, :usp_id => usp_id
162 assert json_response['exists'] 162 assert json_response['exists']
163 end 163 end
@@ -166,12 +166,12 @@ class StoaPluginControllerTest &lt; ActionController::TestCase @@ -166,12 +166,12 @@ class StoaPluginControllerTest &lt; ActionController::TestCase
166 usp_id_with_cpf = '12345678' 166 usp_id_with_cpf = '12345678'
167 user_with_cpf = mock 167 user_with_cpf = mock
168 user_with_cpf.stubs(:cpf).returns('12345678') 168 user_with_cpf.stubs(:cpf).returns('12345678')
169 - StoaPlugin::UspUser.stubs(:find_by_codpes).with(usp_id_with_cpf).returns(user_with_cpf) 169 + StoaPlugin::UspUser.stubs(:find_by).with(codpes: usp_id_with_cpf).returns(user_with_cpf)
170 get :check_cpf, :usp_id => usp_id_with_cpf 170 get :check_cpf, :usp_id => usp_id_with_cpf
171 usp_id_without_cpf = '87654321' 171 usp_id_without_cpf = '87654321'
172 user_without_cpf = mock 172 user_without_cpf = mock
173 user_with_cpf.stubs(:cpf).returns(nil) 173 user_with_cpf.stubs(:cpf).returns(nil)
174 - StoaPlugin::UspUser.stubs(:find_by_codpes).with(usp_id_without_cpf).returns(user_without_cpf) 174 + StoaPlugin::UspUser.stubs(:find_by).with(codpes: usp_id_without_cpf).returns(user_without_cpf)
175 get :check_cpf, :usp_id => usp_id_without_cpf 175 get :check_cpf, :usp_id => usp_id_without_cpf
176 refute json_response['exists'] 176 refute json_response['exists']
177 end 177 end
plugins/sub_organizations/features/step_definitions/sub_organizations_block_steps.rb
1 Given /^"([^\"]*)" is a sub organization of "([^\"]*)"$/ do |child, parent| 1 Given /^"([^\"]*)" is a sub organization of "([^\"]*)"$/ do |child, parent|
2 - child = Organization.find_by_name(child) || Organization[child]  
3 - parent = Organization.find_by_name(parent) || Organization[parent] 2 + child = Organization.find_by(name: child) || Organization[child]
  3 + parent = Organization.find_by(name: parent) || Organization[parent]
4 4
5 SubOrganizationsPlugin::Relation.add_children(parent, child) 5 SubOrganizationsPlugin::Relation.add_children(parent, child)
6 end 6 end
plugins/sub_organizations/lib/sub_organizations_plugin.rb
@@ -56,7 +56,7 @@ class SubOrganizationsPlugin &lt; Noosfero::Plugin @@ -56,7 +56,7 @@ class SubOrganizationsPlugin &lt; Noosfero::Plugin
56 end 56 end
57 57
58 def self.limit(organizations) 58 def self.limit(organizations)
59 - organizations.all(:limit => DISPLAY_LIMIT, :order => 'updated_at DESC').sort_by{ rand } 59 + organizations.limit(DISPLAY_LIMIT).order('updated_at DESC').sort_by{ rand }
60 end 60 end
61 61
62 def self.extra_blocks 62 def self.extra_blocks
plugins/suppliers/db/migrate/20130902115916_add_active_to_suppliers_plugin_supplier.rb
@@ -3,8 +3,8 @@ end @@ -3,8 +3,8 @@ end
3 3
4 class AddActiveToSuppliersPluginSupplier < ActiveRecord::Migration 4 class AddActiveToSuppliersPluginSupplier < ActiveRecord::Migration
5 def self.up 5 def self.up
6 - add_column :suppliers_plugin_suppliers, :active, :boolean, :default => true  
7 - SuppliersPlugin::Supplier.update_all ['active = ?', true] 6 + add_column :suppliers_plugin_suppliers, :active, :boolean, default: true
  7 + SuppliersPlugin::Supplier.update_all active: true
8 end 8 end
9 9
10 def self.down 10 def self.down
plugins/suppliers/lib/ext/profile.rb
@@ -24,10 +24,14 @@ subclass.class_eval do @@ -24,10 +24,14 @@ subclass.class_eval do
24 has_many :from_products, through: :products 24 has_many :from_products, through: :products
25 has_many :to_products, through: :products 25 has_many :to_products, through: :products
26 26
27 - has_many :suppliers, class_name: 'SuppliersPlugin::Supplier', foreign_key: :consumer_id, dependent: :destroy,  
28 - include: [{profile: [:domains], consumer: [:domains]}], order: 'name ASC'  
29 - has_many :consumers, class_name: 'SuppliersPlugin::Consumer', foreign_key: :profile_id, dependent: :destroy,  
30 - include: [{profile: [:domains], consumer: [:domains]}], order: 'name ASC' 27 + has_many :suppliers, -> {
  28 + includes(profile: [:domains], consumer: [:domains])
  29 + .order('name ASC')
  30 + }, class_name: 'SuppliersPlugin::Supplier', foreign_key: :consumer_id, dependent: :destroy
  31 + has_many :consumers, -> {
  32 + includes(profile: [:domains], consumer: [:domains])
  33 + .order('name ASC')
  34 + }, class_name: 'SuppliersPlugin::Consumer', foreign_key: :profile_id, dependent: :destroy
31 35
32 end 36 end
33 end 37 end
plugins/suppliers/lib/suppliers_plugin/import.rb
@@ -22,7 +22,7 @@ class SuppliersPlugin::Import @@ -22,7 +22,7 @@ class SuppliersPlugin::Import
22 end 22 end
23 23
24 def self.products consumer, csv 24 def self.products consumer, csv
25 - default_product_category = consumer.environment.product_categories.find_by_name 'Produtos' 25 + default_product_category = consumer.environment.product_categories.find_by name: 'Produtos'
26 26
27 detection = CharlockHolmes::EncodingDetector.detect csv 27 detection = CharlockHolmes::EncodingDetector.detect csv
28 csv = CharlockHolmes::Converter.convert csv, detection[:encoding], 'UTF-8' 28 csv = CharlockHolmes::Converter.convert csv, detection[:encoding], 'UTF-8'
plugins/suppliers/models/suppliers_plugin/base_product.rb
@@ -7,17 +7,15 @@ class SuppliersPlugin::BaseProduct &lt; Product @@ -7,17 +7,15 @@ class SuppliersPlugin::BaseProduct &lt; Product
7 7
8 accepts_nested_attributes_for :supplier_product 8 accepts_nested_attributes_for :supplier_product
9 9
10 - default_scope include: [  
11 - # from_products is required for products.available  
12 - :from_products,  
13 - # FIXME: move use cases to a scope called 'includes_for_links'  
14 - {  
15 - suppliers: [{ profile: [:domains, {environment: :domains}] }]  
16 - },  
17 - {  
18 - profile: [:domains, {environment: :domains}]  
19 - }  
20 - ] 10 + default_scope -> {
  11 + includes(
  12 + # from_products is required for products.available
  13 + :from_products,
  14 + # FIXME: move use cases to a scope called 'includes_for_links'
  15 + {suppliers: [{ profile: [:domains, {environment: :domains}] }]},
  16 + {profile: [:domains, {environment: :domains}]}
  17 + )
  18 + }
21 19
22 # if abstract_class is true then it will trigger https://github.com/rails/rails/issues/20871 20 # if abstract_class is true then it will trigger https://github.com/rails/rails/issues/20871
23 #self.abstract_class = true 21 #self.abstract_class = true
plugins/suppliers/models/suppliers_plugin/source_product.rb
@@ -2,7 +2,7 @@ class SuppliersPlugin::SourceProduct &lt; ActiveRecord::Base @@ -2,7 +2,7 @@ class SuppliersPlugin::SourceProduct &lt; ActiveRecord::Base
2 2
3 attr_accessible :from_product, :to_product, :quantity 3 attr_accessible :from_product, :to_product, :quantity
4 4
5 - default_scope include: [:from_product, :to_product] 5 + default_scope -> { includes :from_product, :to_product }
6 6
7 belongs_to :from_product, class_name: 'Product' 7 belongs_to :from_product, class_name: 'Product'
8 belongs_to :to_product, class_name: 'Product' 8 belongs_to :to_product, class_name: 'Product'
plugins/tolerance_time/controllers/tolerance_time_plugin_myprofile_controller.rb
1 class ToleranceTimePluginMyprofileController < MyProfileController 1 class ToleranceTimePluginMyprofileController < MyProfileController
2 def index 2 def index
3 - @tolerance = ToleranceTimePlugin::Tolerance.find_by_profile_id(profile.id) || ToleranceTimePlugin::Tolerance.create!(:profile => profile) 3 + @tolerance = ToleranceTimePlugin::Tolerance.find_by(profile_id: profile.id) || ToleranceTimePlugin::Tolerance.create!(:profile => profile)
4 convert_values 4 convert_values
5 if request.post? 5 if request.post?
6 begin 6 begin
plugins/tolerance_time/lib/ext/article.rb
@@ -10,14 +10,14 @@ class Article @@ -10,14 +10,14 @@ class Article
10 if article.published 10 if article.published
11 ToleranceTimePlugin::Publication.create!(:target => article) 11 ToleranceTimePlugin::Publication.create!(:target => article)
12 else 12 else
13 - publication = ToleranceTimePlugin::Publication.find_by_target(article) 13 + publication = ToleranceTimePlugin::Publication.find_by target: article
14 publication.destroy if publication.present? 14 publication.destroy if publication.present?
15 end 15 end
16 end 16 end
17 end 17 end
18 18
19 before_destroy do |article| 19 before_destroy do |article|
20 - publication = ToleranceTimePlugin::Publication.find_by_target(article) 20 + publication = ToleranceTimePlugin::Publication.find_by target: article
21 publication.destroy if publication.present? 21 publication.destroy if publication.present?
22 end 22 end
23 end 23 end
plugins/tolerance_time/lib/ext/comment.rb
@@ -6,7 +6,7 @@ class Comment @@ -6,7 +6,7 @@ class Comment
6 end 6 end
7 7
8 before_destroy do |comment| 8 before_destroy do |comment|
9 - publication = ToleranceTimePlugin::Publication.find_by_target(comment) 9 + publication = ToleranceTimePlugin::Publication.find_by target: comment
10 publication.destroy if publication.present? 10 publication.destroy if publication.present?
11 end 11 end
12 end 12 end
plugins/tolerance_time/lib/tolerance_time_plugin.rb
@@ -12,7 +12,7 @@ class ToleranceTimePlugin &lt; Noosfero::Plugin @@ -12,7 +12,7 @@ class ToleranceTimePlugin &lt; Noosfero::Plugin
12 return false if content.kind_of?(Comment) && !content.article.kind_of?(Article) 12 return false if content.kind_of?(Comment) && !content.article.kind_of?(Article)
13 13
14 expirable = content.kind_of?(Comment) || (!content.folder? && content.published?) 14 expirable = content.kind_of?(Comment) || (!content.folder? && content.published?)
15 - publication = ToleranceTimePlugin::Publication.find_by_target(content) 15 + publication = ToleranceTimePlugin::Publication.find_by target: content
16 publication = ToleranceTimePlugin::Publication.create!(:target => content) if expirable && publication.nil? 16 publication = ToleranceTimePlugin::Publication.create!(:target => content) if expirable && publication.nil?
17 person_article = content.kind_of?(Article) && content.profile.kind_of?(Person) 17 person_article = content.kind_of?(Article) && content.profile.kind_of?(Person)
18 18
plugins/tolerance_time/lib/tolerance_time_plugin/publication.rb
@@ -13,7 +13,7 @@ class ToleranceTimePlugin::Publication &lt; ActiveRecord::Base @@ -13,7 +13,7 @@ class ToleranceTimePlugin::Publication &lt; ActiveRecord::Base
13 13
14 def expired? 14 def expired?
15 profile = (target.kind_of?(Article) ? target.profile : target.article.profile) 15 profile = (target.kind_of?(Article) ? target.profile : target.article.profile)
16 - profile_tolerance = ToleranceTimePlugin::Tolerance.find_by_profile_id(profile.id) 16 + profile_tolerance = ToleranceTimePlugin::Tolerance.find_by profile_id: profile.id
17 content_tolerance = profile_tolerance ? profile_tolerance.content_tolerance : nil 17 content_tolerance = profile_tolerance ? profile_tolerance.content_tolerance : nil
18 comment_tolerance = profile_tolerance ? profile_tolerance.comment_tolerance : nil 18 comment_tolerance = profile_tolerance ? profile_tolerance.comment_tolerance : nil
19 if target.kind_of?(Article) 19 if target.kind_of?(Article)
plugins/tolerance_time/test/unit/article_test.rb
@@ -3,11 +3,11 @@ require &#39;test_helper&#39; @@ -3,11 +3,11 @@ require &#39;test_helper&#39;
3 class ArticleTest < ActiveSupport::TestCase 3 class ArticleTest < ActiveSupport::TestCase
4 should 'create a publication after publishing the article' do 4 should 'create a publication after publishing the article' do
5 article = fast_create(Article, :published => false, :profile_id => fast_create(Profile).id) 5 article = fast_create(Article, :published => false, :profile_id => fast_create(Profile).id)
6 - assert_nil ToleranceTimePlugin::Publication.find_by_target(article) 6 + assert_nil ToleranceTimePlugin::Publication.find_by target: article
7 7
8 article.published = true 8 article.published = true
9 article.save! 9 article.save!
10 - assert_not_nil ToleranceTimePlugin::Publication.find_by_target(article) 10 + assert_not_nil ToleranceTimePlugin::Publication.find_by target: article
11 end 11 end
12 12
13 should 'destroy publication if the article is destroyed' do 13 should 'destroy publication if the article is destroyed' do
plugins/tolerance_time/test/unit/comment_test.rb
@@ -7,7 +7,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -7,7 +7,7 @@ class CommentTest &lt; ActiveSupport::TestCase
7 assert_difference 'ToleranceTimePlugin::Publication.count', 1 do 7 assert_difference 'ToleranceTimePlugin::Publication.count', 1 do
8 comment.save! 8 comment.save!
9 end 9 end
10 - assert_not_nil ToleranceTimePlugin::Publication.find_by_target(comment) 10 + assert_not_nil ToleranceTimePlugin::Publication.find_by target: comment
11 end 11 end
12 12
13 should 'destroy publication if the comment is destroyed' do 13 should 'destroy publication if the comment is destroyed' do
plugins/tolerance_time/test/unit/tolerance_time_plugin/publication_test.rb
@@ -26,7 +26,7 @@ class ToleranceTimePlugin::PublicationTest &lt; ActiveSupport::TestCase @@ -26,7 +26,7 @@ class ToleranceTimePlugin::PublicationTest &lt; ActiveSupport::TestCase
26 should 'be able to find publication by target' do 26 should 'be able to find publication by target' do
27 article = fast_create(Article) 27 article = fast_create(Article)
28 publication = ToleranceTimePlugin::Publication.create!(:target => article) 28 publication = ToleranceTimePlugin::Publication.create!(:target => article)
29 - assert_equal publication, ToleranceTimePlugin::Publication.find_by_target(article) 29 + assert_equal publication, ToleranceTimePlugin::Publication.find_by(target: article)
30 end 30 end
31 31
32 should 'avaliate if the publication is expired' do 32 should 'avaliate if the publication is expired' do
plugins/video/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 :video_gallery, :conditions => ["articles.type = 'VideoPlugin::VideoGallery'"] 5 + scope :video_gallery, -> { where "articles.type = 'VideoPlugin::VideoGallery'" }
6 6
7 #FIXME This should be done via hotspot 7 #FIXME This should be done via hotspot
8 def self.folder_types_with_video 8 def self.folder_types_with_video
@@ -16,10 +16,9 @@ class Article @@ -16,10 +16,9 @@ class Article
16 16
17 def self.owner_video_galleries(owner) 17 def self.owner_video_galleries(owner)
18 conditions = owner.kind_of?(Environment) ? [] : ["profile_id = ?", owner.id] 18 conditions = owner.kind_of?(Environment) ? [] : ["profile_id = ?", owner.id]
19 - result = Article.video_gallery.find(  
20 - :all,  
21 - :order => 'created_at desc',  
22 - :conditions => conditions) 19 + result = Article.video_gallery
  20 + .order('created_at desc')
  21 + .where(conditions)
23 end 22 end
24 23
25 end 24 end
plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
@@ -7,7 +7,7 @@ before_filter :protect_if, :only =&gt; [:edit_visibility] @@ -7,7 +7,7 @@ before_filter :protect_if, :only =&gt; [:edit_visibility]
7 7
8 def edit_visibility 8 def edit_visibility
9 unless params[:article_id].blank? 9 unless params[:article_id].blank?
10 - folder = profile.environment.articles.find_by_id(params[:article_id]) 10 + folder = profile.environment.articles.find_by id: params[:article_id]
11 @back_to = url_for(folder.parent.url) 11 @back_to = url_for(folder.parent.url)
12 unless params[:article].blank? 12 unless params[:article].blank?
13 folder.published = params[:article][:published] 13 folder.published = params[:article][:published]
@@ -29,7 +29,7 @@ def edit_visibility @@ -29,7 +29,7 @@ def edit_visibility
29 protected 29 protected
30 30
31 def protect_if 31 def protect_if
32 - article = environment.articles.find_by_id(params[:article_id]) 32 + article = environment.articles.find_by id: params[:article_id]
33 render_access_denied unless (user && !article.nil? && (user.is_member_of? article.profile) && 33 render_access_denied unless (user && !article.nil? && (user.is_member_of? article.profile) &&
34 article.parent.allow_visibility_edition && article.folder? && 34 article.parent.allow_visibility_edition && article.folder? &&
35 (article.author == user || user.has_permission?('view_private_content', profile))) 35 (article.author == user || user.has_permission?('view_private_content', profile)))
plugins/work_assignment/lib/work_assignment_plugin.rb
@@ -38,7 +38,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -38,7 +38,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
38 def content_viewer_controller_filters 38 def content_viewer_controller_filters
39 block = proc do 39 block = proc do
40 path = get_path(params[:page], params[:format]) 40 path = get_path(params[:page], params[:format])
41 - content = profile.articles.find_by_path(path) 41 + content = profile.articles.find_by path: path
42 42
43 if WorkAssignmentPlugin.is_submission?(content) && !WorkAssignmentPlugin.can_download_submission?(user, content) 43 if WorkAssignmentPlugin.is_submission?(content) && !WorkAssignmentPlugin.can_download_submission?(user, content)
44 render_access_denied 44 render_access_denied
@@ -75,7 +75,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -75,7 +75,7 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
75 75
76 def upload_files_extra_fields(article) 76 def upload_files_extra_fields(article)
77 proc do 77 proc do
78 - @article = Article.find_by_id(article) 78 + @article = Article.find_by id: article
79 if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment" 79 if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment"
80 render :partial => 'notify_text_field', :locals => { :size => '45'} 80 render :partial => 'notify_text_field', :locals => { :size => '45'}
81 end 81 end
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
@@ -73,7 +73,7 @@ module WorkAssignmentPlugin::Helper @@ -73,7 +73,7 @@ module WorkAssignmentPlugin::Helper
73 end 73 end
74 74
75 def display_privacy_button(author_folder, user) 75 def display_privacy_button(author_folder, user)
76 - folder = environment.articles.find_by_id(author_folder.id) 76 + folder = environment.articles.find_by id: author_folder.id
77 work_assignment = folder.parent 77 work_assignment = folder.parent
78 @back_to = url_for(work_assignment.url) 78 @back_to = url_for(work_assignment.url)
79 79
plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
@@ -7,7 +7,7 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder @@ -7,7 +7,7 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder
7 attr_accessible :publish_submissions 7 attr_accessible :publish_submissions
8 attr_accessible :default_email 8 attr_accessible :default_email
9 attr_accessible :allow_visibility_edition 9 attr_accessible :allow_visibility_edition
10 - 10 +
11 def self.icon_name(article = nil) 11 def self.icon_name(article = nil)
12 'work-assignment' 12 'work-assignment'
13 end 13 end
@@ -39,14 +39,14 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder @@ -39,14 +39,14 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder
39 end 39 end
40 40
41 def find_or_create_author_folder(author) 41 def find_or_create_author_folder(author)
42 - children.find_by_slug(author.name.to_slug) || Folder.create!( 42 + children.find_by(slug: author.name.to_slug) || Folder.create!(
43 { 43 {
44 :name => author.name, 44 :name => author.name,
45 :parent => self, 45 :parent => self,
46 :profile => profile, 46 :profile => profile,
47 :author => author, 47 :author => author,
48 :published => publish_submissions, 48 :published => publish_submissions,
49 - }, 49 + },
50 :without_protection => true 50 :without_protection => true
51 ) 51 )
52 end 52 end
@@ -58,5 +58,5 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder @@ -58,5 +58,5 @@ class WorkAssignmentPlugin::WorkAssignment &lt; Folder
58 def cache_key_with_person(params = {}, user = nil, language = 'en') 58 def cache_key_with_person(params = {}, user = nil, language = 'en')
59 cache_key_without_person + (user && profile.members.include?(user) ? "-#{user.identifier}" : '') 59 cache_key_without_person + (user && profile.members.include?(user) ? "-#{user.identifier}" : '')
60 end 60 end
61 - alias_method_chain :cache_key, :person 61 + alias_method_chain :cache_key, :person
62 end 62 end
plugins/work_assignment/test/functional/work_assignment_plugin_myprofile_controller_test.rb
@@ -32,7 +32,7 @@ class WorkAssignmentPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -32,7 +32,7 @@ class WorkAssignmentPluginMyprofileControllerTest &lt; ActionController::TestCase
32 }, 32 },
33 :without_protection => true 33 :without_protection => true
34 ) 34 )
35 - submission = UploadedFile.find_by_filename("test.txt") 35 + submission = UploadedFile.find_by filename: 'test.txt'
36 assert_equal false, submission.published 36 assert_equal false, submission.published
37 assert_equal false, submission.parent.published 37 assert_equal false, submission.parent.published
38 38
@@ -78,7 +78,7 @@ class WorkAssignmentPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -78,7 +78,7 @@ class WorkAssignmentPluginMyprofileControllerTest &lt; ActionController::TestCase
78 :without_protection => true 78 :without_protection => true
79 ) 79 )
80 logout 80 logout
81 - submission = UploadedFile.find_by_filename("test.txt") 81 + submission = UploadedFile.find_by filename: 'test.txt'
82 assert_equal false, submission.parent.published 82 assert_equal false, submission.parent.published
83 assert_equal false, submission.published 83 assert_equal false, submission.published
84 84
@@ -113,7 +113,7 @@ class WorkAssignmentPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -113,7 +113,7 @@ class WorkAssignmentPluginMyprofileControllerTest &lt; ActionController::TestCase
113 login_as :other_user 113 login_as :other_user
114 114
115 @organization.add_member(other_person) 115 @organization.add_member(other_person)
116 - submission = UploadedFile.find_by_filename("test.txt") 116 + submission = UploadedFile.find_by filename: 'test.txt'
117 assert_equal(submission.author, @person) 117 assert_equal(submission.author, @person)
118 118
119 post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id 119 post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id
@@ -143,7 +143,7 @@ class WorkAssignmentPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -143,7 +143,7 @@ class WorkAssignmentPluginMyprofileControllerTest &lt; ActionController::TestCase
143 }, 143 },
144 :without_protection => true 144 :without_protection => true
145 ) 145 )
146 - submission = UploadedFile.find_by_filename("test.txt") 146 + submission = UploadedFile.find_by filename: 'test.txt'
147 assert_equal false, submission.article_privacy_exceptions.include?(other_person) 147 assert_equal false, submission.article_privacy_exceptions.include?(other_person)
148 post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id, :article => { :published => false }, :q => other_person.id 148 post :edit_visibility, :profile => @organization.identifier, :article_id => parent.id, :article => { :published => false }, :q => other_person.id
149 submission.reload 149 submission.reload
@@ -166,7 +166,7 @@ class WorkAssignmentPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -166,7 +166,7 @@ class WorkAssignmentPluginMyprofileControllerTest &lt; ActionController::TestCase
166 :without_protection => true 166 :without_protection => true
167 ) 167 )
168 @organization.remove_member(@person) 168 @organization.remove_member(@person)
169 - submission = UploadedFile.find_by_filename("test.txt") 169 + submission = UploadedFile.find_by filename: 'test.txt'
170 170
171 assert_equal false, (@person.is_member_of? submission.profile) 171 assert_equal false, (@person.is_member_of? submission.profile)
172 172
plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
@@ -5,10 +5,10 @@ class WorkAssignmentTest &lt; ActiveSupport::TestCase @@ -5,10 +5,10 @@ class WorkAssignmentTest &lt; ActiveSupport::TestCase
5 profile = fast_create(Profile) 5 profile = fast_create(Profile)
6 author = fast_create(Person) 6 author = fast_create(Person)
7 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Sample Work Assignment', :profile => profile) 7 work_assignment = WorkAssignmentPlugin::WorkAssignment.create!(:name => 'Sample Work Assignment', :profile => profile)
8 - assert_nil work_assignment.children.find_by_slug(author.identifier) 8 + assert_nil work_assignment.children.find_by slug: author.identifier
9 9
10 folder = work_assignment.find_or_create_author_folder(author) 10 folder = work_assignment.find_or_create_author_folder(author)
11 - assert_not_nil work_assignment.children.find_by_slug(author.identifier) 11 + assert_not_nil work_assignment.children.find_by slug: author.identifier
12 assert_equal folder, work_assignment.find_or_create_author_folder(author) 12 assert_equal folder, work_assignment.find_or_create_author_folder(author)
13 end 13 end
14 14
plugins/work_assignment/views/work_assignment_plugin_myprofile/edit_visibility.html.erb
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 <%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %> 3 <%= labelled_form_for 'article', :html => { :multipart => true, :class => @type } do |f| %>
4 4
5 - <% @article = environment.articles.find_by_id((params[:article_id]))%> 5 + <% @article = environment.articles.find_by id: params[:article_id] %>
6 6
7 <% @tokenized_children = params[:tokenized_children]%> 7 <% @tokenized_children = params[:tokenized_children]%>
8 8
script/apply-template
@@ -65,7 +65,7 @@ when &#39;community&#39; @@ -65,7 +65,7 @@ when &#39;community&#39;
65 when 'person' 65 when 'person'
66 template = env.person_template 66 template = env.person_template
67 offset = 0 67 offset = 0
68 - while person = Person.find(:first, :order => :id, :offset => offset) 68 + while person = Person.order(:id).offset(offset).first
69 if person != template 69 if person != template
70 report_doing offset, person.identifier 70 report_doing offset, person.identifier
71 person.apply_template(template) 71 person.apply_template(template)
test/api/helpers_test.rb
@@ -45,7 +45,7 @@ class APIHelpersTest &lt; ActiveSupport::TestCase @@ -45,7 +45,7 @@ class APIHelpersTest &lt; ActiveSupport::TestCase
45 # should 'set current_user to nil after logout' do 45 # should 'set current_user to nil after logout' do
46 # user = create_user('someuser') 46 # user = create_user('someuser')
47 # user.stubs(:private_token_expired?).returns(false) 47 # user.stubs(:private_token_expired?).returns(false)
48 -# User.stubs(:find_by_private_token).returns(user) 48 +# User.stubs(:find_by(private_token).returns: user)
49 # assert_not_nil current_user 49 # assert_not_nil current_user
50 # assert false 50 # assert false
51 # logout 51 # logout
@@ -103,7 +103,8 @@ class APIHelpersTest &lt; ActiveSupport::TestCase @@ -103,7 +103,8 @@ class APIHelpersTest &lt; ActiveSupport::TestCase
103 fast_create(Article, :profile_id => user.person.id) 103 fast_create(Article, :profile_id => user.person.id)
104 104
105 user.generate_private_token! 105 user.generate_private_token!
106 - User.expects(:find_by_private_token).returns(user) 106 + self.params = {private_token: user.private_token}
  107 + User.expects(:find_by).with(private_token: user.private_token).returns(user)
107 assert_equal a, find_article(user.person.articles, a.id) 108 assert_equal a, find_article(user.person.articles, a.id)
108 end 109 end
109 110
@@ -114,7 +115,8 @@ class APIHelpersTest &lt; ActiveSupport::TestCase @@ -114,7 +115,8 @@ class APIHelpersTest &lt; ActiveSupport::TestCase
114 fast_create(Article, :profile_id => p.id) 115 fast_create(Article, :profile_id => p.id)
115 116
116 user.generate_private_token! 117 user.generate_private_token!
117 - User.expects(:find_by_private_token).returns(user) 118 + self.params = {private_token: user.private_token}
  119 + User.expects(:find_by).with(private_token: user.private_token).returns(user)
118 assert_equal 403, find_article(p.articles, a.id).last 120 assert_equal 403, find_article(p.articles, a.id).last
119 end 121 end
120 122
test/functional/account_controller_test.rb
@@ -198,7 +198,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -198,7 +198,7 @@ class AccountControllerTest &lt; ActionController::TestCase
198 post :change_password, :current_password => 'wrong', :new_password => 'blabla', :new_password_confirmation => 'blabla' 198 post :change_password, :current_password => 'wrong', :new_password => 'blabla', :new_password_confirmation => 'blabla'
199 assert_response :success 199 assert_response :success
200 assert_template 'change_password' 200 assert_template 'change_password'
201 - refute User.find_by_login('ze').authenticated?('blabla') 201 + refute User.find_by(login: 'ze').authenticated?('blabla')
202 assert_equal users(:ze), @controller.send(:current_user) 202 assert_equal users(:ze), @controller.send(:current_user)
203 end 203 end
204 204
@@ -454,7 +454,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -454,7 +454,7 @@ class AccountControllerTest &lt; ActionController::TestCase
454 454
455 ent.reload 455 ent.reload
456 456
457 - assert_nil User.find_by_login('test_user') 457 + assert_nil User.find_by(login: 'test_user')
458 assert ent.blocked? 458 assert ent.blocked?
459 assert_template 'blocked' 459 assert_template 'blocked'
460 end 460 end
@@ -637,7 +637,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -637,7 +637,7 @@ class AccountControllerTest &lt; ActionController::TestCase
637 env.enable('skip_new_user_email_confirmation') 637 env.enable('skip_new_user_email_confirmation')
638 env.save! 638 env.save!
639 new_user(:login => 'activated_user') 639 new_user(:login => 'activated_user')
640 - user = User.find_by_login('activated_user') 640 + user = User.find_by(login: 'activated_user')
641 assert user.activated? 641 assert user.activated?
642 end 642 end
643 643
@@ -702,14 +702,14 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -702,14 +702,14 @@ class AccountControllerTest &lt; ActionController::TestCase
702 end 702 end
703 Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name]) 703 Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name])
704 704
705 - e = User.find_by_login('ze').environment 705 + e = User.find_by(login: 'ze').environment
706 e.enable_plugin(Plugin1.name) 706 e.enable_plugin(Plugin1.name)
707 e.enable_plugin(Plugin2.name) 707 e.enable_plugin(Plugin2.name)
708 708
709 login_as 'ze' 709 login_as 'ze'
710 710
711 xhr :get, :user_data 711 xhr :get, :user_data
712 - assert_equal User.find_by_login('ze').data_hash(@controller.gravatar_default).merge({ 'foo' => 'bar', 'test' => 5 }), ActiveSupport::JSON.decode(@response.body) 712 + assert_equal User.find_by(login: 'ze').data_hash(@controller.gravatar_default).merge({ 'foo' => 'bar', 'test' => 5 }), ActiveSupport::JSON.decode(@response.body)
713 end 713 end
714 714
715 should 'activate user when activation code is present and correct' do 715 should 'activate user when activation code is present and correct' do
test/functional/categories_controller_test.rb
@@ -152,7 +152,7 @@ class CategoriesControllerTest &lt; ActionController::TestCase @@ -152,7 +152,7 @@ class CategoriesControllerTest &lt; ActionController::TestCase
152 should 'use parent\'s type to determine subcategory\'s type' do 152 should 'use parent\'s type to determine subcategory\'s type' do
153 parent = create(ProductCategory, :name => 'Sample category', :environment => Environment.default) 153 parent = create(ProductCategory, :name => 'Sample category', :environment => Environment.default)
154 post :new, :parent_id => parent.id, :parent_type => parent.class.name, :category => {:name => 'Subcategory'} 154 post :new, :parent_id => parent.id, :parent_type => parent.class.name, :category => {:name => 'Subcategory'}
155 - sub = ProductCategory.find_by_name('Subcategory') 155 + sub = ProductCategory.find_by(name: 'Subcategory')
156 assert_equal parent.class, sub.class 156 assert_equal parent.class, sub.class
157 end 157 end
158 158
test/functional/cms_controller_test.rb
@@ -200,7 +200,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -200,7 +200,7 @@ class CmsControllerTest &lt; ActionController::TestCase
200 200
201 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'changed by me', :body => 'content ...' } 201 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'changed by me', :body => 'content ...' }
202 202
203 - a = profile.articles.find_by_path('changed-by-me') 203 + a = profile.articles.find_by(path: 'changed-by-me')
204 assert_not_nil a 204 assert_not_nil a
205 assert_equal profile, a.last_changed_by 205 assert_equal profile, a.last_changed_by
206 end 206 end
@@ -308,14 +308,14 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -308,14 +308,14 @@ class CmsControllerTest &lt; ActionController::TestCase
308 assert_difference 'UploadedFile.count' do 308 assert_difference 'UploadedFile.count' do
309 post :new, :type => UploadedFile.name, :profile => profile.identifier, :article => { :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')} 309 post :new, :type => UploadedFile.name, :profile => profile.identifier, :article => { :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')}
310 end 310 end
311 - assert_not_nil profile.articles.find_by_path('test.txt') 311 + assert_not_nil profile.articles.find_by(path: 'test.txt')
312 assigns(:article).destroy 312 assigns(:article).destroy
313 end 313 end
314 314
315 should 'be able to update an uploaded file' do 315 should 'be able to update an uploaded file' do
316 post :new, :type => UploadedFile.name, :profile => profile.identifier, :article => { :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')} 316 post :new, :type => UploadedFile.name, :profile => profile.identifier, :article => { :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')}
317 317
318 - file = profile.articles.find_by_path('test.txt') 318 + file = profile.articles.find_by(path: 'test.txt')
319 assert_equal 'test.txt', file.name 319 assert_equal 'test.txt', file.name
320 320
321 post :edit, :profile => profile.identifier, :id => file.id, :article => { :uploaded_data => fixture_file_upload('/files/test_another.txt', 'text/plain')} 321 post :edit, :profile => profile.identifier, :id => file.id, :article => { :uploaded_data => fixture_file_upload('/files/test_another.txt', 'text/plain')}
@@ -347,8 +347,8 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -347,8 +347,8 @@ class CmsControllerTest &lt; ActionController::TestCase
347 assert_difference 'UploadedFile.count', 2 do 347 assert_difference 'UploadedFile.count', 2 do
348 post :upload_files, :profile => profile.identifier, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain'), fixture_file_upload('/files/rails.png', 'text/plain')] 348 post :upload_files, :profile => profile.identifier, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain'), fixture_file_upload('/files/rails.png', 'text/plain')]
349 end 349 end
350 - assert_not_nil profile.articles.find_by_path('test.txt')  
351 - assert_not_nil profile.articles.find_by_path('rails.png') 350 + assert_not_nil profile.articles.find_by(path: 'test.txt')
  351 + assert_not_nil profile.articles.find_by(path: 'rails.png')
352 end 352 end
353 353
354 should 'upload to rigth folder' do 354 should 'upload to rigth folder' do
@@ -364,7 +364,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -364,7 +364,7 @@ class CmsControllerTest &lt; ActionController::TestCase
364 f = Folder.new(:name => 'f'); profile.articles << f; f.save! 364 f = Folder.new(:name => 'f'); profile.articles << f; f.save!
365 post :upload_files, :profile => profile.identifier, :parent_id => f.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')] 365 post :upload_files, :profile => profile.identifier, :parent_id => f.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
366 366
367 - uf = profile.articles.find_by_name('test.txt') 367 + uf = profile.articles.find_by(name: 'test.txt')
368 assert_equal profile, uf.author 368 assert_equal profile, uf.author
369 end 369 end
370 370
@@ -385,14 +385,14 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -385,14 +385,14 @@ class CmsControllerTest &lt; ActionController::TestCase
385 assert_nothing_raised do 385 assert_nothing_raised do
386 post :upload_files, :profile => profile.identifier, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain'), '' ] 386 post :upload_files, :profile => profile.identifier, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain'), '' ]
387 end 387 end
388 - assert_not_nil profile.articles.find_by_path('test.txt') 388 + assert_not_nil profile.articles.find_by(path: 'test.txt')
389 end 389 end
390 390
391 should 'not crash when parent_id is blank' do 391 should 'not crash when parent_id is blank' do
392 assert_nothing_raised do 392 assert_nothing_raised do
393 post :upload_files, :profile => profile.identifier, :parent_id => '', :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain'), '' ] 393 post :upload_files, :profile => profile.identifier, :parent_id => '', :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain'), '' ]
394 end 394 end
395 - assert_not_nil profile.articles.find_by_path('test.txt') 395 + assert_not_nil profile.articles.find_by(path: 'test.txt')
396 end 396 end
397 397
398 should 'redirect to cms after uploading files' do 398 should 'redirect to cms after uploading files' do
@@ -512,7 +512,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -512,7 +512,7 @@ class CmsControllerTest &lt; ActionController::TestCase
512 # post is in c1 and c3 512 # post is in c1 and c3
513 post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id] } 513 post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id] }
514 514
515 - saved = profile.articles.find_by_name('adding-categories-test') 515 + saved = profile.articles.find_by(name: 'adding-categories-test')
516 assert_includes saved.categories, c1 516 assert_includes saved.categories, c1
517 assert_not_includes saved.categories, c2 517 assert_not_includes saved.categories, c2
518 assert_includes saved.categories, c3 518 assert_includes saved.categories, c3
@@ -527,7 +527,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -527,7 +527,7 @@ class CmsControllerTest &lt; ActionController::TestCase
527 # post is in c1, c3 and c3 527 # post is in c1, c3 and c3
528 post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id, c3.id ] } 528 post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id, c3.id ] }
529 529
530 - saved = profile.articles.find_by_name('adding-categories-test') 530 + saved = profile.articles.find_by(name: 'adding-categories-test')
531 assert_equal [c1, c3], saved.categories.all 531 assert_equal [c1, c3], saved.categories.all
532 end 532 end
533 533
@@ -559,7 +559,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -559,7 +559,7 @@ class CmsControllerTest &lt; ActionController::TestCase
559 should 'keep informed parent_id' do 559 should 'keep informed parent_id' do
560 fast_create(:blog, :name=>"Sample blog", :profile_id=>@profile.id) 560 fast_create(:blog, :name=>"Sample blog", :profile_id=>@profile.id)
561 561
562 - profile.home_page = profile.blogs.find_by_name "Sample blog" 562 + profile.home_page = profile.blogs.find_by name: "Sample blog"
563 profile.save! 563 profile.save!
564 564
565 get :new, :profile => @profile.identifier, :parent_id => profile.home_page.id, :type => 'TextileArticle' 565 get :new, :profile => @profile.identifier, :parent_id => profile.home_page.id, :type => 'TextileArticle'
@@ -608,20 +608,20 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -608,20 +608,20 @@ class CmsControllerTest &lt; ActionController::TestCase
608 should 'redirect to article after creating top-level article' do 608 should 'redirect to article after creating top-level article' do
609 post :new, :profile => profile.identifier, :type => 'TextileArticle', :article => { :name => 'top-level-article' } 609 post :new, :profile => profile.identifier, :type => 'TextileArticle', :article => { :name => 'top-level-article' }
610 610
611 - assert_redirected_to @profile.articles.find_by_name('top-level-article').url 611 + assert_redirected_to @profile.articles.find_by(name: 'top-level-article').url
612 end 612 end
613 613
614 should 'redirect to article after creating article inside a folder' do 614 should 'redirect to article after creating article inside a folder' do
615 f = Folder.new(:name => 'f'); profile.articles << f; f.save! 615 f = Folder.new(:name => 'f'); profile.articles << f; f.save!
616 post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => f.id, :article => { :name => 'article-inside-folder' } 616 post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => f.id, :article => { :name => 'article-inside-folder' }
617 617
618 - assert_redirected_to @profile.articles.find_by_name('article-inside-folder').url 618 + assert_redirected_to @profile.articles.find_by(name: 'article-inside-folder').url
619 end 619 end
620 620
621 should 'redirect back to article after editing top-level article' do 621 should 'redirect back to article after editing top-level article' do
622 f = Folder.new(:name => 'top-level-article'); profile.articles << f; f.save! 622 f = Folder.new(:name => 'top-level-article'); profile.articles << f; f.save!
623 post :edit, :profile => profile.identifier, :id => f.id 623 post :edit, :profile => profile.identifier, :id => f.id
624 - assert_redirected_to @profile.articles.find_by_name('top-level-article').url 624 + assert_redirected_to @profile.articles.find_by(name: 'top-level-article').url
625 end 625 end
626 626
627 should 'redirect back to article after editing article inside a folder' do 627 should 'redirect back to article after editing article inside a folder' do
@@ -629,7 +629,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -629,7 +629,7 @@ class CmsControllerTest &lt; ActionController::TestCase
629 a = create(TextileArticle, :parent => f, :name => 'article-inside-folder', :profile_id => profile.id) 629 a = create(TextileArticle, :parent => f, :name => 'article-inside-folder', :profile_id => profile.id)
630 630
631 post :edit, :profile => profile.identifier, :id => a.id 631 post :edit, :profile => profile.identifier, :id => a.id
632 - assert_redirected_to @profile.articles.find_by_name('article-inside-folder').url 632 + assert_redirected_to @profile.articles.find_by(name: 'article-inside-folder').url
633 end 633 end
634 634
635 should 'point back to index when cancelling creation of top-level article' do 635 should 'point back to index when cancelling creation of top-level article' do
@@ -696,14 +696,14 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -696,14 +696,14 @@ class CmsControllerTest &lt; ActionController::TestCase
696 696
697 should 'be able to add image with alignment' do 697 should 'be able to add image with alignment' do
698 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'image-alignment', :body => "the text of the article with image <img src='#' align='right'/> right align..." } 698 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'image-alignment', :body => "the text of the article with image <img src='#' align='right'/> right align..." }
699 - saved = TinyMceArticle.find_by_name('image-alignment') 699 + saved = TinyMceArticle.find_by(name: 'image-alignment')
700 assert_match /<img.*src="#".*>/, saved.body 700 assert_match /<img.*src="#".*>/, saved.body
701 assert_match /<img.*align="right".*>/, saved.body 701 assert_match /<img.*align="right".*>/, saved.body
702 end 702 end
703 703
704 should 'be able to add image with alignment when textile' do 704 should 'be able to add image with alignment when textile' do
705 post :new, :type => 'TextileArticle', :profile => profile.identifier, :article => { :name => 'image-alignment', :body => "the text of the article with image <img src='#' align='right'/> right align..." } 705 post :new, :type => 'TextileArticle', :profile => profile.identifier, :article => { :name => 'image-alignment', :body => "the text of the article with image <img src='#' align='right'/> right align..." }
706 - saved = TextileArticle.find_by_name('image-alignment') 706 + saved = TextileArticle.find_by(name: 'image-alignment')
707 assert_match /align="right"/, saved.body 707 assert_match /align="right"/, saved.body
708 end 708 end
709 709
@@ -770,7 +770,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -770,7 +770,7 @@ class CmsControllerTest &lt; ActionController::TestCase
770 should 'go to public view after creating article coming from there' do 770 should 'go to public view after creating article coming from there' do
771 post :new, :profile => 'testinguser', :type => 'TextileArticle', :back_to => 'public_view', :article => { :name => 'new-article-from-public-view' } 771 post :new, :profile => 'testinguser', :type => 'TextileArticle', :back_to => 'public_view', :article => { :name => 'new-article-from-public-view' }
772 assert_response :redirect 772 assert_response :redirect
773 - assert_redirected_to @profile.articles.find_by_name('new-article-from-public-view').url 773 + assert_redirected_to @profile.articles.find_by(name: 'new-article-from-public-view').url
774 end 774 end
775 775
776 should 'keep the back_to hint in unsuccessfull saves' do 776 should 'keep the back_to hint in unsuccessfull saves' do
@@ -1034,14 +1034,14 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1034,14 +1034,14 @@ class CmsControllerTest &lt; ActionController::TestCase
1034 assert_difference 'Blog.count' do 1034 assert_difference 'Blog.count' do
1035 post :new, :type => Blog.name, :profile => profile.identifier, :article => { :name => 'my-blog' }, :back_to => 'control_panel' 1035 post :new, :type => Blog.name, :profile => profile.identifier, :article => { :name => 'my-blog' }, :back_to => 'control_panel'
1036 end 1036 end
1037 - assert_redirected_to @profile.articles.find_by_name('my-blog').view_url 1037 + assert_redirected_to @profile.articles.find_by(name: 'my-blog').view_url
1038 end 1038 end
1039 1039
1040 should 'back to blog after config blog' do 1040 should 'back to blog after config blog' do
1041 profile.articles << Blog.new(:name => 'my-blog', :profile => profile) 1041 profile.articles << Blog.new(:name => 'my-blog', :profile => profile)
1042 post :edit, :profile => profile.identifier, :id => profile.blog.id 1042 post :edit, :profile => profile.identifier, :id => profile.blog.id
1043 1043
1044 - assert_redirected_to @profile.articles.find_by_name('my-blog').view_url 1044 + assert_redirected_to @profile.articles.find_by(name: 'my-blog').view_url
1045 end 1045 end
1046 1046
1047 should 'back to control panel if cancel create blog' do 1047 should 'back to control panel if cancel create blog' do
@@ -1068,7 +1068,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1068,7 +1068,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1068 :article => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} 1068 :article => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}
1069 1069
1070 process_delayed_job_queue 1070 process_delayed_job_queue
1071 - file = FilePresenter.for profile.articles.find_by_name('rails.png') 1071 + file = FilePresenter.for profile.articles.find_by(name: 'rails.png')
1072 assert File.exists?(file.icon_name) 1072 assert File.exists?(file.icon_name)
1073 file.destroy 1073 file.destroy
1074 end 1074 end
@@ -1079,7 +1079,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1079,7 +1079,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1079 :article => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} 1079 :article => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}
1080 1080
1081 process_delayed_job_queue 1081 process_delayed_job_queue
1082 - file = FilePresenter.for profile.articles.find_by_name('rails.png') 1082 + file = FilePresenter.for profile.articles.find_by(name: 'rails.png')
1083 assert File.exists?(file.icon_name) 1083 assert File.exists?(file.icon_name)
1084 file.destroy 1084 file.destroy
1085 end 1085 end
@@ -1320,8 +1320,8 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1320,8 +1320,8 @@ class CmsControllerTest &lt; ActionController::TestCase
1320 1320
1321 should 'create thumbnails for images with delayed_job' do 1321 should 'create thumbnails for images with delayed_job' do
1322 post :upload_files, :profile => profile.identifier, :uploaded_files => [fixture_file_upload('/files/rails.png', 'image/png'), fixture_file_upload('/files/test.txt', 'text/plain')] 1322 post :upload_files, :profile => profile.identifier, :uploaded_files => [fixture_file_upload('/files/rails.png', 'image/png'), fixture_file_upload('/files/test.txt', 'text/plain')]
1323 - file_1 = profile.articles.find_by_path('rails.png')  
1324 - file_2 = profile.articles.find_by_path('test.txt') 1323 + file_1 = profile.articles.find_by(path: 'rails.png')
  1324 + file_2 = profile.articles.find_by(path: 'test.txt')
1325 1325
1326 process_delayed_job_queue 1326 process_delayed_job_queue
1327 1327
@@ -1413,7 +1413,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1413,7 +1413,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1413 assert_difference 'Forum.count' do 1413 assert_difference 'Forum.count' do
1414 post :new, :type => Forum.name, :profile => profile.identifier, :article => { :name => 'my-forum' }, :back_to => 'control_panel' 1414 post :new, :type => Forum.name, :profile => profile.identifier, :article => { :name => 'my-forum' }, :back_to => 'control_panel'
1415 end 1415 end
1416 - assert_redirected_to @profile.articles.find_by_name('my-forum').view_url 1416 + assert_redirected_to @profile.articles.find_by(name: 'my-forum').view_url
1417 end 1417 end
1418 1418
1419 should 'back to forum after config forum' do 1419 should 'back to forum after config forum' do
@@ -1421,7 +1421,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1421,7 +1421,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1421 post :new, :type => Forum.name, :profile => profile.identifier, :article => { :name => 'my-forum' }, :back_to => 'control_panel' 1421 post :new, :type => Forum.name, :profile => profile.identifier, :article => { :name => 'my-forum' }, :back_to => 'control_panel'
1422 end 1422 end
1423 post :edit, :type => Forum.name, :profile => profile.identifier, :article => { :name => 'my forum' }, :id => profile.forum.id 1423 post :edit, :type => Forum.name, :profile => profile.identifier, :article => { :name => 'my forum' }, :id => profile.forum.id
1424 - assert_redirected_to @profile.articles.find_by_name('my forum').view_url 1424 + assert_redirected_to @profile.articles.find_by(name: 'my forum').view_url
1425 end 1425 end
1426 1426
1427 should 'back to control panel if cancel create forum' do 1427 should 'back to control panel if cancel create forum' do
@@ -1829,7 +1829,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1829,7 +1829,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1829 1829
1830 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'Sample Article', :body => 'content ...' } 1830 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'Sample Article', :body => 'content ...' }
1831 1831
1832 - a = profile.articles.find_by_path('sample-article') 1832 + a = profile.articles.find_by(path: 'sample-article')
1833 assert_not_nil a 1833 assert_not_nil a
1834 assert_equal profile, a.author 1834 assert_equal profile, a.author
1835 end 1835 end
@@ -1913,7 +1913,7 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1913,7 +1913,7 @@ class CmsControllerTest &lt; ActionController::TestCase
1913 1913
1914 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'changed by me', :body => 'content ...' } 1914 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'changed by me', :body => 'content ...' }
1915 1915
1916 - a = profile.articles.find_by_path('changed-by-me') 1916 + a = profile.articles.find_by(path: 'changed-by-me')
1917 assert_not_nil a 1917 assert_not_nil a
1918 assert_equal profile, a.created_by 1918 assert_equal profile, a.created_by
1919 end 1919 end
@@ -1960,13 +1960,13 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1960,13 +1960,13 @@ class CmsControllerTest &lt; ActionController::TestCase
1960 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :parent_id => f.id, 1960 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :parent_id => f.id,
1961 :article => { :name => 'Main Article', :body => 'some content' } 1961 :article => { :name => 'Main Article', :body => 'some content' }
1962 1962
1963 - main_article = profile.articles.find_by_name('Main Article') 1963 + main_article = profile.articles.find_by(name: 'Main Article')
1964 assert_not_nil main_article 1964 assert_not_nil main_article
1965 1965
1966 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :parent_id => f.id, 1966 post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :parent_id => f.id,
1967 :id => main_article.id, :clone => true 1967 :id => main_article.id, :clone => true
1968 1968
1969 - cloned_main_article = profile.articles.find_by_name('Main Article') 1969 + cloned_main_article = profile.articles.find_by(name: 'Main Article')
1970 assert_not_nil cloned_main_article 1970 assert_not_nil cloned_main_article
1971 1971
1972 assert_equal main_article.parent_id, cloned_main_article.parent_id 1972 assert_equal main_article.parent_id, cloned_main_article.parent_id
test/functional/content_viewer_controller_test.rb
@@ -1444,7 +1444,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -1444,7 +1444,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
1444 community.add_member(@profile) 1444 community.add_member(@profile)
1445 community.save! 1445 community.save!
1446 1446
1447 - blog = community.articles.find_by_name("Blog") 1447 + blog = community.articles.find_by(name: "Blog")
1448 1448
1449 article = TinyMceArticle.create(:name => 'Article to be shared with images', 1449 article = TinyMceArticle.create(:name => 'Article to be shared with images',
1450 :body => 'This article should be shared with all social networks', 1450 :body => 'This article should be shared with all social networks',
@@ -1570,7 +1570,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -1570,7 +1570,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
1570 community.add_member(@profile) 1570 community.add_member(@profile)
1571 community.save! 1571 community.save!
1572 1572
1573 - blog = community.articles.find_by_name("Blog") 1573 + blog = community.articles.find_by(name: "Blog")
1574 blog.visualization_format = 'compact' 1574 blog.visualization_format = 'compact'
1575 blog.save! 1575 blog.save!
1576 1576
test/functional/environment_themes_controller_test.rb
@@ -12,7 +12,7 @@ class EnvironmentThemesControllerTest &lt; ActionController::TestCase @@ -12,7 +12,7 @@ class EnvironmentThemesControllerTest &lt; ActionController::TestCase
12 @env = Environment.default 12 @env = Environment.default
13 login = create_admin_user(@env) 13 login = create_admin_user(@env)
14 login_as(login) 14 login_as(login)
15 - @profile = User.find_by_login(login).person 15 + @profile = User.find_by(login: login).person
16 end 16 end
17 17
18 def teardown 18 def teardown
test/functional/features_controller_test.rb
@@ -162,7 +162,7 @@ class FeaturesControllerTest &lt; ActionController::TestCase @@ -162,7 +162,7 @@ class FeaturesControllerTest &lt; ActionController::TestCase
162 162
163 should 'create custom field' do 163 should 'create custom field' do
164 uses_host 'anhetegua.net' 164 uses_host 'anhetegua.net'
165 - assert_nil Environment.find(2).custom_fields.find_by_name('foo') 165 + assert_nil Environment.find(2).custom_fields.find_by(name: 'foo')
166 post :manage_custom_fields, :customized_type => 'Person', :custom_fields => { 166 post :manage_custom_fields, :customized_type => 'Person', :custom_fields => {
167 Time.now.to_i => { 167 Time.now.to_i => {
168 :name => 'foo', 168 :name => 'foo',
@@ -175,7 +175,7 @@ class FeaturesControllerTest &lt; ActionController::TestCase @@ -175,7 +175,7 @@ class FeaturesControllerTest &lt; ActionController::TestCase
175 } 175 }
176 } 176 }
177 assert_redirected_to :action => 'manage_fields' 177 assert_redirected_to :action => 'manage_fields'
178 - assert_not_nil Environment.find(2).custom_fields.find_by_name('foo') 178 + assert_not_nil Environment.find(2).custom_fields.find_by(name: 'foo')
179 end 179 end
180 180
181 should 'update custom field' do 181 should 'update custom field' do
@@ -204,7 +204,7 @@ class FeaturesControllerTest &lt; ActionController::TestCase @@ -204,7 +204,7 @@ class FeaturesControllerTest &lt; ActionController::TestCase
204 post :manage_custom_fields, :customized_type => 'Enterprise' 204 post :manage_custom_fields, :customized_type => 'Enterprise'
205 205
206 assert_redirected_to :action => 'manage_fields' 206 assert_redirected_to :action => 'manage_fields'
207 - assert_nil Environment.find(2).custom_fields.find_by_name('foo') 207 + assert_nil Environment.find(2).custom_fields.find_by(name: 'foo')
208 end 208 end
209 209
210 end 210 end
test/functional/manage_products_controller_test.rb
@@ -84,7 +84,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -84,7 +84,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
84 assert_response :success 84 assert_response :success
85 assert assigns(:product) 85 assert assigns(:product)
86 refute assigns(:product).new_record? 86 refute assigns(:product).new_record?
87 - assert_equal product, Product.find_by_name('new test product') 87 + assert_equal product, Product.find_by(name: 'new test product')
88 end 88 end
89 89
90 should "edit product description" do 90 should "edit product description" do
@@ -93,7 +93,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -93,7 +93,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
93 assert_response :success 93 assert_response :success
94 assert assigns(:product) 94 assert assigns(:product)
95 refute assigns(:product).new_record? 95 refute assigns(:product).new_record?
96 - assert_equal 'A very good product!', Product.find_by_name('test product').description 96 + assert_equal 'A very good product!', Product.find_by(name: 'test product').description
97 end 97 end
98 98
99 should "edit product image" do 99 should "edit product image" do
@@ -102,7 +102,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -102,7 +102,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
102 assert_response :success 102 assert_response :success
103 assert assigns(:product) 103 assert assigns(:product)
104 refute assigns(:product).new_record? 104 refute assigns(:product).new_record?
105 - assert_equal 'rails.png', Product.find_by_name('test product').image.filename 105 + assert_equal 'rails.png', Product.find_by(name: 'test product').image.filename
106 end 106 end
107 107
108 should "not edit to invalid parameters" do 108 should "not edit to invalid parameters" do
@@ -126,7 +126,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -126,7 +126,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
126 assert_response :redirect 126 assert_response :redirect
127 assert_redirected_to :action => 'index' 127 assert_redirected_to :action => 'index'
128 assert assigns(:product) 128 assert assigns(:product)
129 - refute Product.find_by_name('test product') 129 + refute Product.find_by(name: 'test product')
130 end 130 end
131 end 131 end
132 132
@@ -138,7 +138,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -138,7 +138,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
138 assert_response :redirect 138 assert_response :redirect
139 assert_redirected_to :controller => "manage_products", :profile => @enterprise.identifier, :action => 'show', :id => product.id 139 assert_redirected_to :controller => "manage_products", :profile => @enterprise.identifier, :action => 'show', :id => product.id
140 assert assigns(:product) 140 assert assigns(:product)
141 - assert Product.find_by_name('test product') 141 + assert Product.find_by(name: 'test product')
142 end 142 end
143 end 143 end
144 144
test/functional/memberships_controller_test.rb
@@ -32,7 +32,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase @@ -32,7 +32,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
32 post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '} 32 post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '}
33 assert_response :redirect 33 assert_response :redirect
34 34
35 - assert Community.find_by_identifier('my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created" 35 + assert Community.find_by(identifier: 'my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created"
36 end 36 end
37 end 37 end
38 38
@@ -42,7 +42,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase @@ -42,7 +42,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
42 CustomField.create!(:name => "zombies", :format=>"String", :default_value => "awrrr", :customized_type=>"Community", :active => true, :required => true, :signup => true, :environment => Environment.default) 42 CustomField.create!(:name => "zombies", :format=>"String", :default_value => "awrrr", :customized_type=>"Community", :active => true, :required => true, :signup => true, :environment => Environment.default)
43 post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '}, "profile_data"=>{"custom_values"=>{"zombies"=>{"value"=>"BRAINSSS"}}} 43 post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '}, "profile_data"=>{"custom_values"=>{"zombies"=>{"value"=>"BRAINSSS"}}}
44 assert_response :redirect 44 assert_response :redirect
45 - assert Community.find_by_identifier('my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created" 45 + assert Community.find_by(identifier: 'my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created"
46 end 46 end
47 end 47 end
48 end 48 end
@@ -94,7 +94,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase @@ -94,7 +94,7 @@ class MembershipsControllerTest &lt; ActionController::TestCase
94 94
95 should 'current user is added as admin after create new community' do 95 should 'current user is added as admin after create new community' do
96 post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '} 96 post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '}
97 - assert_equal Profile::Roles.admin(profile.environment.id), profile.find_roles(Community.find_by_identifier('my-shiny-new-community')).first.role 97 + assert_equal Profile::Roles.admin(profile.environment.id), profile.find_roles(Community.find_by(identifier: 'my-shiny-new-community')).first.role
98 end 98 end
99 99
100 should 'display button to create community' do 100 should 'display button to create community' do
test/functional/profile_design_controller_test.rb
@@ -30,37 +30,29 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -30,37 +30,29 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
30 ###### BOX 1 30 ###### BOX 1
31 @b1 = ArticleBlock.new 31 @b1 = ArticleBlock.new
32 @box1.blocks << @b1 32 @box1.blocks << @b1
33 - @b1.save!  
34 33
35 @b2 = Block.new 34 @b2 = Block.new
36 @box1.blocks << @b2 35 @box1.blocks << @b2
37 - @b2.save!  
38 36
39 ###### BOX 2 37 ###### BOX 2
40 @b3 = Block.new 38 @b3 = Block.new
41 @box2.blocks << @b3 39 @box2.blocks << @b3
42 - @b3.save!  
43 40
44 @b4 = MainBlock.new 41 @b4 = MainBlock.new
45 @box2.blocks << @b4 42 @box2.blocks << @b4
46 - @b4.save!  
47 43
48 @b5 = Block.new 44 @b5 = Block.new
49 @box2.blocks << @b5 45 @box2.blocks << @b5
50 - @b5.save!  
51 46
52 @b6 = Block.new 47 @b6 = Block.new
53 @box2.blocks << @b6 48 @box2.blocks << @b6
54 - @b6.save!  
55 49
56 ###### BOX 3 50 ###### BOX 3
57 @b7 = Block.new 51 @b7 = Block.new
58 @box3.blocks << @b7 52 @box3.blocks << @b7
59 - @b7.save!  
60 53
61 @b8 = Block.new 54 @b8 = Block.new
62 @box3.blocks << @b8 55 @box3.blocks << @b8
63 - @b8.save!  
64 56
65 @request.env['HTTP_REFERER'] = '/editor' 57 @request.env['HTTP_REFERER'] = '/editor'
66 58
@@ -424,7 +416,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -424,7 +416,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
424 should 'be able to save FeedReaderBlock configurations' do 416 should 'be able to save FeedReaderBlock configurations' do
425 @box1.blocks << FeedReaderBlock.new(:address => 'feed address') 417 @box1.blocks << FeedReaderBlock.new(:address => 'feed address')
426 holder.blocks(true) 418 holder.blocks(true)
427 - block = @box1.blocks.last 419 + block = @box1.blocks.find_by(type: FeedReaderBlock)
428 420
429 post :save, :profile => 'designtestuser', :id => block.id, :block => {:address => 'new feed address', :limit => '20'} 421 post :save, :profile => 'designtestuser', :id => block.id, :block => {:address => 'new feed address', :limit => '20'}
430 422
test/functional/profile_members_controller_test.rb
@@ -250,7 +250,7 @@ class ProfileMembersControllerTest &lt; ActionController::TestCase @@ -250,7 +250,7 @@ class ProfileMembersControllerTest &lt; ActionController::TestCase
250 u = create_user('member_wannabe').person 250 u = create_user('member_wannabe').person
251 post :add_member, :profile => ent.identifier, :id => u.id 251 post :add_member, :profile => ent.identifier, :id => u.id
252 252
253 - assert_equivalent Profile::Roles.all_roles(ent.environment).compact, u.role_assignments.find_all_by_resource_id(ent.id).map(&:role).compact 253 + assert_equivalent Profile::Roles.all_roles(ent.environment).compact, u.role_assignments.where(resource_id: ent.id).map(&:role).compact
254 end 254 end
255 255
256 should 'not add member to community' do 256 should 'not add member to community' do
test/functional/profile_roles_controller_test.rb
@@ -7,7 +7,7 @@ class ProfileRolesControllerTest &lt; ActionController::TestCase @@ -7,7 +7,7 @@ class ProfileRolesControllerTest &lt; ActionController::TestCase
7 @controller = ProfileRolesController.new 7 @controller = ProfileRolesController.new
8 @request = ActionController::TestRequest.new 8 @request = ActionController::TestRequest.new
9 @response = ActionController::TestResponse.new 9 @response = ActionController::TestResponse.new
10 - @role = Role.find(:first) 10 + @role = Role.first
11 end 11 end
12 12
13 should 'create a custom role' do 13 should 'create a custom role' do
@@ -55,7 +55,7 @@ class ProfileRolesControllerTest &lt; ActionController::TestCase @@ -55,7 +55,7 @@ class ProfileRolesControllerTest &lt; ActionController::TestCase
55 login_as :admin_user 55 login_as :admin_user
56 role = Role.create!({:name => 'delete_article', :key => 'profile_delete_article', :profile_id => community.id, :environment => Environment.default}, :without_protection => true) 56 role = Role.create!({:name => 'delete_article', :key => 'profile_delete_article', :profile_id => community.id, :environment => Environment.default}, :without_protection => true)
57 admin.add_role(role, community) 57 admin.add_role(role, community)
58 - moderator_role = Role.find_by_name("moderator") 58 + moderator_role = Role.find_by(name: "moderator")
59 59
60 assert_not_includes community.members_by_role(moderator_role), admin 60 assert_not_includes community.members_by_role(moderator_role), admin
61 61
@@ -87,7 +87,7 @@ class ProfileRolesControllerTest &lt; ActionController::TestCase @@ -87,7 +87,7 @@ class ProfileRolesControllerTest &lt; ActionController::TestCase
87 moderator = create_user_with_permission('profile_admin', 'edit_profile', community) 87 moderator = create_user_with_permission('profile_admin', 'edit_profile', community)
88 login_as :admin_user 88 login_as :admin_user
89 role = Role.create!({:name => 'delete_article', :key => 'profile_delete_article', :profile_id => community.id, :environment => Environment.default}, :without_protection => true) 89 role = Role.create!({:name => 'delete_article', :key => 'profile_delete_article', :profile_id => community.id, :environment => Environment.default}, :without_protection => true)
90 - moderator_role = Role.find_by_name("moderator") 90 + moderator_role = Role.find_by(name: "moderator")
91 admin.add_role(moderator_role, community) 91 admin.add_role(moderator_role, community)
92 92
93 assert_not_includes community.members_by_role(role), admin 93 assert_not_includes community.members_by_role(role), admin
test/functional/role_controller_test.rb
@@ -8,7 +8,7 @@ class RoleControllerTest &lt; ActionController::TestCase @@ -8,7 +8,7 @@ class RoleControllerTest &lt; ActionController::TestCase
8 @controller = RoleController.new 8 @controller = RoleController.new
9 @request = ActionController::TestRequest.new 9 @request = ActionController::TestRequest.new
10 @response = ActionController::TestResponse.new 10 @response = ActionController::TestResponse.new
11 - @role = Role.find(:first) 11 + @role = Role.first
12 login_as(:ze) 12 login_as(:ze)
13 end 13 end
14 14
test/functional/tasks_controller_test.rb
@@ -208,7 +208,7 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -208,7 +208,7 @@ class TasksControllerTest &lt; ActionController::TestCase
208 t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) 208 t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile)
209 209
210 post :close, :tasks => {t.id => {:decision => 'finish', :task => {:name => 'new_name'}}} 210 post :close, :tasks => {t.id => {:decision => 'finish', :task => {:name => 'new_name'}}}
211 - assert_equal article, c.articles.find_by_name('new_name').reference_article 211 + assert_equal article, c.articles.find_by(name: 'new_name').reference_article
212 end 212 end
213 213
214 should 'create published article in folder after finish approve article task' do 214 should 'create published article in folder after finish approve article task' do
@@ -221,7 +221,7 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -221,7 +221,7 @@ class TasksControllerTest &lt; ActionController::TestCase
221 t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) 221 t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile)
222 222
223 post :close, :tasks => {t.id => {:decision => 'finish', :task => {:name => 'new_name', :article_parent_id => folder.id}}} 223 post :close, :tasks => {t.id => {:decision => 'finish', :task => {:name => 'new_name', :article_parent_id => folder.id}}}
224 - assert_equal folder, c.articles.find_by_name('new_name').parent 224 + assert_equal folder, c.articles.find_by(name: 'new_name').parent
225 end 225 end
226 226
227 should 'be highlighted if asked when approving a published article' do 227 should 'be highlighted if asked when approving a published article' do
@@ -234,7 +234,7 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -234,7 +234,7 @@ class TasksControllerTest &lt; ActionController::TestCase
234 t = ApproveArticle.create!(:article => article, :target => c, :requestor => profile) 234 t = ApproveArticle.create!(:article => article, :target => c, :requestor => profile)
235 235
236 post :close, :tasks => {t.id => {:decision => 'finish', :task => {:name => 'new_name', :article_parent_id => folder.id, :highlighted => true}}} 236 post :close, :tasks => {t.id => {:decision => 'finish', :task => {:name => 'new_name', :article_parent_id => folder.id, :highlighted => true}}}
237 - assert_equal true, c.articles.find_by_name('new_name').highlighted 237 + assert_equal true, c.articles.find_by(name: 'new_name').highlighted
238 end 238 end
239 239
240 should 'create article of same class after choosing root folder on approve article task' do 240 should 'create article of same class after choosing root folder on approve article task' do
@@ -246,7 +246,7 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -246,7 +246,7 @@ class TasksControllerTest &lt; ActionController::TestCase
246 t = ApproveArticle.create!(:article => article, :target => c, :requestor => profile) 246 t = ApproveArticle.create!(:article => article, :target => c, :requestor => profile)
247 247
248 post :close, :tasks => {t.id => {:decision => 'finish', :task => {:name => 'new_name', :article_parent_id => ""}}} 248 post :close, :tasks => {t.id => {:decision => 'finish', :task => {:name => 'new_name', :article_parent_id => ""}}}
249 - assert_not_nil c.articles.find_by_name('new_name') 249 + assert_not_nil c.articles.find_by(name: 'new_name')
250 end 250 end
251 251
252 should 'handle blank names for published articles' do 252 should 'handle blank names for published articles' do
@@ -266,7 +266,7 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -266,7 +266,7 @@ class TasksControllerTest &lt; ActionController::TestCase
266 assert_difference 'article.class.count' do 266 assert_difference 'article.class.count' do
267 post :close, :tasks => {a.id => {:decision => 'finish', :task => {:name => "", :highlighted => "0", :article_parent_id => c_blog2.id.to_s}}} 267 post :close, :tasks => {a.id => {:decision => 'finish', :task => {:name => "", :highlighted => "0", :article_parent_id => c_blog2.id.to_s}}}
268 end 268 end
269 - assert p_article = article.class.find_by_reference_article_id(article.id) 269 + assert p_article = article.class.find_by(reference_article_id: article.id)
270 assert_includes c_blog2.children(true), p_article 270 assert_includes c_blog2.children(true), p_article
271 end 271 end
272 272
@@ -306,7 +306,7 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -306,7 +306,7 @@ class TasksControllerTest &lt; ActionController::TestCase
306 t = SuggestArticle.create!(:article => {:name => 'test name', :body => 'test body'}, :name => 'some name', :email => 'test@localhost.com', :target => c) 306 t = SuggestArticle.create!(:article => {:name => 'test name', :body => 'test body'}, :name => 'some name', :email => 'test@localhost.com', :target => c)
307 307
308 post :close, :tasks => {t.id => { :task => {}, :decision => "finish"}} 308 post :close, :tasks => {t.id => { :task => {}, :decision => "finish"}}
309 - assert_not_nil TinyMceArticle.find(:first) 309 + assert_not_nil TinyMceArticle.first
310 end 310 end
311 311
312 should "change the article's attributes on suggested article task approval" do 312 should "change the article's attributes on suggested article task approval" do
@@ -322,11 +322,11 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -322,11 +322,11 @@ class TasksControllerTest &lt; ActionController::TestCase
322 t.save! 322 t.save!
323 323
324 post :close, :tasks => {t.id => { :task => {:article => {:name => 'new article name', :body => 'new body', :source => 'http://www.noosfero.com', :source_name => 'new source'}, :name => 'new name'}, :decision => "finish"}} 324 post :close, :tasks => {t.id => { :task => {:article => {:name => 'new article name', :body => 'new body', :source => 'http://www.noosfero.com', :source_name => 'new source'}, :name => 'new name'}, :decision => "finish"}}
325 - assert_equal 'new article name', TinyMceArticle.find(:first).name  
326 - assert_equal 'new name', TinyMceArticle.find(:first).author_name  
327 - assert_equal 'new body', TinyMceArticle.find(:first).body  
328 - assert_equal 'http://www.noosfero.com', TinyMceArticle.find(:first).source  
329 - assert_equal 'new source', TinyMceArticle.find(:first).source_name 325 + assert_equal 'new article name', TinyMceArticle.first.name
  326 + assert_equal 'new name', TinyMceArticle.first.author_name
  327 + assert_equal 'new body', TinyMceArticle.first.body
  328 + assert_equal 'http://www.noosfero.com', TinyMceArticle.first.source
  329 + assert_equal 'new source', TinyMceArticle.first.source_name
330 end 330 end
331 331
332 should "display name from article suggestion when requestor was not setted" do 332 should "display name from article suggestion when requestor was not setted" do
test/functional/trusted_sites_controller_test.rb
@@ -8,7 +8,7 @@ class TrustedSitesControllerTest &lt; ActionController::TestCase @@ -8,7 +8,7 @@ class TrustedSitesControllerTest &lt; ActionController::TestCase
8 @controller = TrustedSitesController.new 8 @controller = TrustedSitesController.new
9 @request = ActionController::TestRequest.new 9 @request = ActionController::TestRequest.new
10 @response = ActionController::TestResponse.new 10 @response = ActionController::TestResponse.new
11 - @role = Role.find(:first) 11 + @role = Role.first
12 @environment = Environment.default 12 @environment = Environment.default
13 @environment.trusted_sites_for_iframe = ['existing.site.com'] 13 @environment.trusted_sites_for_iframe = ['existing.site.com']
14 @environment.save! 14 @environment.save!
test/integration/enterprise_registration_test.rb
@@ -44,7 +44,7 @@ class EnterpriseRegistrationTest &lt; ActionDispatch::IntegrationTest @@ -44,7 +44,7 @@ class EnterpriseRegistrationTest &lt; ActionDispatch::IntegrationTest
44 assert_template 'confirmation' 44 assert_template 'confirmation'
45 assert_tag :tag => 'a', :attributes => { :href => '/' } 45 assert_tag :tag => 'a', :attributes => { :href => '/' }
46 46
47 - code = CreateEnterprise.find(:first, :order => 'id desc').code 47 + code = CreateEnterprise.order('id DESC').first.code
48 48
49 post '/account/logout' 49 post '/account/logout'
50 50
test/integration/forgot_password_test.rb
@@ -25,7 +25,7 @@ class ForgotPasswordTest &lt; ActionDispatch::IntegrationTest @@ -25,7 +25,7 @@ class ForgotPasswordTest &lt; ActionDispatch::IntegrationTest
25 assert_template 'password_recovery_sent' 25 assert_template 'password_recovery_sent'
26 26
27 assert_equal 1, ChangePassword.count 27 assert_equal 1, ChangePassword.count
28 - code = ChangePassword.find(:first).code 28 + code = ChangePassword.first.code
29 29
30 get "/account/new_password/#{code}" 30 get "/account/new_password/#{code}"
31 assert_response :success 31 assert_response :success
@@ -58,7 +58,7 @@ class ForgotPasswordTest &lt; ActionDispatch::IntegrationTest @@ -58,7 +58,7 @@ class ForgotPasswordTest &lt; ActionDispatch::IntegrationTest
58 assert_template 'password_recovery_sent' 58 assert_template 'password_recovery_sent'
59 59
60 assert_equal 1, ChangePassword.count 60 assert_equal 1, ChangePassword.count
61 - code = ChangePassword.find(:first).code 61 + code = ChangePassword.first.code
62 62
63 get "/account/new_password/#{code}" 63 get "/account/new_password/#{code}"
64 assert_response :success 64 assert_response :success
test/integration/manage_documents_test.rb
@@ -28,7 +28,7 @@ class ManageDocumentsTest &lt; ActionDispatch::IntegrationTest @@ -28,7 +28,7 @@ class ManageDocumentsTest &lt; ActionDispatch::IntegrationTest
28 end 28 end
29 29
30 assert_response :success 30 assert_response :success
31 - a = Article.find_by_path('my-article') 31 + a = Article.find_by(path: 'my-article')
32 assert_equal "/myuser/#{a.slug}", path 32 assert_equal "/myuser/#{a.slug}", path
33 end 33 end
34 34
@@ -61,7 +61,7 @@ class ManageDocumentsTest &lt; ActionDispatch::IntegrationTest @@ -61,7 +61,7 @@ class ManageDocumentsTest &lt; ActionDispatch::IntegrationTest
61 assert_equal 'this is the body of the article', article.body 61 assert_equal 'this is the body of the article', article.body
62 62
63 assert_response :success 63 assert_response :success
64 - a = Article.find_by_path('my-article') 64 + a = Article.find_by path: 'my-article'
65 assert_equal "/myuser/#{a.slug}", path 65 assert_equal "/myuser/#{a.slug}", path
66 end 66 end
67 67
test/integration/user_registers_at_the_application_test.rb
@@ -23,7 +23,7 @@ class UserRegistersAtTheApplicationTest &lt; ActionDispatch::IntegrationTest @@ -23,7 +23,7 @@ class UserRegistersAtTheApplicationTest &lt; ActionDispatch::IntegrationTest
23 env.min_signup_delay = 0 23 env.min_signup_delay = 0
24 env.save! 24 env.save!
25 25
26 - assert User.find_by_login('ze') # just to make sure that 'ze' already exists 26 + assert User.find_by(login: 'ze') # just to make sure that 'ze' already exists
27 27
28 get '/' 28 get '/'
29 assert_can_login 29 assert_can_login
test/support/authenticated_test_helper.rb
@@ -2,7 +2,7 @@ module AuthenticatedTestHelper @@ -2,7 +2,7 @@ module AuthenticatedTestHelper
2 2
3 # Sets the current user in the session from the user fixtures. 3 # Sets the current user in the session from the user fixtures.
4 def login_as(user) 4 def login_as(user)
5 - @request.session[:user] = User.find_by_login(user.to_s).id 5 + @request.session[:user] = User.find_by(login: user.to_s).id
6 end 6 end
7 7
8 def logout 8 def logout
test/support/factories.rb
@@ -13,7 +13,7 @@ module Noosfero::Factory @@ -13,7 +13,7 @@ module Noosfero::Factory
13 else 13 else
14 fast_insert(klass, data) 14 fast_insert(klass, data)
15 end 15 end
16 - obj = klass.last(:order => "id") 16 + obj = klass.order(:id).last
17 if options[:category] 17 if options[:category]
18 categories = options[:category] 18 categories = options[:category]
19 unless categories.is_a?(Array) 19 unless categories.is_a?(Array)
@@ -65,8 +65,8 @@ module Noosfero::Factory @@ -65,8 +65,8 @@ module Noosfero::Factory
65 65
66 ###### old stuff to be rearranged 66 ###### old stuff to be rearranged
67 def create_admin_user(env) 67 def create_admin_user(env)
68 - admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env)  
69 - admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_trusted_sites', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_organizations', 'manage_environment_templates', 'manage_environment_licenses', 'edit_appearance']) 68 + admin_user = User.find_by(login: 'adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env)
  69 + admin_role = Role.find_by(name: 'admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_trusted_sites', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_organizations', 'manage_environment_templates', 'manage_environment_licenses', 'edit_appearance'])
70 create(RoleAssignment, :accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env]) 70 create(RoleAssignment, :accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env])
71 admin_user.login 71 admin_user.login
72 end 72 end
@@ -132,7 +132,7 @@ module Noosfero::Factory @@ -132,7 +132,7 @@ module Noosfero::Factory
132 values = names.map {|k| ActiveRecord::Base.send(:sanitize_sql_array, ['?', data[k]]) } 132 values = names.map {|k| ActiveRecord::Base.send(:sanitize_sql_array, ['?', data[k]]) }
133 sql = 'insert into %s(%s) values (%s)' % [klass.table_name, names.join(','), values.join(',')] 133 sql = 'insert into %s(%s) values (%s)' % [klass.table_name, names.join(','), values.join(',')]
134 klass.connection.execute(sql) 134 klass.connection.execute(sql)
135 - klass.last(:order => 'id') 135 + klass.order(:id).last
136 end 136 end
137 137
138 def fast_insert_with_timestamps(klass, data) 138 def fast_insert_with_timestamps(klass, data)
@@ -145,10 +145,10 @@ module Noosfero::Factory @@ -145,10 +145,10 @@ module Noosfero::Factory
145 end 145 end
146 146
147 def give_permission(user, permission, target) 147 def give_permission(user, permission, target)
148 - user = Person.find_by_identifier(user) if user.kind_of?(String) 148 + user = Person.find_by(identifier: user) if user.kind_of?(String)
149 target ||= user 149 target ||= user
150 i = 0 150 i = 0
151 - while Role.find_by_name('test_role' + i.to_s) 151 + while Role.find_by(name: 'test_role' + i.to_s)
152 i+=1 152 i+=1
153 end 153 end
154 154
test/test_helper.rb
@@ -181,7 +181,7 @@ class ActiveSupport::TestCase @@ -181,7 +181,7 @@ class ActiveSupport::TestCase
181 end 181 end
182 182
183 def process_delayed_job_queue 183 def process_delayed_job_queue
184 - silence_stream(STDOUT) do 184 + silence_stream STDOUT do
185 Delayed::Worker.new.work_off 185 Delayed::Worker.new.work_off
186 end 186 end
187 end 187 end
test/unit/abuse_complaint_test.rb
@@ -24,15 +24,15 @@ class AbuseComplaintTest &lt; ActiveSupport::TestCase @@ -24,15 +24,15 @@ class AbuseComplaintTest &lt; ActiveSupport::TestCase
24 assert_equal Task::Status::HIDDEN, abuse_complaint.status 24 assert_equal Task::Status::HIDDEN, abuse_complaint.status
25 25
26 reported.environment.stubs(:reports_lower_bound).returns(2) 26 reported.environment.stubs(:reports_lower_bound).returns(2)
27 - r1 = AbuseReport.new(:reason => 'some reason').tap do |a| 27 + r1 = AbuseReport.new(:reason => 'some reason').tap do |a|
28 a.reporter = p1 28 a.reporter = p1
29 a.abuse_complaint = abuse_complaint 29 a.abuse_complaint = abuse_complaint
30 end.save 30 end.save
31 - r2 = AbuseReport.new(:reason => 'some reason').tap do |a| 31 + r2 = AbuseReport.new(:reason => 'some reason').tap do |a|
32 a.reporter = p2 32 a.reporter = p2
33 a.abuse_complaint = abuse_complaint 33 a.abuse_complaint = abuse_complaint
34 end.save 34 end.save
35 - r3 = AbuseReport.new(:reason => 'some reason').tap do |a| 35 + r3 = AbuseReport.new(:reason => 'some reason').tap do |a|
36 a.reporter = p3 36 a.reporter = p3
37 a.abuse_complaint = abuse_complaint 37 a.abuse_complaint = abuse_complaint
38 end.save 38 end.save
@@ -50,10 +50,10 @@ class AbuseComplaintTest &lt; ActiveSupport::TestCase @@ -50,10 +50,10 @@ class AbuseComplaintTest &lt; ActiveSupport::TestCase
50 reported_id = reported.id 50 reported_id = reported.id
51 abuse_complaint = AbuseComplaint.create!(:reported => reported) 51 abuse_complaint = AbuseComplaint.create!(:reported => reported)
52 52
53 - assert AbuseComplaint.find_by_requestor_id(reported_id), "AbuseComplaint was not created!" 53 + assert AbuseComplaint.find_by(requestor_id: reported_id), "AbuseComplaint was not created!"
54 54
55 reported.destroy 55 reported.destroy
56 56
57 - refute AbuseComplaint.find_by_requestor_id(reported_id), "AbuseComplaint still exist!" 57 + refute AbuseComplaint.find_by(requestor_id: reported_id), "AbuseComplaint still exist!"
58 end 58 end
59 end 59 end
test/unit/action_tracker_notification_test.rb
@@ -81,8 +81,8 @@ class ActionTrackerNotificationTest &lt; ActiveSupport::TestCase @@ -81,8 +81,8 @@ class ActionTrackerNotificationTest &lt; ActiveSupport::TestCase
81 friend = fast_create(Person) 81 friend = fast_create(Person)
82 person.add_friend(friend) 82 person.add_friend(friend)
83 process_delayed_job_queue 83 process_delayed_job_queue
84 - activity = ActionTracker::Record.find_last_by_verb 'new_friendship'  
85 - notification = ActionTrackerNotification.find_by_action_tracker_id activity.id 84 + activity = ActionTracker::Record.where(verb: 'new_friendship').last
  85 + notification = ActionTrackerNotification.find_by action_tracker_id: activity.id
86 86
87 comment = create(Comment, :source => activity, :author => person) 87 comment = create(Comment, :source => activity, :author => person)
88 assert_equal activity.comments, notification.comments 88 assert_equal activity.comments, notification.comments
test/unit/acts_as_customizable_test.rb
@@ -8,7 +8,7 @@ class ActsAsCustomizableTest &lt; ActiveSupport::TestCase @@ -8,7 +8,7 @@ class ActsAsCustomizableTest &lt; ActiveSupport::TestCase
8 assert_difference 'CustomFieldValue.count' do 8 assert_difference 'CustomFieldValue.count' do
9 person.custom_values = { "Blog" => { "value" => "www.blog.org", "public" => "0"} } 9 person.custom_values = { "Blog" => { "value" => "www.blog.org", "public" => "0"} }
10 person.save! 10 person.save!
11 - assert_equal 'www.blog.org', CustomFieldValue.find(:last, :conditions => {:customized_id => person.id}).value 11 + assert_equal 'www.blog.org', CustomFieldValue.where(customized_id: person.id).last.value
12 end 12 end
13 end 13 end
14 14
test/unit/approve_article_test.rb
@@ -301,7 +301,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -301,7 +301,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
301 a = create(ApproveArticle, :article => article, :target => community, :requestor => profile) 301 a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
302 a.finish 302 a.finish
303 303
304 - approved_article = community.articles.find_by_name(article.name) 304 + approved_article = community.articles.find_by(name: article.name)
305 305
306 assert_equal approved_article, ActionTracker::Record.last.target 306 assert_equal approved_article, ActionTracker::Record.last.target
307 end 307 end
@@ -314,7 +314,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -314,7 +314,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
314 a = create(ApproveArticle, :article => article, :target => person, :requestor => person) 314 a = create(ApproveArticle, :article => article, :target => person, :requestor => person)
315 a.finish 315 a.finish
316 316
317 - approved_article = person.articles.find_by_name(article.name) 317 + approved_article = person.articles.find_by(name: article.name)
318 318
319 assert_equal approved_article, ActionTracker::Record.last.target 319 assert_equal approved_article, ActionTracker::Record.last.target
320 end 320 end
test/unit/article_categorization_test.rb
@@ -32,7 +32,7 @@ class ArticleCategorizationTest &lt; ActiveSupport::TestCase @@ -32,7 +32,7 @@ class ArticleCategorizationTest &lt; ActiveSupport::TestCase
32 ArticleCategorization.add_category_to_article(c2, a) 32 ArticleCategorization.add_category_to_article(c2, a)
33 end 33 end
34 34
35 - assert_equal 2, ArticleCategorization.find_all_by_article_id(a.id).size 35 + assert_equal 2, ArticleCategorization.where(article_id: a.id).count
36 end 36 end
37 37
38 should 'not duplicate entry for category that is parent of two others' do 38 should 'not duplicate entry for category that is parent of two others' do
test/unit/article_test.rb
@@ -597,7 +597,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -597,7 +597,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
597 a.name = 'new-name' 597 a.name = 'new-name'
598 a.save! 598 a.save!
599 599
600 - page = Article.find_by_old_path(old_path) 600 + page = Article.find_by_old_path old_path
601 601
602 assert_equal a.path, page.path 602 assert_equal a.path, page.path
603 end 603 end
@@ -610,7 +610,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -610,7 +610,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
610 a1.save! 610 a1.save!
611 a2 = p.articles.create!(:name => 'old-name') 611 a2 = p.articles.create!(:name => 'old-name')
612 612
613 - page = Article.find_by_old_path(old_path) 613 + page = Article.find_by_old_path old_path
614 614
615 assert_equal a2.path, page.path 615 assert_equal a2.path, page.path
616 end 616 end
@@ -625,7 +625,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -625,7 +625,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
625 a2.name = 'other-new-name' 625 a2.name = 'other-new-name'
626 a2.save! 626 a2.save!
627 627
628 - page = Article.find_by_old_path(old_path) 628 + page = Article.find_by_old_path old_path
629 629
630 assert_equal a2.path, page.path 630 assert_equal a2.path, page.path
631 end 631 end
@@ -639,7 +639,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -639,7 +639,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
639 639
640 p2 = create_user('another_user').person 640 p2 = create_user('another_user').person
641 641
642 - page = p2.articles.find_by_old_path(old_path) 642 + page = p2.articles.find_by_old_path old_path
643 643
644 assert_nil page 644 assert_nil page
645 end 645 end
@@ -799,7 +799,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -799,7 +799,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
799 # also ignore parent with id = 0 799 # also ignore parent with id = 0
800 assert_equal [c], a.categories_including_virtual 800 assert_equal [c], a.categories_including_virtual
801 801
802 - a = profile.articles.find_by_name 'a test article' 802 + a = profile.articles.find_by name: 'a test article'
803 assert_equal [c], a.categories 803 assert_equal [c], a.categories
804 end 804 end
805 805
@@ -917,7 +917,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -917,7 +917,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
917 a = create(ApproveArticle, :article => article, :target => community, :requestor => profile) 917 a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
918 a.finish 918 a.finish
919 919
920 - published = community.articles.find_by_name('article name') 920 + published = community.articles.find_by(name: 'article name')
921 published.name = 'title with "quotes"' 921 published.name = 'title with "quotes"'
922 published.save 922 published.save
923 assert_equal 'title with "quotes"', published.name 923 assert_equal 'title with "quotes"', published.name
@@ -988,8 +988,8 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -988,8 +988,8 @@ class ArticleTest &lt; ActiveSupport::TestCase
988 activity = article.activity 988 activity = article.activity
989 989
990 process_delayed_job_queue 990 process_delayed_job_queue
991 - assert_equal 3, ActionTrackerNotification.find_all_by_action_tracker_id(activity.id).count  
992 - assert_equivalent [p1,p2,community], ActionTrackerNotification.find_all_by_action_tracker_id(activity.id).map(&:profile) 991 + assert_equal 3, ActionTrackerNotification.where(action_tracker_id: activity.id).count
  992 + assert_equivalent [p1,p2,community], ActionTrackerNotification.where(action_tracker_id: activity.id).map(&:profile)
993 end 993 end
994 994
995 should 'destroy activity when a published article is removed' do 995 should 'destroy activity when a published article is removed' do
@@ -1090,17 +1090,17 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1090,17 +1090,17 @@ class ArticleTest &lt; ActiveSupport::TestCase
1090 assert_equal [first_activity], ActionTracker::Record.where(verb: 'create_article') 1090 assert_equal [first_activity], ActionTracker::Record.where(verb: 'create_article')
1091 1091
1092 process_delayed_job_queue 1092 process_delayed_job_queue
1093 - assert_equal 2, ActionTrackerNotification.find_all_by_action_tracker_id(first_activity.id).count 1093 + assert_equal 2, ActionTrackerNotification.where(action_tracker_id: first_activity.id).count
1094 1094
1095 member_2 = fast_create(Person) 1095 member_2 = fast_create(Person)
1096 community.add_member(member_2) 1096 community.add_member(member_2)
1097 1097
1098 article2 = create TinyMceArticle, :name => 'Tracked Article 2', :profile_id => community.id 1098 article2 = create TinyMceArticle, :name => 'Tracked Article 2', :profile_id => community.id
1099 second_activity = article2.activity 1099 second_activity = article2.activity
1100 - assert_equivalent [first_activity, second_activity], ActionTracker::Record.find_all_by_verb('create_article') 1100 + assert_equivalent [first_activity, second_activity], ActionTracker::Record.where(verb: 'create_article')
1101 1101
1102 process_delayed_job_queue 1102 process_delayed_job_queue
1103 - assert_equal 3, ActionTrackerNotification.find_all_by_action_tracker_id(second_activity.id).count 1103 + assert_equal 3, ActionTrackerNotification.where(action_tracker_id: second_activity.id).count
1104 end 1104 end
1105 1105
1106 should 'create notifications to friends when creating an article' do 1106 should 'create notifications to friends when creating an article' do
@@ -1122,16 +1122,16 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1122,16 +1122,16 @@ class ArticleTest &lt; ActiveSupport::TestCase
1122 1122
1123 User.current = profile.user 1123 User.current = profile.user
1124 article = create TinyMceArticle, :name => 'Tracked Article 1', :profile_id => profile.id 1124 article = create TinyMceArticle, :name => 'Tracked Article 1', :profile_id => profile.id
1125 - assert_equal 1, ActionTracker::Record.find_all_by_verb('create_article').count 1125 + assert_equal 1, ActionTracker::Record.where(verb: 'create_article').count
1126 process_delayed_job_queue 1126 process_delayed_job_queue
1127 - assert_equal 2, ActionTrackerNotification.find_all_by_action_tracker_id(article.activity.id).count 1127 + assert_equal 2, ActionTrackerNotification.where(action_tracker_id: article.activity.id).count
1128 1128
1129 f2 = fast_create(Person) 1129 f2 = fast_create(Person)
1130 profile.add_friend(f2) 1130 profile.add_friend(f2)
1131 article2 = create TinyMceArticle, :name => 'Tracked Article 2', :profile_id => profile.id 1131 article2 = create TinyMceArticle, :name => 'Tracked Article 2', :profile_id => profile.id
1132 - assert_equal 2, ActionTracker::Record.find_all_by_verb('create_article').count 1132 + assert_equal 2, ActionTracker::Record.where(verb: 'create_article').count
1133 process_delayed_job_queue 1133 process_delayed_job_queue
1134 - assert_equal 3, ActionTrackerNotification.find_all_by_action_tracker_id(article2.activity.id).count 1134 + assert_equal 3, ActionTrackerNotification.where(action_tracker_id: article2.activity.id).count
1135 end 1135 end
1136 1136
1137 should 'destroy activity and notifications of friends when destroying an article' do 1137 should 'destroy activity and notifications of friends when destroying an article' do
@@ -1145,7 +1145,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1145,7 +1145,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1145 activity = article.activity 1145 activity = article.activity
1146 1146
1147 process_delayed_job_queue 1147 process_delayed_job_queue
1148 - assert_equal 2, ActionTrackerNotification.find_all_by_action_tracker_id(activity.id).count 1148 + assert_equal 2, ActionTrackerNotification.where(action_tracker_id: activity.id).count
1149 1149
1150 assert_difference 'ActionTrackerNotification.count', -2 do 1150 assert_difference 'ActionTrackerNotification.count', -2 do
1151 article.destroy 1151 article.destroy
@@ -1168,7 +1168,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1168,7 +1168,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1168 activity = article.activity 1168 activity = article.activity
1169 1169
1170 process_delayed_job_queue 1170 process_delayed_job_queue
1171 - assert_equal 3, ActionTrackerNotification.find_all_by_action_tracker_id(activity.id).count 1171 + assert_equal 3, ActionTrackerNotification.where(action_tracker_id: activity.id).count
1172 1172
1173 assert_difference 'ActionTrackerNotification.count', -3 do 1173 assert_difference 'ActionTrackerNotification.count', -3 do
1174 article.destroy 1174 article.destroy
@@ -2237,9 +2237,9 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -2237,9 +2237,9 @@ class ArticleTest &lt; ActiveSupport::TestCase
2237 p = fast_create(Person) 2237 p = fast_create(Person)
2238 assert_difference "a.reload.followers_count" do 2238 assert_difference "a.reload.followers_count" do
2239 a.person_followers << p 2239 a.person_followers << p
2240 - end 2240 + end
2241 end 2241 end
2242 - 2242 +
2243 should "decrement followers count when a person unfollow an article" do 2243 should "decrement followers count when a person unfollow an article" do
2244 p = fast_create(Person) 2244 p = fast_create(Person)
2245 a = fast_create(Article, :profile_id => p) 2245 a = fast_create(Article, :profile_id => p)
test/unit/community_test.rb
@@ -39,10 +39,10 @@ class CommunityTest &lt; ActiveSupport::TestCase @@ -39,10 +39,10 @@ class CommunityTest &lt; ActiveSupport::TestCase
39 Community.any_instance.stubs(:default_set_of_articles).returns([blog]) 39 Community.any_instance.stubs(:default_set_of_articles).returns([blog])
40 community = create(Community, :environment => Environment.default, :name => 'my new community') 40 community = create(Community, :environment => Environment.default, :name => 'my new community')
41 41
42 - assert_kind_of Blog, community.articles.find_by_path(blog.path)  
43 - assert community.articles.find_by_path(blog.path).published?  
44 - assert_kind_of RssFeed, community.articles.find_by_path(blog.feed.path)  
45 - assert community.articles.find_by_path(blog.feed.path).published? 42 + assert_kind_of Blog, community.articles.find_by(path: blog.path)
  43 + assert community.articles.find_by(path: blog.path).published?
  44 + assert_kind_of RssFeed, community.articles.find_by(path: blog.feed.path)
  45 + assert community.articles.find_by(path: blog.feed.path).published?
46 end 46 end
47 47
48 should 'have contact_person' do 48 should 'have contact_person' do
test/unit/domain_test.rb
@@ -69,8 +69,8 @@ class DomainTest &lt; ActiveSupport::TestCase @@ -69,8 +69,8 @@ class DomainTest &lt; ActiveSupport::TestCase
69 def test_find_by_name 69 def test_find_by_name
70 Domain.delete_all 70 Domain.delete_all
71 fast_create(Domain, :name => 'example.net') 71 fast_create(Domain, :name => 'example.net')
72 - d1 = Domain.find_by_name('example.net')  
73 - d2 = Domain.find_by_name('www.example.net') 72 + d1 = Domain.by_name('example.net')
  73 + d2 = Domain.by_name('www.example.net')
74 refute d1.nil? 74 refute d1.nil?
75 refute d2.nil? 75 refute d2.nil?
76 assert d1 == d2 76 assert d1 == d2
@@ -87,21 +87,21 @@ class DomainTest &lt; ActiveSupport::TestCase @@ -87,21 +87,21 @@ class DomainTest &lt; ActiveSupport::TestCase
87 87
88 def test_environment 88 def test_environment
89 # domain directly linked to Environment 89 # domain directly linked to Environment
90 - domain = Domain.find_by_name('colivre.net') 90 + domain = Domain.by_name('colivre.net')
91 assert_kind_of Environment, domain.owner 91 assert_kind_of Environment, domain.owner
92 assert_kind_of Environment, domain.environment 92 assert_kind_of Environment, domain.environment
93 93
94 # domain linked to Profile 94 # domain linked to Profile
95 - domain = Domain.find_by_name('johndoe.net') 95 + domain = Domain.by_name('johndoe.net')
96 assert_kind_of Profile, domain.owner 96 assert_kind_of Profile, domain.owner
97 assert_kind_of Environment, domain.environment 97 assert_kind_of Environment, domain.environment
98 end 98 end
99 99
100 def test_profile 100 def test_profile
101 # domain linked to profile 101 # domain linked to profile
102 - assert_not_nil Domain.find_by_name('johndoe.net').profile 102 + assert_not_nil Domain.by_name('johndoe.net').profile
103 # domain linked to Environment 103 # domain linked to Environment
104 - assert_nil Domain.find_by_name('colivre.net').profile 104 + assert_nil Domain.by_name('colivre.net').profile
105 end 105 end
106 106
107 def test_hosted_domain 107 def test_hosted_domain
test/unit/email_template_test.rb
@@ -6,7 +6,7 @@ class EmailTemplateTest &lt; ActiveSupport::TestCase @@ -6,7 +6,7 @@ class EmailTemplateTest &lt; ActiveSupport::TestCase
6 EmailTemplate.create!(:template_type => :type1, :name => 'template1') 6 EmailTemplate.create!(:template_type => :type1, :name => 'template1')
7 EmailTemplate.create!(:template_type => :type2, :name => 'template2') 7 EmailTemplate.create!(:template_type => :type2, :name => 'template2')
8 EmailTemplate.create!(:template_type => :type2, :name => 'template3') 8 EmailTemplate.create!(:template_type => :type2, :name => 'template3')
9 - assert_equal ['template2', 'template3'], EmailTemplate.find_all_by_template_type(:type2).map(&:name) 9 + assert_equal ['template2', 'template3'], EmailTemplate.where(template_type: :type2).map(&:name)
10 end 10 end
11 11
12 should 'parse body using params' do 12 should 'parse body using params' do
test/unit/enterprise_test.rb
@@ -76,8 +76,8 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -76,8 +76,8 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
76 Enterprise.any_instance.expects(:default_set_of_articles).returns([blog]) 76 Enterprise.any_instance.expects(:default_set_of_articles).returns([blog])
77 enterprise = create(Enterprise, :name => 'my test enterprise', :identifier => 'myenterprise') 77 enterprise = create(Enterprise, :name => 'my test enterprise', :identifier => 'myenterprise')
78 78
79 - assert_kind_of Blog, enterprise.articles.find_by_path(blog.path)  
80 - assert_kind_of RssFeed, enterprise.articles.find_by_path(blog.feed.path) 79 + assert_kind_of Blog, enterprise.articles.find_by(path: blog.path)
  80 + assert_kind_of RssFeed, enterprise.articles.find_by(path: blog.feed.path)
81 end 81 end
82 82
83 should 'create default set of blocks' do 83 should 'create default set of blocks' do
@@ -206,13 +206,13 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -206,13 +206,13 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
206 should 'create EnterpriseActivation task when creating with enabled = false' do 206 should 'create EnterpriseActivation task when creating with enabled = false' do
207 EnterpriseActivation.delete_all 207 EnterpriseActivation.delete_all
208 ent = create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false) 208 ent = create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
209 - assert_equal [ent], EnterpriseActivation.find(:all).map(&:enterprise) 209 + assert_equal [ent], EnterpriseActivation.all.map(&:enterprise)
210 end 210 end
211 211
212 should 'create EnterpriseActivation with 7-characters codes' do 212 should 'create EnterpriseActivation with 7-characters codes' do
213 EnterpriseActivation.delete_all 213 EnterpriseActivation.delete_all
214 create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false) 214 create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false)
215 - assert_equal 7, EnterpriseActivation.find(:first).code.size 215 + assert_equal 7, EnterpriseActivation.first.code.size
216 end 216 end
217 217
218 should 'not create activation task when enabled = true' do 218 should 'not create activation task when enabled = true' do
test/unit/environment_mailing_test.rb
@@ -86,7 +86,7 @@ class EnvironmentMailingTest &lt; ActiveSupport::TestCase @@ -86,7 +86,7 @@ class EnvironmentMailingTest &lt; ActiveSupport::TestCase
86 mailing = create_mailing(environment, :person => person_1) 86 mailing = create_mailing(environment, :person => person_1)
87 process_delayed_job_queue 87 process_delayed_job_queue
88 88
89 - assert mailing.mailing_sents.find_by_person_id(person_1.id) 89 + assert mailing.mailing_sents.find_by(person_id: person_1.id)
90 end 90 end
91 91
92 should 'return false if did not sent mailing to a recipient' do 92 should 'return false if did not sent mailing to a recipient' do
@@ -95,7 +95,7 @@ class EnvironmentMailingTest &lt; ActiveSupport::TestCase @@ -95,7 +95,7 @@ class EnvironmentMailingTest &lt; ActiveSupport::TestCase
95 mailing = create_mailing(environment, :person => person_1) 95 mailing = create_mailing(environment, :person => person_1)
96 process_delayed_job_queue 96 process_delayed_job_queue
97 97
98 - refute mailing.mailing_sents.find_by_person_id(recipient.id) 98 + refute mailing.mailing_sents.find_by(person_id: recipient.id)
99 end 99 end
100 100
101 def new_mailing(environment) 101 def new_mailing(environment)
test/unit/environment_test.rb
@@ -359,16 +359,16 @@ class EnvironmentTest &lt; ActiveSupport::TestCase @@ -359,16 +359,16 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
359 end 359 end
360 360
361 should 'have admin role' do 361 should 'have admin role' do
362 - Role.expects(:find_by_key_and_environment_id).with('environment_administrator', Environment.default.id).returns(Role.new) 362 + Role.expects(:find_by).with(key: 'environment_administrator', environment_id: Environment.default.id).returns(Role.new)
363 assert_kind_of Role, Environment::Roles.admin(Environment.default.id) 363 assert_kind_of Role, Environment::Roles.admin(Environment.default.id)
364 end 364 end
365 365
366 should 'create environment and profile default roles' do 366 should 'create environment and profile default roles' do
367 env = Environment.default 367 env = Environment.default
368 - assert_equal 'Environment', env.roles.find_by_key('environment_administrator').kind  
369 - assert_equal 'Profile', env.roles.find_by_key('profile_admin').kind  
370 - assert_equal 'Profile', env.roles.find_by_key('profile_member').kind  
371 - assert_equal 'Profile', env.roles.find_by_key('profile_moderator').kind 368 + assert_equal 'Environment', env.roles.find_by(key: 'environment_administrator').kind
  369 + assert_equal 'Profile', env.roles.find_by(key: 'profile_admin').kind
  370 + assert_equal 'Profile', env.roles.find_by(key: 'profile_member').kind
  371 + assert_equal 'Profile', env.roles.find_by(key: 'profile_moderator').kind
372 end 372 end
373 373
374 should 'be able to add admins easily' do 374 should 'be able to add admins easily' do
test/unit/folder_test.rb
@@ -98,7 +98,7 @@ class FolderTest &lt; ActiveSupport::TestCase @@ -98,7 +98,7 @@ class FolderTest &lt; ActiveSupport::TestCase
98 a = create(ApproveArticle, :article => image, :target => community, :requestor => person, :article_parent => folder) 98 a = create(ApproveArticle, :article => image, :target => community, :requestor => person, :article_parent => folder)
99 a.finish 99 a.finish
100 100
101 - assert_includes folder.images(true), community.articles.find_by_name('rails.png') 101 + assert_includes folder.images(true), community.articles.find_by(name: 'rails.png')
102 end 102 end
103 103
104 should 'not let pass javascript in the name' do 104 should 'not let pass javascript in the name' do
test/unit/gallery_test.rb
@@ -107,7 +107,7 @@ class GalleryTest &lt; ActiveSupport::TestCase @@ -107,7 +107,7 @@ class GalleryTest &lt; ActiveSupport::TestCase
107 a = create(ApproveArticle, :article => i, :target => c, :requestor => p, :article_parent => gallery) 107 a = create(ApproveArticle, :article => i, :target => c, :requestor => p, :article_parent => gallery)
108 a.finish 108 a.finish
109 109
110 - assert_includes gallery.images(true), c.articles.find_by_name('rails.png') 110 + assert_includes gallery.images(true), c.articles.find_by(name: 'rails.png')
111 end 111 end
112 112
113 should 'not let pass javascript in the body' do 113 should 'not let pass javascript in the body' do
test/unit/moderate_user_registration_test.rb
@@ -17,6 +17,6 @@ class ModerateUserRegistrationTest &lt; ActiveSupport::TestCase @@ -17,6 +17,6 @@ class ModerateUserRegistrationTest &lt; ActiveSupport::TestCase
17 t.save! 17 t.save!
18 refute user.activated? 18 refute user.activated?
19 t.perform 19 t.perform
20 - assert environment.users.find_by_id(user.id).activated? 20 + assert environment.users.find_by(id: user.id).activated?
21 end 21 end
22 end 22 end
test/unit/notify_activity_to_profiles_job_test.rb
@@ -19,7 +19,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase @@ -19,7 +19,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase
19 19
20 assert_equal 1, ActionTrackerNotification.count 20 assert_equal 1, ActionTrackerNotification.count
21 [community].each do |profile| 21 [community].each do |profile|
22 - notification = ActionTrackerNotification.find_by_profile_id profile.id 22 + notification = ActionTrackerNotification.find_by profile_id: profile.id
23 assert_equal action_tracker, notification.action_tracker 23 assert_equal action_tracker, notification.action_tracker
24 end 24 end
25 end 25 end
@@ -41,7 +41,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase @@ -41,7 +41,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase
41 41
42 assert_equal 3, ActionTrackerNotification.count 42 assert_equal 3, ActionTrackerNotification.count
43 [person, p1, p2].each do |profile| 43 [person, p1, p2].each do |profile|
44 - notification = ActionTrackerNotification.find_by_profile_id profile.id 44 + notification = ActionTrackerNotification.find_by profile_id: profile.id
45 assert_equal action_tracker, notification.action_tracker 45 assert_equal action_tracker, notification.action_tracker
46 end 46 end
47 end 47 end
@@ -61,7 +61,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase @@ -61,7 +61,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase
61 61
62 assert_equal 4, ActionTrackerNotification.count 62 assert_equal 4, ActionTrackerNotification.count
63 [person, community, m1, m2].each do |profile| 63 [person, community, m1, m2].each do |profile|
64 - notification = ActionTrackerNotification.find_by_profile_id profile.id 64 + notification = ActionTrackerNotification.find_by profile_id: profile.id
65 assert_equal action_tracker, notification.action_tracker 65 assert_equal action_tracker, notification.action_tracker
66 end 66 end
67 end 67 end
@@ -83,7 +83,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase @@ -83,7 +83,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase
83 83
84 assert_equal 6, ActionTrackerNotification.count 84 assert_equal 6, ActionTrackerNotification.count
85 [person, community, p1, p2, m1, m2].each do |profile| 85 [person, community, p1, p2, m1, m2].each do |profile|
86 - notification = ActionTrackerNotification.find_by_profile_id profile.id 86 + notification = ActionTrackerNotification.find_by profile_id: profile.id
87 assert_equal action_tracker, notification.action_tracker 87 assert_equal action_tracker, notification.action_tracker
88 end 88 end
89 end 89 end
@@ -105,11 +105,11 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase @@ -105,11 +105,11 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase
105 105
106 assert_equal 1, ActionTrackerNotification.count 106 assert_equal 1, ActionTrackerNotification.count
107 [person, p1, p2, m1, m2].each do |profile| 107 [person, p1, p2, m1, m2].each do |profile|
108 - notification = ActionTrackerNotification.find_by_profile_id profile.id 108 + notification = ActionTrackerNotification.find_by profile_id: profile.id
109 assert notification.nil? 109 assert notification.nil?
110 end 110 end
111 111
112 - notification = ActionTrackerNotification.find_by_profile_id private_community.id 112 + notification = ActionTrackerNotification.find_by profile_id: private_community.id
113 assert_equal action_tracker, notification.action_tracker 113 assert_equal action_tracker, notification.action_tracker
114 end 114 end
115 115
@@ -130,7 +130,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase @@ -130,7 +130,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase
130 130
131 assert_equal 5, ActionTrackerNotification.count 131 assert_equal 5, ActionTrackerNotification.count
132 [person, p1, p2, m1, m2].each do |profile| 132 [person, p1, p2, m1, m2].each do |profile|
133 - notification = ActionTrackerNotification.find_by_profile_id profile.id 133 + notification = ActionTrackerNotification.find_by profile_id: profile.id
134 assert_equal action_tracker, notification.action_tracker 134 assert_equal action_tracker, notification.action_tracker
135 end 135 end
136 end 136 end
test/unit/organization_mailing_test.rb
@@ -112,7 +112,7 @@ class OrganizationMailingTest &lt; ActiveSupport::TestCase @@ -112,7 +112,7 @@ class OrganizationMailingTest &lt; ActiveSupport::TestCase
112 member = Person['user_one'] 112 member = Person['user_one']
113 mailing = create(OrganizationMailing, :source => community, :subject => 'Hello', :body => 'We have some news', :person => person) 113 mailing = create(OrganizationMailing, :source => community, :subject => 'Hello', :body => 'We have some news', :person => person)
114 process_delayed_job_queue 114 process_delayed_job_queue
115 - assert mailing.mailing_sents.find_by_person_id(member.id) 115 + assert mailing.mailing_sents.find_by(person_id: member.id)
116 end 116 end
117 117
118 should 'return false if did not sent mailing to a recipient' do 118 should 'return false if did not sent mailing to a recipient' do
@@ -120,7 +120,7 @@ class OrganizationMailingTest &lt; ActiveSupport::TestCase @@ -120,7 +120,7 @@ class OrganizationMailingTest &lt; ActiveSupport::TestCase
120 mailing = create(OrganizationMailing, :source => community, :subject => 'Hello', :body => 'We have some news', :person => person) 120 mailing = create(OrganizationMailing, :source => community, :subject => 'Hello', :body => 'We have some news', :person => person)
121 process_delayed_job_queue 121 process_delayed_job_queue
122 122
123 - refute mailing.mailing_sents.find_by_person_id(recipient.id) 123 + refute mailing.mailing_sents.find_by(person_id: recipient.id)
124 end 124 end
125 125
126 protected 126 protected
test/unit/person_test.rb
@@ -180,10 +180,10 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -180,10 +180,10 @@ class PersonTest &lt; ActiveSupport::TestCase
180 Person.any_instance.stubs(:default_set_of_articles).returns([blog]) 180 Person.any_instance.stubs(:default_set_of_articles).returns([blog])
181 person = create(User).person 181 person = create(User).person
182 182
183 - assert_kind_of Blog, person.articles.find_by_path(blog.path)  
184 - assert person.articles.find_by_path(blog.path).published?  
185 - assert_kind_of RssFeed, person.articles.find_by_path(blog.feed.path)  
186 - assert person.articles.find_by_path(blog.feed.path).published? 183 + assert_kind_of Blog, person.articles.find_by(path: blog.path)
  184 + assert person.articles.find_by(path: blog.path).published?
  185 + assert_kind_of RssFeed, person.articles.find_by(path: blog.feed.path)
  186 + assert person.articles.find_by(path: blog.feed.path).published?
187 end 187 end
188 188
189 should 'create a default set of blocks' do 189 should 'create a default set of blocks' do
@@ -831,9 +831,9 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -831,9 +831,9 @@ class PersonTest &lt; ActiveSupport::TestCase
831 should "destroy scrap if sender was removed" do 831 should "destroy scrap if sender was removed" do
832 person = fast_create(Person) 832 person = fast_create(Person)
833 scrap = fast_create(Scrap, :sender_id => person.id) 833 scrap = fast_create(Scrap, :sender_id => person.id)
834 - assert_not_nil Scrap.find_by_id(scrap.id) 834 + assert_not_nil Scrap.find_by(id: scrap.id)
835 person.destroy 835 person.destroy
836 - assert_nil Scrap.find_by_id(scrap.id) 836 + assert_nil Scrap.find_by(id: scrap.id)
837 end 837 end
838 838
839 should "the tracked action be notified to person friends and herself" do 839 should "the tracked action be notified to person friends and herself" do
@@ -1123,7 +1123,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1123,7 +1123,7 @@ class PersonTest &lt; ActiveSupport::TestCase
1123 organization.add_admin(person) 1123 organization.add_admin(person)
1124 1124
1125 assert person.is_last_admin_leaving?(organization, []) 1125 assert person.is_last_admin_leaving?(organization, [])
1126 - refute person.is_last_admin_leaving?(organization, [Role.find_by_key('profile_admin')]) 1126 + refute person.is_last_admin_leaving?(organization, [Role.find_by(key: 'profile_admin')])
1127 end 1127 end
1128 1128
1129 should 'return unique members of a community' do 1129 should 'return unique members of a community' do
@@ -1467,13 +1467,13 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -1467,13 +1467,13 @@ class PersonTest &lt; ActiveSupport::TestCase
1467 should 'merge memberships of plugins to original memberships' do 1467 should 'merge memberships of plugins to original memberships' do
1468 class Plugin1 < Noosfero::Plugin 1468 class Plugin1 < Noosfero::Plugin
1469 def person_memberships(person) 1469 def person_memberships(person)
1470 - Profile.memberships_of(Person.find_by_identifier('person1')) 1470 + Profile.memberships_of(Person.find_by(identifier: 'person1'))
1471 end 1471 end
1472 end 1472 end
1473 1473
1474 class Plugin2 < Noosfero::Plugin 1474 class Plugin2 < Noosfero::Plugin
1475 def person_memberships(person) 1475 def person_memberships(person)
1476 - Profile.memberships_of(Person.find_by_identifier('person2')) 1476 + Profile.memberships_of(Person.find_by(identifier: 'person2'))
1477 end 1477 end
1478 end 1478 end
1479 Noosfero::Plugin.stubs(:all).returns(['PersonTest::Plugin1', 'PersonTest::Plugin2']) 1479 Noosfero::Plugin.stubs(:all).returns(['PersonTest::Plugin1', 'PersonTest::Plugin2'])
test/unit/product_test.rb
@@ -368,7 +368,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -368,7 +368,7 @@ class ProductTest &lt; ActiveSupport::TestCase
368 refute product.price_details.empty? 368 refute product.price_details.empty?
369 369
370 product.update_price_details([{:production_cost_id => cost.id, :price => 20}, {:production_cost_id => cost2.id, :price => 30}]) 370 product.update_price_details([{:production_cost_id => cost.id, :price => 20}, {:production_cost_id => cost2.id, :price => 30}])
371 - assert_equal 20, product.price_details.find_by_production_cost_id(cost.id).price 371 + assert_equal 20, product.price_details.find_by(production_cost_id: cost.id).price
372 assert_equal 2, Product.find(product.id).price_details.size 372 assert_equal 2, Product.find(product.id).price_details.size
373 end 373 end
374 374
test/unit/profile_categorization_test.rb
@@ -9,7 +9,7 @@ class ProfileCategorizationTest &lt; ActiveSupport::TestCase @@ -9,7 +9,7 @@ class ProfileCategorizationTest &lt; ActiveSupport::TestCase
9 person.save! 9 person.save!
10 assert_includes person.categories, cat 10 assert_includes person.categories, cat
11 assert_includes cat.people, person 11 assert_includes cat.people, person
12 - assert_equal [cat.id], person.category_ids 12 + assert_equal [cat.id], person.category_ids
13 end 13 end
14 14
15 should 'create instances for the entire hierarchy' do 15 should 'create instances for the entire hierarchy' do
@@ -24,7 +24,7 @@ class ProfileCategorizationTest &lt; ActiveSupport::TestCase @@ -24,7 +24,7 @@ class ProfileCategorizationTest &lt; ActiveSupport::TestCase
24 ProfileCategorization.add_category_to_profile(c2, p) 24 ProfileCategorization.add_category_to_profile(c2, p)
25 end 25 end
26 26
27 - assert_equal 2, ProfileCategorization.find_all_by_profile_id(p.id).size 27 + assert_equal 2, ProfileCategorization.where(profile_id: p.id).count
28 end 28 end
29 29
30 should 'not duplicate entry for category that is parent of two others' do 30 should 'not duplicate entry for category that is parent of two others' do
test/unit/profile_test.rb
@@ -319,17 +319,17 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -319,17 +319,17 @@ class ProfileTest &lt; ActiveSupport::TestCase
319 end 319 end
320 320
321 should 'have administator role' do 321 should 'have administator role' do
322 - Role.expects(:find_by_key_and_environment_id).with('profile_admin', Environment.default.id).returns(Role.new) 322 + Role.expects(:find_by).with(key: 'profile_admin', environment_id: Environment.default.id).returns(Role.new)
323 assert_kind_of Role, Profile::Roles.admin(Environment.default.id) 323 assert_kind_of Role, Profile::Roles.admin(Environment.default.id)
324 end 324 end
325 325
326 should 'have member role' do 326 should 'have member role' do
327 - Role.expects(:find_by_key_and_environment_id).with('profile_member', Environment.default.id).returns(Role.new) 327 + Role.expects(:find_by).with(key: 'profile_member', environment_id: Environment.default.id).returns(Role.new)
328 assert_kind_of Role, Profile::Roles.member(Environment.default.id) 328 assert_kind_of Role, Profile::Roles.member(Environment.default.id)
329 end 329 end
330 330
331 should 'have moderator role' do 331 should 'have moderator role' do
332 - Role.expects(:find_by_key_and_environment_id).with('profile_moderator', Environment.default.id).returns(Role.new) 332 + Role.expects(:find_by).with(key: 'profile_moderator', environment_id: Environment.default.id).returns(Role.new)
333 assert_kind_of Role, Profile::Roles.moderator(Environment.default.id) 333 assert_kind_of Role, Profile::Roles.moderator(Environment.default.id)
334 end 334 end
335 335
@@ -434,14 +434,14 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -434,14 +434,14 @@ class ProfileTest &lt; ActiveSupport::TestCase
434 should 'not advertise articles created together with the profile' do 434 should 'not advertise articles created together with the profile' do
435 Profile.any_instance.stubs(:default_set_of_articles).returns([Article.new(:name => 'home'), RssFeed.new(:name => 'feed')]) 435 Profile.any_instance.stubs(:default_set_of_articles).returns([Article.new(:name => 'home'), RssFeed.new(:name => 'feed')])
436 profile = create(Profile) 436 profile = create(Profile)
437 - refute profile.articles.find_by_path('home').advertise?  
438 - refute profile.articles.find_by_path('feed').advertise? 437 + refute profile.articles.find_by(path: 'home').advertise?
  438 + refute profile.articles.find_by(path: 'feed').advertise?
439 end 439 end
440 440
441 should 'advertise article after update' do 441 should 'advertise article after update' do
442 Profile.any_instance.stubs(:default_set_of_articles).returns([Article.new(:name => 'home')]) 442 Profile.any_instance.stubs(:default_set_of_articles).returns([Article.new(:name => 'home')])
443 profile = create(Profile) 443 profile = create(Profile)
444 - article = profile.articles.find_by_path('home') 444 + article = profile.articles.find_by(path: 'home')
445 refute article.advertise? 445 refute article.advertise?
446 article.name = 'Changed name' 446 article.name = 'Changed name'
447 article.save! 447 article.save!
@@ -1033,7 +1033,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1033,7 +1033,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1033 1033
1034 p.apply_template(template) 1034 p.apply_template(template)
1035 1035
1036 - assert_not_nil p.articles.find_by_name('template article') 1036 + assert_not_nil p.articles.find_by(name: 'template article')
1037 end 1037 end
1038 1038
1039 should 'rename existing articles when applying template' do 1039 should 'rename existing articles when applying template' do
@@ -1049,8 +1049,8 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1049,8 +1049,8 @@ class ProfileTest &lt; ActiveSupport::TestCase
1049 1049
1050 p.apply_template(template) 1050 p.apply_template(template)
1051 1051
1052 - assert_not_nil p.articles.find_by_name('some article 2')  
1053 - assert_not_nil p.articles.find_by_name('some article') 1052 + assert_not_nil p.articles.find_by(name: 'some article 2')
  1053 + assert_not_nil p.articles.find_by(name: 'some article')
1054 end 1054 end
1055 1055
1056 should 'copy header when applying template' do 1056 should 'copy header when applying template' do
@@ -1326,7 +1326,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1326,7 +1326,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
1326 task2 = Task.create!(:requestor => person, :target => another) 1326 task2 = Task.create!(:requestor => person, :target => another)
1327 1327
1328 person.stubs(:is_admin?).with(other).returns(true) 1328 person.stubs(:is_admin?).with(other).returns(true)
1329 - Environment.find(:all).select{|i| i != other }.each do |env| 1329 + Environment.all.select{|i| i != other }.each do |env|
1330 person.stubs(:is_admin?).with(env).returns(false) 1330 person.stubs(:is_admin?).with(env).returns(false)
1331 end 1331 end
1332 1332
@@ -1778,9 +1778,9 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1778,9 +1778,9 @@ class ProfileTest &lt; ActiveSupport::TestCase
1778 should "destroy scrap if receiver was removed" do 1778 should "destroy scrap if receiver was removed" do
1779 person = fast_create(Person) 1779 person = fast_create(Person)
1780 scrap = fast_create(Scrap, :receiver_id => person.id) 1780 scrap = fast_create(Scrap, :receiver_id => person.id)
1781 - assert_not_nil Scrap.find_by_id(scrap.id) 1781 + assert_not_nil Scrap.find_by(id: scrap.id)
1782 person.destroy 1782 person.destroy
1783 - assert_nil Scrap.find_by_id(scrap.id) 1783 + assert_nil Scrap.find_by(id: scrap.id)
1784 end 1784 end
1785 1785
1786 should 'have forum' do 1786 should 'have forum' do
@@ -1928,13 +1928,13 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -1928,13 +1928,13 @@ class ProfileTest &lt; ActiveSupport::TestCase
1928 should 'merge members of plugins to original members' do 1928 should 'merge members of plugins to original members' do
1929 class Plugin1 < Noosfero::Plugin 1929 class Plugin1 < Noosfero::Plugin
1930 def organization_members(profile) 1930 def organization_members(profile)
1931 - Person.members_of(Community.find_by_identifier('community1')) 1931 + Person.members_of(Community.find_by(identifier: 'community1'))
1932 end 1932 end
1933 end 1933 end
1934 1934
1935 class Plugin2 < Noosfero::Plugin 1935 class Plugin2 < Noosfero::Plugin
1936 def organization_members(profile) 1936 def organization_members(profile)
1937 - Person.members_of(Community.find_by_identifier('community2')) 1937 + Person.members_of(Community.find_by(identifier: 'community2'))
1938 end 1938 end
1939 end 1939 end
1940 Noosfero::Plugin.stubs(:all).returns(['ProfileTest::Plugin1', 'ProfileTest::Plugin2']) 1940 Noosfero::Plugin.stubs(:all).returns(['ProfileTest::Plugin1', 'ProfileTest::Plugin2'])
@@ -2148,7 +2148,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -2148,7 +2148,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
2148 suggested_person = fast_create(Person) 2148 suggested_person = fast_create(Person)
2149 suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_person, :enabled => true) 2149 suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_person, :enabled => true)
2150 2150
2151 - assert_difference 'ProfileSuggestion.find_all_by_suggestion_id(suggested_person.id).count', -1 do 2151 + assert_difference 'ProfileSuggestion.where(suggestion_id: suggested_person.id).count', -1 do
2152 suggested_person.destroy 2152 suggested_person.destroy
2153 end 2153 end
2154 end 2154 end
test/unit/text_article_test.rb
@@ -11,7 +11,7 @@ class TextArticleTest &lt; ActiveSupport::TestCase @@ -11,7 +11,7 @@ class TextArticleTest &lt; ActiveSupport::TestCase
11 should 'found TextileArticle by TextArticle class' do 11 should 'found TextileArticle by TextArticle class' do
12 person = create_user('testuser').person 12 person = create_user('testuser').person
13 article = fast_create(TextileArticle, :name => 'textile article test', :profile_id => person.id) 13 article = fast_create(TextileArticle, :name => 'textile article test', :profile_id => person.id)
14 - assert_includes TextArticle.find(:all), article 14 + assert_includes TextArticle.all, article
15 end 15 end
16 16
17 should 'be translatable' do 17 should 'be translatable' do
test/unit/uploaded_file_test.rb
@@ -320,7 +320,7 @@ class UploadedFileTest &lt; ActiveSupport::TestCase @@ -320,7 +320,7 @@ class UploadedFileTest &lt; ActiveSupport::TestCase
320 should 'use gallery as target for action tracker' do 320 should 'use gallery as target for action tracker' do
321 gallery = fast_create(Gallery, :profile_id => profile.id) 321 gallery = fast_create(Gallery, :profile_id => profile.id)
322 image = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile) 322 image = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile)
323 - activity = ActionTracker::Record.find_last_by_verb 'upload_image' 323 + activity = ActionTracker::Record.where(verb: 'upload_image').last
324 assert_equal gallery, activity.target 324 assert_equal gallery, activity.target
325 end 325 end
326 326
@@ -329,10 +329,10 @@ class UploadedFileTest &lt; ActiveSupport::TestCase @@ -329,10 +329,10 @@ class UploadedFileTest &lt; ActiveSupport::TestCase
329 gallery = fast_create(Gallery, :profile_id => profile.id) 329 gallery = fast_create(Gallery, :profile_id => profile.id)
330 330
331 image1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile) 331 image1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile)
332 - assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count 332 + assert_equal 1, ActionTracker::Record.where(verb: 'upload_image').count
333 333
334 image2 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :parent => gallery, :profile => profile) 334 image2 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :parent => gallery, :profile => profile)
335 - assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count 335 + assert_equal 1, ActionTracker::Record.where(verb: 'upload_image').count
336 end 336 end
337 337
338 { 338 {
test/unit/user_test.rb
@@ -164,9 +164,9 @@ class UserTest &lt; ActiveSupport::TestCase @@ -164,9 +164,9 @@ class UserTest &lt; ActiveSupport::TestCase
164 164
165 def test_should_create_person_when_creating_user 165 def test_should_create_person_when_creating_user
166 count = Person.count 166 count = Person.count
167 - refute Person.find_by_identifier('lalala') 167 + refute Person.find_by(identifier: 'lalala')
168 new_user(:login => 'lalala', :email => 'lalala@example.com') 168 new_user(:login => 'lalala', :email => 'lalala@example.com')
169 - assert Person.find_by_identifier('lalala') 169 + assert Person.find_by(identifier: 'lalala')
170 end 170 end
171 171
172 should 'set the same environment for user and person objects' do 172 should 'set the same environment for user and person objects' do
@@ -178,9 +178,9 @@ class UserTest &lt; ActiveSupport::TestCase @@ -178,9 +178,9 @@ class UserTest &lt; ActiveSupport::TestCase
178 178
179 def test_should_destroy_person_when_destroying_user 179 def test_should_destroy_person_when_destroying_user
180 user = new_user(:login => 'lalala', :email => 'lalala@example.com') 180 user = new_user(:login => 'lalala', :email => 'lalala@example.com')
181 - assert Person.find_by_identifier('lalala') 181 + assert Person.find_by(identifier: 'lalala')
182 user.destroy 182 user.destroy
183 - refute Person.find_by_identifier('lalala') 183 + refute Person.find_by(identifier: 'lalala')
184 end 184 end
185 185
186 def test_should_encrypt_password_with_salted_sha1 186 def test_should_encrypt_password_with_salted_sha1
vendor/plugins/access_control/lib/acts_as_accessible.rb
@@ -32,7 +32,7 @@ module ActsAsAccessible @@ -32,7 +32,7 @@ module ActsAsAccessible
32 end 32 end
33 33
34 def roles 34 def roles
35 - Role.find_all_by_environment_id(environment.id).select do |r| 35 + Role.where(environment_id: environment.id).select do |r|
36 r.permissions.any?{ |p| PERMISSIONS[self.class.base_class.name].include?(p) } 36 r.permissions.any?{ |p| PERMISSIONS[self.class.base_class.name].include?(p) }
37 end 37 end
38 end 38 end
vendor/plugins/access_control/lib/acts_as_accessor.rb
@@ -23,7 +23,7 @@ module ActsAsAccessor @@ -23,7 +23,7 @@ module ActsAsAccessor
23 23
24 def add_role(role, resource, attributes = {}) 24 def add_role(role, resource, attributes = {})
25 attributes = role_attributes(role, resource).merge attributes 25 attributes = role_attributes(role, resource).merge attributes
26 - if RoleAssignment.find(:all, :conditions => attributes).empty? 26 + if RoleAssignment.find_by(attributes).nil?
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
vendor/plugins/action_tracker/lib/action_tracker.rb
@@ -73,7 +73,8 @@ module ActionTracker @@ -73,7 +73,8 @@ module ActionTracker
73 end 73 end
74 74
75 def acts_as_trackable(options = {}) 75 def acts_as_trackable(options = {})
76 - has_many :tracked_actions, { :class_name => "ActionTracker::Record", :order => "updated_at DESC", :foreign_key => :user_id, :dependent => :destroy }.merge(options) 76 + has_many :tracked_actions, -> { order 'updated_at DESC' },
  77 + {class_name: "ActionTracker::Record", foreign_key: :user_id, dependent: :destroy }.merge(options)
77 send :include, InstanceMethods 78 send :include, InstanceMethods
78 end 79 end
79 end 80 end
vendor/plugins/acts_as_list/lib/active_record/acts/list.rb
@@ -31,46 +31,22 @@ module ActiveRecord @@ -31,46 +31,22 @@ module ActiveRecord
31 # to give it an entire string that is interpolated if you need a tighter scope than just a foreign key. 31 # to give it an entire string that is interpolated if you need a tighter scope than just a foreign key.
32 # Example: <tt>acts_as_list :scope => 'todo_list_id = #{todo_list_id} AND completed = 0'</tt> 32 # Example: <tt>acts_as_list :scope => 'todo_list_id = #{todo_list_id} AND completed = 0'</tt>
33 def acts_as_list(options = {}) 33 def acts_as_list(options = {})
34 - configuration = { :column => "position", :scope => "1 = 1" } 34 + configuration = { column: 'position' }
35 configuration.update(options) if options.is_a?(Hash) 35 configuration.update(options) if options.is_a?(Hash)
36 36
37 - configuration[:scope] = "#{configuration[:scope]}_id".intern if configuration[:scope].is_a?(Symbol) && configuration[:scope].to_s !~ /_id$/  
38 -  
39 - if configuration[:scope].is_a?(Symbol)  
40 - scope_condition_method = %(  
41 - def scope_condition  
42 - self.class.send(:sanitize_sql_hash_for_conditions, { :#{configuration[:scope].to_s} => send(:#{configuration[:scope].to_s}) })  
43 - end  
44 - )  
45 - elsif configuration[:scope].is_a?(Array)  
46 - scope_condition_method = %(  
47 - def scope_condition  
48 - attrs = %w(#{configuration[:scope].join(" ")}).inject({}) do |memo,column|  
49 - memo[column.intern] = send(column.intern); memo  
50 - end  
51 - self.class.send(:sanitize_sql_hash_for_conditions, attrs)  
52 - end  
53 - )  
54 - else  
55 - scope_condition_method = "def scope_condition() \"#{configuration[:scope]}\" end"  
56 - end  
57 -  
58 - class_eval <<-EOV  
59 - include ActiveRecord::Acts::List::InstanceMethods 37 + class_attribute :acts_as_list_class
  38 + self.acts_as_list_class = self
60 39
61 - def acts_as_list_class  
62 - ::#{self.name}  
63 - end 40 + include ActiveRecord::Acts::List::InstanceMethods
64 41
65 - def position_column  
66 - '#{configuration[:column]}'  
67 - end 42 + define_method :position_column do
  43 + configuration[:column]
  44 + end
68 45
69 - #{scope_condition_method} 46 + scope :acts_as_list_scope, configuration[:scope]
70 47
71 - before_destroy :decrement_positions_on_lower_items  
72 - before_create :add_to_list_bottom  
73 - EOV 48 + before_destroy :decrement_positions_on_lower_items
  49 + before_create :add_to_list_bottom
74 end 50 end
75 end 51 end
76 52
@@ -159,13 +135,19 @@ module ActiveRecord @@ -159,13 +135,19 @@ module ActiveRecord
159 # Return the next higher item in the list. 135 # Return the next higher item in the list.
160 def higher_item 136 def higher_item
161 return nil unless in_list? 137 return nil unless in_list?
162 - acts_as_list_class.where("#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}").first 138 + acts_as_list_class
  139 + .acts_as_list_scope(self)
  140 + .where(position_column => send(position_column).to_i - 1)
  141 + .first
163 end 142 end
164 143
165 # Return the next lower item in the list. 144 # Return the next lower item in the list.
166 def lower_item 145 def lower_item
167 return nil unless in_list? 146 return nil unless in_list?
168 - acts_as_list_class.where("#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}").first 147 + acts_as_list_class
  148 + .acts_as_list_scope(self)
  149 + .where(position_column => send(position_column).to_i + 1)
  150 + .first
169 end 151 end
170 152
171 # Test if this record is in a list 153 # Test if this record is in a list
@@ -182,9 +164,6 @@ module ActiveRecord @@ -182,9 +164,6 @@ module ActiveRecord
182 self[position_column] = bottom_position_in_list.to_i + 1 164 self[position_column] = bottom_position_in_list.to_i + 1
183 end 165 end
184 166
185 - # Overwrite this method to define the scope of the list changes  
186 - def scope_condition() "1" end  
187 -  
188 # Returns the bottom position number in the list. 167 # Returns the bottom position number in the list.
189 # bottom_position_in_list # => 2 168 # bottom_position_in_list # => 2
190 def bottom_position_in_list(except = nil) 169 def bottom_position_in_list(except = nil)
@@ -194,9 +173,11 @@ module ActiveRecord @@ -194,9 +173,11 @@ module ActiveRecord
194 173
195 # Returns the bottom item 174 # Returns the bottom item
196 def bottom_item(except = nil) 175 def bottom_item(except = nil)
197 - conditions = scope_condition  
198 - conditions = "#{conditions} AND #{self.class.primary_key} != #{except.id}" if except  
199 - acts_as_list_class.where(conditions).order("#{position_column} DESC").first 176 + conditions = "#{self.class.primary_key} != #{except.id}" if except
  177 + acts_as_list_class
  178 + .acts_as_list_scope(self)
  179 + .where(conditions).order("#{position_column} DESC")
  180 + .first
200 end 181 end
201 182
202 # Forces item to assume the bottom position in the list. 183 # Forces item to assume the bottom position in the list.
@@ -211,39 +192,43 @@ module ActiveRecord @@ -211,39 +192,43 @@ module ActiveRecord
211 192
212 # This has the effect of moving all the higher items up one. 193 # This has the effect of moving all the higher items up one.
213 def decrement_positions_on_higher_items(position) 194 def decrement_positions_on_higher_items(position)
214 - acts_as_list_class.update_all(  
215 - "#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} <= #{position}"  
216 - ) 195 + acts_as_list_class
  196 + .acts_as_list_scope(self)
  197 + .where("#{position_column} <= #{position}")
  198 + .update_all("#{position_column} = (#{position_column} - 1)")
217 end 199 end
218 200
219 # This has the effect of moving all the lower items up one. 201 # This has the effect of moving all the lower items up one.
220 def decrement_positions_on_lower_items 202 def decrement_positions_on_lower_items
221 return unless in_list? 203 return unless in_list?
222 - acts_as_list_class.update_all(  
223 - "#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{send(position_column).to_i}"  
224 - ) 204 + acts_as_list_class
  205 + .acts_as_list_scope(self)
  206 + .where("#{position_column} > #{send(position_column).to_i}")
  207 + .update_all("#{position_column} = (#{position_column} - 1)")
225 end 208 end
226 209
227 # This has the effect of moving all the higher items down one. 210 # This has the effect of moving all the higher items down one.
228 def increment_positions_on_higher_items 211 def increment_positions_on_higher_items
229 return unless in_list? 212 return unless in_list?
230 - acts_as_list_class.update_all(  
231 - "#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column).to_i}"  
232 - ) 213 + acts_as_list_class
  214 + .acts_as_list_scope(self)
  215 + .where("#{position_column} < #{send(position_column).to_i}")
  216 + .update_all("#{position_column} = (#{position_column} + 1)")
233 end 217 end
234 218
235 # This has the effect of moving all the lower items down one. 219 # This has the effect of moving all the lower items down one.
236 def increment_positions_on_lower_items(position) 220 def increment_positions_on_lower_items(position)
237 - acts_as_list_class.update_all(  
238 - "#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} >= #{position}"  
239 - ) 221 + acts_as_list_class
  222 + .acts_as_list_scope(self)
  223 + .where("#{position_column} >= #{position}")
  224 + .update_all("#{position_column} = (#{position_column} + 1)")
240 end 225 end
241 226
242 # Increments position (<tt>position_column</tt>) of all items in the list. 227 # Increments position (<tt>position_column</tt>) of all items in the list.
243 def increment_positions_on_all_items 228 def increment_positions_on_all_items
244 - acts_as_list_class.update_all(  
245 - "#{position_column} = (#{position_column} + 1)", "#{scope_condition}"  
246 - ) 229 + acts_as_list_class
  230 + .acts_as_list_scope(self)
  231 + .update_all("#{position_column} = (#{position_column} + 1)")
247 end 232 end
248 233
249 def insert_at_position(position) 234 def insert_at_position(position)
vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb
@@ -43,20 +43,21 @@ module ActiveRecord @@ -43,20 +43,21 @@ module ActiveRecord
43 configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil } 43 configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil }
44 configuration.update(options) if options.is_a?(Hash) 44 configuration.update(options) if options.is_a?(Hash)
45 45
46 - belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache]  
47 - has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => :destroy 46 + belongs_to :parent, class_name: name, foreign_key: configuration[:foreign_key], counter_cache: configuration[:counter_cache]
  47 + has_many :children, -> { order configuration[:order] },
  48 + class_name: name, foreign_key: configuration[:foreign_key], dependent: :destroy
48 49
49 - class_eval <<-EOV  
50 - include ActiveRecord::Acts::Tree::InstanceMethods 50 + include ActiveRecord::Acts::Tree::InstanceMethods
51 51
52 - def self.roots  
53 - find(:all, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})  
54 - end 52 + scope :roots, -> {
  53 + s = where("#{configuration[:foreign_key]} IS NULL")
  54 + s = s.order configuration[:order] if configuration[:order]
  55 + s
  56 + }
55 57
56 - def self.root  
57 - find(:first, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})  
58 - end  
59 - EOV 58 + def self.root
  59 + self.roots.first
  60 + end
60 end 61 end
61 end 62 end
62 63
vendor/plugins/kandadaboggu-vote_fu/examples/users_controller.rb
1 # I usually use the user class from restful_authentication as my principle voter class 1 # I usually use the user class from restful_authentication as my principle voter class
2 -# There are generally no changes required to support voting in this controller. 2 +# There are generally no changes required to support voting in this controller.
3 3
4 class UsersController < ApplicationController 4 class UsersController < ApplicationController
5 # Be sure to include AuthenticationSystem in Application Controller instead 5 # Be sure to include AuthenticationSystem in Application Controller instead
6 include AuthenticatedSystem 6 include AuthenticatedSystem
7 - 7 +
8 # Protect these actions behind an admin login 8 # Protect these actions behind an admin login
9 before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge] 9 before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge]
10 before_filter :find_user, :only => [:suspend, :unsuspend, :destroy, :purge, :show] 10 before_filter :find_user, :only => [:suspend, :unsuspend, :destroy, :purge, :show]
@@ -18,7 +18,7 @@ class UsersController &lt; ApplicationController @@ -18,7 +18,7 @@ class UsersController &lt; ApplicationController
18 # GET /users/:id 18 # GET /users/:id
19 def show 19 def show
20 end 20 end
21 - 21 +
22 22
23 def create 23 def create
24 cookies.delete :auth_token 24 cookies.delete :auth_token
@@ -36,7 +36,7 @@ class UsersController &lt; ApplicationController @@ -36,7 +36,7 @@ class UsersController &lt; ApplicationController
36 36
37 def activate 37 def activate
38 unless params[:activation_code].blank? 38 unless params[:activation_code].blank?
39 - self.current_user = User.find_by_activation_code(params[:activation_code]) 39 + self.current_user = User.find_by(activation_code: params[:activation_code])
40 if logged_in? && !current_user.active? 40 if logged_in? && !current_user.active?
41 current_user.activate! 41 current_user.activate!
42 flash[:notice] = "Signup complete!" 42 flash[:notice] = "Signup complete!"
@@ -45,16 +45,16 @@ class UsersController &lt; ApplicationController @@ -45,16 +45,16 @@ class UsersController &lt; ApplicationController
45 flash[:error] = "Sorry, we couldn't find that activation code. Please cut and paste your activation code into the space at left." 45 flash[:error] = "Sorry, we couldn't find that activation code. Please cut and paste your activation code into the space at left."
46 end 46 end
47 end 47 end
48 - # render activate.html.erb 48 + # render activate.html.erb
49 end 49 end
50 50
51 def suspend 51 def suspend
52 - @user.suspend! 52 + @user.suspend!
53 redirect_to users_path 53 redirect_to users_path
54 end 54 end
55 55
56 def unsuspend 56 def unsuspend
57 - @user.unsuspend! 57 + @user.unsuspend!
58 redirect_to users_path 58 redirect_to users_path
59 end 59 end
60 60
vendor/plugins/kandadaboggu-vote_fu/lib/acts_as_voteable.rb
@@ -72,7 +72,7 @@ module Juixe @@ -72,7 +72,7 @@ module Juixe
72 # :at_least_total - Item must have at least X votes total 72 # :at_least_total - Item must have at least X votes total
73 # :at_most_total - Item may not have more than X votes total 73 # :at_most_total - Item may not have more than X votes total
74 def tally(options = {}) 74 def tally(options = {})
75 - find(:all, options_for_tally({:order =>"total DESC" }.merge(options))) 75 + order("total DESC").all options_for_tally(options)
76 end 76 end
77 77
78 def options_for_tally (options = {}) 78 def options_for_tally (options = {})
vendor/plugins/kandadaboggu-vote_fu/lib/has_karma.rb
@@ -27,42 +27,34 @@ module PeteOnRails @@ -27,42 +27,34 @@ module PeteOnRails
27 end 27 end
28 end 28 end
29 end 29 end
30 - 30 +
31 # This module contains class methods 31 # This module contains class methods
32 module SingletonMethods 32 module SingletonMethods
33 - 33 +
34 ## Not yet implemented. Don't use it! 34 ## Not yet implemented. Don't use it!
35 # Find the most popular users 35 # Find the most popular users
36 def find_most_karmic 36 def find_most_karmic
37 - find(:all) 37 + all
38 end 38 end
39 - 39 +
40 end 40 end
41 - 41 +
42 # This module contains instance methods 42 # This module contains instance methods
43 module InstanceMethods 43 module InstanceMethods
44 def karma(options = {}) 44 def karma(options = {})
45 - #FIXME cannot have 2 models imapcting the karma simultaneously  
46 - # count the total number of votes on all of the voteable objects that are related to this object  
47 - #2009-01-30 GuillaumeNM The following line is not SQLite3 compatible, because boolean are stored as 'f' or 't', not '1', or '0'  
48 - #self.karma_voteable.sum(:vote, options_for_karma(options))  
49 - #self.karma_voteable.find(:all, options_for_karma(options)).length  
50 karma_value = 0 45 karma_value = 0
51 self.class.karmatic_objects.each do |object| 46 self.class.karmatic_objects.each do |object|
52 - karma_value += object.find(:all, options_for_karma(object, options)).length 47 + karma_value += object
  48 + .where("u.id = ? AND vote = ?" , self[:id] , true)
  49 + .joins("inner join votes v on #{object.table_name}.id = v.voteable_id")
  50 + .joins("inner join #{self.class.table_name} u on u.id = #{object.name.tableize}.#{self.class.name.foreign_key}")
  51 + .length
53 end 52 end
54 return karma_value 53 return karma_value
55 end 54 end
56 -  
57 - def options_for_karma (object, options = {})  
58 - #GuillaumeNM : 2009-01-30 Adding condition for SQLite3  
59 - conditions = ["u.id = ? AND vote = ?" , self[:id] , true]  
60 - joins = ["inner join votes v on #{object.table_name}.id = v.voteable_id", "inner join #{self.class.table_name} u on u.id = #{object.name.tableize}.#{self.class.name.foreign_key}"]  
61 - { :joins => joins.join(" "), :conditions => conditions }.update(options)  
62 - end  
63 - 55 +
64 end 56 end
65 - 57 +
66 end 58 end
67 end 59 end
68 end 60 end
vendor/plugins/xss_terminate/tasks/xss_terminate_tasks.rake
@@ -2,6 +2,6 @@ desc &quot;Given MODELS=Foo,Bar,Baz find all instances in the DB and save to sanitize @@ -2,6 +2,6 @@ desc &quot;Given MODELS=Foo,Bar,Baz find all instances in the DB and save to sanitize
2 task :xss_terminate => :environment do 2 task :xss_terminate => :environment do
3 models = ENV['MODELS'].split(',') 3 models = ENV['MODELS'].split(',')
4 models.each do |model| 4 models.each do |model|
5 - model.constantize.find(:all).map(&:save) 5 + model.constantize.all.map(&:save)
6 end 6 end
7 end 7 end