Commit 3547587281bfe732d1ebcb3281b0f45f6e5ab34f

Authored by Evandro Junior
2 parents 20130dd7 555c63fe
Exists in api_visitor

merge with community master

Showing 381 changed files with 5661 additions and 3925 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 381 files displayed.

.gitlab-ci.yml
... ... @@ -14,6 +14,10 @@ stages:
14 14 # script: bundle exec rake ci:smoke
15 15 # stage: smoke-tests
16 16  
  17 +api:
  18 + script: bundle exec rake test:api
  19 + stage: all-tests
  20 +
17 21 units:
18 22 script: bundle exec rake test:units
19 23 stage: all-tests
... ...
.travis.yml
... ... @@ -6,24 +6,21 @@ notifications:
6 6 template:
7 7 - "%{repository_slug} %{branch} %{commit} %{commit_subject} - %{result} %{build_url}"
8 8  
  9 +# trusty constainers take more time to start
  10 +#dist: trusty
  11 +
9 12 language: ruby
10 13 rvm:
11   - - 2.2.3
  14 + - 2.2
  15 + # ruby 2.3 works but isn't stable on travis
  16 +
  17 +cache: bundler
12 18  
13   -sudo: false
14 19 addons:
15 20 apt:
16 21 packages:
17   - - po4a
18   - - iso-codes
19 22 - tango-icon-theme
20 23 - pidgin-data
21   - # for gem extensions
22   - - libmagickwand-dev
23   - - libpq-dev
24   - - libreadline-dev
25   - - libsqlite3-dev
26   - - libxslt1-dev
27 24 artifacts:
28 25 paths:
29 26 - $(ls tmp/artifact* | tr "\n" ":")
... ... @@ -32,7 +29,6 @@ addons:
32 29 before_install:
33 30 - export GEM_HOME=$PWD/vendor/bundle/ruby/2.2.0
34 31 - gem install bundler
35   -cache: bundler
36 32  
37 33 before_script:
38 34 - mkdir -p tmp/{pids,cache} log cache
... ... @@ -41,19 +37,25 @@ before_script:
41 37 # database
42 38 - cp config/database.yml.travis config/database.yml
43 39 - psql -c 'create database myapp_test;' -U postgres
44   - - bundle exec rake db:schema:load &>/dev/null
  40 + - bundle exec rake db:schema:load
45 41 - bundle exec rake db:migrate &>/dev/null
46 42  
47 43 env:
  44 + - TASK=test:api
48 45 - TASK=test:units
49 46 - TASK=test:functionals
50 47 - TASK=test:integration
51   - - TASK=cucumber LANG=en
52   - - TASK=selenium
53   - - SLICE=1/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install
54   - - SLICE=2/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install
55   - - SLICE=3/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install
56   - - SLICE=4/4 TASK=test:noosfero_plugins BUNDLE_OPTS=install
  48 + - SLICE=1/2 TASK=cucumber LANG=en
  49 + - SLICE=2/2 TASK=cucumber LANG=en
  50 + - SLICE=1/4 TASK=selenium
  51 + - SLICE=2/4 TASK=selenium
  52 + - SLICE=3/4 TASK=selenium
  53 + - SLICE=4/4 TASK=selenium
  54 + - SLICE=1/5 TASK=test:noosfero_plugins BUNDLE_OPTS=install
  55 + - SLICE=2/5 TASK=test:noosfero_plugins BUNDLE_OPTS=install
  56 + - SLICE=3/5 TASK=test:noosfero_plugins BUNDLE_OPTS=install
  57 + - SLICE=4/5 TASK=test:noosfero_plugins BUNDLE_OPTS=install
  58 + - SLICE=5/5 TASK=test:noosfero_plugins BUNDLE_OPTS=install
57 59  
58 60 script:
59 61 - bundle exec rake $TASK
... ...
Gemfile
... ... @@ -31,6 +31,7 @@ gem 'whenever', :require => false
31 31 gem 'eita-jrails', '~> 0.10.0', require: 'jrails'
32 32 gem 'diffy', '~> 3.0'
33 33 gem 'slim'
  34 +gem 'activerecord-session_store', ('1.0.0.pre' if RUBY_VERSION >= '2.3.0')
