Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial work on more thorough config reset, refs #275, #289, #515

  • Loading branch information...
commit 42aba16e8601ba5cc2595e523f73faec331573cf 1 parent 55aa1cf
@kaapa kaapa authored
View
6 app/controllers/rails_admin/application_controller.rb
@@ -31,15 +31,15 @@ def get_object
private
def _authenticate!
- instance_eval &RailsAdmin.authenticate_with
+ instance_eval &RailsAdmin::Config.authenticate_with
end
def _authorize!
- instance_eval &RailsAdmin.authorize_with
+ instance_eval &RailsAdmin::Config.authorize_with
end
def _current_user
- instance_eval &RailsAdmin.current_user_method
+ instance_eval &RailsAdmin::Config.current_user_method
end
def set_plugin_name
View
4 config/initializers/active_record_extensions.rb
@@ -1,5 +1,9 @@
if defined?(::ActiveRecord)
class ActiveRecord::Base
+ def self.rails_admin(&block)
+ RailsAdmin::Config.model(self, &block)
+ end
+
def rails_admin_default_object_label_method
"#{self.class.to_s} ##{self.try :id}"
end
View
159 lib/rails_admin.rb
@@ -8,152 +8,57 @@
require 'rails_admin/support/core_extensions'
module RailsAdmin
- class AuthenticationNotConfigured < StandardError; end
-
- # RailsAdmin is setup to try and authenticate with warden
- # If warden is found, then it will try to authenticate
- #
- # This is valid for custom warden setups, and also devise
- # If you're using the admin setup for devise, you should set RailsAdmin to use the admin
- #
- # By default, this will raise in any of the following environments
- # * production
- # * beta
- # * uat
- # * staging
+ # Copy of initializer blocks for reset and reinitialization
#
- # @see RailsAdmin.authenticate_with
- # @see RailsAdmin.authorize_with
- DEFAULT_AUTHENTICATION = Proc.new do
- warden = request.env['warden']
- if warden
- warden.authenticate!
- else
- if %w(production beta uat staging).include?(Rails.env)
- raise AuthenticationNotConfigured, "See RailsAdmin.authenticate_with or setup Devise / Warden"
- end
- end
- end
-
- DEFAULT_AUTHORIZE = Proc.new {}
-
- DEFAULT_CURRENT_USER = Proc.new do
- warden = request.env["warden"]
- if warden
- warden.user
- elsif respond_to?(:current_user)
- current_user
- else
- raise "See RailsAdmin.current_user_method or setup Devise / Warden"
- end
- end
+ # @see RailsAdmin.reset
+ @initializers = []
- # Setup authentication to be run as a before filter
- # This is run inside the controller instance so you can setup any authentication you need to
- #
- # By default, the authentication will run via warden if available
- # and will run the default.
- #
- # If you use devise, this will authenticate the same as _authenticate_user!_
- #
- # @example Devise admin
- # RailsAdmin.authenticate_with do
- # authenticate_admin!
- # end
- #
- # @example Custom Warden
- # RailsAdmin.authenticate_with do
- # warden.authenticate! :scope => :paranoid
- # end
- #
- # @see RailsAdmin::DEFAULT_AUTHENTICATION
- def self.authenticate_with(&blk)
- @authenticate = blk if blk
- @authenticate || DEFAULT_AUTHENTICATION
+ def self.authenticate_with(&block)
+ ActiveSupport::Deprecation.warn("'#{self.name}.authenticate_with { }' is deprecated, use 'RailsAdmin.config{|c| c.authenticate_with { } instead", caller)
+ self.config {|c| c.authenticate_with(&block) }
end
- # Setup authorization to be run as a before filter
- # This is run inside the controller instance so you can setup any authorization you need to.
- #
- # By default, there is no authorization.
- #
- # @example Custom
- # RailsAdmin.authorize_with do
- # redirect_to root_path unless warden.user.is_admin?
- # end
- #
- # To use an authorization adapter, pass the name of the adapter. For example,
- # to use with CanCan[https://github.com/ryanb/cancan], pass it like this.
- #
- # @example CanCan
- # RailsAdmin.authorize_with :cancan
- #
- # See the wiki[https://github.com/sferik/rails_admin/wiki] for more on authorization.
- #
- # @see RailsAdmin::DEFAULT_AUTHORIZE
def self.authorize_with(*args, &block)
- extension = args.shift
-
- if(extension)
- @authorize = Proc.new {
- @authorization_adapter = AUTHORIZATION_ADAPTERS[extension].new(*([self] + args).compact)
- }
- else
- @authorize = block if block
- end
-
- @authorize || DEFAULT_AUTHORIZE
+ ActiveSupport::Deprecation.warn("'#{self.name}.authorize_with { }' is deprecated, use 'RailsAdmin.config{|c| c.authorize_with { } instead", caller)
+ self.config {|c| c.authorize_with(*args, &block) }
end
- # Setup a different method to determine the current user or admin logged in.
- # This is run inside the controller instance and made available as a helper.
- #
- # By default, _request.env["warden"].user_ or _current_user_ will be used.
- #
- # @example Custom
- # RailsAdmin.current_user_method do
- # current_admin
- # end
- #
- # @see RailsAdmin::DEFAULT_CURRENT_USER
def self.current_user_method(&block)
- @current_user = block if block
- @current_user || DEFAULT_CURRENT_USER
+ ActiveSupport::Deprecation.warn("'#{self.name}.current_user_method { }' is deprecated, use 'RailsAdmin.config{|c| c.current_user_method { } instead", caller)
+ self.config {|c| c.current_user_method(&block) }
end
- # Setup configuration using an extension-provided ConfigurationAdapter
- #
- # @example Custom configuration for role-based setup.
- # RailsAdmin.configure_with(:custom) do |config|
- # config.models = ['User', 'Comment']
- # config.roles = {
- # 'Admin' => :all,
- # 'User' => ['User']
- # }
- # end
- #
- # RailsAdmin.config do
- # # standard config still applies...
- # end
- def self.configure_with(extension)
- configuration = CONFIGURATION_ADAPTERS[extension].new
- yield(configuration) if block_given?
+ def self.configure_with(extension, &block)
+ ActiveSupport::Deprecation.warn("'#{self.name}.configure_with { }' is deprecated, use 'RailsAdmin.config{|c| c.configure_with { } instead", caller)
+ self.config {|c| c.configure_with(extension, &block) }
end
# Setup RailsAdmin
#
- # If a model class is provided as the first argument model specific
- # configuration is loaded and returned.
+ # Given the first argument is a model class, a model class name
+ # or an abstract model object proxies to model configuration method.
+ #
+ # If only a block is passed, yields RailsAdmin::Config. The block will be
+ # stored for resetting the engine before each request in development mode.
#
- # Otherwise yields self for general configuration to be used in
- # an initializer.
+ # Otherwise returns RailsAdmin::Config class.
#
- # @see RailsAdmin::Config.load
+ # @see RailsAdmin::Config
def self.config(entity = nil, &block)
- if not entity
+ if entity
+ RailsAdmin::Config.model(entity, &block)
+ elsif block_given?
+ @initializers << block
yield RailsAdmin::Config
else
- RailsAdmin::Config.model(entity, &block)
+ RailsAdmin::Config
end
end
+
+ # Reset RailsAdmin configuration to defaults and then reapply all stored
+ # initialization blocks.
+ def self.reset
+ RailsAdmin::Config.reset
+ @initializers.clear.each {|block| self.config(&block)}
+ end
end
View
335 lib/rails_admin/config.rb
@@ -5,114 +5,267 @@
module RailsAdmin
module Config
- # Stores model configuration objects in a hash identified by model's class
- # name.
+ class AuthenticationNotConfigured < StandardError; end
+ # RailsAdmin is setup to try and authenticate with warden
+ # If warden is found, then it will try to authenticate
#
- # @see RailsAdmin::Config.model
- @@registry = {}
-
- # Configuration option to specify which models you want to exclude.
- @@excluded_models = []
- mattr_accessor :excluded_models
-
- # Configuration option to specify a whitelist of models you want to RailsAdmin to work with.
- # The excluded_models list applies against the whitelist as well and further reduces the models
- # RailsAdmin will use.
- # If included_models is left empty ([]), then RailsAdmin will automatically use all the models
- # in your application (less any excluded_models you may have specified).
- @@included_models = []
- mattr_accessor :included_models
-
- @@default_search_operator = 'default'
- def self.default_search_operator=(operator)
- if %w{ default like starts_with ends_with is = }.include? operator
- @@default_search_operator = operator
+ # This is valid for custom warden setups, and also devise
+ # If you're using the admin setup for devise, you should set RailsAdmin to use the admin
+ #
+ # By default, this will raise in any of the following environments
+ # * production
+ # * beta
+ # * uat
+ # * staging
+ #
+ # @see RailsAdmin::Config.authenticate_with
+ # @see RailsAdmin::Config.authorize_with
+ DEFAULT_AUTHENTICATION = Proc.new do
+ warden = request.env['warden']
+ if warden
+ warden.authenticate!
else
- raise ArgumentError, "Search operator '#{operator}' not supported"
+ if %w(production beta uat staging).include?(Rails.env)
+ raise AuthenticationNotConfigured, "See RailsAdmin::Config.authenticate_with or setup Devise / Warden"
+ end
end
end
- mattr_reader :default_search_operator
- # Configuration option to specify which method names will be searched for
- # to be used as a label for object records. This defaults to [:name, :title]
- mattr_accessor :label_methods
- self.label_methods = [:name, :title]
+ DEFAULT_AUTHORIZE = Proc.new {}
- # Shortcut to access the list section's class configuration
- # within a config DSL block
- #
- # @see RailsAdmin::Config::Sections::List
- def self.list
- RailsAdmin::Config::Sections::List
+ DEFAULT_CURRENT_USER = Proc.new do
+ warden = request.env["warden"]
+ if warden
+ warden.user
+ elsif respond_to?(:current_user)
+ current_user
+ else
+ raise "See RailsAdmin::Config.current_user_method or setup Devise / Warden"
+ end
end
- # Loads a model configuration instance from the registry or registers
- # a new one if one is yet to be added.
- #
- # First argument can be an instance of requested model, it's class object,
- # it's class name as a string or symbol or a RailsAdmin::AbstractModel
- # instance.
- #
- # If a block is given it is evaluated in the context of configuration instance.
- #
- # Returns given model's configuration
- #
- # @see RailsAdmin::Config.registry
- def self.model(entity, &block)
- key = begin
- if entity.kind_of?(RailsAdmin::AbstractModel)
- entity.model.name.to_sym
- elsif entity.kind_of?(Class)
- entity.name.to_sym
- elsif entity.kind_of?(String) || entity.kind_of?(Symbol)
- entity.to_sym
+ class << self
+ # Setup authentication to be run as a before filter
+ # This is run inside the controller instance so you can setup any authentication you need to
+ #
+ # By default, the authentication will run via warden if available
+ # and will run the default.
+ #
+ # If you use devise, this will authenticate the same as _authenticate_user!_
+ #
+ # @example Devise admin
+ # RailsAdmin.config do |config|
+ # config.authenticate_with do
+ # authenticate_admin!
+ # end
+ # end
+ #
+ # @example Custom Warden
+ # RailsAdmin.config do |config|
+ # config.authenticate_with do
+ # warden.authenticate! :scope => :paranoid
+ # end
+ # end
+ #
+ # @see RailsAdmin::Config::DEFAULT_AUTHENTICATION
+ def authenticate_with(&blk)
+ @authenticate = blk if blk
+ @authenticate || DEFAULT_AUTHENTICATION
+ end
+
+ # Setup authorization to be run as a before filter
+ # This is run inside the controller instance so you can setup any authorization you need to.
+ #
+ # By default, there is no authorization.
+ #
+ # @example Custom
+ # RailsAdmin.config do |config|
+ # config.authorize_with do
+ # redirect_to root_path unless warden.user.is_admin?
+ # end
+ # end
+ #
+ # To use an authorization adapter, pass the name of the adapter. For example,
+ # to use with CanCan[https://github.com/ryanb/cancan], pass it like this.
+ #
+ # @example CanCan
+ # RailsAdmin.config do |config|
+ # config.authorize_with :cancan
+ # end
+ #
+ # See the wiki[https://github.com/sferik/rails_admin/wiki] for more on authorization.
+ #
+ # @see RailsAdmin::Config::DEFAULT_AUTHORIZE
+ def authorize_with(*args, &block)
+ extension = args.shift
+ if(extension)
+ @authorize = Proc.new {
+ @authorization_adapter = RailsAdmin::AUTHORIZATION_ADAPTERS[extension].new(*([RailsAdmin] + args).compact)
+ }
else
- entity.class.name.to_sym
+ @authorize = block if block
end
+ @authorize || DEFAULT_AUTHORIZE
end
- config = @@registry[key] ||= RailsAdmin::Config::Model.new(entity)
- config.instance_eval(&block) if block
- config
- end
- # Returns all model configurations
- #
- # If a block is given it is evaluated in the context of configuration
- # instances.
- #
- # @see RailsAdmin::Config.registry
- def self.models(&block)
- RailsAdmin::AbstractModel.all.map{|m| model(m, &block)}
- end
+ # Setup configuration using an extension-provided ConfigurationAdapter
+ #
+ # @example Custom configuration for role-based setup.
+ # RailsAdmin.config do |config|
+ # config.configure_with(:custom) do |config|
+ # config.models = ['User', 'Comment']
+ # config.roles = {
+ # 'Admin' => :all,
+ # 'User' => ['User']
+ # }
+ # end
+ # end
+ def configure_with(extension)
+ configuration = RailsAdmin::CONFIGURATION_ADAPTERS[extension].new
+ yield(configuration) if block_given?
+ end
- # Shortcut to access the navigation section's class configuration
- # within a config DSL block
- #
- # @see RailsAdmin::Config::Sections::Navigation
- def self.navigation
- RailsAdmin::Config::Sections::Navigation
- end
+ # Setup a different method to determine the current user or admin logged in.
+ # This is run inside the controller instance and made available as a helper.
+ #
+ # By default, _request.env["warden"].user_ or _current_user_ will be used.
+ #
+ # @example Custom
+ # RailsAdmin.config do |config|
+ # config.current_user_method do
+ # current_admin
+ # end
+ # end
+ #
+ # @see RailsAdmin::Config::DEFAULT_CURRENT_USER
+ def current_user_method(&block)
+ @current_user = block if block
+ @current_user || DEFAULT_CURRENT_USER
+ end
- # Reset a provided model's configuration. If omitted, reset all model
- # configurations.
- #
- # @see RailsAdmin::Config.registry
- def self.reset(model = nil)
- if model.kind_of?(Class) || model.kind_of?(String) || model.kind_of?(Symbol)
+ # Configuration option to specify which models you want to exclude.
+ attr_accessor :excluded_models
+
+ # Configuration option to specify a whitelist of models you want to RailsAdmin to work with.
+ # The excluded_models list applies against the whitelist as well and further reduces the models
+ # RailsAdmin will use.
+ # If included_models is left empty ([]), then RailsAdmin will automatically use all the models
+ # in your application (less any excluded_models you may have specified).
+ attr_accessor :included_models
+
+ # Default items per page value used if a model level option has not
+ # been configured
+ attr_accessor :default_items_per_page
+
+ attr_reader :default_search_operator
+
+ def default_search_operator=(operator)
+ if %w{ default like starts_with ends_with is = }.include? operator
+ @default_search_operator = operator
+ else
+ raise ArgumentError, "Search operator '#{operator}' not supported"
+ end
+ end
+
+ # Configuration option to specify which method names will be searched for
+ # to be used as a label for object records. This defaults to [:name, :title]
+ attr_accessor :label_methods
+
+ # Stores model configuration objects in a hash identified by model's class
+ # name.
+ #
+ # @see RailsAdmin::Config.model
+ attr_reader :registry
+
+ # Shortcut to access the list section's class configuration
+ # within a config DSL block
+ #
+ # @see RailsAdmin::Config::Sections::List
+ def list
+ RailsAdmin::Config::Sections::List
+ end
+
+ # Loads a model configuration instance from the registry or registers
+ # a new one if one is yet to be added.
+ #
+ # First argument can be an instance of requested model, it's class object,
+ # it's class name as a string or symbol or a RailsAdmin::AbstractModel
+ # instance.
+ #
+ # If a block is given it is evaluated in the context of configuration instance.
+ #
+ # Returns given model's configuration
+ #
+ # @see RailsAdmin::Config.registry
+ def model(entity, &block)
+ key = begin
+ if entity.kind_of?(RailsAdmin::AbstractModel)
+ entity.model.name.to_sym
+ elsif entity.kind_of?(Class)
+ entity.name.to_sym
+ elsif entity.kind_of?(String) || entity.kind_of?(Symbol)
+ entity.to_sym
+ else
+ entity.class.name.to_sym
+ end
+ end
+ config = @registry[key] ||= RailsAdmin::Config::Model.new(entity)
+ config.instance_eval(&block) if block
+ config
+ end
+
+ # Returns all model configurations
+ #
+ # If a block is given it is evaluated in the context of configuration
+ # instances.
+ #
+ # @see RailsAdmin::Config.registry
+ def models(&block)
+ RailsAdmin::AbstractModel.all.map{|m| model(m, &block)}
+ end
+
+ # Shortcut to access the navigation section's class configuration
+ # within a config DSL block
+ #
+ # @see RailsAdmin::Config::Sections::Navigation
+ def navigation
+ RailsAdmin::Config::Sections::Navigation
+ end
+
+ # Reset all configurations to defaults.
+ #
+ # @see RailsAdmin::Config.registry
+ def reset
+ @authenticate = nil
+ @authorize = nil
+ @current_user = nil
+ @default_items_per_page = 20
+ @default_search_operator = 'default'
+ @excluded_models = []
+ @included_models = []
+ @label_methods = [:name, :title]
+ @registry = {}
+ end
+
+ # Reset a provided model's configuration.
+ #
+ # @see RailsAdmin::Config.registry
+ def reset_model(model)
key = model.kind_of?(Class) ? model.name.to_sym : model.to_sym
- @@registry.delete(key)
- else
- @@registry.clear
+ @registry.delete(key)
end
- end
- # Get all models that are configured as visible sorted by their weight and label.
- #
- # @see RailsAdmin::Config::Hideable
- def self.visible_models
- RailsAdmin::Config.models.select {|m| m.visible? }.sort do |a, b|
- (weight_order = a.weight <=> b.weight) == 0 ? a.label.downcase <=> b.label.downcase : weight_order
+ # Get all models that are configured as visible sorted by their weight and label.
+ #
+ # @see RailsAdmin::Config::Hideable
+ def visible_models
+ self.models.select {|m| m.visible? }.sort do |a, b|
+ (weight_order = a.weight <=> b.weight) == 0 ? a.label.downcase <=> b.label.downcase : weight_order
+ end
end
end
+
+ # Set default values for configuration options on load
+ self.reset
end
-end
+end
View
17 lib/rails_admin/config/sections/list.rb
@@ -21,14 +21,21 @@ def initialize(parent)
end
end
- # Default items per page value used if a model level option has not
- # been configured
- cattr_accessor :default_items_per_page
- @@default_items_per_page = 20
+ def self.default_items_per_page
+ ActiveSupport::Deprecation.warn("'#{self.name}.default_items_per_page' is deprecated, use 'RailsAdmin::Config.default_items_per_page' instead", caller)
+ RailsAdmin::Config.default_items_per_page
+ end
+
+ def self.default_items_per_page=(value)
+ ActiveSupport::Deprecation.warn("'#{self.name}.default_items_per_page=' is deprecated, use 'RailsAdmin.config{|c| c.default_items_per_page = #{value}}' instead", caller)
+ RailsAdmin.config do |config|
+ config.default_items_per_page = value
+ end
+ end
# Number of items listed per page
register_instance_option(:items_per_page) do
- RailsAdmin::Config::Sections::List.default_items_per_page
+ RailsAdmin::Config.default_items_per_page
end
register_instance_option(:sort_by) do
View
7 lib/rails_admin/engine.rb
@@ -8,5 +8,12 @@ class Engine < Rails::Engine
app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
end
end
+
+ config.to_prepare do
+ if @reset_rails_admin
+ RailsAdmin.reset
+ end
+ @reset_rails_admin = true
+ end
end
end
View
37 spec/lib/rails_admin_spec.rb
@@ -27,10 +27,6 @@
end
describe ".authorize_with" do
- after do
- RailsAdmin.authorize_with(nil) { @authorization_adapter = nil }
- end
-
context "given a key for a extension with authorization" do
before do
RailsAdmin.add_extension(:example, ExampleModule, {
@@ -39,19 +35,20 @@
end
it "initializes the authorization adapter" do
- options = nil
- proc = RailsAdmin.authorize_with(:example, options)
-
ExampleModule::AuthorizationAdapter.should_receive(:new).with(RailsAdmin)
- proc.call
+ RailsAdmin.config do |config|
+ config.authorize_with(:example)
+ end
+ RailsAdmin.config.authorize_with.call
end
it "passes through any additional arguments to the initializer" do
options = { :option => true }
- proc = RailsAdmin.authorize_with(:example, options)
-
ExampleModule::AuthorizationAdapter.should_receive(:new).with(RailsAdmin, options)
- proc.call
+ RailsAdmin.config do |config|
+ config.authorize_with(:example, options)
+ end
+ RailsAdmin.config.authorize_with.call
end
end
end
@@ -66,14 +63,17 @@
it "initializes configuration adapter" do
ExampleModule::ConfigurationAdapter.should_receive(:new)
- RailsAdmin.configure_with(:example)
+ RailsAdmin.config do |config|
+ config.configure_with(:example)
+ end
end
it "yields the (optionally) provided block, passing the initialized adapter" do
configurator = nil
-
- RailsAdmin.configure_with(:example) do |config|
- configurator = config
+ RailsAdmin.config do |config|
+ config.configure_with(:example) do |configuration_adapter|
+ configurator = configuration_adapter
+ end
end
configurator.should be_a(ExampleModule::ConfigurationAdapter)
end
@@ -82,17 +82,10 @@
describe ".config" do
context ".default_search_operator" do
- around(:each) do |example|
- old_search_operator = RailsAdmin::Config.default_search_operator
- example.run
- RailsAdmin::Config.default_search_operator = old_search_operator
- end
-
it "sets the default_search_operator" do
RailsAdmin.config do |config|
config.default_search_operator = 'starts_with'
end
-
RailsAdmin::Config.default_search_operator.should == 'starts_with'
end
View
4 spec/requests/basic/list/rails_admin_basic_list_spec.rb
@@ -270,7 +270,7 @@
describe "GET /admin/player with 20 pages, page 8" do
before(:each) do
- items_per_page = RailsAdmin::Config::Sections::List.default_items_per_page
+ items_per_page = RailsAdmin.config.default_items_per_page
(items_per_page * 20).times { FactoryGirl.create(:player) }
visit rails_admin_list_path(:model_name => "player", :page => 8)
end
@@ -282,7 +282,7 @@
describe "list with 20 pages, page 20" do
before(:each) do
- items_per_page = RailsAdmin::Config::Sections::List.default_items_per_page
+ items_per_page = RailsAdmin.config.default_items_per_page
@players = (items_per_page * 20).times.map { FactoryGirl.create(:player) }
visit rails_admin_list_path(:model_name => "player", :page => 20)
end
View
9 spec/requests/history/rails_admin_history_spec.rb
@@ -57,7 +57,6 @@
describe "model history fetch" do
before :all do
- @default_items_per_page = RailsAdmin::Config::Sections::List.default_items_per_page
@model = RailsAdmin::AbstractModel.new("Player")
player = FactoryGirl.create :player
30.times do |i|
@@ -72,8 +71,8 @@
histories[1].all.count.should == 20
end
- it "should respect RailsAdmin::Config::Sections::List.default_items_per_page" do
- RailsAdmin::Config::Sections::List.default_items_per_page = 15
+ it "should respect RailsAdmin::Config.default_items_per_page" do
+ RailsAdmin.config.default_items_per_page = 15
histories = RailsAdmin::AbstractHistory.history_for_model @model, nil, false, false, false, nil
histories[0].should == 2
histories[1].all.count.should == 15
@@ -106,10 +105,6 @@
end
end
end
-
- after :all do
- RailsAdmin::Config::Sections::List.default_items_per_page = @default_items_per_page
- end
end
end
View
24 spec/requests/rails_admin_spec.rb
@@ -73,33 +73,19 @@
describe "model whitelist:" do
- before do
- RailsAdmin::AbstractModel.instance_variable_get("@models").clear
- RailsAdmin::Config.excluded_models = []
- RailsAdmin::Config.included_models = []
- RailsAdmin::Config.reset
- end
-
- after :all do
- RailsAdmin::AbstractModel.instance_variable_get("@models").clear
- RailsAdmin::Config.excluded_models = []
- RailsAdmin::Config.included_models = []
- RailsAdmin::Config.reset
- end
-
it 'should only use included models' do
- RailsAdmin::Config.included_models = [Team, League]
+ RailsAdmin.config.included_models = [Team, League]
RailsAdmin::AbstractModel.all.map(&:model).should == [League, Team] #it gets sorted
end
it 'should not restrict models if included_models is left empty' do
- RailsAdmin::Config.included_models = []
+ RailsAdmin.config.included_models = []
RailsAdmin::AbstractModel.all.map(&:model).should include(Team, League)
end
it 'should further remove excluded models (whitelist - blacklist)' do
- RailsAdmin::Config.excluded_models = [Team]
- RailsAdmin::Config.included_models = [Team, League]
+ RailsAdmin.config.excluded_models = [Team]
+ RailsAdmin.config.included_models = [Team, League]
RailsAdmin::AbstractModel.all.map(&:model).should == [League]
end
@@ -108,7 +94,7 @@
end
it 'excluded? returns true for any model not on the list' do
- RailsAdmin::Config.included_models = [Team, League]
+ RailsAdmin.config.included_models = [Team, League]
team_config = RailsAdmin.config(RailsAdmin::AbstractModel.new('Team'))
fan_config = RailsAdmin.config(RailsAdmin::AbstractModel.new('Fan'))
View
2  spec/spec_helper.rb
@@ -51,9 +51,9 @@
config.include Warden::Test::Helpers
config.before(:each) do
+ RailsAdmin::Config.reset
RailsAdmin::Config.excluded_models = [RelTest, FieldTest]
RailsAdmin::AbstractModel.instance_variable_get("@models").clear
- RailsAdmin::Config.reset
RailsAdmin::AbstractModel.new("Division").destroy_all!
RailsAdmin::AbstractModel.new("Draft").destroy_all!
Please sign in to comment.
Something went wrong with that request. Please try again.