Browse files

refactor Apartment module to allow easily resetting config

allow db config to be set manually
  • Loading branch information...
1 parent 505ea1f commit e3d16889f99190bb2f9567010951eae561a08e02 @bradrobertson bradrobertson committed May 31, 2012
View
13 lib/apartment.rb
@@ -3,8 +3,11 @@
module Apartment
class << self
- attr_accessor :use_postgres_schemas, :seed_after_create, :prepend_environment
- attr_writer :database_names, :excluded_models, :default_schema
+ ACCESSOR_METHODS = [:use_postgres_schemas, :seed_after_create, :prepend_environment]
+ WRITER_METHODS = [:database_names, :excluded_models, :default_schema]
+
+ attr_accessor(*ACCESSOR_METHODS)
+ attr_writer(*WRITER_METHODS)
# configure apartment with available options
def configure
@@ -24,6 +27,12 @@ def excluded_models
def default_schema
@default_schema || "public"
end
+
+ # Reset all the config for Apartment
+ def reset
+ (ACCESSOR_METHODS + WRITER_METHODS).each{|method| instance_variable_set(:"@#{method}", nil) }
+ end
+
end
autoload :Database, 'apartment/database'
View
2 lib/apartment/database.rb
@@ -10,6 +10,8 @@ module Database
delegate :create, :current_database, :drop, :process, :process_excluded_models, :reset, :seed, :switch, :to => :adapter
+ attr_writer :config
+
# Initialize Apartment config options such as excluded_models
#
def init
View
2 spec/integration/delayed_job_integration_spec.rb
@@ -26,7 +26,7 @@
after do
Apartment::Test.drop_schema database
Apartment::Test.drop_schema database2
- Apartment::Test.reset
+ Apartment.reset
end
describe Apartment::Delayed::Requirements do
View
2 spec/spec_helper.rb
@@ -32,7 +32,7 @@
end
config.after(:each) do
- Apartment::Test.reset
+ Apartment.reset
end
end
View
4 spec/unit/config_spec.rb
@@ -6,10 +6,6 @@
let(:excluded_models){ [Company] }
- after do
- Apartment::Test.reset
- end
-
it "should yield the Apartment object" do
Apartment.configure do |config|
config.excluded_models = []

0 comments on commit e3d1688

Please sign in to comment.