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

Allow multiple config blocks for a single resource in RailsAdmin #1781

Conversation

sepastian
Copy link

When using RailsAdmin within another gem, it should be possible to spread out and merge configuration blocks for a single resource across initializers and models, in an attempt to produce DRY code.

Currently, RailsAdmin allows multiple configuration blocks for a single resource, however, blocks evaluating later will overwrite earlier blocks.

This pull requests contains two small changes to RailsAdmin::Config::LazyModel and RailsAdmin::Config, to implement multiple configuration blocks for a single resource.

For example, in the current version of RailsAdmin, these two blocks would overwrite each other - depending on the exact order of loading (see comment in lib/rails_admin/config/lazy_model.rb) :

# app/models/some_model.rb
class SomeModel
  rails_admin do
    :
  end
end

# config/initializers/rails_admin.rb
config.model SomeModel do
  :
end

After applying this pull request, the settings defined in config/initializers/rails_admin.rb will evaluate before the ones found in SomeModel. The settings from config/initializers/rails_admin.rb will be maintained, although SomeModel may chose to overwrite some settings.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.17%) when pulling e9962f2 on sepastian:feature_multiple_config_blocks into 9a4d1ba on sferik:master.

@sepastian
Copy link
Author

Hi, I am trying to run the RA rspec test suite, but bundler keeps complaining about my adapter specification. What is required in terms of database settings to get rspec up and running?

rails_admin$ rspec
git://github.com/mongoid/mongoid.git (at master) is not checked out. Please run `bundle install`
/var/lib/gems/1.9.1/gems/multi_json-1.8.0/lib/multi_json.rb:108:in `rescue in load_adapter': Did not recognize your adapter specification. (ArgumentError)
    from /var/lib/gems/1.9.1/gems/multi_json-1.8.0/lib/multi_json.rb:97:in `load_adapter'
    from /var/lib/gems/1.9.1/gems/multi_json-1.8.0/lib/multi_json.rb:101:in `load_adapter'
    from /var/lib/gems/1.9.1/gems/multi_json-1.8.0/lib/multi_json.rb:91:in `use'
    from /var/lib/gems/1.9.1/gems/multi_json-1.8.0/lib/multi_json.rb:73:in `adapter'
    from /var/lib/gems/1.9.1/gems/multi_json-1.8.0/lib/multi_json.rb:131:in `current_adapter'
    from /var/lib/gems/1.9.1/gems/multi_json-1.8.0/lib/multi_json.rb:137:in `dump'
    from /var/lib/gems/1.9.1/gems/simplecov-0.7.1/lib/simplecov/json.rb:20:in `dump'
    from /var/lib/gems/1.9.1/gems/simplecov-0.7.1/lib/simplecov/result_merger.rb:69:in `block in store_result'
    from /var/lib/gems/1.9.1/gems/simplecov-0.7.1/lib/simplecov/result_merger.rb:68:in `open'
    from /var/lib/gems/1.9.1/gems/simplecov-0.7.1/lib/simplecov/result_merger.rb:68:in `store_result'
    from /var/lib/gems/1.9.1/gems/simplecov-0.7.1/lib/simplecov.rb:48:in `result'
    from /var/lib/gems/1.9.1/gems/simplecov-0.7.1/lib/simplecov/configuration.rb:133:in `block in at_exit'
    from /var/lib/gems/1.9.1/gems/simplecov-0.7.1/lib/simplecov/defaults.rb:52:in `call'
    from /var/lib/gems/1.9.1/gems/simplecov-0.7.1/lib/simplecov/defaults.rb:52:in `block in <top (required)>'

@caboteria
Copy link
Collaborator

@sepastian it looks as if you need to run "bundle install" to install the mongoid gem from git.

@ideadapt
Copy link
Contributor

Others already had this problem as well, including me. I am not exactly sure which step made it finally work, but I tried with this: https://github.com/bundler/bundler/blob/master/ISSUES.md#other-problems

@bbenezech
Copy link
Collaborator

Closing this as stalled. Please reopen and rebase if you still want to add it. Some tests would definitely be needed as well for such a feature.

@bbenezech bbenezech closed this Feb 4, 2016
semenovDL added a commit to semenovDL/rails_admin that referenced this pull request Jul 9, 2016
semenovDL added a commit to semenovDL/rails_admin that referenced this pull request Jul 11, 2016
semenovDL added a commit to semenovDL/rails_admin that referenced this pull request Jul 11, 2016
* feature/allow_multiple_configuration_blocks:
  Correct behavior of LazyModel with multiple blocks. Add specs.
  Add opportunity for chain of configuration from initializers to concerns and models. Based on railsadminteam#1781
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants