Browse files

use duck typing instead of looking for PG adapter specifically

  • Loading branch information...
1 parent aa4dec4 commit 8029d320a7343a9aa408032c40bc79e8e7a9fe5a @adamwiggins adamwiggins committed Jun 25, 2008
Showing with 4 additions and 6 deletions.
  1. +1 −1 lib/yaml_db.rb
  2. +3 −5 spec/yaml_load_spec.rb
View
2 lib/yaml_db.rb
@@ -161,7 +161,7 @@ def self.load_records(table, column_names, records)
end
def self.reset_pk_sequence!(table_name)
- if ActiveRecord::Base.connection.kind_of?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
+ if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
ActiveRecord::Base.connection.reset_pk_sequence!(table_name)
end
end
View
8 spec/yaml_load_spec.rb
@@ -73,15 +73,13 @@
end
it "should call reset pk sequence if the connection adapter is postgres" do
- module ActiveRecord; module ConnectionAdapters; class PostgreSQLAdapter; end; end; end;
- ActiveRecord::Base.connection.stub!(:kind_of?).with(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).and_return(true)
+ ActiveRecord::Base.connection.should_receive(:respond_to?).with(:reset_pk_sequence!).and_return(true)
ActiveRecord::Base.connection.should_receive(:reset_pk_sequence!).with('mytable')
YamlDb::Load.reset_pk_sequence!('mytable')
end
- it "should not call reset_pk_sequence if the connection adapter is not postgres" do
- module ActiveRecord; module ConnectionAdapters; class PostgreSQLAdapter; end; end; end;
- ActiveRecord::Base.connection.stub!(:kind_of?).with(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter).and_return(false)
+ it "should not call reset pk sequence for other adapters" do
+ ActiveRecord::Base.connection.should_receive(:respond_to?).with(:reset_pk_sequence!).and_return(false)
ActiveRecord::Base.connection.should_not_receive(:reset_pk_sequence!)
YamlDb::Load.reset_pk_sequence!('mytable')
end

0 comments on commit 8029d32

Please sign in to comment.