Skip to content

Commit

Permalink
Merge pull request nulldb#10 from avdi/master
Browse files Browse the repository at this point in the history
Moving away from Rails and RSpec dependence
  • Loading branch information
myronmarston committed Oct 21, 2011
2 parents a10169c + 6ba9106 commit 2f9e02d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
13 changes: 6 additions & 7 deletions activerecord-nulldb-adapter.gemspec
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Avdi Grimm", "Myron Marston"]
s.date = %q{2010-09-01}
s.date = %q{2011-09-12}
s.description = %q{A database backend that translates database interactions into no-ops. Using NullDB enables you to test your model business logic - including after_save hooks - without ever touching a real database.}
s.email = %q{myron.marston@gmail.com}
s.extra_rdoc_files = [
Expand All @@ -18,12 +18,16 @@ Gem::Specification.new do |s|
]
s.files = [
".gitignore",
"Gemfile",
"Gemfile.lock",
"LICENSE",
"README.rdoc",
"Rakefile",
"VERSION",
"activerecord-nulldb-adapter.gemspec",
"ginger_scenarios.rb",
"lib/nulldb.rb",
"lib/activerecord-nulldb-adapter.rb",
"lib/active_record/connection_adapters/nulldb_adapter.rb",
"lib/nulldb/arel_compiler.rb",
"lib/nulldb_rspec.rb",
Expand All @@ -46,13 +50,8 @@ Gem::Specification.new do |s|
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
if ENV['TEST_RAILS_3_1']
s.add_runtime_dependency(%q<activerecord>, [">= 3.1.0.rc4"])
else
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0", "< 3.1"])
end
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0", "< 3.1"])
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
s.add_development_dependency(%q<rake>)
else
s.add_dependency(%q<activerecord>, [">= 2.0.0", "< 3.1"])
s.add_dependency(%q<rspec>, [">= 1.2.9"])
Expand Down
8 changes: 7 additions & 1 deletion lib/active_record/connection_adapters/nulldb_adapter.rb
@@ -1,6 +1,7 @@
require 'logger'
require 'stringio'
require 'singleton'
require 'pathname'
require 'active_record/connection_adapters/abstract_adapter'

unless respond_to?(:tap)
Expand Down Expand Up @@ -159,7 +160,12 @@ def tables
def columns(table_name, name = nil)
if @tables.size <= 1
ActiveRecord::Migration.verbose = false
Kernel.load(File.join(Rails.root, @schema_path))
schema_path = if Pathname(@schema_path).absolute?
@schema_path
else
File.join(Rails.root, @schema_path)
end
Kernel.load(schema_path)
end

if table = @tables[table_name]
Expand Down
1 change: 1 addition & 0 deletions lib/activerecord-nulldb-adapter.rb
@@ -0,0 +1 @@
require 'nulldb'
17 changes: 17 additions & 0 deletions lib/nulldb.rb
@@ -0,0 +1,17 @@
module NullDB
def self.nullify(options={})
@prev_connection = ActiveRecord::Base.connection_pool.try(:spec)
ActiveRecord::Base.establish_connection(options.merge(:adapter => :nulldb))
end

def self.restore
if @prev_connection
ActiveRecord::Base.establish_connection(@prev_connection)
end
end

def self.checkpoint
ActiveRecord::Base.connection.checkpoint!
end
end

0 comments on commit 2f9e02d

Please sign in to comment.