Skip to content

Commit

Permalink
Pass symbol as an argument to iterator instead of a block
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Sep 7, 2014
1 parent 5b03a6e commit e6afddc
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 17 deletions.
4 changes: 1 addition & 3 deletions app/controllers/rails_admin/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/abstract_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/rails_admin/config/fields/types/belongs_to_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/has_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/active_record/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/mongoid/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/orm/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_admin/adapters/mongoid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/rails_admin/config/fields/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e6afddc

Please sign in to comment.