Skip to content

Commit

Permalink
Show the warning message if asset_source is not set
Browse files Browse the repository at this point in the history
Refs. #3467
  • Loading branch information
mshibuya committed Feb 19, 2022
1 parent 1f1a478 commit 3771542
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Metrics/MethodLength:
Max: 29 # TODO: Lower to 15

Metrics/ModuleLength:
Max: 207 # TODO: Lower to 100
Max: 217 # TODO: Lower to 100

Metrics/ParameterLists:
Max: 8 # TODO: Lower to 4
Expand Down
15 changes: 13 additions & 2 deletions lib/rails_admin/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class << self
attr_accessor :navigation_static_label

# Set where RailsAdmin fetches JS/CSS from, defaults to :sprockets
attr_accessor :asset_source
attr_writer :asset_source

# Finish initialization by executing deferred configuration blocks
def initialize!
Expand Down Expand Up @@ -257,6 +257,17 @@ def model(entity, &block)
@registry[key]
end

def asset_source
@asset_source ||=
begin
warn <<-MSG.gsub(/^ +/, '').freeze
[Warning] After upgrading RailsAdmin to 3.x you haven't set asset_source yet, using :sprockets as the default.
To suppress this message, run 'rails rails_admin:install' to setup the asset delivery method suitable to you.
MSG
:sprockets
end
end

def default_hidden_fields=(fields)
if fields.is_a?(Array)
@default_hidden_fields = {}
Expand Down Expand Up @@ -326,7 +337,7 @@ def reset
@show_gravatar = true
@navigation_static_links = {}
@navigation_static_label = nil
@asset_source = (defined?(Webpacker) ? :webpacker : :sprockets)
@asset_source = nil
@parent_controller = '::ActionController::Base'
@forgery_protection_settings = {with: :exception}
RailsAdmin::Config::Actions.reset
Expand Down
2 changes: 1 addition & 1 deletion rails_admin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.summary = 'Admin for Rails'
spec.version = RailsAdmin::Version
spec.post_install_message = '
### Upgrading from 2.x.x to 3.x.x ###
### Upgrading RailsAdmin from 2.x.x to 3.x.x ###
Due to introduction of Webpack/Webpacker support, some additional dependencies and configuration will be needed.
Running `bin/rails g rails_admin:install` will suggest required changes, based on the current setup of your app.
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def password_digest(password)

DatabaseCleaner.start
RailsAdmin::Config.reset
RailsAdmin::Config.asset_source = CI_ASSET
end

config.after(:each) do
Expand Down

0 comments on commit 3771542

Please sign in to comment.