34 35  
35 36 # API dependencies
36 37 gem 'grape', '~> 0.12'
... ... @@ -51,8 +52,6 @@ gem 'protected_attributes'
51 52 gem 'rails-observers'
52 53 gem 'actionpack-page_caching'
53 54 gem 'actionpack-action_caching'
54   -gem 'activerecord-session_store'
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
... ... @@ -3,6 +3,7 @@ class CmsController &lt; MyProfileController
3 3 protect 'edit_profile', :profile, :only => [:set_home_page]
4 4  
5 5 include ArticleHelper
  6 + include CategoriesHelper
6 7  
7 8 def search_tags
8 9 arg = params[:term].downcase
... ... @@ -33,7 +34,7 @@ class CmsController &lt; MyProfileController
33 34  
34 35 protect_if :only => [:new, :upload_files] do |c, user, profile|
35 36 parent_id = c.params[:article].present? ? c.params[:article][:parent_id] : c.params[:parent_id]
36   - parent = profile.articles.find_by_id(parent_id)
  37 + parent = profile.articles.find_by(id: parent_id)
37 38 user && user.can_post_content?(profile, parent)
38 39 end
39 40  
... ... @@ -58,11 +59,10 @@ class CmsController &lt; MyProfileController
58 59  
59 60 def index
60 61 @article = nil
61   - @articles = profile.top_level_articles.paginate(
62   - :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC",
63   - :per_page => per_page,
64   - :page => params[:npage]
65   - )
  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 +
66 66 render :action => 'view'
67 67 end
68 68  
... ... @@ -256,12 +256,7 @@ class CmsController &lt; MyProfileController
256 256  
257 257 def update_categories
258 258 @object = params[:id] ? @profile.articles.find(params[:id]) : Article.new
259   - @categories = @toplevel_categories = environment.top_level_categories
260   - if params[:category_id]
261   - @current_category = Category.find(params[:category_id])
262   - @categories = @current_category.children
263   - end
264   - render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => 'article' }
  259 + render_categories 'article'
265 260 end
266 261  
267 262 def search_communities_to_publish
... ...
app/controllers/my_profile/friends_controller.rb
... ... @@ -22,7 +22,7 @@ class FriendsController &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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_design_controller.rb
... ... @@ -6,6 +6,7 @@ class ProfileDesignController &lt; BoxOrganizerController
6 6  
7 7 before_filter :protect_uneditable_block, :only => [:save]
8 8 before_filter :protect_fixed_block, :only => [:move_block]
  9 + include CategoriesHelper
9 10  
10 11 def protect_uneditable_block
11 12 block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, ''))
... ... @@ -67,4 +68,9 @@ class ProfileDesignController &lt; BoxOrganizerController
67 68 blocks
68 69 end
69 70  
  71 + def update_categories
  72 + @object = params[:id] ? @profile.blocks.find(params[:id]) : Block.new
  73 + render_categories 'block'
  74 + end
  75 +
70 76 end
... ...
app/controllers/my_profile/profile_editor_controller.rb
... ... @@ -9,6 +9,7 @@ class ProfileEditorController &lt; MyProfileController
9 9 before_filter :check_user_can_edit_header_footer, :only => [:header_footer]
10 10 helper_method :has_welcome_page
11 11 helper CustomFieldsHelper
  12 + include CategoriesHelper
12 13  
13 14 def index
14 15 @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)}
... ... @@ -60,12 +61,7 @@ class ProfileEditorController &lt; MyProfileController
60 61  
61 62 def update_categories
62 63 @object = profile
63   - @categories = @toplevel_categories = environment.top_level_categories
64   - if params[:category_id]
65   - @current_category = Category.find(params[:category_id])
66   - @categories = @current_category.children
67   - end
68   - render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => 'profile_data' }
  64 + render_categories 'profile_data'
