activerecord-nulldb-adapter 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,6 +8,10 @@ interactions into no-ops. Using NullDB enables you to test your model
8
8
  business logic - including +after_save+ hooks - without ever touching
9
9
  a real database.
10
10
 
11
+ == Installation
12
+
13
+ gem install activerecord-nulldb-adapter
14
+
11
15
  == How
12
16
 
13
17
  Once installed, NullDB can be used much like any other ActiveRecord
@@ -124,7 +128,7 @@ nothing will be saved.
124
128
  == Version Compatibility
125
129
 
126
130
  The specs pass against ruby {1.8.6}[http://integrity186.heroku.com/null-db], {1.8.7}[http://integrity187.heroku.com/null-db]
127
- and {1.9.1}[http://integrity191.heroku.com/null-db], using ActiveRecord 2.0.0 to 2.3.5.
131
+ and {1.9.1}[http://integrity191.heroku.com/null-db], using any version of ActiveRecord since 2.0.0, including ActiveRecord 3.0.0.beta.
128
132
 
129
133
  == Who
130
134
 
@@ -133,9 +137,7 @@ It is currently maintained by {Myron Marston}[http://github.com/myronmarston].
133
137
 
134
138
  == Where
135
139
 
136
- * Homepage: http://nulldb.rubyforge.org
137
- * Project Info: http://rubyforge.org/projects/nulldb/
138
- * SCM: http://rubyforge.org/scm/?group_id=7512
140
+ * Homepage: http://github.com/nulldb/nulldb
139
141
 
140
142
  == Changes
141
143
 
@@ -144,7 +146,11 @@ It is currently maintained by {Myron Marston}[http://github.com/myronmarston].
144
146
  * Version 0.0.2 (2007-05-31)
145
147
  - Moved to Rubyforge
146
148
  * Version 0.1.0 (2010-03-02)
147
- - Released as a gem, with some bug fixes.
149
+ - Released as nulldb gem, with some bug fixes.
150
+ * Version 0.1.1 (2010-03-15)
151
+ - Released as activerecord-nulldb-adapter gem.
152
+ * Version 0.2.0 (2010-03-20)
153
+ - Rails 3 support. All specs pass against ActiveRecord 3.0.0.beta.
148
154
 
149
155
  == License
150
156
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{activerecord-nulldb-adapter}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Avdi Grimm", "Myron Marston"]
12
- s.date = %q{2010-03-15}
12
+ s.date = %q{2010-03-20}
13
13
  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.}
14
14
  s.email = %q{myron.marston@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -26,9 +26,9 @@ Gem::Specification.new do |s|
26
26
  "ginger_scenarios.rb",
27
27
  "lib/active_record/connection_adapters/nulldb_adapter.rb",
28
28
  "lib/nulldb_rspec.rb",
29
+ "lib/tasks/database.rake",
29
30
  "spec/nulldb_spec.rb",
30
- "spec/spec.opts",
31
- "tasks/database.rake"
31
+ "spec/spec.opts"
32
32
  ]
33
33
  s.homepage = %q{http://github.com/nulldb/nulldb}
34
34
  s.rdoc_options = ["--charset=UTF-8"]
data/ginger_scenarios.rb CHANGED
@@ -11,7 +11,11 @@ Ginger.configure do |config|
11
11
  config.aliases["active_record"] = "activerecord"
12
12
  config.aliases["active_support"] = "activesupport"
13
13
 
14
- versions = %w( 2.3.5 2.3.4 2.3.3 2.3.2 )
14
+ versions = []
15
+
16
+ # Rails 3 doesn't work on Ruby 1.8.6, so skip it.
17
+ versions << '3.0.0.beta' unless RUBY_VERSION == '1.8.6'
18
+ versions += %w( 2.3.5 2.3.4 2.3.3 2.3.2 )
15
19
  versions += %w(
16
20
  2.2.3 2.2.2
17
21
  2.1.2 2.1.1 2.1.0
@@ -2,6 +2,7 @@ require 'logger'
2
2
  require 'stringio'
3
3
  require 'singleton'
4
4
  require 'active_record/connection_adapters/abstract_adapter'
5
+ require 'active_support/core_ext/object/returning' unless Object.new.respond_to?(:returning)
5
6
 
6
7
  class ActiveRecord::Base
7
8
  # Instantiate a new NullDB connection. Used by ActiveRecord internally.
@@ -68,7 +69,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
68
69
 
69
70
  # Recognized options:
70
71
  #
71
- # [+:schema+] path to the schema file, relative to RAILS_ROOT
72
+ # [+:schema+] path to the schema file, relative to Rails.root
72
73
  def initialize(config={})
73
74
  @log = StringIO.new
74
75
  @logger = Logger.new(@log)
@@ -134,7 +135,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
134
135
  def columns(table_name, name = nil)
135
136
  if @tables.size <= 1
136
137
  ActiveRecord::Migration.verbose = false
137
- Kernel.load(File.join(RAILS_ROOT, @schema_path))
138
+ Kernel.load(File.join(Rails.root, @schema_path))
138
139
  end
139
140
 
140
141
  if table = @tables[table_name]
@@ -160,13 +161,14 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
160
161
  end
161
162
  end
162
163
 
163
- def insert(statement, name, primary_key, object_id, sequence_name)
164
+ def insert(statement, name = nil, primary_key = nil, object_id = nil, sequence_name = nil)
164
165
  returning(object_id || next_unique_id) do
165
166
  with_entry_point(:insert) do
166
167
  super(statement, name, primary_key, object_id, sequence_name)
167
168
  end
168
169
  end
169
170
  end
171
+ alias :create :insert
170
172
 
171
173
  def update(statement, name=nil)
172
174
  with_entry_point(:update) do
@@ -19,15 +19,14 @@ def wrap_task(task_name, &wrapper)
19
19
  end
20
20
  end
21
21
 
22
- # For later exploration...
23
- # namespace :db do
24
- # namespace :test do
25
- # wrap_task :purge do |wrapped_task|
26
- # if ActiveRecord::Base.configurations["test"]["adapter"] == "nulldb"
27
- # # NO-OP
28
- # else
29
- # wrapped_task.invoke
30
- # end
31
- # end
32
- # end
33
- # end
22
+ namespace :db do
23
+ namespace :test do
24
+ wrap_task :purge do |wrapped_task|
25
+ if ActiveRecord::Base.configurations["test"]["adapter"] == "nulldb"
26
+ # NO-OP
27
+ else
28
+ wrapped_task.invoke
29
+ end
30
+ end
31
+ end
32
+ end
data/spec/nulldb_spec.rb CHANGED
@@ -15,7 +15,11 @@ end
15
15
  class TablelessModel < ActiveRecord::Base
16
16
  end
17
17
 
18
- RAILS_ROOT = "RAILS_ROOT"
18
+ module Rails
19
+ def self.root
20
+ 'Rails.root'
21
+ end
22
+ end
19
23
 
20
24
  describe "NullDB with no schema pre-loaded" do
21
25
  before :each do
@@ -23,14 +27,14 @@ describe "NullDB with no schema pre-loaded" do
23
27
  ActiveRecord::Migration.stub!(:verbose=)
24
28
  end
25
29
 
26
- it "should load RAILS_ROOT/db/schema.rb if no alternate is specified" do
30
+ it "should load Rails.root/db/schema.rb if no alternate is specified" do
27
31
  ActiveRecord::Base.establish_connection :adapter => :nulldb
28
- Kernel.should_receive(:load).with("RAILS_ROOT/db/schema.rb")
32
+ Kernel.should_receive(:load).with("Rails.root/db/schema.rb")
29
33
  ActiveRecord::Base.connection.columns('schema_info')
30
34
  end
31
35
 
32
- it "should load the specified schema relative to RAILS_ROOT" do
33
- Kernel.should_receive(:load).with("RAILS_ROOT/foo/myschema.rb")
36
+ it "should load the specified schema relative to Rails.root" do
37
+ Kernel.should_receive(:load).with("Rails.root/foo/myschema.rb")
34
38
  ActiveRecord::Base.establish_connection :adapter => :nulldb,
35
39
  :schema => "foo/myschema.rb"
36
40
  ActiveRecord::Base.connection.columns('schema_info')
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Avdi Grimm
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-03-15 00:00:00 -07:00
18
+ date: 2010-03-20 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -65,9 +65,9 @@ files:
65
65
  - ginger_scenarios.rb
66
66
  - lib/active_record/connection_adapters/nulldb_adapter.rb
67
67
  - lib/nulldb_rspec.rb
68
+ - lib/tasks/database.rake
68
69
  - spec/nulldb_spec.rb
69
70
  - spec/spec.opts
70
- - tasks/database.rake
71
71
  has_rdoc: true
72
72
  homepage: http://github.com/nulldb/nulldb
73
73
  licenses: []