Skip to content
Browse files

add scanned models memoization.

  • Loading branch information...
1 parent 78ec124 commit c1a380eb6d57158edca46212f1127ff924eefa7c @bbenezech bbenezech committed Feb 17, 2012
View
5 lib/rails_admin.rb
@@ -31,9 +31,4 @@ def self.config(entity = nil, &block)
RailsAdmin::Config
end
end
-
- # Reset RailsAdmin configuration to defaults
- def self.reset
- RailsAdmin::Config.reset
- end
end
View
4 lib/rails_admin/abstract_model.rb
@@ -6,6 +6,10 @@ class AbstractModel
attr_reader :model, :adapter
class << self
+ def reset
+ @@all = nil
+ end
+
def all(adapter = nil)
@@all ||= Config.models_pool.map{ |m| new(m) }.compact
adapter ? @@all.select{|m| m.adapter == adapter} : @@all
View
10 lib/rails_admin/adapters/active_record.rb
@@ -4,7 +4,7 @@
module RailsAdmin
module Adapters
- module ActiveRecord
+ module ActiveRecord
DISABLED_COLUMN_TYPES = [:tsvector, :blob, :binary, :spatial]
@@polymorphic_parents = nil
@@ -55,13 +55,7 @@ def new(params = {})
end
def destroy(objects)
- [objects].flatten.map &:destroy
- end
-
- def destroy_all!
- model.all.each do |object|
- object.destroy
- end
+ Array.wrap(objects).each &:destroy
end
def has_and_belongs_to_many_associations
View
20 lib/rails_admin/config.rb
@@ -194,17 +194,19 @@ def default_search_operator=(operator)
# pool of all found model names from the whole application
def models_pool
possible =
- included_models.map(&:to_s).presence ||
- ([Rails.application] + Rails::Application::Railties.engines).map do |app|
- (app.paths['app/models'] + app.config.autoload_paths).map do |load_path|
- Dir.glob(app.root.join(load_path)).map do |load_dir|
- Dir.glob(load_dir + "/**/*.rb").map do |filename|
- # app/models/module/class.rb => module/class.rb => module/class => Module::Class
- lchomp(filename, "#{app.root.join(load_dir)}/").chomp('.rb').camelize
+ included_models.map(&:to_s).presence || (
+ @@system_models ||= # memoization for tests
+ ([Rails.application] + Rails::Application::Railties.engines).map do |app|
+ (app.paths['app/models'] + app.config.autoload_paths).map do |load_path|
+ Dir.glob(app.root.join(load_path)).map do |load_dir|
+ Dir.glob(load_dir + "/**/*.rb").map do |filename|
+ # app/models/module/class.rb => module/class.rb => module/class => Module::Class
+ lchomp(filename, "#{app.root.join(load_dir)}/").chomp('.rb').camelize
+ end
end
end
- end
- end.flatten
+ end.flatten
+ )
excluded = (excluded_models.map(&:to_s) + ['RailsAdmin::History'])
View
30 spec/spec_helper.rb
@@ -60,31 +60,27 @@ def password_digest(password)
config.include Warden::Test::Helpers
config.before(:each) do
- RailsAdmin.reset
+ RailsAdmin::Config.reset
+ RailsAdmin::AbstractModel.reset
RailsAdmin::Config.excluded_models = [RelTest, FieldTest, Category]
RailsAdmin::Config.audit_with :history
- RailsAdmin::AbstractModel.all = nil
- RailsAdmin::AbstractModel.new("Category").destroy_all!
- RailsAdmin::AbstractModel.new("Division").destroy_all!
- RailsAdmin::AbstractModel.new("Draft").destroy_all!
- RailsAdmin::AbstractModel.new("Fan").destroy_all!
- RailsAdmin::AbstractModel.new("League").destroy_all!
- RailsAdmin::AbstractModel.new("Player").destroy_all!
- RailsAdmin::AbstractModel.new("Team").destroy_all!
- RailsAdmin::AbstractModel.new("User").destroy_all!
- RailsAdmin::AbstractModel.new("Foo::Bar").destroy_all!
- RailsAdmin::AbstractModel.new("FieldTest").destroy_all!
-
- user = User.create(
+ Category.delete_all
+ Division.delete_all
+ Draft.delete_all
+ Fan.delete_all
+ League.delete_all
+ Player.delete_all
+ Team.delete_all
+ User.delete_all
+ Foo::Bar.delete_all
+ FieldTest.delete_all
+ login_as User.create(
:email => "username@example.com",
:password => "password"
)
-
- login_as user
end
config.after(:each) do
-
Warden.test_reset!
end
end

0 comments on commit c1a380e

Please sign in to comment.
Something went wrong with that request. Please try again.