diff --git a/lib/database_cleaner/active_record/base.rb b/lib/database_cleaner/active_record/base.rb index a8d6672..7a90b3a 100644 --- a/lib/database_cleaner/active_record/base.rb +++ b/lib/database_cleaner/active_record/base.rb @@ -38,14 +38,12 @@ module DatabaseCleaner end end - def create_connection_klass + def create_connection_class Class.new(::ActiveRecord::Base) end - - - def connection_klass - @connection_klass ||= if @db == :default || (@db.nil? && connection_hash.nil?) + def connection_class + @connection_class ||= if @db == :default || (@db.nil? && connection_hash.nil?) ::ActiveRecord::Base elsif connection_hash lookup_from_connection_pool || establish_connection @@ -65,9 +63,9 @@ module DatabaseCleaner end def establish_connection - klass = create_connection_klass - klass.send :establish_connection, connection_hash - klass + strategy_class = create_connection_class + strategy_class.send :establish_connection, connection_hash + strategy_class end end diff --git a/lib/database_cleaner/active_record/deletion.rb b/lib/database_cleaner/active_record/deletion.rb index 29da584..2eebdea 100644 --- a/lib/database_cleaner/active_record/deletion.rb +++ b/lib/database_cleaner/active_record/deletion.rb @@ -53,7 +53,7 @@ module DatabaseCleaner::ActiveRecord class Deletion < Truncation def clean - connection = connection_klass.connection + connection = connection_class.connection connection.disable_referential_integrity do tables_to_truncate(connection).each do |table_name| connection.delete_table table_name diff --git a/lib/database_cleaner/active_record/transaction.rb b/lib/database_cleaner/active_record/transaction.rb index d19b82a..077b33c 100644 --- a/lib/database_cleaner/active_record/transaction.rb +++ b/lib/database_cleaner/active_record/transaction.rb @@ -7,24 +7,24 @@ module DatabaseCleaner::ActiveRecord include ::DatabaseCleaner::Generic::Transaction def start - if connection_klass.connection.respond_to?(:increment_open_transactions) - connection_klass.connection.increment_open_transactions + if connection_class.connection.respond_to?(:increment_open_transactions) + connection_class.connection.increment_open_transactions else - connection_klass.__send__(:increment_open_transactions) + connection_class.__send__(:increment_open_transactions) end - connection_klass.connection.begin_db_transaction + connection_class.connection.begin_db_transaction end def clean - return unless connection_klass.connection.open_transactions > 0 + return unless connection_class.connection.open_transactions > 0 - connection_klass.connection.rollback_db_transaction + connection_class.connection.rollback_db_transaction - if connection_klass.connection.respond_to?(:decrement_open_transactions) - connection_klass.connection.decrement_open_transactions + if connection_class.connection.respond_to?(:decrement_open_transactions) + connection_class.connection.decrement_open_transactions else - connection_klass.__send__(:decrement_open_transactions) + connection_class.__send__(:decrement_open_transactions) end end end diff --git a/lib/database_cleaner/active_record/truncation.rb b/lib/database_cleaner/active_record/truncation.rb index d15dc39..deef5bb 100755 --- a/lib/database_cleaner/active_record/truncation.rb +++ b/lib/database_cleaner/active_record/truncation.rb @@ -224,7 +224,7 @@ module DatabaseCleaner::ActiveRecord include ::DatabaseCleaner::Generic::Truncation def clean - connection = connection_klass.connection + connection = connection_class.connection connection.disable_referential_integrity do if pre_count? && connection.respond_to?(:pre_count_truncate_tables) connection.pre_count_truncate_tables(tables_to_truncate(connection), {:reset_ids => reset_ids?}) diff --git a/spec/database_cleaner/active_record/base_spec.rb b/spec/database_cleaner/active_record/base_spec.rb index 5e21a54..0bed4f3 100644 --- a/spec/database_cleaner/active_record/base_spec.rb +++ b/spec/database_cleaner/active_record/base_spec.rb @@ -105,20 +105,20 @@ my_db: end end - describe "create_connection_klass" do + describe "create_connection_class" do it "should return a class" do - subject.create_connection_klass.should be_a(Class) + subject.create_connection_class.should be_a(Class) end it "should return a class extending ::ActiveRecord::Base" do - subject.create_connection_klass.ancestors.should include(::ActiveRecord::Base) + subject.create_connection_class.ancestors.should include(::ActiveRecord::Base) end end - describe "connection_klass" do - it { expect{ subject.connection_klass }.to_not raise_error } + describe "connection_class" do + it { expect{ subject.connection_class }.to_not raise_error } it "should default to ActiveRecord::Base" do - subject.connection_klass.should == ::ActiveRecord::Base + subject.connection_class.should == ::ActiveRecord::Base end context "when connection_hash is set" do @@ -126,17 +126,17 @@ my_db: before { ::ActiveRecord::Base.stub!(:respond_to?).and_return(false)} before { subject.stub(:connection_hash).and_return(hash) } - it "should create connection_klass if it doesnt exist if connection_hash is set" do - subject.should_receive(:create_connection_klass).and_return(mock('class').as_null_object) - subject.connection_klass + 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_klass if connection_hash is set" do - klass = mock('klass') - klass.should_receive(:establish_connection).with(hash) + 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) - subject.should_receive(:create_connection_klass).and_return(klass) - subject.connection_klass + subject.should_receive(:create_connection_class).and_return(strategy_class) + subject.connection_class end end end diff --git a/spec/database_cleaner/base_spec.rb b/spec/database_cleaner/base_spec.rb index 58dd2a7..6cb27df 100644 --- a/spec/database_cleaner/base_spec.rb +++ b/spec/database_cleaner/base_spec.rb @@ -274,10 +274,10 @@ module DatabaseCleaner end describe "create_strategy" do - let(:klass) { mock("klass",:new => mock("instance")) } + let(:strategy_class) { mock("strategy_class",:new => mock("instance")) } before :each do - subject.stub(:orm_strategy).and_return(klass) + subject.stub(:orm_strategy).and_return(strategy_class) end it "should pass the first argument to orm_strategy" do @@ -285,12 +285,12 @@ module DatabaseCleaner subject.create_strategy :strategy end it "should pass the remainding argument to orm_strategy.new" do - klass.should_receive(:new).with(:params => {:lorum => "ipsum"}) + strategy_class.should_receive(:new).with(:params => {:lorum => "ipsum"}) subject.create_strategy :strategy, {:params => {:lorum => "ipsum"}} end it "should return the resulting strategy" do - subject.create_strategy( :strategy ).should == klass.new + subject.create_strategy( :strategy ).should == strategy_class.new end end @@ -415,10 +415,10 @@ module DatabaseCleaner end describe "orm_strategy" do - let (:klass) { mock("klass") } + let (:strategy_class) { mock("strategy_class") } before(:each) do - subject.stub(:orm_module).and_return(klass) + subject.stub(:orm_module).and_return(strategy_class) end context "in response to a LoadError" do @@ -433,31 +433,31 @@ module DatabaseCleaner end it "should ask orm_module if it will list available_strategies" do - klass.should_receive(:respond_to?).with(:available_strategies) + strategy_class.should_receive(:respond_to?).with(:available_strategies) - subject.stub(:orm_module).and_return(klass) + subject.stub(:orm_module).and_return(strategy_class) expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified end it "should use available_strategies (for the error message) if its available" do - klass.stub(:respond_to?).with(:available_strategies).and_return(true) - klass.should_receive(:available_strategies).and_return([]) + strategy_class.stub(:respond_to?).with(:available_strategies).and_return(true) + strategy_class.should_receive(:available_strategies).and_return([]) - subject.stub(:orm_module).and_return(klass) + subject.stub(:orm_module).and_return(strategy_class) expect { subject.send(:orm_strategy,:a_strategy) }.to raise_error UnknownStrategySpecified end end it "should return the constant of the Strategy class requested" do - strategy_klass = mock("strategy klass") + strategy_strategy_class = mock("strategy strategy_class") subject.stub(:require).with(anything).and_return(true) - klass.should_receive(:const_get).with("Cunningplan").and_return(strategy_klass) + strategy_class.should_receive(:const_get).with("Cunningplan").and_return(strategy_strategy_class) - subject.send(:orm_strategy, :cunningplan).should == strategy_klass + subject.send(:orm_strategy, :cunningplan).should == strategy_strategy_class end end