69 65 end
70 66  
71 67 def header_footer
... ...
app/controllers/my_profile/profile_members_controller.rb
... ... @@ -60,7 +60,7 @@ class ProfileMembersController &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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
... ... @@ -218,7 +218,10 @@ class ProfileController &lt; PublicController
218 218  
219 219 def more_comments
220 220 profile_filter = @profile.person? ? {:user_id => @profile} : {:target_id => @profile}
221   - activity = ActionTracker::Record.where({:id => params[:activity]}.merge profile_filter).first
  221 + activity = ActionTracker::Record.where(:id => params[:activity])
  222 + activity = activity.where(profile_filter) if !logged_in? || !current_person.follows?(@profile)
  223 + activity = activity.first
  224 +
222 225 comments_count = activity.comments.count
223 226 comment_page = (params[:comment_page] || 1).to_i
224 227 comments_per_page = 5
... ... @@ -336,7 +339,7 @@ class ProfileController &lt; PublicController
336 339 user.register_report(abuse_report, profile)
337 340  
338 341 if !params[:content_type].blank?
339   - 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)
340 343 Delayed::Job.enqueue DownloadReportedImagesJob.new(abuse_report, article)
341 344 end
342 345  
... ... @@ -371,7 +374,7 @@ class ProfileController &lt; PublicController
371 374 def send_mail
372 375 @mailing = profile.mailings.build(params[:mailing])
373 376 @mailing.data = session[:members_filtered] ? {:members_filtered => session[:members_filtered]} : {}
374   - @email_templates = profile.email_templates.find_all_by_template_type(:organization_members)
  377 + @email_templates = profile.email_templates.where template_type: :organization_members
375 378 if request.post?
376 379 @mailing.locale = locale
377 380 @mailing.person = user
... ...
app/controllers/public/search_controller.rb
... ... @@ -167,7 +167,7 @@ class SearchController &lt; 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 &lt; 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 &lt; 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
... ... @@ -940,7 +940,8 @@ module ApplicationHelper
940 940 end
941 941  
942 942 def expandable_text_area(object_name, method, text_area_id, options = {})
943   - text_area(object_name, method, { :id => text_area_id, :onkeyup => "grow_text_area('#{text_area_id}')" }.merge(options))
  943 + options[:class] = (options[:class] || '') + ' autogrow'
  944 + text_area(object_name, method, { :id => text_area_id }.merge(options))
944 945 end
945 946  
946 947 def pluralize_without_count(count, singular, plural = nil)
... ... @@ -1153,8 +1154,8 @@ module ApplicationHelper
1153 1154 end
1154 1155  
1155 1156 def default_folder_for_image_upload(profile)
1156   - default_folder = profile.folders.find_by_type('Gallery')
1157   - 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?
1158 1159 default_folder
1159 1160 end
1160 1161  
... ...
app/helpers/block_helper.rb
1 1 module BlockHelper
2 2  
3   - def block_title(title)
4   - tag_class = 'block-title'
  3 + def block_title(title, subtitle=nil)
  4 + block_header = block_heading title
  5 + block_header += block_heading(subtitle, 'h4') if subtitle
  6 + content_tag 'div', block_header, :class => 'block-header'
  7 + end
  8 +
  9 + def block_heading(title, heading='h3')
  10 + tag_class = 'block-' + (heading == 'h3' ? 'title' : 'subtitle')
5 11 tag_class += ' empty' if title.empty?
6   - content_tag 'h3', content_tag('span', h(title)), :class => tag_class
  12 + content_tag heading, content_tag('span', h(title)), :class => tag_class
7 13 end
8 14  
9 15 def highlights_block_config_image_fields(block, image={}, row_number=nil)
... ...
app/helpers/categories_helper.rb
... ... @@ -34,4 +34,15 @@ module CategoriesHelper
34 34 {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => html_class}.merge(html_options)
35 35 end
36 36  
  37 + def render_categories object_name
  38 + @toplevel_categories = environment.top_level_categories
  39 + if params[:category_id]
  40 + @current_category = Category.find(params[:category_id])
  41 + @categories = @current_category.children
  42 + else
  43 + @categories = @toplevel_categories
  44 + end
  45 + render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => object_name }
  46 + end
  47 +
