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