diff --git a/app/controllers/rails_admin/main_controller.rb b/app/controllers/rails_admin/main_controller.rb index afc68ff8f3..815b098cb7 100644 --- a/app/controllers/rails_admin/main_controller.rb +++ b/app/controllers/rails_admin/main_controller.rb @@ -90,9 +90,7 @@ def redirect_to_on_success def sanitize_params_for!(action, model_config = @model_config, target_params = params[@abstract_model.param_key]) return unless target_params.present? fields = model_config.send(action).with(controller: self, view: view_context, object: @object).visible_fields - allowed_methods = fields.collect do|f| - f.allowed_methods - end.flatten.uniq.collect(&:to_s) << 'id' << '_destroy' + allowed_methods = fields.collect(&:allowed_methods).flatten.uniq.collect(&:to_s) << 'id' << '_destroy' fields.each { |f| f.parse_input(target_params) } target_params.slice!(*allowed_methods) target_params.permit! if target_params.respond_to?(:permit!) diff --git a/lib/rails_admin/abstract_model.rb b/lib/rails_admin/abstract_model.rb index ecbd5f099b..9800aa51df 100644 --- a/lib/rails_admin/abstract_model.rb +++ b/lib/rails_admin/abstract_model.rb @@ -27,7 +27,7 @@ def new(m) def polymorphic_parents(adapter, model_name, name) @@polymorphic_parents[adapter.to_sym] ||= {}.tap do |hash| all(adapter).each do |am| - am.associations.select { |r| r.as }.each do |association| + am.associations.select(&:as).each do |association| (hash[[association.klass.to_s.underscore, association.as].join('_').to_sym] ||= []) << am.model end end diff --git a/lib/rails_admin/config/fields/base.rb b/lib/rails_admin/config/fields/base.rb index 15637d769f..91c5484e9a 100644 --- a/lib/rails_admin/config/fields/base.rb +++ b/lib/rails_admin/config/fields/base.rb @@ -152,7 +152,7 @@ def virtual? # Accessor for field's length restrictions per validations # register_instance_option :valid_length do - @valid_length ||= abstract_model.model.validators_on(name).detect { |v| v.kind == :length }.try { |v| v.options } || {} + @valid_length ||= abstract_model.model.validators_on(name).detect { |v| v.kind == :length }.try(&:options) || {} end register_instance_option :partial do diff --git a/lib/rails_admin/config/fields/types/belongs_to_association.rb b/lib/rails_admin/config/fields/types/belongs_to_association.rb index 5d048610b2..2899f19c83 100644 --- a/lib/rails_admin/config/fields/types/belongs_to_association.rb +++ b/lib/rails_admin/config/fields/types/belongs_to_association.rb @@ -12,11 +12,11 @@ class BelongsToAssociation < RailsAdmin::Config::Fields::Association end register_instance_option :sortable do - @sortable ||= abstract_model.adapter_supports_joins? && associated_model_config.abstract_model.properties.collect { |p| p.name }.include?(associated_model_config.object_label_method) ? associated_model_config.object_label_method : {abstract_model.table_name => method_name} + @sortable ||= abstract_model.adapter_supports_joins? && associated_model_config.abstract_model.properties.collect(&:name).include?(associated_model_config.object_label_method) ? associated_model_config.object_label_method : {abstract_model.table_name => method_name} end register_instance_option :searchable do - @searchable ||= associated_model_config.abstract_model.properties.collect { |p| p.name }.include?(associated_model_config.object_label_method) ? [associated_model_config.object_label_method, {abstract_model.model => method_name}] : {abstract_model.model => method_name} + @searchable ||= associated_model_config.abstract_model.properties.collect(&:name).include?(associated_model_config.object_label_method) ? [associated_model_config.object_label_method, {abstract_model.model => method_name}] : {abstract_model.model => method_name} end register_instance_option :partial do diff --git a/lib/rails_admin/config/has_fields.rb b/lib/rails_admin/config/has_fields.rb index c247805864..5957c7cde4 100644 --- a/lib/rails_admin/config/has_fields.rb +++ b/lib/rails_admin/config/has_fields.rb @@ -83,7 +83,7 @@ def fields(*field_names, &block) return all_fields if field_names.empty? && !block if field_names.empty? - defined = _fields.select { |f| f.defined } + defined = _fields.select(&:defined) defined = _fields if defined.empty? else defined = field_names.collect { |field_name| _fields.detect { |f| f.name == field_name } } diff --git a/spec/dummy_app/app/active_record/team.rb b/spec/dummy_app/app/active_record/team.rb index 7cb3f110e9..f5e31c4437 100644 --- a/spec/dummy_app/app/active_record/team.rb +++ b/spec/dummy_app/app/active_record/team.rb @@ -15,7 +15,7 @@ class Team < ActiveRecord::Base belongs_to :division def player_names_truncated - players.collect { |p| p.name }.join(', ')[0..32] + players.collect(&:name).join(', ')[0..32] end def color_enum diff --git a/spec/dummy_app/app/mongoid/team.rb b/spec/dummy_app/app/mongoid/team.rb index 8ea92ecd47..a82bcf0a53 100644 --- a/spec/dummy_app/app/mongoid/team.rb +++ b/spec/dummy_app/app/mongoid/team.rb @@ -36,7 +36,7 @@ class Team validates_length_of :mascot, maximum: 100 def player_names_truncated - players.collect { |p| p.name }.join(', ')[0..32] + players.collect(&:name).join(', ')[0..32] end def color_enum diff --git a/spec/orm/active_record.rb b/spec/orm/active_record.rb index 81ea328e79..c00801b6e3 100644 --- a/spec/orm/active_record.rb +++ b/spec/orm/active_record.rb @@ -27,7 +27,7 @@ def columns_hash end def column_names - @column_names ||= columns.collect { |column| column.name } + @column_names ||= columns.collect(&:name) end def column_defaults diff --git a/spec/rails_admin/adapters/active_record/association_spec.rb b/spec/rails_admin/adapters/active_record/association_spec.rb index 9a643f5f27..60e378e674 100644 --- a/spec/rails_admin/adapters/active_record/association_spec.rb +++ b/spec/rails_admin/adapters/active_record/association_spec.rb @@ -54,7 +54,7 @@ class ARComment < ActiveRecord::Base it 'list associations types in supported [:belongs_to, :has_and_belongs_to_many, :has_many, :has_one]' do # ActiveRecord 4.1 converts has_and_belongs_to_many association to has_many - expect((@post.associations + @blog.associations + @user.associations).collect { |a| a.type }.uniq.collect(&:to_s)).to include(*%w(belongs_to has_many has_one)) + expect((@post.associations + @blog.associations + @user.associations).collect(&:type).uniq.collect(&:to_s)).to include(*%w(belongs_to has_many has_one)) end describe 'belongs_to association' do diff --git a/spec/rails_admin/adapters/mongoid_spec.rb b/spec/rails_admin/adapters/mongoid_spec.rb index 25015de5f0..6c54fafa35 100644 --- a/spec/rails_admin/adapters/mongoid_spec.rb +++ b/spec/rails_admin/adapters/mongoid_spec.rb @@ -56,7 +56,7 @@ end it 'supports eager loading' do - expect(@abstract_model.all(include: :team).inclusions.collect { |i| i.class_name }).to eq(['Team']) + expect(@abstract_model.all(include: :team).inclusions.collect(&:class_name)).to eq(['Team']) end it 'supports limiting' do diff --git a/spec/rails_admin/config/fields/base_spec.rb b/spec/rails_admin/config/fields/base_spec.rb index 5ab85e3731..02a42f2bf1 100644 --- a/spec/rails_admin/config/fields/base_spec.rb +++ b/spec/rails_admin/config/fields/base_spec.rb @@ -379,10 +379,10 @@ class FieldVisibilityTest < Tableless column :updated_on, :datetime column :deleted_on, :datetime end - expect(RailsAdmin.config(FieldVisibilityTest).base.fields.select { |f| f.visible? }.collect(&:name)).to match_array [:_id, :created_at, :created_on, :deleted_at, :deleted_on, :id, :name, :updated_at, :updated_on] - expect(RailsAdmin.config(FieldVisibilityTest).list.fields.select { |f| f.visible? }.collect(&:name)).to match_array [:_id, :created_at, :created_on, :deleted_at, :deleted_on, :id, :name, :updated_at, :updated_on] - expect(RailsAdmin.config(FieldVisibilityTest).edit.fields.select { |f| f.visible? }.collect(&:name)).to match_array [:name] - expect(RailsAdmin.config(FieldVisibilityTest).show.fields.select { |f| f.visible? }.collect(&:name)).to match_array [:name] + expect(RailsAdmin.config(FieldVisibilityTest).base.fields.select(&:visible?).collect(&:name)).to match_array [:_id, :created_at, :created_on, :deleted_at, :deleted_on, :id, :name, :updated_at, :updated_on] + expect(RailsAdmin.config(FieldVisibilityTest).list.fields.select(&:visible?).collect(&:name)).to match_array [:_id, :created_at, :created_on, :deleted_at, :deleted_on, :id, :name, :updated_at, :updated_on] + expect(RailsAdmin.config(FieldVisibilityTest).edit.fields.select(&:visible?).collect(&:name)).to match_array [:name] + expect(RailsAdmin.config(FieldVisibilityTest).show.fields.select(&:visible?).collect(&:name)).to match_array [:name] end end