Skip to content

Commit

Permalink
Merge pull request #2409 from aquajach/master
Browse files Browse the repository at this point in the history
Changing a field's type shouldn't position it at the bottom
  • Loading branch information
mshibuya committed Sep 23, 2015
2 parents ab86b2f + 651e3cc commit 817e34b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rails_admin/config/has_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def field(name, type = nil, add_to_section = true, &block)
elsif type && type != (field.nil? ? nil : field.type)
if field
properties = field.properties
_fields.delete(field)
field = _fields[_fields.index(field)] = RailsAdmin::Config::Fields::Types.load(type).new(self, name, properties)
else
properties = abstract_model.properties.detect { |p| name == p.name }
field = (_fields << RailsAdmin::Config::Fields::Types.load(type).new(self, name, properties)).last
end
field = (_fields << RailsAdmin::Config::Fields::Types.load(type).new(self, name, properties)).last
end

# If field has not been yet defined add some default properties
Expand Down
16 changes: 16 additions & 0 deletions spec/rails_admin/config/has_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,20 @@
end
expect(RailsAdmin.config(Team).fields.detect { |f| f.name == :players }.properties).not_to be_nil
end

it 'does not change the order of existing fields, if some field types of them are changed' do
original_fields_order = RailsAdmin.config(Team).fields.map(&:name)

RailsAdmin.config do |config|
config.model Team do
configure :players, :enum do
enum { [] }
end

configure :revenue, :integer
end
end

expect(RailsAdmin.config(Team).fields.map(&:name)).to eql(original_fields_order)
end
end

0 comments on commit 817e34b

Please sign in to comment.