Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing a field's type shouldn't position it at the bottom #2409

Merged
merged 1 commit into from
Sep 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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