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