Commit 25033623491e9412b9ff53c1b5866040b9887c6e
Exists in
web_steps_improvements
and in
6 other branches
Merge branch 'drop-find_by_' into 'master'
Drop deprecated finders Finally (I hope) the last code from rails 2 See merge request !846
Showing
234 changed files
with
890 additions
and
932 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 234 files displayed.
Gemfile
| ... | ... | @@ -52,7 +52,6 @@ gem 'protected_attributes' |
| 52 | 52 | gem 'rails-observers' |
| 53 | 53 | gem 'actionpack-page_caching' |
| 54 | 54 | gem 'actionpack-action_caching' |
| 55 | -gem 'activerecord-deprecated_finders', require: 'active_record/deprecated_finders' | |
| 56 | 55 | |
| 57 | 56 | group :production do |
| 58 | 57 | gem 'dalli', '~> 2.7.0' | ... | ... |
app/controllers/admin/admin_panel_controller.rb
| ... | ... | @@ -34,7 +34,7 @@ class AdminPanelController < AdminController |
| 34 | 34 | env = environment |
| 35 | 35 | @portal_community = env.portal_community || Community.new |
| 36 | 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 | 38 | if portal_community |
| 39 | 39 | if (env.portal_community != portal_community) |
| 40 | 40 | env.portal_community = portal_community | ... | ... |
app/controllers/admin/environment_role_manager_controller.rb
| ... | ... | @@ -7,7 +7,7 @@ class EnvironmentRoleManagerController < AdminController |
| 7 | 7 | |
| 8 | 8 | def change_roles |
| 9 | 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 | 11 | end |
| 12 | 12 | |
| 13 | 13 | def update_roles |
| ... | ... | @@ -22,7 +22,7 @@ class EnvironmentRoleManagerController < AdminController |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | 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 | 26 | @admin = Person.find(params[:id]) |
| 27 | 27 | @associations = @admin.find_roles(environment) |
| 28 | 28 | end |
| ... | ... | @@ -34,7 +34,7 @@ class EnvironmentRoleManagerController < AdminController |
| 34 | 34 | redirect_to :action => 'index' |
| 35 | 35 | else |
| 36 | 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 | 38 | render :action => 'affiliate' |
| 39 | 39 | end |
| 40 | 40 | end |
| ... | ... | @@ -60,7 +60,7 @@ class EnvironmentRoleManagerController < AdminController |
| 60 | 60 | end |
| 61 | 61 | |
| 62 | 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 | 65 | end |
| 66 | 66 | end | ... | ... |
app/controllers/admin/features_controller.rb
| ... | ... | @@ -60,7 +60,7 @@ class FeaturesController < AdminController |
| 60 | 60 | CustomField.destroy(custom_fields_to_destroy) |
| 61 | 61 | |
| 62 | 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 | 64 | if not field.blank? |
| 65 | 65 | params_to_update = custom_field.except(:format, :extras, :customized_type,:environment) |
| 66 | 66 | field.update_attributes(params_to_update) | ... | ... |
app/controllers/admin/role_controller.rb
| ... | ... | @@ -2,7 +2,7 @@ class RoleController < AdminController |
| 2 | 2 | protect 'manage_environment_roles', :environment |
| 3 | 3 | |
| 4 | 4 | def index |
| 5 | - @roles = environment.roles.find(:all, :conditions => {:profile_id => nil}) | |
| 5 | + @roles = environment.roles.where profile_id: nil | |
| 6 | 6 | end |
| 7 | 7 | |
| 8 | 8 | def new | ... | ... |
app/controllers/admin/users_controller.rb
| ... | ... | @@ -48,7 +48,7 @@ class UsersController < AdminController |
| 48 | 48 | |
| 49 | 49 | def destroy_user |
| 50 | 50 | if request.post? |
| 51 | - person = environment.people.find_by_id(params[:id]) | |
| 51 | + person = environment.people.find_by id: params[:id] | |
| 52 | 52 | if person && person.destroy |
| 53 | 53 | session[:notice] = _('The profile was deleted.') |
| 54 | 54 | else | ... | ... |
app/controllers/application_controller.rb
| ... | ... | @@ -123,7 +123,7 @@ class ApplicationController < ActionController::Base |
| 123 | 123 | # Sets text domain based on request host for custom internationalization |
| 124 | 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 | 127 | if @domain.nil? |
| 128 | 128 | @environment = Environment.default |
| 129 | 129 | # Avoid crashes on test and development setups |
| ... | ... | @@ -138,7 +138,7 @@ class ApplicationController < ActionController::Base |
| 138 | 138 | |
| 139 | 139 | # Check if the requested profile belongs to another domain |
| 140 | 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 | 142 | redirect_to url_for(params.merge host: @profile.default_hostname) |
| 143 | 143 | end |
| 144 | 144 | end |
| ... | ... | @@ -170,7 +170,7 @@ class ApplicationController < ActionController::Base |
| 170 | 170 | def load_category |
| 171 | 171 | unless params[:category_path].blank? |
| 172 | 172 | path = params[:category_path] |
| 173 | - @category = environment.categories.find_by_path(path) | |
| 173 | + @category = environment.categories.find_by(path: path) | |
| 174 | 174 | if @category.nil? |
| 175 | 175 | render_not_found(path) |
| 176 | 176 | end | ... | ... |
app/controllers/box_organizer_controller.rb
| ... | ... | @@ -16,10 +16,9 @@ class BoxOrganizerController < ApplicationController |
| 16 | 16 | target_position = block_before.position |
| 17 | 17 | |
| 18 | 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 | 22 | end |
| 24 | 23 | |
| 25 | 24 | @block = new_block(params[:type], @target_box) if @block.nil? |
| ... | ... | @@ -35,8 +34,8 @@ class BoxOrganizerController < ApplicationController |
| 35 | 34 | @block.insert_at(@target_box.blocks.size + 1) |
| 36 | 35 | @block.move_to_bottom |
| 37 | 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 | 39 | end |
| 41 | 40 | |
| 42 | 41 | @block.save! | ... | ... |
app/controllers/my_profile/cms_controller.rb
| ... | ... | @@ -34,7 +34,7 @@ class CmsController < MyProfileController |
| 34 | 34 | |
| 35 | 35 | protect_if :only => [:new, :upload_files] do |c, user, profile| |
| 36 | 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 | 38 | user && user.can_post_content?(profile, parent) |
| 39 | 39 | end |
| 40 | 40 | |
| ... | ... | @@ -59,11 +59,10 @@ class CmsController < MyProfileController |
| 59 | 59 | |
| 60 | 60 | def index |
| 61 | 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 | 66 | render :action => 'view' |
| 68 | 67 | end |
| 69 | 68 | ... | ... |
app/controllers/my_profile/friends_controller.rb
| ... | ... | @@ -22,7 +22,7 @@ class FriendsController < MyProfileController |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | 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 | 26 | redirect_to :action => 'suggest' unless @person |
| 27 | 27 | if @person && request.post? |
| 28 | 28 | profile.remove_suggestion(@person) |
| ... | ... | @@ -32,7 +32,7 @@ class FriendsController < MyProfileController |
| 32 | 32 | end |
| 33 | 33 | |
| 34 | 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 | 36 | if @suggestion |
| 37 | 37 | @tags = @suggestion.tag_connections |
| 38 | 38 | @profiles = @suggestion.profile_connections | ... | ... |
app/controllers/my_profile/manage_products_controller.rb
| ... | ... | @@ -35,7 +35,7 @@ class ManageProductsController < ApplicationController |
| 35 | 35 | end |
| 36 | 36 | |
| 37 | 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 | 39 | @object_name = params[:object_name] |
| 40 | 40 | if @category |
| 41 | 41 | @categories = @category.children |
| ... | ... | @@ -103,7 +103,7 @@ class ManageProductsController < ApplicationController |
| 103 | 103 | def search_categories |
| 104 | 104 | @term = params[:term].downcase |
| 105 | 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 | 107 | render :json => (@categories.map do |category| |
| 108 | 108 | {:label => category.name, :value => category.id} |
| 109 | 109 | end) |
| ... | ... | @@ -169,7 +169,7 @@ class ManageProductsController < ApplicationController |
| 169 | 169 | |
| 170 | 170 | def edit_input |
| 171 | 171 | if request.xhr? |
| 172 | - @input = @profile.inputs.find_by_id(params[:id]) | |
| 172 | + @input = @profile.inputs.find_by id: params[:id] | |
| 173 | 173 | if @input |
| 174 | 174 | if request.post? |
| 175 | 175 | if @input.update(params[:input]) | ... | ... |
app/controllers/my_profile/memberships_controller.rb
| ... | ... | @@ -5,7 +5,7 @@ class MembershipsController < MyProfileController |
| 5 | 5 | |
| 6 | 6 | def index |
| 7 | 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 | 9 | ra.present? && ra.resource_type == 'Profile' |
| 10 | 10 | end |
| 11 | 11 | @filter = params[:filter_type].to_i |
| ... | ... | @@ -47,7 +47,7 @@ class MembershipsController < MyProfileController |
| 47 | 47 | end |
| 48 | 48 | |
| 49 | 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 | 51 | custom_per_page = params[:per_page] || per_page |
| 52 | 52 | redirect_to :action => 'suggest' unless @community |
| 53 | 53 | if @community && request.post? |
| ... | ... | @@ -58,7 +58,7 @@ class MembershipsController < MyProfileController |
| 58 | 58 | end |
| 59 | 59 | |
| 60 | 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 | 62 | if @suggestion |
| 63 | 63 | @tags = @suggestion.tag_connections |
| 64 | 64 | @profiles = @suggestion.profile_connections | ... | ... |
app/controllers/my_profile/profile_members_controller.rb
| ... | ... | @@ -60,7 +60,7 @@ class ProfileMembersController < MyProfileController |
| 60 | 60 | redirect_to :action => 'index' |
| 61 | 61 | else |
| 62 | 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 | 64 | render :action => 'affiliate' |
| 65 | 65 | end |
| 66 | 66 | end |
| ... | ... | @@ -120,7 +120,7 @@ class ProfileMembersController < MyProfileController |
| 120 | 120 | @collection = :profile_admins |
| 121 | 121 | |
| 122 | 122 | if profile.community? |
| 123 | - member = profile.members.find_by_identifier(params[:id]) | |
| 123 | + member = profile.members.find_by(identifier: params[:id]) | |
| 124 | 124 | profile.add_admin(member) |
| 125 | 125 | end |
| 126 | 126 | render :layout => false |
| ... | ... | @@ -131,7 +131,7 @@ class ProfileMembersController < MyProfileController |
| 131 | 131 | @collection = :profile_admins |
| 132 | 132 | |
| 133 | 133 | if profile.community? |
| 134 | - member = profile.members.find_by_identifier(params[:id]) | |
| 134 | + member = profile.members.find_by(identifier: params[:id]) | |
| 135 | 135 | profile.remove_admin(member) |
| 136 | 136 | end |
| 137 | 137 | render :layout => false | ... | ... |
app/controllers/my_profile/spam_controller.rb
| ... | ... | @@ -15,12 +15,12 @@ class SpamController < MyProfileController |
| 15 | 15 | profile.comments_received.find(params[:remove_comment]).destroy |
| 16 | 16 | end |
| 17 | 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 | 19 | end |
| 20 | 20 | if params[:mark_comment_as_ham] |
| 21 | 21 | profile.comments_received.find(params[:mark_comment_as_ham]).ham! |
| 22 | 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 | 24 | t.ham! |
| 25 | 25 | end |
| 26 | 26 | if request.xhr? | ... | ... |
app/controllers/my_profile/tasks_controller.rb
| ... | ... | @@ -7,8 +7,8 @@ class TasksController < MyProfileController |
| 7 | 7 | helper CustomFieldsHelper |
| 8 | 8 | |
| 9 | 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 | 13 | @filter_type = params[:filter_type].presence |
| 14 | 14 | @filter_text = params[:filter_text].presence |
| ... | ... | @@ -88,7 +88,7 @@ class TasksController < MyProfileController |
| 88 | 88 | end |
| 89 | 89 | |
| 90 | 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 | 92 | end |
| 93 | 93 | |
| 94 | 94 | def ticket_details | ... | ... |
app/controllers/public/account_controller.rb
| ... | ... | @@ -17,7 +17,7 @@ class AccountController < ApplicationController |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | 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 | 21 | if @user |
| 22 | 22 | unless @user.environment.enabled?('admin_must_approve_new_users') |
| 23 | 23 | if @user.activate |
| ... | ... | @@ -118,7 +118,7 @@ class AccountController < ApplicationController |
| 118 | 118 | end |
| 119 | 119 | @user.community_to_join = session[:join] |
| 120 | 120 | @user.signup! |
| 121 | - owner_role = Role.find_by_name('owner') | |
| 121 | + owner_role = Role.find_by(name: 'owner') | |
| 122 | 122 | @user.person.affiliate(@user.person, [owner_role]) if owner_role |
| 123 | 123 | invitation = Task.from_code(@invitation_code).first |
| 124 | 124 | if invitation |
| ... | ... | @@ -305,7 +305,7 @@ class AccountController < ApplicationController |
| 305 | 305 | end |
| 306 | 306 | |
| 307 | 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 | 309 | @status = _('This e-mail address is available') |
| 310 | 310 | @status_class = 'validated' |
| 311 | 311 | else |
| ... | ... | @@ -502,7 +502,7 @@ class AccountController < ApplicationController |
| 502 | 502 | def check_join_in_community(user) |
| 503 | 503 | profile_to_join = session[:join] |
| 504 | 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 | 506 | session.delete(:join) |
| 507 | 507 | end |
| 508 | 508 | end | ... | ... |
app/controllers/public/chat_controller.rb
| ... | ... | @@ -44,7 +44,7 @@ class ChatController < PublicController |
| 44 | 44 | end |
| 45 | 45 | |
| 46 | 46 | def avatar |
| 47 | - profile = environment.profiles.find_by_identifier(params[:id]) | |
| 47 | + profile = environment.profiles.find_by(identifier: params[:id]) | |
| 48 | 48 | filename, mimetype = profile_icon(profile, :minor, true) |
| 49 | 49 | if filename =~ /^(https?:)?\/\// |
| 50 | 50 | redirect_to filename |
| ... | ... | @@ -87,7 +87,7 @@ class ChatController < PublicController |
| 87 | 87 | end |
| 88 | 88 | |
| 89 | 89 | def recent_messages |
| 90 | - other = environment.profiles.find_by_identifier(params[:identifier]) | |
| 90 | + other = environment.profiles.find_by(identifier: params[:identifier]) | |
| 91 | 91 | if other.kind_of?(Organization) |
| 92 | 92 | messages = ChatMessage.where('to_id=:other', :other => other.id) |
| 93 | 93 | else | ... | ... |
app/controllers/public/content_viewer_controller.rb
| ... | ... | @@ -18,7 +18,7 @@ class ContentViewerController < ApplicationController |
| 18 | 18 | @page = profile.home_page |
| 19 | 19 | return if redirected_to_profile_index |
| 20 | 20 | else |
| 21 | - @page = profile.articles.find_by_path(path) | |
| 21 | + @page = profile.articles.find_by path: path | |
| 22 | 22 | return if redirected_page_from_old_path(path) |
| 23 | 23 | end |
| 24 | 24 | |
| ... | ... | @@ -76,13 +76,13 @@ class ContentViewerController < ApplicationController |
| 76 | 76 | |
| 77 | 77 | def versions_diff |
| 78 | 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 | 81 | end |
| 82 | 82 | |
| 83 | 83 | def article_versions |
| 84 | 84 | path = params[:page] |
| 85 | - @page = profile.articles.find_by_path(path) | |
| 85 | + @page = profile.articles.find_by path: path | |
| 86 | 86 | return unless allow_access_to_page(path) |
| 87 | 87 | |
| 88 | 88 | render_access_denied unless @page.display_versions? |
| ... | ... | @@ -169,7 +169,7 @@ class ContentViewerController < ApplicationController |
| 169 | 169 | |
| 170 | 170 | def redirected_page_from_old_path(path) |
| 171 | 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 | 173 | if page_from_old_path |
| 174 | 174 | redirect_to profile.url.merge(:page => page_from_old_path.explode_path) |
| 175 | 175 | return true |
| ... | ... | @@ -190,7 +190,7 @@ class ContentViewerController < ApplicationController |
| 190 | 190 | end |
| 191 | 191 | |
| 192 | 192 | def rendered_versioned_article |
| 193 | - @versioned_article = @page.versions.find_by_version(@version) | |
| 193 | + @versioned_article = @page.versions.find_by version: @version | |
| 194 | 194 | if @versioned_article && @page.versions.latest.version != @versioned_article.version |
| 195 | 195 | render :template => 'content_viewer/versioned_article.html.erb' |
| 196 | 196 | return true | ... | ... |
app/controllers/public/enterprise_registration_controller.rb
| ... | ... | @@ -68,7 +68,7 @@ class EnterpriseRegistrationController < ApplicationController |
| 68 | 68 | # saying to the user that the enterprise was created. |
| 69 | 69 | def creation |
| 70 | 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 | 72 | end |
| 73 | 73 | |
| 74 | 74 | end | ... | ... |
app/controllers/public/profile_controller.rb
| ... | ... | @@ -339,7 +339,7 @@ class ProfileController < PublicController |
| 339 | 339 | user.register_report(abuse_report, profile) |
| 340 | 340 | |
| 341 | 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 | 343 | Delayed::Job.enqueue DownloadReportedImagesJob.new(abuse_report, article) |
| 344 | 344 | end |
| 345 | 345 | |
| ... | ... | @@ -374,7 +374,7 @@ class ProfileController < PublicController |
| 374 | 374 | def send_mail |
| 375 | 375 | @mailing = profile.mailings.build(params[:mailing]) |
| 376 | 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 | 378 | if request.post? |
| 379 | 379 | @mailing.locale = locale |
| 380 | 380 | @mailing.person = user | ... | ... |
app/controllers/public/search_controller.rb
| ... | ... | @@ -167,7 +167,7 @@ class SearchController < PublicController |
| 167 | 167 | render_not_found if params[:action] == 'category_index' |
| 168 | 168 | else |
| 169 | 169 | path = params[:category_path] |
| 170 | - @category = environment.categories.find_by_path(path) | |
| 170 | + @category = environment.categories.find_by path: path | |
| 171 | 171 | if @category.nil? |
| 172 | 172 | render_not_found(path) |
| 173 | 173 | else |
| ... | ... | @@ -177,14 +177,14 @@ class SearchController < PublicController |
| 177 | 177 | end |
| 178 | 178 | |
| 179 | 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 | 188 | end |
| 189 | 189 | |
| 190 | 190 | def load_search_assets |
| ... | ... | @@ -256,13 +256,13 @@ class SearchController < PublicController |
| 256 | 256 | end |
| 257 | 257 | |
| 258 | 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 | 266 | end |
| 267 | 267 | |
| 268 | 268 | end | ... | ... |
app/helpers/application_helper.rb
| ... | ... | @@ -318,7 +318,7 @@ module ApplicationHelper |
| 318 | 318 | if File.exists?(Rails.root.join('public', theme_path, 'favicon.ico')) |
| 319 | 319 | '/designs/themes/' + profile.theme + '/favicon.ico' |
| 320 | 320 | else |
| 321 | - favicon = profile.articles.find_by_path('favicon.ico') | |
| 321 | + favicon = profile.articles.find_by path: 'favicon.ico' | |
| 322 | 322 | if favicon |
| 323 | 323 | favicon.public_filename |
| 324 | 324 | else |
| ... | ... | @@ -1154,8 +1154,8 @@ module ApplicationHelper |
| 1154 | 1154 | end |
| 1155 | 1155 | |
| 1156 | 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 | 1159 | default_folder |
| 1160 | 1160 | end |
| 1161 | 1161 | ... | ... |
app/helpers/forms_helper.rb
| ... | ... | @@ -50,15 +50,15 @@ module FormsHelper |
| 50 | 50 | end |
| 51 | 51 | |
| 52 | 52 | def select_city( simple=false ) |
| 53 | - states = State.find(:all, :order => 'name') | |
| 54 | - | |
| 53 | + states = State.order(:name).all | |
| 54 | + | |
| 55 | 55 | state_id = 'state-' + FormsHelper.next_id_number |
| 56 | 56 | city_id = 'city-' + FormsHelper.next_id_number |
| 57 | 57 | |
| 58 | 58 | if states.length < 1 |
| 59 | 59 | return |
| 60 | 60 | end |
| 61 | - | |
| 61 | + | |
| 62 | 62 | if simple |
| 63 | 63 | states = [State.new(:name => _('Select the State'))] + states |
| 64 | 64 | cities = [City.new(:name => _('Select the City'))] |
| ... | ... | @@ -82,7 +82,7 @@ module FormsHelper |
| 82 | 82 | states = [State.new(:name => '---')] + states |
| 83 | 83 | cities = [City.new(:name => '---')] |
| 84 | 84 | |
| 85 | - html = | |
| 85 | + html = | |
| 86 | 86 | content_tag( 'div', |
| 87 | 87 | labelled_select( _('State:'), 'state', :id, :name, nil, states, :id => state_id ), |
| 88 | 88 | :class => 'select_state_for_origin' ) + |
| ... | ... | @@ -90,7 +90,7 @@ module FormsHelper |
| 90 | 90 | labelled_select( _('City:'), 'city', :id, :name, nil, cities, :id => city_id ), |
| 91 | 91 | :class => 'select_city_for_origin' ) |
| 92 | 92 | end |
| 93 | - | |
| 93 | + | |
| 94 | 94 | html + |
| 95 | 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 | 96 | end | ... | ... |
app/helpers/manage_products_helper.rb
| ... | ... | @@ -222,7 +222,7 @@ module ManageProductsHelper |
| 222 | 222 | end |
| 223 | 223 | def select_certifiers(qualifier, product = nil) |
| 224 | 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 | 226 | select_tag("product[qualifiers_list][#{qualifier.id}]", options_for_select(certifiers_for_select(qualifier), selected)) |
| 227 | 227 | else |
| 228 | 228 | select_tag("product[qualifiers_list][nil]") | ... | ... |
app/helpers/profile_helper.rb
| 1 | 1 | module ProfileHelper |
| 2 | 2 | |
| 3 | - COMMON_CATEGORIES = ActiveSupport::OrderedHash.new | |
| 3 | + COMMON_CATEGORIES = {} | |
| 4 | 4 | COMMON_CATEGORIES[:content] = [:blogs, :image_galleries, :events, :article_tags] |
| 5 | 5 | COMMON_CATEGORIES[:interests] = [:interests] |
| 6 | 6 | COMMON_CATEGORIES[:general] = nil |
| 7 | 7 | |
| 8 | - PERSON_CATEGORIES = ActiveSupport::OrderedHash.new | |
| 8 | + PERSON_CATEGORIES = {} | |
| 9 | 9 | PERSON_CATEGORIES[:basic_information] = [:nickname, :sex, :birth_date, :location, :privacy_setting, :created_at] |
| 10 | 10 | PERSON_CATEGORIES[:contact] = [:contact_phone, :cell_phone, :comercial_phone, :contact_information, :email, :personal_website, :jabber_id] |
| 11 | 11 | PERSON_CATEGORIES[:location] = [:address, :address_reference, :zip_code, :city, :state, :district, :country, :nationality] |
| ... | ... | @@ -14,13 +14,13 @@ module ProfileHelper |
| 14 | 14 | PERSON_CATEGORIES[:network] = [:friends, :communities, :enterprises] |
| 15 | 15 | PERSON_CATEGORIES.merge!(COMMON_CATEGORIES) |
| 16 | 16 | |
| 17 | - ORGANIZATION_CATEGORIES = ActiveSupport::OrderedHash.new | |
| 17 | + ORGANIZATION_CATEGORIES = {} | |
| 18 | 18 | ORGANIZATION_CATEGORIES[:basic_information] = [:display_name, :created_at, :foundation_year, :type, :language, :members_count, :location, :address_reference, :historic_and_current_context, :admins] |
| 19 | 19 | ORGANIZATION_CATEGORIES[:contact] = [:contact_person, :contact_phone, :contact_email, :organization_website, :jabber_id] |
| 20 | 20 | ORGANIZATION_CATEGORIES[:economic] = [:business_name, :acronym, :economic_activity, :legal_form, :products, :activities_short_description, :management_information] |
| 21 | 21 | ORGANIZATION_CATEGORIES.merge!(COMMON_CATEGORIES) |
| 22 | 22 | |
| 23 | - CATEGORY_MAP = ActiveSupport::OrderedHash.new | |
| 23 | + CATEGORY_MAP = {} | |
| 24 | 24 | CATEGORY_MAP[:person] = PERSON_CATEGORIES |
| 25 | 25 | CATEGORY_MAP[:organization] = ORGANIZATION_CATEGORIES |
| 26 | 26 | ... | ... |
app/models/add_friend.rb
| ... | ... | @@ -57,7 +57,7 @@ class AddFriend < Task |
| 57 | 57 | end |
| 58 | 58 | |
| 59 | 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 | 61 | suggestion.disable if suggestion |
| 62 | 62 | end |
| 63 | 63 | end | ... | ... |
app/models/add_member.rb
| ... | ... | @@ -59,7 +59,7 @@ class AddMember < Task |
| 59 | 59 | end |
| 60 | 60 | |
| 61 | 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 | 63 | suggestion.disable if suggestion |
| 64 | 64 | end |
| 65 | 65 | ... | ... |
app/models/approve_article.rb
| ... | ... | @@ -20,7 +20,7 @@ class ApproveArticle < Task |
| 20 | 20 | end |
| 21 | 21 | |
| 22 | 22 | def article |
| 23 | - Article.find_by_id data[:article_id] | |
| 23 | + Article.find_by id: data[:article_id] | |
| 24 | 24 | end |
| 25 | 25 | |
| 26 | 26 | def article= value |
| ... | ... | @@ -39,7 +39,7 @@ class ApproveArticle < Task |
| 39 | 39 | settings_items :create_link, :type => :boolean, :default => false |
| 40 | 40 | |
| 41 | 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 | 43 | end |
| 44 | 44 | |
| 45 | 45 | def article_parent= value | ... | ... |
app/models/approve_comment.rb
app/models/article.rb
| ... | ... | @@ -74,11 +74,11 @@ class Article < ActiveRecord::Base |
| 74 | 74 | belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id' |
| 75 | 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 | 79 | has_many :article_followers, :dependent => :destroy |
| 80 | 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 | 83 | has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false } |
| 84 | 84 | has_many :categories, :through => :article_categorizations |
| ... | ... | @@ -279,7 +279,7 @@ class Article < ActiveRecord::Base |
| 279 | 279 | # retrives the most commented articles, sorted by the comment count (largest |
| 280 | 280 | # first) |
| 281 | 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 | 283 | end |
| 284 | 284 | |
| 285 | 285 | scope :more_popular, -> { order 'hits DESC' } |
| ... | ... | @@ -288,7 +288,7 @@ class Article < ActiveRecord::Base |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | def self.recent(limit = nil, extra_conditions = {}, pagination = true) |
| 291 | - result = scoped({:conditions => extra_conditions}). | |
| 291 | + result = where(extra_conditions). | |
| 292 | 292 | is_public. |
| 293 | 293 | relevant_as_recent. |
| 294 | 294 | limit(limit). |
| ... | ... | @@ -470,7 +470,7 @@ class Article < ActiveRecord::Base |
| 470 | 470 | |
| 471 | 471 | def rotate_translations |
| 472 | 472 | unless self.translations.empty? |
| 473 | - rotate = self.translations.all | |
| 473 | + rotate = self.translations.to_a | |
| 474 | 474 | root = rotate.shift |
| 475 | 475 | root.update_attribute(:translation_of_id, nil) |
| 476 | 476 | root.translations = rotate |
| ... | ... | @@ -752,7 +752,7 @@ class Article < ActiveRecord::Base |
| 752 | 752 | |
| 753 | 753 | def version_license(version_number = nil) |
| 754 | 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 | 756 | end |
| 757 | 757 | |
| 758 | 758 | alias :active_record_cache_key :cache_key | ... | ... |
app/models/block.rb
| ... | ... | @@ -11,7 +11,8 @@ class Block < ActiveRecord::Base |
| 11 | 11 | |
| 12 | 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 | 16 | belongs_to :box |
| 16 | 17 | belongs_to :mirror_block, :class_name => "Block" |
| 17 | 18 | has_many :observers, :class_name => "Block", :foreign_key => "mirror_block_id" | ... | ... |
app/models/blog.rb
| ... | ... | @@ -98,8 +98,9 @@ class Blog < Folder |
| 98 | 98 | when :by_year |
| 99 | 99 | posts.published.native_translations |
| 100 | 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 | 104 | when :by_month |
| 104 | 105 | posts.published.native_translations |
| 105 | 106 | .except(:order) | ... | ... |
app/models/box.rb
| 1 | 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 | 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 | 8 | attr_accessible :owner |
| 7 | 9 | ... | ... |
app/models/category.rb
| ... | ... | @@ -90,7 +90,7 @@ class Category < ActiveRecord::Base |
| 90 | 90 | |
| 91 | 91 | def children_for_menu |
| 92 | 92 | results = [] |
| 93 | - pending = children.where(display_in_menu: true).all | |
| 93 | + pending = children.where(display_in_menu: true).to_a | |
| 94 | 94 | while pending.present? |
| 95 | 95 | cat = pending.shift |
| 96 | 96 | results << cat | ... | ... |
app/models/comment.rb
| ... | ... | @@ -92,7 +92,7 @@ class Comment < ActiveRecord::Base |
| 92 | 92 | end |
| 93 | 93 | |
| 94 | 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 | 96 | end |
| 97 | 97 | |
| 98 | 98 | def notification_emails | ... | ... |
app/models/community.rb
| ... | ... | @@ -77,7 +77,7 @@ class Community < Organization |
| 77 | 77 | end |
| 78 | 78 | |
| 79 | 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 | 81 | yield member |
| 82 | 82 | offset = offset + 1 |
| 83 | 83 | end | ... | ... |
app/models/domain.rb
| ... | ... | @@ -36,8 +36,8 @@ class Domain < ActiveRecord::Base |
| 36 | 36 | # finds a domain by its name. The argument <tt>name</tt> can start with |
| 37 | 37 | # "www.", but it will be removed before searching. So searching for |
| 38 | 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 | 41 | end |
| 42 | 42 | |
| 43 | 43 | # turns the argument (expected to be a String) into a domain name that is |
| ... | ... | @@ -82,7 +82,7 @@ class Domain < ActiveRecord::Base |
| 82 | 82 | Noosfero::MultiTenancy.setup!(domainname) |
| 83 | 83 | @hosting[domainname] ||= |
| 84 | 84 | begin |
| 85 | - domain = Domain.find_by_name(domainname) | |
| 85 | + domain = Domain.by_name(domainname) | |
| 86 | 86 | !domain.nil? && (domain.owner_type == 'Profile') |
| 87 | 87 | end |
| 88 | 88 | end | ... | ... |
app/models/environment.rb
| ... | ... | @@ -61,7 +61,7 @@ class Environment < ActiveRecord::Base |
| 61 | 61 | |
| 62 | 62 | module Roles |
| 63 | 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 | 65 | end |
| 66 | 66 | end |
| 67 | 67 | |
| ... | ... | @@ -248,7 +248,7 @@ class Environment < ActiveRecord::Base |
| 248 | 248 | |
| 249 | 249 | acts_as_accessible |
| 250 | 250 | |
| 251 | - has_many :units, :order => 'position' | |
| 251 | + has_many :units, -> { order 'position' } | |
| 252 | 252 | has_many :production_costs, :as => :owner |
| 253 | 253 | |
| 254 | 254 | def superior_intances |
| ... | ... | @@ -714,7 +714,7 @@ class Environment < ActiveRecord::Base |
| 714 | 714 | def default_hostname(email_hostname = false) |
| 715 | 715 | domain = 'localhost' |
| 716 | 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 | 718 | domain = email_hostname ? domain : (force_www ? ('www.' + domain) : domain) |
| 719 | 719 | end |
| 720 | 720 | domain |
| ... | ... | @@ -808,7 +808,7 @@ class Environment < ActiveRecord::Base |
| 808 | 808 | end |
| 809 | 809 | |
| 810 | 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 | 812 | template if template && template.is_template? |
| 813 | 813 | end |
| 814 | 814 | |
| ... | ... | @@ -821,7 +821,7 @@ class Environment < ActiveRecord::Base |
| 821 | 821 | end |
| 822 | 822 | |
| 823 | 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 | 825 | template if template && template.is_template? |
| 826 | 826 | end |
| 827 | 827 | |
| ... | ... | @@ -834,7 +834,7 @@ class Environment < ActiveRecord::Base |
| 834 | 834 | end |
| 835 | 835 | |
| 836 | 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 | 838 | template if template && template.is_template? |
| 839 | 839 | end |
| 840 | 840 | |
| ... | ... | @@ -843,7 +843,7 @@ class Environment < ActiveRecord::Base |
| 843 | 843 | end |
| 844 | 844 | |
| 845 | 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 | 847 | template if template && template.is_template |
| 848 | 848 | end |
| 849 | 849 | ... | ... |
app/models/forum.rb
| 1 | 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 | 4 | include PostsLimit |
| 5 | 5 | |
| 6 | 6 | attr_accessible :has_terms_of_use, :terms_of_use, :topic_creation |
| ... | ... | @@ -12,7 +12,7 @@ class Forum < Folder |
| 12 | 12 | |
| 13 | 13 | before_save do |forum| |
| 14 | 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 | 16 | if last_editor && !forum.users_with_agreement.exists?(last_editor) |
| 17 | 17 | forum.users_with_agreement << last_editor |
| 18 | 18 | end |
| ... | ... | @@ -34,14 +34,14 @@ class Forum < Folder |
| 34 | 34 | end |
| 35 | 35 | |
| 36 | 36 | module TopicCreation |
| 37 | - BASE = ActiveSupport::OrderedHash.new | |
| 37 | + BASE = {} | |
| 38 | 38 | BASE['users'] = _('Logged users') |
| 39 | 39 | |
| 40 | - PERSON = ActiveSupport::OrderedHash.new | |
| 40 | + PERSON = {} | |
| 41 | 41 | PERSON['self'] = _('Me') |
| 42 | 42 | PERSON['related'] = _('Friends') |
| 43 | 43 | |
| 44 | - GROUP = ActiveSupport::OrderedHash.new | |
| 44 | + GROUP = {} | |
| 45 | 45 | GROUP['self'] = _('Administrators') |
| 46 | 46 | GROUP['related'] = _('Members') |
| 47 | 47 | ... | ... |
app/models/input.rb
app/models/invitation.rb
| ... | ... | @@ -67,7 +67,7 @@ class Invitation < Task |
| 67 | 67 | end |
| 68 | 68 | |
| 69 | 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 | 71 | rescue |
| 72 | 72 | user = nil |
| 73 | 73 | end | ... | ... |
app/models/moderate_user_registration.rb
app/models/national_region.rb
| ... | ... | @@ -27,12 +27,13 @@ class NationalRegion < ActiveRecord::Base |
| 27 | 27 | :type => NationalRegionType::CITY, |
| 28 | 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 | 37 | return region |
| 37 | 38 | end |
| 38 | 39 | |
| ... | ... | @@ -50,19 +51,19 @@ class NationalRegion < ActiveRecord::Base |
| 50 | 51 | {:name => state_name, |
| 51 | 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 | 60 | return region |
| 59 | 61 | end |
| 60 | 62 | |
| 61 | 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 | 68 | if(country_region) |
| 68 | 69 | ... | ... |
app/models/organization.rb
| ... | ... | @@ -55,7 +55,7 @@ class Organization < Profile |
| 55 | 55 | |
| 56 | 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 | 60 | validate :presence_of_required_fieds, :unless => :is_template |
| 61 | 61 | ... | ... |
app/models/person.rb
| ... | ... | @@ -109,7 +109,8 @@ class Person < Profile |
| 109 | 109 | has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' |
| 110 | 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 | 114 | has_many :suggested_people, -> { |
| 114 | 115 | where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true |
| 115 | 116 | }, through: :suggested_profiles, source: :suggestion |
| ... | ... | @@ -392,7 +393,7 @@ class Person < Profile |
| 392 | 393 | |
| 393 | 394 | |
| 394 | 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 | 397 | end |
| 397 | 398 | |
| 398 | 399 | def has_organization_pending_tasks? |
| ... | ... | @@ -486,7 +487,7 @@ class Person < Profile |
| 486 | 487 | end |
| 487 | 488 | |
| 488 | 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 | 491 | yield friend |
| 491 | 492 | offset = offset + 1 |
| 492 | 493 | end |
| ... | ... | @@ -568,7 +569,7 @@ class Person < Profile |
| 568 | 569 | end |
| 569 | 570 | |
| 570 | 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 | 573 | suggestion.disable if suggestion |
| 573 | 574 | end |
| 574 | 575 | ... | ... |
app/models/product.rb
| ... | ... | @@ -28,7 +28,7 @@ class Product < ActiveRecord::Base |
| 28 | 28 | |
| 29 | 29 | belongs_to :product_category |
| 30 | 30 | |
| 31 | - has_many :inputs, :dependent => :destroy, :order => 'position' | |
| 31 | + has_many :inputs, -> { order 'position' }, dependent: :destroy | |
| 32 | 32 | has_many :price_details, :dependent => :destroy |
| 33 | 33 | has_many :production_costs, :through => :price_details |
| 34 | 34 | |
| ... | ... | @@ -50,7 +50,7 @@ class Product < ActiveRecord::Base |
| 50 | 50 | validates_numericality_of :price, :allow_nil => true |
| 51 | 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 | 55 | scope :from_category, -> category { |
| 56 | 56 | joins(:product_category).where('categories.path LIKE ?', "%#{category.slug}%") if category |
| ... | ... | @@ -75,6 +75,8 @@ class Product < ActiveRecord::Base |
| 75 | 75 | ).uniq |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | + scope :recent, -> limit=nil { order('id DESC').limit(limit) } | |
| 79 | + | |
| 78 | 80 | after_update :save_image |
| 79 | 81 | |
| 80 | 82 | def lat |
| ... | ... | @@ -128,10 +130,6 @@ class Product < ActiveRecord::Base |
| 128 | 130 | product_category ? product_category.name : _('Uncategorized product') |
| 129 | 131 | end |
| 130 | 132 | |
| 131 | - def self.recent(limit = nil) | |
| 132 | - self.find(:all, :order => 'id desc', :limit => limit) | |
| 133 | - end | |
| 134 | - | |
| 135 | 133 | def url |
| 136 | 134 | self.profile.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => id) |
| 137 | 135 | end | ... | ... |
app/models/product_category.rb
| ... | ... | @@ -5,7 +5,7 @@ class ProductCategory < Category |
| 5 | 5 | |
| 6 | 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 | 9 | scope :by_enterprise, -> enterprise { |
| 10 | 10 | distinct.joins(:products). |
| 11 | 11 | where('products.profile_id = ?', enterprise.id) | ... | ... |
app/models/profile.rb
| ... | ... | @@ -62,7 +62,7 @@ class Profile < ActiveRecord::Base |
| 62 | 62 | end |
| 63 | 63 | private |
| 64 | 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 | 66 | end |
| 67 | 67 | end |
| 68 | 68 | |
| ... | ... | @@ -115,6 +115,9 @@ class Profile < ActiveRecord::Base |
| 115 | 115 | } |
| 116 | 116 | scope :no_templates, -> { where is_template: false } |
| 117 | 117 | |
| 118 | + scope :recent, -> limit=nil { order('id DESC').limit(limit) } | |
| 119 | + | |
| 120 | + | |
| 118 | 121 | # Returns a scoped object to select profiles in a given location or in a radius |
| 119 | 122 | # distance from the given location center. |
| 120 | 123 | # The parameter can be the `request.params` with the keys: |
| ... | ... | @@ -178,14 +181,6 @@ class Profile < ActiveRecord::Base |
| 178 | 181 | members(field).where("LOWER(#{field}) LIKE ?", "%#{value.downcase}%") if value |
| 179 | 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 | 184 | def members_by_role(roles) |
| 190 | 185 | Person.members_of(self).by_role(roles) |
| 191 | 186 | end |
| ... | ... | @@ -203,18 +198,17 @@ class Profile < ActiveRecord::Base |
| 203 | 198 | scope :is_public, -> { where visible: true, public_profile: true, secret: false } |
| 204 | 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 | 206 | acts_as_trackable :dependent => :destroy |
| 213 | 207 | |
| 214 | 208 | has_many :profile_activities |
| 215 | 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 | 212 | belongs_to :template, :class_name => 'Profile', :foreign_key => 'template_id' |
| 219 | 213 | |
| 220 | 214 | has_many :comments_received, :class_name => 'Comment', :through => :articles, :source => :comments |
| ... | ... | @@ -295,7 +289,7 @@ class Profile < ActiveRecord::Base |
| 295 | 289 | |
| 296 | 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 | 294 | def find_in_all_tasks(task_id) |
| 301 | 295 | begin |
| ... | ... | @@ -559,7 +553,7 @@ class Profile < ActiveRecord::Base |
| 559 | 553 | # person = Profile['username'] |
| 560 | 554 | # org = Profile.['orgname'] |
| 561 | 555 | def [](identifier) |
| 562 | - self.find_by_identifier(identifier) | |
| 556 | + self.find_by identifier: identifier | |
| 563 | 557 | end |
| 564 | 558 | |
| 565 | 559 | end |
| ... | ... | @@ -738,11 +732,11 @@ private :generate_url, :url_options |
| 738 | 732 | |
| 739 | 733 | def copy_article_tree(article, parent=nil) |
| 740 | 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 | 736 | if original_article |
| 743 | 737 | num = 2 |
| 744 | 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 | 740 | num = num + 1 |
| 747 | 741 | new_name = original_article.name + ' ' + num.to_s |
| 748 | 742 | end |
| ... | ... | @@ -799,10 +793,6 @@ private :generate_url, :url_options |
| 799 | 793 | end |
| 800 | 794 | end |
| 801 | 795 | |
| 802 | - def self.recent(limit = nil) | |
| 803 | - self.find(:all, :order => 'id desc', :limit => limit) | |
| 804 | - end | |
| 805 | - | |
| 806 | 796 | # returns +true+ if the given +user+ can see profile information about this |
| 807 | 797 | # +profile+, and +false+ otherwise. |
| 808 | 798 | def display_info_to?(user) |
| ... | ... | @@ -896,7 +886,7 @@ private :generate_url, :url_options |
| 896 | 886 | has_many :blogs, :source => 'articles', :class_name => 'Blog' |
| 897 | 887 | |
| 898 | 888 | def blog |
| 899 | - self.has_blog? ? self.blogs.first(:order => 'id') : nil | |
| 889 | + self.has_blog? ? self.blogs.order(:id).first : nil | |
| 900 | 890 | end |
| 901 | 891 | |
| 902 | 892 | def has_blog? |
| ... | ... | @@ -906,7 +896,7 @@ private :generate_url, :url_options |
| 906 | 896 | has_many :forums, :source => 'articles', :class_name => 'Forum' |
| 907 | 897 | |
| 908 | 898 | def forum |
| 909 | - self.has_forum? ? self.forums.first(:order => 'id') : nil | |
| 899 | + self.has_forum? ? self.forums.order(:id).first : nil | |
| 910 | 900 | end |
| 911 | 901 | |
| 912 | 902 | def has_forum? |
| ... | ... | @@ -1134,7 +1124,7 @@ private :generate_url, :url_options |
| 1134 | 1124 | settings_items :custom_url_redirection, type: String, default: nil |
| 1135 | 1125 | |
| 1136 | 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 | 1128 | suggestion.disable if suggestion |
| 1139 | 1129 | end |
| 1140 | 1130 | ... | ... |
app/models/profile_activity.rb
| ... | ... | @@ -9,8 +9,12 @@ class ProfileActivity < ActiveRecord::Base |
| 9 | 9 | belongs_to :activity, polymorphic: true |
| 10 | 10 | |
| 11 | 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 | 19 | before_validation :copy_timestamps |
| 16 | 20 | ... | ... |
app/models/profile_list_block.rb
| ... | ... | @@ -18,11 +18,11 @@ class ProfileListBlock < Block |
| 18 | 18 | result = nil |
| 19 | 19 | public_profiles = profiles.is_public.includes([:image,:domains,:preferred_domain,:environment]) |
| 20 | 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 | 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 | 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 | 26 | end |
| 27 | 27 | result.slice(0..get_limit-1) |
| 28 | 28 | end | ... | ... |
app/models/profile_suggestion.rb
| ... | ... | @@ -120,7 +120,8 @@ class ProfileSuggestion < ActiveRecord::Base |
| 120 | 120 | return if suggested_profiles.blank? |
| 121 | 121 | |
| 122 | 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 | 125 | RULES.each do |rule, options| |
| 125 | 126 | begin |
| 126 | 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 | 2 | class Region < Category |
| 3 | - | |
| 4 | - attr_accessible :name | |
| 5 | - | |
| 3 | + | |
| 4 | + attr_accessible :name | |
| 5 | + | |
| 6 | 6 | has_and_belongs_to_many :validators, :class_name => 'Organization', :join_table => :region_validators |
| 7 | 7 | |
| 8 | 8 | require_dependency 'enterprise' # enterprises can also be validators |
| ... | ... | @@ -11,8 +11,10 @@ class Region < Category |
| 11 | 11 | validators.count > 0 |
| 12 | 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 | 19 | end |
| 18 | 20 | ... | ... |
app/models/scrap.rb
| ... | ... | @@ -13,7 +13,9 @@ class Scrap < ActiveRecord::Base |
| 13 | 13 | has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy |
| 14 | 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 | 20 | after_create :create_activity |
| 19 | 21 | after_update :update_activity | ... | ... |
app/models/search_term.rb
| ... | ... | @@ -25,7 +25,7 @@ class SearchTerm < ActiveRecord::Base |
| 25 | 25 | # Therefore the score is 97. Them we sum every score to get the total score |
| 26 | 26 | # for a search term. |
| 27 | 27 | def self.occurrences_scores |
| 28 | - ActiveSupport::OrderedHash[*ActiveRecord::Base.connection.execute( | |
| 28 | + Hash[*ActiveRecord::Base.connection.execute( | |
| 29 | 29 | joins(:occurrences). |
| 30 | 30 | select("search_terms.id, sum(#{SearchTermOccurrence::EXPIRATION_TIME.to_i} - extract(epoch from (now() - search_term_occurrences.created_at))) as value"). |
| 31 | 31 | where("search_term_occurrences.created_at > ?", DateTime.now - SearchTermOccurrence::EXPIRATION_TIME). | ... | ... |
app/models/task.rb
| ... | ... | @@ -137,9 +137,9 @@ class Task < ActiveRecord::Base |
| 137 | 137 | group = klass.to_s.downcase.pluralize |
| 138 | 138 | id = attribute.to_s + "_id" |
| 139 | 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 | 141 | else |
| 142 | - attrb = value || klass.find_by_id(record.send(id)) | |
| 142 | + attrb = value || klass.find_by(id: record.send(id)) | |
| 143 | 143 | end |
| 144 | 144 | if attrb.respond_to?(klass.to_s.downcase + "?") |
| 145 | 145 | unless attrb.send(klass.to_s.downcase + "?") | ... | ... |
app/models/unit.rb
| 1 | 1 | class Unit < ActiveRecord::Base |
| 2 | 2 | |
| 3 | + acts_as_list scope: -> unit { where environment_id: unit.environment_id } | |
| 4 | + | |
| 3 | 5 | attr_accessible :name, :singular, :plural, :environment |
| 4 | 6 | |
| 5 | 7 | validates_presence_of :singular |
| 6 | 8 | validates_presence_of :plural |
| 7 | 9 | |
| 8 | 10 | belongs_to :environment |
| 11 | + | |
| 9 | 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 | 16 | def name |
| 13 | 17 | self.singular | ... | ... |
app/models/user.rb
app/views/layouts/_user.html.erb
app/views/shared/_list_groups.html.erb
| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | </div> |
| 7 | 7 | <span class='profile-details'> |
| 8 | 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 | 10 | <%= _('Type: %s') % _(group.class.identification) %> <br/> |
| 11 | 11 | <%= _('Description: %s') % group.description + '<br/>' if group.community? %> |
| 12 | 12 | <%= _('Members: %s') % group.members_count.to_s %> <br/> | ... | ... |
app/views/spam/_suggest_article.html.erb
| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | <li><strong><%=_('Email')%></strong>: <%=task.email%> </li> |
| 10 | 10 | <li><strong><%=_('Source')%></strong>: <%=task.article_object.source_name%> </li> |
| 11 | 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 | 13 | <li><strong><%=_('Lead')%></strong>: <%=task.article_object.abstract.blank? ? '<em>' + s_('Abstract|empty') + '</em>' : task.article_object.abstract%> </li> |
| 14 | 14 | <li><strong><%=_('Body')%></strong>: |
| 15 | 15 | <div class='suggest-article-body'> | ... | ... |
db/migrate/033_destroy_organization_and_person_infos.rb
| 1 | 1 | class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration |
| 2 | 2 | def self.up |
| 3 | - Person.find(:all).each do |i| | |
| 3 | + Person.find_each do |i| | |
| 4 | 4 | info = ActiveRecord::Base.connection.select_one("select * from person_infos where person_id = #{i.id}") |
| 5 | 5 | i.name = info["name"] unless info["name"].nil? |
| 6 | 6 | i.address = info["address"] unless info["address"].nil? |
| ... | ... | @@ -11,7 +11,7 @@ class DestroyOrganizationAndPersonInfos < ActiveRecord::Migration |
| 11 | 11 | end |
| 12 | 12 | drop_table :person_infos |
| 13 | 13 | |
| 14 | - Organization.find(:all).each do |i| | |
| 14 | + Organization.find_each do |i| | |
| 15 | 15 | info = ActiveRecord::Base.connection.select_one("select * from organization_infos where organization_id = #{i.id}") |
| 16 | 16 | [ "contact_person", "contact_email", "acronym", "foundation_year", "legal_form", "economic_activity", "management_information", "validated" ].each do |field| |
| 17 | 17 | i.send("#{field}=", info[field]) | ... | ... |
db/migrate/043_add_virtual_flag_to_categorizations.rb
| ... | ... | @@ -2,13 +2,13 @@ class AddVirtualFlagToCategorizations < ActiveRecord::Migration |
| 2 | 2 | def self.up |
| 3 | 3 | add_column :articles_categories, :virtual, :boolean, :default => false |
| 4 | 4 | execute('update articles_categories set virtual = (1!=1)') |
| 5 | - Article.find(:all).each do |article| | |
| 5 | + Article.find_each do |article| | |
| 6 | 6 | article.category_ids = article.categories.map(&:id) |
| 7 | 7 | end |
| 8 | 8 | |
| 9 | 9 | add_column :categories_profiles, :virtual, :boolean, :default => false |
| 10 | 10 | execute('update categories_profiles set virtual = (1!=1)') |
| 11 | - Profile.find(:all).each do |profile| | |
| 11 | + Profile.find_each do |profile| | |
| 12 | 12 | profile.category_ids = profile.categories.map(&:id) |
| 13 | 13 | end |
| 14 | 14 | end | ... | ... |
db/migrate/044_create_product_categorizations.rb
| 1 | 1 | class CreateProductCategorizations < ActiveRecord::Migration |
| 2 | 2 | def self.up |
| 3 | - | |
| 3 | + | |
| 4 | 4 | create_table :product_categorizations do |t| |
| 5 | 5 | t.integer :category_id |
| 6 | 6 | t.integer :product_id |
| ... | ... | @@ -11,7 +11,7 @@ class CreateProductCategorizations < ActiveRecord::Migration |
| 11 | 11 | |
| 12 | 12 | total = Product.count.to_f |
| 13 | 13 | percent = 0 |
| 14 | - Product.find(:all).each_with_index do |p,i| | |
| 14 | + Product.find_each_with_index do |p,i| | |
| 15 | 15 | if p.product_category |
| 16 | 16 | ProductCategorization.add_category_to_product(p.product_category, p) |
| 17 | 17 | end | ... | ... |
db/migrate/052_create_templates.rb
db/migrate/069_add_enviroment_id_to_role.rb
| ... | ... | @@ -12,13 +12,13 @@ class AddEnviromentIdToRole < ActiveRecord::Migration |
| 12 | 12 | def self.up |
| 13 | 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 | 17 | roles.each do |role| |
| 18 | 18 | re = RoleWithEnvironment.new(role.attributes) |
| 19 | 19 | re.environment = env |
| 20 | 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 | 22 | ra.role_id = re.id |
| 23 | 23 | ra.save |
| 24 | 24 | end |
| ... | ... | @@ -30,14 +30,14 @@ class AddEnviromentIdToRole < ActiveRecord::Migration |
| 30 | 30 | def self.down |
| 31 | 31 | roles_by_name = {} |
| 32 | 32 | roles_by_key = {} |
| 33 | - roles_with_environment = RoleWithEnvironment.find(:all) | |
| 33 | + roles_with_environment = RoleWithEnvironment.all | |
| 34 | 34 | roles_with_environment.each do |re| |
| 35 | 35 | if re.key |
| 36 | 36 | role = roles_by_name[re.key] || roles_by_key[re.name] || Role.create(re.attributes) |
| 37 | 37 | roles_by_name[role.name] ||= roles_by_key[role.key] ||= role |
| 38 | 38 | end |
| 39 | 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 | 41 | ra.role_id = role.id |
| 42 | 42 | ra.save |
| 43 | 43 | end | ... | ... |
db/migrate/20100413231206_strip_html_from_tag_names.rb
db/migrate/20100621235235_set_product_category_id_to_products.rb
| 1 | 1 | class SetProductCategoryIdToProducts < ActiveRecord::Migration |
| 2 | 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 | 4 | next if product.enterprise.nil? |
| 5 | 5 | product.update_attribute(:product_category_id, ProductCategory.top_level_for(product.enterprise.environment).first.id) |
| 6 | 6 | end | ... | ... |
db/migrate/20100730141134_set_owner_environment_to_enterprises_environment.rb
| 1 | 1 | class SetOwnerEnvironmentToEnterprisesEnvironment < ActiveRecord::Migration |
| 2 | 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 | 5 | update("UPDATE profiles SET environment_id = '%s' WHERE identifier = '%s'" % |
| 6 | 6 | [Person.find(t.requestor_id).environment.id, t.data[:identifier]]) |
| 7 | 7 | end | ... | ... |
db/migrate/20100809044243_dont_accept_null_to_environment_theme.rb
| 1 | 1 | class DontAcceptNullToEnvironmentTheme < ActiveRecord::Migration |
| 2 | 2 | def self.up |
| 3 | - Environment.all(:conditions => {:theme => nil}).each do |environment| | |
| 3 | + Environment.where(theme: nil).find_each do |environment| | |
| 4 | 4 | environment.update_attribute(:theme, 'default') |
| 5 | 5 | end |
| 6 | 6 | |
| ... | ... | @@ -10,7 +10,7 @@ class DontAcceptNullToEnvironmentTheme < ActiveRecord::Migration |
| 10 | 10 | def self.down |
| 11 | 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 | 14 | environment.update_attribute(:theme, nil) |
| 15 | 15 | end |
| 16 | 16 | end | ... | ... |
db/migrate/20100920182433_change_action_tracker_record.rb
| ... | ... | @@ -2,7 +2,7 @@ class ChangeActionTrackerRecord < ActiveRecord::Migration |
| 2 | 2 | def self.up |
| 3 | 3 | rename_column(:action_tracker, :dispatcher_type, :target_type) |
| 4 | 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 | 6 | end |
| 7 | 7 | |
| 8 | 8 | def self.down | ... | ... |
db/migrate/20111228202739_remove_useless_tracked_actions.rb
| ... | ... | @@ -2,7 +2,7 @@ class RemoveUselessTrackedActions < ActiveRecord::Migration |
| 2 | 2 | def self.up |
| 3 | 3 | select_all("SELECT id FROM action_tracker").each do |tracker| |
| 4 | 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 | 6 | if activity |
| 7 | 7 | if (activity.updated_at.to_time < Time.now.months_ago(3)) || verbs.include?(activity.verb) |
| 8 | 8 | activity.destroy | ... | ... |
db/migrate/20120228202739_adapt_create_articles_activity.rb
| ... | ... | @@ -4,7 +4,7 @@ class AdaptCreateArticlesActivity < ActiveRecord::Migration |
| 4 | 4 | # Creating new activities only to recent articles (not grouping) |
| 5 | 5 | def self.up |
| 6 | 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 | 8 | if activity |
| 9 | 9 | activity.destroy |
| 10 | 10 | end | ... | ... |
db/migrate/20120718162001_create_default_licenses.rb
| ... | ... | @@ -14,14 +14,14 @@ class CreateDefaultLicenses < ActiveRecord::Migration |
| 14 | 14 | |
| 15 | 15 | def self.down |
| 16 | 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 | 25 | licenses.compact.map(&:destroy) |
| 26 | 26 | end |
| 27 | 27 | end | ... | ... |
db/migrate/20120818030329_remove_action_tracker_with_target_nil.rb
| 1 | 1 | class RemoveActionTrackerWithTargetNil < ActiveRecord::Migration |
| 2 | 2 | def self.up |
| 3 | 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 | 5 | if activity && activity.target.nil? |
| 6 | 6 | activity.destroy |
| 7 | 7 | end | ... | ... |
db/migrate/20140221142304_move_title_virtual_field_to_name_in_uploaded_file.rb
| ... | ... | @@ -2,8 +2,8 @@ class MoveTitleVirtualFieldToNameInUploadedFile < ActiveRecord::Migration |
| 2 | 2 | def self.up |
| 3 | 3 | UploadedFile.find_each do |uploaded_file| |
| 4 | 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 | 7 | end |
| 8 | 8 | end |
| 9 | 9 | ... | ... |
db/migrate/20140807134625_change_category_display_color_to_string.rb
| ... | ... | @@ -8,7 +8,7 @@ class ChangeCategoryDisplayColorToString < ActiveRecord::Migration |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | 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 | 12 | end |
| 13 | 13 | |
| 14 | 14 | change_table :categories do |t| |
| ... | ... | @@ -25,7 +25,7 @@ class ChangeCategoryDisplayColorToString < ActiveRecord::Migration |
| 25 | 25 | end |
| 26 | 26 | |
| 27 | 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 | 29 | end |
| 30 | 30 | |
| 31 | 31 | change_table :categories do |t| | ... | ... |
db/migrate/20150210143723_add_custom_roles_permission_to_admin_roles.rb
| 1 | 1 | class AddCustomRolesPermissionToAdminRoles < ActiveRecord::Migration |
| 2 | 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 | 5 | environment_admin.permissions.append("manage_custom_roles") |
| 6 | 6 | profile_admin.permissions.append("manage_custom_roles") |
| 7 | 7 | environment_admin.save! |
| 8 | 8 | profile_admin.save! |
| 9 | 9 | end |
| 10 | 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 | 13 | environment_admin.permissions.delete("manage_custom_roles") |
| 14 | 14 | profile_admin.permissions.delete("manage_custom_roles") |
| 15 | 15 | environment_admin.save! | ... | ... |
debian/control
features/step_definitions/activate_enterprise_steps.rb
| 1 | 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 | 3 | value = EnterpriseActivation.all.select { |task| task.enterprise == enterprise}.first.code |
| 4 | 4 | fill_in(field, :with => value) |
| 5 | 5 | end |
| 6 | 6 | |
| 7 | 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 | 9 | end |
| 10 | 10 | |
| 11 | 11 | Given /^"([^\"]*)" is the active enterprise template$/ do |enterprise| |
| 12 | - template = Enterprise.find_by_name(enterprise) | |
| 12 | + template = Enterprise.find_by(name: enterprise) | |
| 13 | 13 | template.boxes.destroy_all |
| 14 | 14 | template.boxes << Box.new |
| 15 | 15 | template.layout_template = 'leftbar' |
| ... | ... | @@ -24,8 +24,8 @@ Given /^"([^\"]*)" is the active enterprise template$/ do |enterprise| |
| 24 | 24 | end |
| 25 | 25 | |
| 26 | 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 | 29 | (template.boxes.size == enterprise.boxes.size).should be_truthy |
| 30 | 30 | (template.layout_template == enterprise.layout_template).should be_truthy |
| 31 | 31 | (template.theme == enterprise.theme).should be_truthy |
| ... | ... | @@ -34,8 +34,8 @@ Given /^"([^\"]*)" has "([^\"]*)" as template$/ do |ent, templ| |
| 34 | 34 | end |
| 35 | 35 | |
| 36 | 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 | 39 | (template.boxes.size == enterprise.boxes.size).should be_falsey |
| 40 | 40 | (template.layout_template == enterprise.layout_template).should be_falsey |
| 41 | 41 | (template.theme == enterprise.theme).should be_falsey |
| ... | ... | @@ -44,16 +44,16 @@ Given /^"([^\"]*)" doesnt have "([^\"]*)" as template$/ do |ent, templ| |
| 44 | 44 | end |
| 45 | 45 | |
| 46 | 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 | 49 | end |
| 50 | 50 | |
| 51 | 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 | 53 | end |
| 54 | 54 | |
| 55 | 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 | 57 | end |
| 58 | 58 | |
| 59 | 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 "([^\"]*)" with the following data$/ do |conte |
| 10 | 10 | end |
| 11 | 11 | |
| 12 | 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 | 14 | community = article.profile |
| 15 | 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 | 18 | raise "Could not find #{user_exception} in #{community.name} community." if my_user.nil? |
| 19 | 19 | |
| 20 | 20 | article.article_privacy_exceptions << my_user | ... | ... |
features/step_definitions/create_community_steps.rb
| ... | ... | @@ -33,7 +33,7 @@ Given /^I reject community "(.+)"$/ do |community| |
| 33 | 33 | end |
| 34 | 34 | |
| 35 | 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 | 37 | text = "Created at: #{show_date(com.created_at)}" |
| 38 | 38 | has_content?(text) |
| 39 | 39 | end | ... | ... |
features/step_definitions/invitation_steps.rb
| 1 | 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 | 3 | visit("/myprofile/#{identifier}/profile_members") |
| 4 | 4 | first(:link, "Invite people to join").click |
| 5 | 5 | choose("Email") | ... | ... |
features/step_definitions/noosfero_steps.rb
| ... | ... | @@ -3,7 +3,7 @@ Given /^the following users?$/ do |table| |
| 3 | 3 | table.hashes.each do |item| |
| 4 | 4 | person_data = item.dup |
| 5 | 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 | 7 | email = item[:email] || item[:login] + "@example.com" |
| 8 | 8 | user = User.create!(:login => item[:login], :password => '123456', :password_confirmation => '123456', :email => email, :person_data => person_data) |
| 9 | 9 | user.activate |
| ... | ... | @@ -15,12 +15,12 @@ Given /^the following users?$/ do |table| |
| 15 | 15 | end |
| 16 | 16 | |
| 17 | 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 | 19 | end |
| 20 | 20 | |
| 21 | 21 | Given /^"(.+)" is (online|offline|busy) in chat$/ do |user, status| |
| 22 | 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 | 24 | end |
| 25 | 25 | |
| 26 | 26 | Given /^the following (community|communities|enterprises?|organizations?)$/ do |kind,table| |
| ... | ... | @@ -40,11 +40,11 @@ Given /^the following (community|communities|enterprises?|organizations?)$/ do | |
| 40 | 40 | d.save(:validate => false) |
| 41 | 41 | end |
| 42 | 42 | if city |
| 43 | - c = City.find_by_name city | |
| 43 | + c = City.find_by name: city | |
| 44 | 44 | organization.region = c |
| 45 | 45 | end |
| 46 | 46 | if category && !category.blank? |
| 47 | - cat = Category.find_by_slug category | |
| 47 | + cat = Category.find_by slug: category | |
| 48 | 48 | ProfileCategorization.add_category_to_profile(cat, organization) |
| 49 | 49 | end |
| 50 | 50 | if img_name |
| ... | ... | @@ -56,15 +56,15 @@ Given /^the following (community|communities|enterprises?|organizations?)$/ do | |
| 56 | 56 | end |
| 57 | 57 | |
| 58 | 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 | 62 | bsc.enterprises << enterprise |
| 63 | 63 | end |
| 64 | 64 | |
| 65 | 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 | 69 | bsc.enterprises.should include(enterprise) |
| 70 | 70 | end |
| ... | ... | @@ -121,7 +121,7 @@ Given /^the following (articles|events|blogs|folders|forums|galleries|uploaded f |
| 121 | 121 | translation_of_id = nil |
| 122 | 122 | if item["translation_of"] |
| 123 | 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 | 125 | translation_of_id = article.id if article |
| 126 | 126 | end |
| 127 | 127 | item.delete("translation_of") |
| ... | ... | @@ -135,10 +135,10 @@ Given /^the following (articles|events|blogs|folders|forums|galleries|uploaded f |
| 135 | 135 | end |
| 136 | 136 | result = klass.new(item) |
| 137 | 137 | if !parent.blank? |
| 138 | - result.parent = Article.find_by_name(parent) | |
| 138 | + result.parent = Article.find_by(name: parent) | |
| 139 | 139 | end |
| 140 | 140 | if category |
| 141 | - cat = Category.find_by_slug category | |
| 141 | + cat = Category.find_by slug: category | |
| 142 | 142 | if cat |
| 143 | 143 | result.add_category(cat) |
| 144 | 144 | end |
| ... | ... | @@ -157,7 +157,7 @@ Given /^the following files$/ do |table| |
| 157 | 157 | file = "/files/#{item[:file]}" |
| 158 | 158 | article = UploadedFile.new(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime])) |
| 159 | 159 | if item[:parent] |
| 160 | - article.parent = Article.find_by_slug(item[:parent]) | |
| 160 | + article.parent = Article.find_by slug: item[:parent] | |
| 161 | 161 | end |
| 162 | 162 | article.save! |
| 163 | 163 | if item[:homepage] |
| ... | ... | @@ -180,7 +180,7 @@ Given /^the following articles? with images?$/ do |table| |
| 180 | 180 | img_tag += "/>" |
| 181 | 181 | article = TinyMceArticle.new(:profile => owner, :name => item[:name], :body => img_tag) |
| 182 | 182 | if item[:parent] |
| 183 | - article.parent = Article.find_by_slug(item[:parent]) | |
| 183 | + article.parent = Article.find_by slug: item[:parent] | |
| 184 | 184 | end |
| 185 | 185 | article.save! |
| 186 | 186 | if item[:homepage] |
| ... | ... | @@ -194,14 +194,14 @@ Given /^the following products?$/ do |table| |
| 194 | 194 | table.hashes.each do |item| |
| 195 | 195 | data = item.dup |
| 196 | 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 | 198 | data.merge!(:enterprise => owner, :product_category => category) |
| 199 | 199 | if data[:img] |
| 200 | 200 | img = Image.create!(:uploaded_data => fixture_file_upload('/files/'+data.delete("img")+'.png', 'image/png')) |
| 201 | 201 | data.merge!(:image_id => img.id) |
| 202 | 202 | end |
| 203 | 203 | if data[:qualifier] |
| 204 | - qualifier = Qualifier.find_by_name(data.delete("qualifier")) | |
| 204 | + qualifier = Qualifier.find_by name: data.delete("qualifier") | |
| 205 | 205 | data.merge!(:qualifiers => [qualifier]) |
| 206 | 206 | end |
| 207 | 207 | product = Product.create!(data, :without_protection => true) |
| ... | ... | @@ -211,9 +211,9 @@ end |
| 211 | 211 | Given /^the following inputs?$/ do |table| |
| 212 | 212 | table.hashes.each do |item| |
| 213 | 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 | 217 | solidary = data.delete("solidary") |
| 218 | 218 | input = Input.create!(data.merge(:product => product, :product_category => category, :unit => unit, |
| 219 | 219 | :is_from_solidarity_economy => solidary), :without_protection => true) |
| ... | ... | @@ -224,7 +224,7 @@ end |
| 224 | 224 | Given /^the following states$/ do |table| |
| 225 | 225 | table.hashes.each do |item| |
| 226 | 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 | 228 | State.create!(data.merge(:environment => Environment.default, :validators => [validator]), :without_protection => true) |
| 229 | 229 | else |
| 230 | 230 | r = State.create!(data.merge(:environment => Environment.default)) |
| ... | ... | @@ -235,7 +235,7 @@ end |
| 235 | 235 | Given /^the following validation info$/ do |table| |
| 236 | 236 | table.hashes.each do |item| |
| 237 | 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 | 239 | ValidationInfo.create!(data.merge(:organization => organization)) |
| 240 | 240 | end |
| 241 | 241 | end |
| ... | ... | @@ -245,7 +245,7 @@ Given /^the following (product_categories|product_category|category|categories|r |
| 245 | 245 | table.hashes.each do |row| |
| 246 | 246 | parent = row.delete("parent") |
| 247 | 247 | if !parent.blank? |
| 248 | - parent = Category.find_by_slug(parent.to_slug) | |
| 248 | + parent = Category.find_by slug: parent.to_slug | |
| 249 | 249 | row.merge!({:parent_id => parent.id}) |
| 250 | 250 | end |
| 251 | 251 | category = klass.create!({:environment => Environment.default}.merge(row)) |
| ... | ... | @@ -263,7 +263,7 @@ Given /^the following certifiers$/ do |table| |
| 263 | 263 | row = row.dup |
| 264 | 264 | qualifiers_list = row.delete("qualifiers") |
| 265 | 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 | 267 | end |
| 268 | 268 | Certifier.create!(row.merge(:environment_id => 1), :without_protection => true) |
| 269 | 269 | end |
| ... | ... | @@ -279,8 +279,8 @@ end |
| 279 | 279 | |
| 280 | 280 | Given /^the following price details?$/ do |table| |
| 281 | 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 | 284 | product.price_details.create!(item.merge(:production_cost => production_cost)) |
| 285 | 285 | end |
| 286 | 286 | end |
| ... | ... | @@ -297,7 +297,7 @@ Given /^I am logged in as "(.+)"$/ do |username| |
| 297 | 297 | end |
| 298 | 298 | |
| 299 | 299 | Given /^"([^"]*)" is environment admin$/ do |person| |
| 300 | - user = Profile.find_by_name(person) | |
| 300 | + user = Profile.find_by name: person | |
| 301 | 301 | e = Environment.default |
| 302 | 302 | |
| 303 | 303 | e.add_admin(user) |
| ... | ... | @@ -337,41 +337,41 @@ Given /^"(.+)" is a member of "(.+)"$/ do |person, profile| |
| 337 | 337 | end |
| 338 | 338 | |
| 339 | 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 | 341 | end |
| 342 | 342 | |
| 343 | 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 | 346 | community.affiliate(person, Profile::Roles.member(community.environment.id)) |
| 347 | 347 | end |
| 348 | 348 | |
| 349 | 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 | 352 | org.add_admin(user) |
| 353 | 353 | end |
| 354 | 354 | |
| 355 | 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 | 358 | org.add_moderator(user) |
| 359 | 359 | end |
| 360 | 360 | |
| 361 | 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 | 364 | org.admins.should include(user) |
| 365 | 365 | end |
| 366 | 366 | |
| 367 | 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 | 370 | profile.members_by_role(Profile::Roles.moderator(profile.environment.id)).should include(person) |
| 371 | 371 | end |
| 372 | 372 | |
| 373 | 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 | 375 | end |
| 376 | 376 | |
| 377 | 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 | 393 | end |
| 394 | 394 | |
| 395 | 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 | 397 | expected = table.hashes.first |
| 398 | 398 | data = expected.keys.inject({}) { |hash, key| hash[key] = profile.send(key).to_s; hash } |
| 399 | 399 | data.should == expected |
| ... | ... | @@ -408,12 +408,12 @@ Given /^"(.+)" is friend of "(.+)"$/ do |person, friend| |
| 408 | 408 | end |
| 409 | 409 | |
| 410 | 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 | 412 | enterprise.block |
| 413 | 413 | end |
| 414 | 414 | |
| 415 | 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 | 417 | enterprise.enabled = false |
| 418 | 418 | enterprise.save |
| 419 | 419 | end |
| ... | ... | @@ -470,7 +470,7 @@ Given /^the profile "(.+)" has no blocks$/ do |profile| |
| 470 | 470 | end |
| 471 | 471 | |
| 472 | 472 | Given /^the articles of "(.+)" are moderated$/ do |organization| |
| 473 | - organization = Organization.find_by_name(organization) | |
| 473 | + organization = Organization.find_by name: organization | |
| 474 | 474 | organization.moderated_articles = true |
| 475 | 475 | organization.save |
| 476 | 476 | end |
| ... | ... | @@ -478,7 +478,7 @@ end |
| 478 | 478 | Given /^the following comments?$/ do |table| |
| 479 | 479 | table.hashes.each do |item| |
| 480 | 480 | data = item.dup |
| 481 | - article = Article.find_by_name(data.delete("article")) | |
| 481 | + article = Article.find_by name: data.delete("article") | |
| 482 | 482 | author = data.delete("author") |
| 483 | 483 | comment = article.comments.build(data) |
| 484 | 484 | if author |
| ... | ... | @@ -489,7 +489,7 @@ Given /^the following comments?$/ do |table| |
| 489 | 489 | end |
| 490 | 490 | |
| 491 | 491 | Given /^the community "(.+)" is closed$/ do |community| |
| 492 | - community = Community.find_by_name(community) | |
| 492 | + community = Community.find_by name: community | |
| 493 | 493 | community.closed = true |
| 494 | 494 | community.save |
| 495 | 495 | end |
| ... | ... | @@ -510,8 +510,8 @@ Given /^the following units?$/ do |table| |
| 510 | 510 | end |
| 511 | 511 | |
| 512 | 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 | 515 | AddMember.create!(:person => person, :organization => organization) |
| 516 | 516 | end |
| 517 | 517 | |
| ... | ... | @@ -531,7 +531,7 @@ Given /^the environment domain is "([^\"]*)"$/ do |domain| |
| 531 | 531 | end |
| 532 | 532 | |
| 533 | 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 | 535 | end |
| 536 | 536 | |
| 537 | 537 | Then /^I should receive an e-mail on (.*)$/ do |address| |
| ... | ... | @@ -547,13 +547,13 @@ end |
| 547 | 547 | |
| 548 | 548 | Then /^there should be an? (.+) named "([^\"]*)"$/ do |klass_name, profile_name| |
| 549 | 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 | 551 | end |
| 552 | 552 | |
| 553 | 553 | Then /^"([^\"]*)" profile should exist$/ do |profile_selector| |
| 554 | 554 | profile = nil |
| 555 | 555 | begin |
| 556 | - profile = Profile.find_by_name(profile_selector) | |
| 556 | + profile = Profile.find_by(name: profile_selector) | |
| 557 | 557 | profile.nil?.should be_falsey |
| 558 | 558 | rescue |
| 559 | 559 | profile.nil?.should be_falsey |
| ... | ... | @@ -563,7 +563,7 @@ end |
| 563 | 563 | Then /^"([^\"]*)" profile should not exist$/ do |profile_selector| |
| 564 | 564 | profile = nil |
| 565 | 565 | begin |
| 566 | - profile = Profile.find_by_name(profile_selector) | |
| 566 | + profile = Profile.find_by(name: profile_selector) | |
| 567 | 567 | profile.nil?.should be_truthy |
| 568 | 568 | rescue |
| 569 | 569 | profile.nil?.should be_truthy |
| ... | ... | @@ -575,7 +575,7 @@ When 'I log off' do |
| 575 | 575 | end |
| 576 | 576 | |
| 577 | 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 | 579 | path = url_for(product.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => product, :only_path => true)) |
| 580 | 580 | if response.class.to_s == 'Webrat::SeleniumResponse' |
| 581 | 581 | URI.parse(response.selenium.get_location).path.should == path_to(path) |
| ... | ... | @@ -589,7 +589,7 @@ Given /^the following enterprise homepages?$/ do |table| |
| 589 | 589 | table.hashes.each do |item| |
| 590 | 590 | data = item.dup |
| 591 | 591 | home = EnterpriseHomepage.new(:name => data[:name]) |
| 592 | - ent = Enterprise.find_by_identifier(data[:enterprise]) | |
| 592 | + ent = Enterprise.find_by(identifier: data[:enterprise]) | |
| 593 | 593 | ent.articles << home |
| 594 | 594 | end |
| 595 | 595 | end |
| ... | ... | @@ -609,7 +609,7 @@ end |
| 609 | 609 | |
| 610 | 610 | Given /^the following cities$/ do |table| |
| 611 | 611 | table.hashes.each do |item| |
| 612 | - state = State.find_by_acronym item[:state] | |
| 612 | + state = State.find_by acronym: item[:state] | |
| 613 | 613 | if !state |
| 614 | 614 | state = State.create!(:name => item[:state], :acronym => item[:state], :environment_id => Environment.default.id) |
| 615 | 615 | end |
| ... | ... | @@ -626,7 +626,7 @@ end |
| 626 | 626 | |
| 627 | 627 | Given /^the following tags$/ do |table| |
| 628 | 628 | table.hashes.each do |item| |
| 629 | - article = Article.find_by_name item[:article] | |
| 629 | + article = Article.find_by name: item[:article] | |
| 630 | 630 | article.tag_list.add item[:name] |
| 631 | 631 | article.save! |
| 632 | 632 | end |
| ... | ... | @@ -639,7 +639,7 @@ When /^I search ([^\"]*) for "([^\"]*)"$/ do |asset, query| |
| 639 | 639 | end |
| 640 | 640 | |
| 641 | 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 | 643 | path = url_for(p.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => p)) |
| 644 | 644 | |
| 645 | 645 | with_scope('.zoomable-image') do |
| ... | ... | @@ -648,7 +648,7 @@ Then /^I should see ([^\"]*)'s product image$/ do |product_name| |
| 648 | 648 | end |
| 649 | 649 | |
| 650 | 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 | 652 | path = url_for(p.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => p)) |
| 653 | 653 | |
| 654 | 654 | with_scope('.zoomable-image') do |
| ... | ... | @@ -673,14 +673,14 @@ Then /^I should not see ([^\"]*)'s community image$/ do |name| |
| 673 | 673 | end |
| 674 | 674 | |
| 675 | 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 | 678 | a.last_changed_by = p |
| 679 | 679 | a.save! |
| 680 | 680 | end |
| 681 | 681 | |
| 682 | 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 | 684 | row = table.hashes.first |
| 685 | 685 | a.update(row) |
| 686 | 686 | end |
| ... | ... | @@ -720,7 +720,7 @@ Given /^the profile (.*) is configured to (.*) after login$/ do |profile, option |
| 720 | 720 | when 'redirect to profile control panel' |
| 721 | 721 | 'user_control_panel' |
| 722 | 722 | end |
| 723 | - profile = Profile.find_by_identifier(profile) | |
| 723 | + profile = Profile.find_by identifier: profile | |
| 724 | 724 | profile.redirection_after_login = redirection |
| 725 | 725 | profile.save |
| 726 | 726 | end | ... | ... |
features/support/paths.rb
| ... | ... | @@ -15,7 +15,7 @@ module NavigationHelpers |
| 15 | 15 | # Here is an example that pulls values out of the Regexp: |
| 16 | 16 | # |
| 17 | 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 | 20 | when /^\// |
| 21 | 21 | page_name |
| ... | ... | @@ -24,19 +24,19 @@ module NavigationHelpers |
| 24 | 24 | '/site/welcome' |
| 25 | 25 | |
| 26 | 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 | 29 | when /category "([^"]+)"/ |
| 30 | - '/cat/%s' % Category.find_by_name($1).slug | |
| 30 | + '/cat/%s' % Category.find_by(name: $1).slug | |
| 31 | 31 | |
| 32 | 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 | 34 | "/myprofile/#{$2}/cms/edit/#{article_id}" |
| 35 | 35 | |
| 36 | 36 | when /edit (.*Block) of (.+)/ |
| 37 | 37 | owner = Profile[$2] |
| 38 | 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 | 40 | "/myprofile/#{$2}/profile_design/edit/#{block.id}" |
| 41 | 41 | |
| 42 | 42 | when /^(.*)'s homepage$/ |
| ... | ... | @@ -85,18 +85,18 @@ module NavigationHelpers |
| 85 | 85 | '/myprofile/%s/cms' % profile_identifier($1) |
| 86 | 86 | |
| 87 | 87 | when /^"(.+)" edit page/ |
| 88 | - article = Article.find_by_name($1) | |
| 88 | + article = Article.find_by name: $1 | |
| 89 | 89 | '/myprofile/%s/cms/edit/%s' % [article.profile.identifier, article.id] |
| 90 | 90 | |
| 91 | 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 | 94 | when /^(.+)'s new product page/ |
| 95 | 95 | '/myprofile/%s/manage_products/new' % profile_identifier($1) |
| 96 | 96 | |
| 97 | 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 | 100 | '/myprofile/%s/manage_products/show/%s' % [enterprise.identifier, product.id] |
| 101 | 101 | |
| 102 | 102 | when /^(.*)'s products page$/ |
| ... | ... | @@ -138,7 +138,7 @@ module NavigationHelpers |
| 138 | 138 | end |
| 139 | 139 | |
| 140 | 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 | 142 | profile.identifier |
| 143 | 143 | end |
| 144 | 144 | end | ... | ... |
lib/acts_as_filesystem.rb
| ... | ... | @@ -120,7 +120,7 @@ module ActsAsFileSystem |
| 120 | 120 | |
| 121 | 121 | def top_ancestor |
| 122 | 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 | 124 | else |
| 125 | 125 | self.hierarchy.first |
| 126 | 126 | end | ... | ... |
lib/acts_as_having_boxes.rb
| ... | ... | @@ -2,7 +2,7 @@ module ActsAsHavingBoxes |
| 2 | 2 | |
| 3 | 3 | module ClassMethods |
| 4 | 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 | 6 | self.send(:include, ActsAsHavingBoxes) |
| 7 | 7 | end |
| 8 | 8 | end | ... | ... |
lib/acts_as_having_posts.rb
| 1 | 1 | module ActsAsHavingPosts |
| 2 | 2 | |
| 3 | 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 | 11 | attr_accessor :feed_attrs |
| 8 | 12 | ... | ... |
lib/noosfero/action_tracker_ext.rb
| ... | ... | @@ -9,7 +9,9 @@ Rails.configuration.to_prepare do |
| 9 | 9 | end |
| 10 | 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 | 16 | after_create :create_activity |
| 15 | 17 | after_update :update_activity | ... | ... |
lib/noosfero/api/helpers.rb
| ... | ... | @@ -22,7 +22,7 @@ require_relative '../../find_by_contents' |
| 22 | 22 | |
| 23 | 23 | def current_user |
| 24 | 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 | 26 | @current_user |
| 27 | 27 | end |
| 28 | 28 | |
| ... | ... | @@ -268,7 +268,7 @@ require_relative '../../find_by_contents' |
| 268 | 268 | # keys (unique) - A hash consisting of keys that must be unique |
| 269 | 269 | def unique_attributes!(obj, keys) |
| 270 | 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 | 272 | end |
| 273 | 273 | end |
| 274 | 274 | |
| ... | ... | @@ -342,7 +342,7 @@ require_relative '../../find_by_contents' |
| 342 | 342 | end |
| 343 | 343 | |
| 344 | 344 | def detect_stuff_by_domain |
| 345 | - @domain = Domain.find_by_name(request.host) | |
| 345 | + @domain = Domain.by_name(request.host) | |
| 346 | 346 | if @domain.nil? |
| 347 | 347 | @environment = Environment.default |
| 348 | 348 | if @environment.nil? && Rails.env.development? | ... | ... |
lib/noosfero/api/session.rb
| ... | ... | @@ -73,7 +73,7 @@ module Noosfero |
| 73 | 73 | # Example Request: |
| 74 | 74 | # PATCH /activate?activation_code=28259abd12cc6a64ef9399cf3286cb998b96aeaf |
| 75 | 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 | 77 | if user |
| 78 | 78 | unless user.environment.enabled?('admin_must_approve_new_users') |
| 79 | 79 | if user.activate |
| ... | ... | @@ -141,7 +141,7 @@ module Noosfero |
| 141 | 141 | # Example Request: |
| 142 | 142 | # PATCH /new_password?code=xxxx&password=secret&password_confirmation=secret |
| 143 | 143 | patch "/new_password" do |
| 144 | - change_password = ChangePassword.find_by_code(params[:code]) | |
| 144 | + change_password = ChangePassword.find_by code: params[:code] | |
| 145 | 145 | not_found! if change_password.nil? |
| 146 | 146 | |
| 147 | 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 | 9 | get ':id/activities' do |
| 10 | 10 | profile = environment.profiles |
| 11 | 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 | 13 | activities = profile.activities.map(&:activity) |
| 14 | 14 | present activities, :with => Entities::Activity, :current_person => current_person |
| 15 | 15 | end | ... | ... |
lib/noosfero/api/v1/articles.rb
| ... | ... | @@ -74,7 +74,7 @@ module Noosfero |
| 74 | 74 | current_person.register_report(abuse_report, profile) |
| 75 | 75 | |
| 76 | 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 | 78 | Delayed::Job.enqueue DownloadReportedImagesJob.new(abuse_report, article) |
| 79 | 79 | end |
| 80 | 80 | |
| ... | ... | @@ -253,7 +253,7 @@ module Noosfero |
| 253 | 253 | get ':id/home_page' do |
| 254 | 254 | profiles = environment.profiles |
| 255 | 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 | 257 | present_partial profile.home_page, :with => Entities::Article |
| 258 | 258 | end |
| 259 | 259 | end |
| ... | ... | @@ -275,7 +275,7 @@ module Noosfero |
| 275 | 275 | profile = environment.send(kind.pluralize).find(params["#{kind}_id"]) |
| 276 | 276 | |
| 277 | 277 | if params[:path].present? |
| 278 | - article = profile.articles.find_by_path(params[:path]) | |
| 278 | + article = profile.articles.find_by path: params[:path] | |
| 279 | 279 | if !article || !article.display_to?(current_person) |
| 280 | 280 | article = forbidden! |
| 281 | 281 | end | ... | ... |
lib/noosfero/api/v1/communities.rb
| ... | ... | @@ -49,7 +49,7 @@ module Noosfero |
| 49 | 49 | end |
| 50 | 50 | |
| 51 | 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 | 53 | present community, :with => Entities::Community, :current_person => current_person |
| 54 | 54 | end |
| 55 | 55 | ... | ... |
lib/noosfero/api/v1/enterprises.rb
| ... | ... | @@ -26,7 +26,7 @@ module Noosfero |
| 26 | 26 | |
| 27 | 27 | desc "Return one enterprise by id" |
| 28 | 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 | 30 | present enterprise, :with => Entities::Enterprise, :current_person => current_person |
| 31 | 31 | end |
| 32 | 32 | ... | ... |
lib/noosfero/api/v1/people.rb
| ... | ... | @@ -46,7 +46,7 @@ module Noosfero |
| 46 | 46 | |
| 47 | 47 | desc "Return the person information" |
| 48 | 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 | 50 | return not_found! if person.blank? |
| 51 | 51 | present person, :with => Entities::Person, :current_person => current_person |
| 52 | 52 | end |
| ... | ... | @@ -87,7 +87,7 @@ module Noosfero |
| 87 | 87 | |
| 88 | 88 | desc "Return the person friends" |
| 89 | 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 | 91 | return not_found! if person.blank? |
| 92 | 92 | friends = person.friends.visible |
| 93 | 93 | present friends, :with => Entities::Person, :current_person => current_person |
| ... | ... | @@ -114,7 +114,7 @@ module Noosfero |
| 114 | 114 | resource :members do |
| 115 | 115 | paginate max_per_page: MAX_PER_PAGE |
| 116 | 116 | get do |
| 117 | - profile = environment.profiles.find_by_id(params[:profile_id]) | |
| 117 | + profile = environment.profiles.find_by id: params[:profile_id] | |
| 118 | 118 | members = select_filtered_collection_of(profile, 'members', params) |
| 119 | 119 | present members, :with => Entities::Person, :current_person => current_person |
| 120 | 120 | end | ... | ... |
lib/noosfero/api/v1/profiles.rb
| ... | ... | @@ -16,7 +16,7 @@ module Noosfero |
| 16 | 16 | get ':id' do |
| 17 | 17 | profiles = environment.profiles |
| 18 | 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 | 20 | present profile, :with => Entities::Profile, :current_person => current_person |
| 21 | 21 | end |
| 22 | 22 | end | ... | ... |
lib/noosfero/api/v1/users.rb
lib/noosfero/core_ext/active_record.rb
| ... | ... | @@ -63,8 +63,12 @@ class ActiveRecord::Base |
| 63 | 63 | end |
| 64 | 64 | |
| 65 | 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 | 72 | end |
| 69 | 73 | alias_method_chain :count, :distinct |
| 70 | 74 | end | ... | ... |
lib/time_scopes.rb
| ... | ... | @@ -8,11 +8,11 @@ module TimeScopes |
| 8 | 8 | if base.respond_to?(:scope) && base.attribute_names.include?('created_at') |
| 9 | 9 | base.class_eval do |
| 10 | 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 | 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 | 17 | end |
| 18 | 18 | end | ... | ... |
plugins/analytics/test/functional/content_viewer_controller_test.rb
| ... | ... | @@ -37,7 +37,7 @@ class ContentViewerControllerTest < ActionController::TestCase |
| 37 | 37 | @request.env['HTTP_REFERER'] = first_url |
| 38 | 38 | get :view_page, profile: @community.identifier, page: @community.articles.last.path.split('/') |
| 39 | 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 | 42 | second_page_view = @community.page_views.order(:id).last |
| 43 | 43 | assert_equal first_page_view, second_page_view.referer_page_view |
| ... | ... | @@ -48,7 +48,7 @@ class ContentViewerControllerTest < ActionController::TestCase |
| 48 | 48 | future = Time.now + 2*AnalyticsPlugin::TimeOnPageUpdateInterval |
| 49 | 49 | Time.stubs(:now).returns(future) |
| 50 | 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 | 52 | end |
| 53 | 53 | |
| 54 | 54 | end | ... | ... |