37 48 end
... ...
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 &lt; 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 &lt; 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 &lt; 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 &lt; 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
... ... @@ -18,7 +18,7 @@ class ApproveComment &lt; Task
18 18 end
19 19  
20 20 def article
21   - Article.find_by_id comment.source_id unless self.comment.nil?
  21 + Article.find_by id: comment.source_id unless self.comment.nil?
22 22 end
23 23  
24 24 def article_name
... ...
app/models/article.rb
... ... @@ -12,6 +12,7 @@ class Article &lt; ActiveRecord::Base
12 12 :author, :display_preview, :published_at, :person_followers
13 13  
14 14 acts_as_having_image
  15 + include Noosfero::Plugin::HotSpot
15 16  
16 17 SEARCHABLE_FIELDS = {
17 18 :name => {:label => _('Name'), :weight => 10},
... ... @@ -73,11 +74,11 @@ class Article &lt; ActiveRecord::Base
73 74 belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id'
74 75 belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id'
75 76  
76   - 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
77 78  
78 79 has_many :article_followers, :dependent => :destroy
79 80 has_many :person_followers, :class_name => 'Person', :through => :article_followers, :source => :person
80   - 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
81 82  
82 83 has_many :article_categorizations, -> { where 'articles_categories.virtual = ?', false }
83 84 has_many :categories, :through => :article_categorizations
... ... @@ -278,7 +279,7 @@ class Article &lt; ActiveRecord::Base
278 279 # retrives the most commented articles, sorted by the comment count (largest
279 280 # first)
280 281 def self.most_commented(limit)
281   - paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit)
  282 + order('comments_count DESC').paginate(page: 1, per_page: limit)
282 283 end
283 284  
284 285 scope :more_popular, -> { order 'hits DESC' }
... ... @@ -287,7 +288,7 @@ class Article &lt; ActiveRecord::Base
287 288 }
288 289  
289 290 def self.recent(limit = nil, extra_conditions = {}, pagination = true)
290   - result = scoped({:conditions => extra_conditions}).
  291 + result = where(extra_conditions).
291 292 is_public.
292 293 relevant_as_recent.
293 294 limit(limit).
... ... @@ -469,7 +470,7 @@ class Article &lt; ActiveRecord::Base
469 470  
470 471 def rotate_translations
471 472 unless self.translations.empty?
472   - rotate = self.translations.all
  473 + rotate = self.translations.to_a
473 474 root = rotate.shift
474 475 root.update_attribute(:translation_of_id, nil)
475 476 root.translations = rotate
... ... @@ -751,7 +752,7 @@ class Article &lt; ActiveRecord::Base
751 752  
752 753 def version_license(version_number = nil)
753 754 return license if version_number.nil?
754   - 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)
755 756 end
756 757  
757 758 alias :active_record_cache_key :cache_key
... ...
app/models/block.rb
1 1 class Block < ActiveRecord::Base
2 2  
3   - attr_accessible :title, :display, :limit, :box_id, :posts_per_page,
  3 + attr_accessible :title, :subtitle, :display, :limit, :box_id, :posts_per_page,
4 4 :visualization_format, :language, :display_user,
5 5 :box, :edit_modes, :move_modes, :mirror
6 6  
7   - # to be able to generate HTML
8   - include ActionView::Helpers::UrlHelper
9 7 include ActionView::Helpers::TagHelper
10 8  
11 9 # Block-specific stuff
... ... @@ -13,7 +11,8 @@ class Block &lt; ActiveRecord::Base
13 11  
14 12 delegate :environment, :to => :box, :allow_nil => true
15 13  
16   - acts_as_list :scope => :box
  14 + acts_as_list scope: -> block { where box_id: block.box_id }
  15 +
17 16 belongs_to :box
18 17 belongs_to :mirror_block, :class_name => "Block"
19 18 has_many :observers, :class_name => "Block", :foreign_key => "mirror_block_id"
... ...
app/models/blog.rb
... ... @@ -98,8 +98,9 @@ class Blog &lt; Folder
98 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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
... ... @@ -9,7 +9,7 @@ class Input &lt; ActiveRecord::Base
9 9 validates_presence_of :product
10 10 validates_presence_of :product_category
11 11  
12   - acts_as_list :scope => :product
  12 + acts_as_list scope: -> input { where product_id: input.product_id }
