Permalink
Browse files

Removed use of Anonymous class when establishing a connection to a da…

…tabase via ActiveRecord since this is no longer supported in ActiveRecord 4.
  • Loading branch information...
1 parent 466ccfd commit 947bb27a20e781a78a05b0a3a2f8aa14d58af89f @davebrace davebrace committed Mar 30, 2013
Showing with 3 additions and 26 deletions.
  1. +1 −7 lib/database_cleaner/active_record/base.rb
  2. +2 −19 spec/database_cleaner/active_record/base_spec.rb
@@ -38,10 +38,6 @@ def load_config
end
end
- def create_connection_class
- Class.new(::ActiveRecord::Base)
- end
-
def connection_class
@connection_class ||= if @db && !@db.is_a?(Symbol)
@db
@@ -63,9 +59,7 @@ def lookup_from_connection_pool
end
def establish_connection
- strategy_class = create_connection_class
- strategy_class.send :establish_connection, connection_hash
- strategy_class
+ ::ActiveRecord::Base.establish_connection(connection_hash)
end
end
@@ -119,16 +119,6 @@ class ExampleStrategy
end
end
- describe "create_connection_class" do
- it "should return a class" do
- subject.create_connection_class.should be_a(Class)
- end
-
- it "should return a class extending ::ActiveRecord::Base" do
- subject.create_connection_class.ancestors.should include(::ActiveRecord::Base)
- end
- end
-
describe "connection_class" do
it { expect { subject.connection_class }.to_not raise_error }
it "should default to ActiveRecord::Base" do
@@ -158,16 +148,9 @@ class ExampleStrategy
before { ::ActiveRecord::Base.stub!(:respond_to?).and_return(false) }
before { subject.stub(:connection_hash).and_return(hash) }
- it "should create connection_class if it doesnt exist if connection_hash is set" do
- subject.should_receive(:create_connection_class).and_return(mock('class').as_null_object)
- subject.connection_class
- end
-
- it "should configure the class from create_connection_class if connection_hash is set" do
- strategy_class = mock('strategy_class')
- strategy_class.should_receive(:establish_connection).with(hash)
+ it "establish a connection using ActiveRecord::Base" do
+ ::ActiveRecord::Base.should_receive(:establish_connection).with(hash)
- subject.should_receive(:create_connection_class).and_return(strategy_class)
subject.connection_class
end
end

0 comments on commit 947bb27

Please sign in to comment.