Skip to content

Commit

Permalink
Merge pull request #2999 from rs-pro/master
Browse files Browse the repository at this point in the history
Fix "can't modify frozen array" exception under certain conditions
  • Loading branch information
mshibuya committed May 3, 2018
2 parents d81dd95 + 1a0e013 commit 37aa038
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
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 @@ -130,7 +130,7 @@ def _fields(readonly = false)
@_ro_fields = @_fields = RailsAdmin::Config::Fields.factory(self)
else
# parent is RailsAdmin::Config::Model, recursion is on Section's classes
@_ro_fields ||= parent.send(self.class.superclass.to_s.underscore.split('/').last)._fields(true).freeze
@_ro_fields ||= parent.send(self.class.superclass.to_s.underscore.split('/').last)._fields(true).clone.freeze
end
readonly ? @_ro_fields : (@_fields ||= @_ro_fields.collect(&:clone))
end
Expand Down
38 changes: 38 additions & 0 deletions spec/rails_admin/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,44 @@ class RecursivelyEmbedsMany
end
end
end

describe "field types code reloading" do
let(:config) { described_class.model(Team) }
let(:fields) { described_class.model(Team).edit.fields }

let(:team_config) do
proc do
field :id
field :wins, :boolean
end
end
let(:team_config2) do
proc do
field :wins, :toggle
end
end

it "allows code reloading" do
Team.send(:rails_admin, &team_config)

# This simulates the way RailsAdmin really does it
config.edit.send(:_fields, true)

module RailsAdmin
module Config
module Fields
module Types
class Toggle < RailsAdmin::Config::Fields::Base
RailsAdmin::Config::Fields::Types.register(self)
end
end
end
end
end
Team.send(:rails_admin, &team_config2)
expect(fields.map(&:name)).to match_array %i(id wins)
end
end
end

module ExampleModule
Expand Down

0 comments on commit 37aa038

Please sign in to comment.