13 13  
14 14 belongs_to :unit
15 15  
... ...
app/models/invitation.rb
... ... @@ -67,7 +67,7 @@ class Invitation &lt; 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
... ... @@ -27,7 +27,7 @@ class ModerateUserRegistration &lt; Task
27 27 end
28 28  
29 29 def perform
30   - user=environment.users.find_by_id(user_id)
  30 + user=environment.users.find_by(id: user_id)
31 31 user.activate
32 32 end
33 33  
... ...
app/models/national_region.rb
... ... @@ -27,12 +27,13 @@ class NationalRegion &lt; 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 &lt; 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
... ... @@ -57,7 +57,7 @@ class Organization &lt; Profile
57 57  
58 58 has_many :custom_roles, :class_name => 'Role', :foreign_key => :profile_id
59 59  
60   - scope :more_popular, :order => 'members_count DESC'
  60 + scope :more_popular, -> { order 'members_count DESC' }
61 61  
62 62 validate :presence_of_required_fieds, :unless => :is_template
63 63  
... ...
app/models/person.rb
... ... @@ -112,7 +112,8 @@ class Person &lt; Profile
112 112 has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people'
113 113 has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions'
114 114  
115   - has_many :suggested_profiles, class_name: 'ProfileSuggestion', foreign_key: :person_id, order: 'score DESC', dependent: :destroy
  115 + has_many :suggested_profiles, -> { order 'score DESC' },
  116 + class_name: 'ProfileSuggestion', foreign_key: :person_id, dependent: :destroy
116 117 has_many :suggested_people, -> {
117 118 where 'profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true
118 119 }, through: :suggested_profiles, source: :suggestion
... ... @@ -395,7 +396,7 @@ class Person &lt; Profile
395 396  
396 397  
397 398 def self.with_pending_tasks
398   - Person.find(:all).select{ |person| !person.tasks.pending.empty? or person.has_organization_pending_tasks? }
  399 + Person.all.select{ |person| !person.tasks.pending.empty? or person.has_organization_pending_tasks? }
399 400 end
400 401  
401 402 def has_organization_pending_tasks?
... ... @@ -489,7 +490,7 @@ class Person &lt; Profile
489 490 end
490 491  
491 492 def each_friend(offset=0)
492   - while friend = self.friends.first(:order => :id, :offset => offset)
  493 + while friend = self.friends.order(:id).offset(offset).first
493 494 yield friend
494 495 offset = offset + 1
495 496 end
... ... @@ -571,7 +572,7 @@ class Person &lt; Profile
571 572 end
572 573  
573 574 def remove_suggestion(profile)
574   - suggestion = suggested_profiles.find_by_suggestion_id profile.id
  575 + suggestion = suggested_profiles.find_by suggestion_id: profile.id
575 576 suggestion.disable if suggestion
576 577 end
577 578  
... ...
app/models/product.rb
... ... @@ -28,7 +28,7 @@ class Product &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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 &lt; 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/session.rb
1 1 class Session < ActiveRecord::SessionStore::Session
2 2  
  3 + attr_accessible :session_id, :data
  4 +
3 5 # removed and redefined on super class
4 6 def self.find_by_session_id session_id
5 7 super
... ...
app/models/task.rb
... ... @@ -31,6 +31,8 @@ class Task &lt; ActiveRecord::Base
31 31 end
32 32 end
33 33  
  34 + include Noosfero::Plugin::HotSpot
  35 +
34 36 belongs_to :requestor, :class_name => 'Profile', :foreign_key => :requestor_id
35 37 belongs_to :target, :foreign_key => :target_id, :polymorphic => true
36 38 belongs_to :responsible, :class_name => 'Person', :foreign_key => :responsible_id
... ... @@ -135,9 +137,9 @@ class Task &lt; ActiveRecord::Base
135 137 group = klass.to_s.downcase.pluralize
136 138 id = attribute.to_s + "_id"
137 139 if environment.respond_to?(group)
138   - attrb = value || environment.send(group).find_by_id(record.send(id))
  140 + attrb = value || environment.send(group).find_by(id: record.send(id))
139 141 else
140   - attrb = value || klass.find_by_id(record.send(id))
  142 + attrb = value || klass.find_by(id: record.send(id))
141 143 end
142 144 if attrb.respond_to?(klass.to_s.downcase + "?")
143 145 unless attrb.send(klass.to_s.downcase + "?")
... ... @@ -253,6 +255,7 @@ class Task &lt; ActiveRecord::Base
253 255 end
254 256  
255 257 def environment
  258 + return target if target.kind_of?(Environment)
256 259 self.target.environment unless self.target.nil?
257 260 end
258 261  
... ...
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
... ... @@ -25,7 +25,7 @@ class User &lt; ActiveRecord::Base
25 25 end
26 26  
27 27 def self.[](login)
28   - self.find_by_login(login)
  28 + self.find_by login: login
29 29 end
30 30  
31 31 # FIXME ugly workaround
... ...
app/views/blocks/article.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2 <% if block.article %>
3 3 <%=
4 4 h(article_to_html(FilePresenter.for(block.article),
... ...
app/views/blocks/blog_archives.html.erb
1 1 <% if block.blog %>
2   - <%= block_title(block.title) %>
  2 + <%= block_title(block.title, block.subtitle) %>
3 3  
4 4 <ul class='blog-archives'>
5 5 <% block.blog.total_number_of_posts(:by_year).each do |year, count| %>
... ...
app/views/blocks/categories.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%= display_category_menu block, block.selected_categories %>
... ...
app/views/blocks/featured_products.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2 <% unless block.products.blank? %>
3 3 <%= link_to content_tag(:span, _('Previous')), '#', :class => 'featured-product-prev featured-product-arrow' %>
4 4 <div class="featured-products-block-container">
... ...
app/views/blocks/feed_reader.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%=
4 4 if block.error_message.blank?
... ...
app/views/blocks/highlights.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
  2 +
2 3 <% if !block.featured_images.empty? %>
3 4 <div class='highlights-border'>
4 5 <div class='highlights-container'>
... ...
app/views/blocks/link_list.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%= block.links.empty? && block.title.empty? ? content_tag('em', _('Please, edit this block to add links')) : '' %>
4 4  
... ...
app/views/blocks/location.html.erb
1 1 <% if block.owner.lat %>
2   - <%= block_title block.title %>
  2 + <%= block_title(block.title, block.subtitle) %>
3 3 <div class='the-localization-map'>
4 4 <img src="https://maps.google.com/maps/api/staticmap?center=<%=block.owner.lat%>,<%=block.owner.lng%>&zoom=<%=block.zoom%>&size=190x250&maptype=<%=block.map_type%>&markers=<%=block.owner.lat%>,<%=block.owner.lng%>&sensor=false"/>
5 5 </div>
... ...
app/views/blocks/my_network.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <ul>
4 4 <li><%= link_to(_('Homepage'), block.owner.url, :class => 'url') %></li>
... ...
app/views/blocks/products.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <ul>
4 4 <% block.products.each do |product| %>
... ...
app/views/blocks/profile_list.html.erb
1   -<%= block_title(block.view_title) %>
  1 +<%= block_title(block.view_title, block.subtitle) %>
2 2  
3 3 <%
4 4 list = block.profile_list.map do |item|
... ...
app/views/blocks/profile_search.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%= render :partial => 'shared/profile_search_form' %>
... ...
app/views/blocks/raw_html.html.erb
1   -<%=h block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%=h block.html %>
... ...
app/views/blocks/recent_documents.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <ul>
4 4 <% block.docs.map do |item| %>
... ...
app/views/blocks/slideshow.html.erb
... ... @@ -7,7 +7,7 @@
7 7 end
8 8 %>
9 9  
10   -<%= block_title(block.title) %>
  10 +<%= block_title(block.title, block.subtitle) %>
11 11  
12 12 <% if images %>
13 13 <% description = images.any? { |img| !img.abstract.blank? } %>
... ...
app/views/blocks/tags.html.erb
1   -<%= block_title(block.title) %>
  1 +<%= block_title(block.title, block.subtitle) %>
2 2  
3 3 <%
4 4 is_env = block.owner.class == Environment
... ...
app/views/box_organizer/edit.html.erb
... ... @@ -4,6 +4,7 @@
4 4 <%= form_tag(:action => 'save', :id => @block.id) do %>
5 5  
6 6 <%= labelled_form_field(_('Custom title for this block: '), text_field(:block, :title, :maxlength => 20)) %>
  7 + <%= labelled_form_field(_('Custom subtitle for this block: '), text_field(:block, :subtitle)) %>
7 8  
8 9 <%= render :partial => partial_for_class(@block.class) %>
9 10  
... ...
app/views/layouts/_user.html.erb
1 1 <div id="user">
2   - <% user = (session[:user] && User.find_by_id(session[:user])) || nil %>
  2 + <% user = (session[:user] && User.find_by(id: session[:user])) || nil %>
3 3 <% if user.present? %>
4 4 <% user = user.person %>
5 5 <span class='logged-in'>
... ...
app/views/profile/_profile_scrap_reply_form.html.erb
1 1 <div id='profile-wall-reply-<%= scrap.id%>' style='display:none'>
2 2 <div id='profile-wall-reply-form-<%= scrap.id%>' style='display:none'>
3 3 <p class='profile-wall-reply'>
4   - <%= form_remote_tag :url => {:controller => 'profile', :action => 'leave_scrap'}, :update => "profile_activities", :html => { :class => 'profile-wall-reply-form'} do %>
  4 + <%= form_remote_tag :url => {:controller => 'profile', :action => 'leave_scrap'}, :update => "profile_activities", :html => { :class => 'profile-wall-reply-form', 'data-update' => 'profile_activities'} do %>
5 5 <%= expandable_text_area :scrap,
6 6 :content,
7 7 "reply_content_#{scrap.id}",
... ...
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'>
... ...
circle.yml 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +machine:
  2 + timezone:
  3 + America/Bahia
  4 + ruby:
  5 + version: 2.3.0
  6 + services:
  7 + - postgresql
  8 +
  9 +dependencies:
  10 + pre:
  11 + - sudo apt-get install po4a iso-codes tango-icon-theme pidgin-data libpq-dev libreadline-dev libxslt1-dev
  12 + - mkdir -p tmp/{pids,cache} log cache
  13 +
  14 +database:
  15 + override:
  16 + - script/noosfero-plugins disableall
  17 + - cp config/database.yml.circleci config/database.yml
  18 + - bundle exec rake db:create
  19 + - bundle exec rake db:schema:load
  20 + - bundle exec rake db:migrate
  21 +
  22 +test:
  23 + override:
  24 + - ? |
  25 + set -x -e
  26 + case $CIRCLE_NODE_INDEX in
  27 + 0)
  28 + bundle exec rake test:api
  29 + bundle exec rake test:functionals
  30 + SLICE=1/4 bundle exec rake selenium
  31 + SLICE=1/4 BUNDLE_OPTS=install bundle exec rake test:noosfero_plugins
  32 + ;;
  33 + 1)
  34 + bundle exec rake test:integration
  35 + SLICE=2/4 bundle exec rake selenium
  36 + SLICE=2/4 BUNDLE_OPTS=install bundle exec rake test:noosfero_plugins
  37 + ;;
  38 + 2)
  39 + bundle exec rake test:units
  40 + SLICE=3/4 bundle exec rake selenium
  41 + SLICE=3/4 BUNDLE_OPTS=install bundle exec rake test:noosfero_plugins
  42 + ;;
  43 + 3)
  44 + bundle exec rake cucumber
  45 + SLICE=4/4 bundle exec rake selenium
  46 + SLICE=4/4 BUNDLE_OPTS=install bundle exec rake test:noosfero_plugins
  47 + ;;
  48 + esac
  49 + :
  50 + parallel: true
... ...
config/cucumber.yml
1   -<% base_requires = '-r features/support -r features/step_definitions' %>
2   -<% default_options = "--format progress --strict --tags ~@selenium --tags ~@selenium-fixme --tags ~@fixme --exclude features/support/selenium.rb #{base_requires}" %>
3 1 <%
4   - default_options += ' --color' if $stdout.isatty
  2 + base_requires = '-r features/support -r features/step_definitions'
  3 + default_options = "--format progress --strict --tags ~@selenium --tags ~@selenium-fixme --tags ~@fixme --exclude features/support/selenium.rb #{base_requires}"
  4 + default_options << ' --color' if $stdout.isatty
  5 + selenium_options = "--strict --tags @selenium #{base_requires}"
  6 +
  7 + core_features = Dir.glob "features/**/*.feature"
  8 + if slice = ENV['SLICE']
  9 + sel,size = slice.split '/'
  10 + size = (core_features.size / size.to_f).ceil
  11 + core_features = core_features.each_slice(size).to_a[sel.to_i - 1]
  12 + end
  13 + core_features = core_features.join ' '
5 14 %>
6   -<% selenium_options = "--strict --tags @selenium #{base_requires}" %>
7 15  
8   -default: <%= default_options %>
9   -selenium: <%= selenium_options %>
  16 +default: <%= default_options %> <%= core_features %>
  17 +selenium: <%= selenium_options %> <%= core_features %>
10 18  
11   -<% enabled_plugins = Dir.glob(File.join('config', 'plugins', '*')).map{|path| plugin = File.basename(path); plugin if File.exist?(File.join('features', 'plugins', plugin)) }.compact %>
  19 +<%
  20 + enabled_plugins = Dir.glob(File.join('config', 'plugins', '*')).map do |path|
  21 + plugin = File.basename(path)
  22 + plugin if File.exist? File.join('features', 'plugins', plugin)
  23 + end.compact
12 24  
13   -<% enabled_plugins.each do |plugin| %>
14   -<% plugin_features_path = File.join('features', 'plugins', plugin) %>
15   -<% plugin_base_requires = '' %>
16   -<% plugin_base_requires += " -r features/plugins/#{plugin}/support" if File.exist?(File.join(plugin_features_path, 'support')) %>
17   -<% plugin_base_requires += " -r features/plugins/#{plugin}/step_definitions" if File.exist?(File.join(plugin_features_path, 'step_definitions')) %>
  25 + enabled_plugins.each do |plugin|
  26 + plugin_features_path = File.join('features', 'plugins', plugin)
  27 + plugin_base_requires = ''
  28 + plugin_base_requires << " -r features/plugins/#{plugin}/support" if File.exist? File.join(plugin_features_path, 'support')
  29 + plugin_base_requires << " -r features/plugins/#{plugin}/step_definitions" if File.exist? File.join(plugin_features_path, 'step_definitions')
  30 +%>
18 31 <%= "#{plugin}: #{default_options} #{plugin_base_requires}" %>
19 32 <%= "#{plugin}_selenium: #{selenium_options} #{plugin_base_requires}" %>
20 33 <% end %>
... ...
config/database.yml.circleci 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +test:
  2 + adapter: postgresql
  3 + database: circle_ruby_test
  4 + username: ubuntu
  5 + host: localhost
... ...
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 &lt; 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 &lt; 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 &lt; 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
1 1 class CreateTemplates < ActiveRecord::Migration
2 2 def self.up
3   - Environment.find(:all).each do |env|
  3 + Environment.find_each do |env|
4 4 if env.person_template.nil? && env.community_template.nil? && env.enterprise_template.nil?
5 5 env.create_templates
6 6 end
... ...
db/migrate/069_add_enviroment_id_to_role.rb
... ... @@ -12,13 +12,13 @@ class AddEnviromentIdToRole &lt; 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 &lt; 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
1 1 class StripHtmlFromTagNames < ActiveRecord::Migration
2 2 def self.up
3   - Tag.all(:conditions => "name LIKE '%<%' OR name LIKE '%>%'").each do |tag|
  3 + Tag.where("name LIKE '%<%' OR name LIKE '%>%'").find_each do |tag|
4 4 tag.name = tag.name.gsub(/[<>]/, '')
5 5 tag.save
6 6 end
... ...
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 &lt; 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 &lt; 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 &lt; 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 &lt; 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
... ...