activerecord-nulldb-adapter 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f69f1b8bd9e94574231d49a3331d7450898dbf53
4
+ data.tar.gz: 30c4eee10acc87ad0cb5506aa9e7ea152d757e61
5
+ SHA512:
6
+ metadata.gz: ef9146cce2f44f0ce28f41a82c8d0267b87a80683495d0db646af723a12203a57260c33027426f15e621b188ddb06ce00444d35a64a01a279ff013e0cd2a2ff9
7
+ data.tar.gz: b26bfde72d5f8f9b50e27c9d1400633825f951db515f71465f8f1f9fb433ac7f3affdc9448821c931ba0855ccfdd5b83766ee6e1f08486de71b8ad59a11ae444
@@ -0,0 +1,22 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - jruby
9
+ - rbx
10
+
11
+ matrix:
12
+ fast_finish: true
13
+ allow_failures:
14
+ - rvm: jruby
15
+ - rvm: rbx
16
+
17
+ gemfile:
18
+ - gemfiles/activerecord_2.3.gemfile
19
+ - gemfiles/activerecord_3.0.gemfile
20
+ - gemfiles/activerecord_3.1.gemfile
21
+ - gemfiles/activerecord_3.2.gemfile
22
+ - gemfiles/activerecord_4.0.gemfile
@@ -0,0 +1,20 @@
1
+ appraise "activerecord-2.3" do
2
+ gem "activerecord", "~> 2.3.0"
3
+ end
4
+
5
+ appraise "activerecord-3.0" do
6
+ gem "activerecord", "~> 3.0.0"
7
+ end
8
+
9
+ appraise "activerecord-3.1" do
10
+ gem "activerecord", "~> 3.1.0"
11
+ end
12
+
13
+ appraise "activerecord-3.2" do
14
+ gem "activerecord", "~> 3.2.0"
15
+ end
16
+
17
+ appraise "activerecord-4.0" do
18
+ gem "activerecord", "~> 4.0.0"
19
+ end
20
+
@@ -0,0 +1,37 @@
1
+ 0.3.0 (2014-01-31)
2
+ -----------
3
+ - Drops 1.8.7 support.
4
+ - Adds support for Ruby 2.0, 2.1 and ActiveRecord 4.
5
+ - Fixes ActiveRecord 2.3 support on Ruby 2 and up.
6
+ - Misc small fixes
7
+
8
+
9
+ 0.2.1 (2010-09-01)
10
+ -----------
11
+ - Updated Rails 3 support so that nulldb works against AR 3.0.0.
12
+ - Add support for RSpec 2.
13
+
14
+
15
+ 0.2.0 (2010-03-20)
16
+ -----------
17
+ - Rails 3 support. All specs pass against ActiveRecord 3.0.0.beta.
18
+
19
+
20
+ 0.1.1 (2010-03-15)
21
+ -----------
22
+ - Released as activerecord-nulldb-adapter gem.
23
+
24
+
25
+ 0.1.0 (2010-03-02)
26
+ -----------
27
+ - Released as nulldb gem, with some bug fixes.
28
+
29
+
30
+ 0.0.2 (2007-05-31)
31
+ -----------
32
+ - Moved to Rubyforge
33
+
34
+
35
+ 0.0.1 (2007-02-18)
36
+ -----------
37
+ - Initial Release
data/Gemfile CHANGED
@@ -1,3 +1,19 @@
1
- source "http://rubygems.org"
2
- gemspec
3
- gem 'appraisal'
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', '>= 2.0.0'
4
+
5
+ platforms :ruby_20, :ruby_21 do
6
+ gem 'iconv'
7
+ gem 'coveralls', :group => :test, :require => false
8
+ end
9
+
10
+ group :development, :test do
11
+ gem 'spec'
12
+ gem 'rspec', '>= 1.2.9'
13
+ gem 'rake'
14
+ end
15
+
16
+ group :development do
17
+ gem 'jeweler'
18
+ gem 'appraisal', :github => 'thoughtbot/appraisal'
19
+ end
@@ -1,3 +1,9 @@
1
+
2
+ {<img src="https://badge.fury.io/rb/activerecord-nulldb-adapter.png" alt="Gem Version" />}[http://badge.fury.io/rb/activerecord-nulldb-adapter]
3
+ {<img src="https://codeclimate.com/github/nulldb/nulldb.png" />}[https://codeclimate.com/github/nulldb/nulldb]
4
+ {<img src="https://travis-ci.org/nulldb/nulldb.png?branch=master" alt="Build Status" />}[https://travis-ci.org/nulldb/nulldb]
5
+
6
+
1
7
  = The NullDB Connection Adapter Plugin
2
8
 
3
9
  == What
@@ -8,11 +14,23 @@ interactions into no-ops. Using NullDB enables you to test your model
8
14
  business logic - including +after_save+ hooks - without ever touching
9
15
  a real database.
10
16
 
17
+ == Compatibility
18
+
19
+ === Ruby
20
+ Currently supported Ruby versions: MRI 1.9.3, 2.0.0, 2.1.0
21
+
22
+ Experimental support provided for: JRuby, Rubinius (both in 1.9 mode)
23
+
24
+ === ActiveRecord
25
+ Any version of ActiveRecord since 2.0, including ActiveRecord 4.0
26
+
27
+ It is tested against AR 2.3, 3.0, 3.1, 3.2 and 4.0.
28
+
11
29
  == Installation
12
30
 
13
31
  gem install activerecord-nulldb-adapter
14
32
 
15
- == How
33
+ == How
16
34
 
17
35
  Once installed, NullDB can be used much like any other ActiveRecord
18
36
  database adapter:
@@ -25,7 +43,7 @@ RAILS_ROOT/db/schema.rb. You can override that by setting the
25
43
  +schema+ option:
26
44
 
27
45
  ActiveRecord::Base.establish_connection :adapter => :nulldb,
28
- :schema => foo/myschema.rb
46
+ :schema => 'foo/myschema.rb'
29
47
 
30
48
  NullDB comes with RSpec integration. To replace the database with
31
49
  NullDB in all of your specs, put the following in your
@@ -83,7 +101,7 @@ into its standard Rake tasks, you may find that this generates
83
101
  unexpected and difficult-to-debug behavior. Workarounds for this are
84
102
  under development.
85
103
 
86
- == Why
104
+ == Why
87
105
 
88
106
  There are a number of advantages to writing unit tests that never
89
107
  touch the database. The biggest is probably speed of execution - unit
@@ -96,22 +114,11 @@ http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database.
96
114
  NullDB is one way to separate your unit tests from the database. It
97
115
  was inspired by the ARBS[http://arbs.rubyforge.org/] and
98
116
  UnitRecord[http://unit-test-ar.rubyforge.org/] libraries. It differs
99
- from them in a couple of ways:
100
-
101
- 1. It works. At the time of writing both ARBS and UnitRecord were
102
- not working for me out of the box with Rails 2.0.
103
-
104
- 2. It avoids monkey-patching as much as possible. Rather than
105
- re-wiring the secret inner workings of ActiveRecord (and thus being
106
- tightly coupled to those inner workings), NullDB implements the
107
- same [semi-]well-documented public interface that the other standard
108
- database adapters, like MySQL and SQLServer, implement.
109
-
110
- 3. UnitRecord takes the approach of eliminating database interaction
111
- in tests by turning almost every database interaction into an
112
- exception. NullDB recognizes that ActiveRecord objects typically
113
- can't take two steps without consulting the database, so instead it
114
- turns database interactions into no-ops.
117
+ from them in that rather than modifying parts of ActiveRecord, it
118
+ implements the same [semi-]well-documented public interface that the
119
+ other standard database adapters, like MySQL and SQLServer,
120
+ implement. This has enabled it to evolve to support new ActiveRecord
121
+ versions relatively easily.
115
122
 
116
123
  One concrete advantage of this null-object pattern design is that it
117
124
  is possible with NullDB to test +after_save+ hooks. With NullDB, you
@@ -127,12 +134,7 @@ nothing will be saved.
127
134
  migrations will probably break it.
128
135
  * Lots of other things probably don't work. Patches welcome!
129
136
 
130
- == Version Compatibility
131
-
132
- The specs pass against ruby {1.8.6}[http://integrity186.heroku.com/null-db], {1.8.7}[http://integrity187.heroku.com/null-db]
133
- and {1.9.1}[http://integrity191.heroku.com/null-db], using any version of ActiveRecord since 2.0.0, including ActiveRecord 3.0.0.
134
-
135
- == Who
137
+ == Who
136
138
 
137
139
  NullDB was originally written by Avdi Grimm <mailto:avdi@avdi.org>.
138
140
  It is currently maintained by {Myron Marston}[http://github.com/myronmarston].
@@ -141,22 +143,6 @@ It is currently maintained by {Myron Marston}[http://github.com/myronmarston].
141
143
 
142
144
  * Homepage: http://github.com/nulldb/nulldb
143
145
 
144
- == Changes
145
-
146
- * Version 0.0.1 (2007-02-18)
147
- - Initial Release
148
- * Version 0.0.2 (2007-05-31)
149
- - Moved to Rubyforge
150
- * Version 0.1.0 (2010-03-02)
151
- - Released as nulldb gem, with some bug fixes.
152
- * Version 0.1.1 (2010-03-15)
153
- - Released as activerecord-nulldb-adapter gem.
154
- * Version 0.2.0 (2010-03-20)
155
- - Rails 3 support. All specs pass against ActiveRecord 3.0.0.beta.
156
- * Version 0.2.1 (2010-09-01)
157
- - Updated Rails 3 support so that nulldb works against AR 3.0.0.
158
- - Add support for RSpec 2.
159
-
160
146
  == License
161
147
 
162
148
  See the LICENSE file for licensing information.
data/Rakefile CHANGED
@@ -1,6 +1,25 @@
1
- require 'appraisal'
1
+ require 'rubygems'
2
+ require 'rake'
2
3
  require 'rspec/core/rake_task'
3
4
 
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = 'activerecord-nulldb-adapter'
9
+ gem.summary = %Q{The Null Object pattern as applied to ActiveRecord database adapters}
10
+ gem.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.}
11
+ gem.email = "myron.marston@gmail.com"
12
+ gem.homepage = "http://github.com/nulldb/nulldb"
13
+ gem.authors = ["Avdi Grimm", "Myron Marston"]
14
+ gem.rubyforge_project = "nulldb"
15
+ gem.license = "MIT"
16
+
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ end
22
+
4
23
  RSpec::Core::RakeTask.new(:spec)
5
24
  task :default => :spec
6
25
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.0
@@ -1,60 +1,83 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: activerecord-nulldb-adapter 0.3.0 ruby lib
6
+
1
7
  Gem::Specification.new do |s|
2
- s.name = %q{activerecord-nulldb-adapter}
3
- s.version = "0.2.3"
8
+ s.name = "activerecord-nulldb-adapter"
9
+ s.version = "0.3.0"
4
10
 
5
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
6
13
  s.authors = ["Avdi Grimm", "Myron Marston"]
7
- s.date = %q{2011-09-12}
8
- 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.}
9
- s.email = %q{myron.marston@gmail.com}
14
+ s.date = "2014-01-31"
15
+ s.description = "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."
16
+ s.email = "myron.marston@gmail.com"
10
17
  s.extra_rdoc_files = [
11
18
  "LICENSE",
12
- "README.rdoc"
19
+ "README.rdoc"
13
20
  ]
14
21
  s.files = [
15
- ".gitignore",
16
- "Gemfile",
17
- "Gemfile.lock",
18
- "LICENSE",
19
- "README.rdoc",
20
- "Rakefile",
21
- "VERSION",
22
- "activerecord-nulldb-adapter.gemspec",
23
- "lib/nulldb.rb",
24
- "lib/activerecord-nulldb-adapter.rb",
25
- "lib/active_record/connection_adapters/nulldb_adapter.rb",
26
- "lib/nulldb/arel_compiler.rb",
27
- "lib/nulldb/rails.rb",
28
- "lib/nulldb/core.rb",
29
- "lib/nulldb_rspec.rb",
30
- "lib/tasks/database.rake",
31
- "spec/nulldb_spec.rb",
32
- "spec/spec.opts"
33
- ]
34
- s.homepage = %q{http://github.com/nulldb/nulldb}
35
- s.rdoc_options = ["--charset=UTF-8"]
36
- s.require_paths = ["lib"]
37
- s.rubyforge_project = %q{nulldb}
38
- s.rubygems_version = %q{1.3.7}
39
- s.summary = %q{The Null Object pattern as applied to ActiveRecord database adapters}
40
- s.test_files = [
41
- "spec/nulldb_spec.rb"
22
+ ".travis.yml",
23
+ "Appraisals",
24
+ "CHANGES.md",
25
+ "Gemfile",
26
+ "LICENSE",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "activerecord-nulldb-adapter.gemspec",
31
+ "gemfiles/activerecord_2.3.gemfile",
32
+ "gemfiles/activerecord_3.0.gemfile",
33
+ "gemfiles/activerecord_3.1.gemfile",
34
+ "gemfiles/activerecord_3.2.gemfile",
35
+ "gemfiles/activerecord_4.0.gemfile",
36
+ "lib/active_record/connection_adapters/nulldb_adapter.rb",
37
+ "lib/activerecord-nulldb-adapter.rb",
38
+ "lib/nulldb.rb",
39
+ "lib/nulldb/arel_compiler.rb",
40
+ "lib/nulldb/core.rb",
41
+ "lib/nulldb/rails.rb",
42
+ "lib/nulldb_rspec.rb",
43
+ "lib/tasks/database.rake",
44
+ "spec/nulldb_spec.rb",
45
+ "spec/spec.opts"
42
46
  ]
47
+ s.homepage = "http://github.com/nulldb/nulldb"
48
+ s.licenses = ["MIT"]
49
+ s.rubyforge_project = "nulldb"
50
+ s.rubygems_version = "2.2.0"
51
+ s.summary = "The Null Object pattern as applied to ActiveRecord database adapters"
43
52
 
44
53
  if s.respond_to? :specification_version then
45
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
- s.specification_version = 3
54
+ s.specification_version = 4
47
55
 
48
56
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
57
  s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0"])
58
+ s.add_runtime_dependency(%q<iconv>, [">= 0"])
59
+ s.add_development_dependency(%q<spec>, [">= 0"])
50
60
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
61
+ s.add_development_dependency(%q<rake>, [">= 0"])
62
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
63
+ s.add_development_dependency(%q<appraisal>, [">= 0"])
51
64
  else
52
65
  s.add_dependency(%q<activerecord>, [">= 2.0.0"])
66
+ s.add_dependency(%q<iconv>, [">= 0"])
67
+ s.add_dependency(%q<spec>, [">= 0"])
53
68
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
69
+ s.add_dependency(%q<rake>, [">= 0"])
70
+ s.add_dependency(%q<jeweler>, [">= 0"])
71
+ s.add_dependency(%q<appraisal>, [">= 0"])
54
72
  end
55
73
  else
56
74
  s.add_dependency(%q<activerecord>, [">= 2.0.0"])
75
+ s.add_dependency(%q<iconv>, [">= 0"])
76
+ s.add_dependency(%q<spec>, [">= 0"])
57
77
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
78
+ s.add_dependency(%q<rake>, [">= 0"])
79
+ s.add_dependency(%q<jeweler>, [">= 0"])
80
+ s.add_dependency(%q<appraisal>, [">= 0"])
58
81
  end
59
82
  end
60
83
 
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 2.3.0"
6
+
7
+ group :development, :test do
8
+ gem "spec"
9
+ gem "rspec", ">= 1.2.9"
10
+ gem "rake"
11
+ end
12
+
13
+ group :development do
14
+ gem "jeweler"
15
+ gem "appraisal", :github=>"thoughtbot/appraisal"
16
+ end
17
+
18
+ platforms :ruby_20, :ruby_21 do
19
+ gem "iconv"
20
+ gem "coveralls", :group=>:test, :require=>false
21
+ end
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.0.0"
6
+
7
+ group :development, :test do
8
+ gem "spec"
9
+ gem "rspec", ">= 1.2.9"
10
+ gem "rake"
11
+ end
12
+
13
+ group :development do
14
+ gem "jeweler"
15
+ gem "appraisal", :github=>"thoughtbot/appraisal"
16
+ end
17
+
18
+ platforms :ruby_20, :ruby_21 do
19
+ gem "iconv"
20
+ gem "coveralls", :group=>:test, :require=>false
21
+ end
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.1.0"
6
+
7
+ group :development, :test do
8
+ gem "spec"
9
+ gem "rspec", ">= 1.2.9"
10
+ gem "rake"
11
+ end
12
+
13
+ group :development do
14
+ gem "jeweler"
15
+ gem "appraisal", :github=>"thoughtbot/appraisal"
16
+ end
17
+
18
+ platforms :ruby_20, :ruby_21 do
19
+ gem "iconv"
20
+ gem "coveralls", :group=>:test, :require=>false
21
+ end
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.2.0"
6
+
7
+ group :development, :test do
8
+ gem "spec"
9
+ gem "rspec", ">= 1.2.9"
10
+ gem "rake"
11
+ end
12
+
13
+ group :development do
14
+ gem "jeweler"
15
+ gem "appraisal", :github=>"thoughtbot/appraisal"
16
+ end
17
+
18
+ platforms :ruby_20, :ruby_21 do
19
+ gem "iconv"
20
+ gem "coveralls", :group=>:test, :require=>false
21
+ end
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.0"
6
+
7
+ group :development, :test do
8
+ gem "spec"
9
+ gem "rspec", ">= 1.2.9"
10
+ gem "rake"
11
+ end
12
+
13
+ group :development do
14
+ gem "jeweler"
15
+ gem "appraisal", :github=>"thoughtbot/appraisal"
16
+ end
17
+
18
+ platforms :ruby_20, :ruby_21 do
19
+ gem "iconv"
20
+ gem "coveralls", :group=>:test, :require=>false
21
+ end
@@ -2,6 +2,7 @@ require 'logger'
2
2
  require 'stringio'
3
3
  require 'singleton'
4
4
  require 'pathname'
5
+ require 'active_support'
5
6
  require 'active_record/connection_adapters/abstract_adapter'
6
7
  require 'nulldb/core'
7
8
 
@@ -92,12 +93,25 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
92
93
  def method_missing(*args, &block)
93
94
  nil
94
95
  end
96
+
97
+ def to_a
98
+ []
99
+ end
95
100
  end
96
101
 
97
- class EmptyResult
102
+ class EmptyResult < Array
103
+ attr_writer :columns
98
104
  def rows
99
105
  []
100
106
  end
107
+
108
+ def column_types
109
+ columns.map{|col| col.type}
110
+ end
111
+
112
+ def columns
113
+ @columns ||= []
114
+ end
101
115
  end
102
116
 
103
117
  # A convenience method for integratinginto RSpec. See README for example of
@@ -119,7 +133,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
119
133
  @log = StringIO.new
120
134
  @logger = Logger.new(@log)
121
135
  @last_unique_id = 0
122
- @tables = {'schema_info' => TableDefinition.new(nil)}
136
+ @tables = {'schema_info' => new_table_definition(nil)}
123
137
  @indexes = Hash.new { |hash, key| hash[key] = [] }
124
138
  @schema_path = config.fetch(:schema){ "db/schema.rb" }
125
139
  @config = config.merge(:adapter => :nulldb)
@@ -155,7 +169,8 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
155
169
  end
156
170
 
157
171
  def create_table(table_name, options = {})
158
- table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new(self)
172
+ table_definition = new_table_definition(self, table_name, options.delete(:temporary), options)
173
+
159
174
  unless options[:id] == false
160
175
  table_definition.primary_key(options[:primary_key] || "id")
161
176
  end
@@ -194,6 +209,14 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
194
209
  end
195
210
  end
196
211
 
212
+ unless instance_methods.include? :index_name_exists?
213
+ def index_name_exists?(table_name, index_name, default)
214
+ return default unless respond_to?(:indexes)
215
+ index_name = index_name.to_s
216
+ indexes(table_name).detect { |i| i.name == index_name }
217
+ end
218
+ end
219
+
197
220
  def add_fk_constraint(*args)
198
221
  # NOOP
199
222
  end
@@ -252,7 +275,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
252
275
  [].tap do
253
276
  self.execution_log << Statement.new(entry_point, statement)
254
277
  end
255
- end
278
+ end
256
279
 
257
280
  def insert(statement, name = nil, primary_key = nil, object_id = nil, sequence_name = nil, binds = [])
258
281
  (object_id || next_unique_id).tap do
@@ -281,32 +304,44 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
281
304
  end
282
305
  end
283
306
 
284
- def select_one(statement, name=nil)
307
+ def select_one(statement, name=nil, binds = [])
285
308
  with_entry_point(:select_one) do
286
309
  super(statement, name)
287
310
  end
288
311
  end
289
312
 
290
- def select_value(statement, name=nil)
313
+ def select_value(statement, name=nil, binds = [])
291
314
  with_entry_point(:select_value) do
292
315
  super(statement, name)
293
316
  end
294
317
  end
295
318
 
319
+ def select_values(statement, name=nil)
320
+ with_entry_point(:select_values) do
321
+ super(statement, name)
322
+ end
323
+ end
324
+
296
325
  def primary_key(table_name)
297
326
  columns(table_name).detect { |col| col.sql_type == :primary_key }.try(:name)
298
327
  end
299
328
 
300
329
  protected
301
330
 
302
- def select(statement, name, binds = [])
303
- [].tap do
331
+ def select(statement, name = nil, binds = [])
332
+ EmptyResult.new.tap do |r|
333
+ r.columns = columns_for(name)
304
334
  self.execution_log << Statement.new(entry_point, statement)
305
335
  end
306
336
  end
307
337
 
308
338
  private
309
339
 
340
+ def columns_for(table_name)
341
+ table_def = @tables[table_name]
342
+ table_def ? table_def.columns : []
343
+ end
344
+
310
345
  def next_unique_id
311
346
  @last_unique_id += 1
312
347
  end
@@ -334,4 +369,15 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
334
369
  Thread.current[name] = old_value
335
370
  end
336
371
  end
372
+
373
+ def new_table_definition(adapter = nil, table_name = nil, is_temporary = nil, options = {})
374
+ case ::ActiveRecord::VERSION::MAJOR
375
+ when 4
376
+ TableDefinition.new(native_database_types, table_name, is_temporary, options)
377
+ when 2,3
378
+ TableDefinition.new(adapter)
379
+ else
380
+ raise "Unsupported ActiveRecord version #{::ActiveRecord::VERSION::STRING}"
381
+ end
382
+ end
337
383
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support'
2
+ require 'active_support/deprecation'
1
3
  require 'active_record/connection_adapters/nulldb_adapter'
2
4
 
3
5
  module NullDB
@@ -1,5 +1,12 @@
1
1
  require 'rubygems'
2
2
 
3
+ # Use Coveralls/SimpleCov when available
4
+ begin
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
+ rescue LoadError
8
+ end
9
+
3
10
  require 'active_record'
4
11
  require 'active_record/version'
5
12
  $: << File.join(File.dirname(__FILE__), "..", "lib")
@@ -26,8 +33,8 @@ NullDB.configure {|ndb| ndb.project_root = 'Rails.root'}
26
33
 
27
34
  describe "NullDB with no schema pre-loaded" do
28
35
  before :each do
29
- Kernel.stub!(:load)
30
- ActiveRecord::Migration.stub!(:verbose=)
36
+ Kernel.stub(:load)
37
+ ActiveRecord::Migration.stub(:verbose=)
31
38
  end
32
39
 
33
40
  it "should load Rails.root/db/schema.rb if no alternate is specified" do
@@ -78,7 +85,7 @@ describe "NullDB" do
78
85
  add_index "employees", ["name"], :name => "index_employees_on_name"
79
86
  add_index "employees", ["employee_number"], :name => "index_employees_on_employee_number", :unique => true
80
87
  add_index "employees_widgets", ["employee_id", "widget_id"], :name => "my_index"
81
-
88
+
82
89
  add_fk_constraint "foo", "bar", "baz", "buz", "bungle"
83
90
  add_pk_constraint "foo", "bar", {}, "baz", "buz"
84
91
  end
@@ -151,30 +158,30 @@ describe "NullDB" do
151
158
  end
152
159
 
153
160
  it "should log executed SQL statements" do
154
- cxn = @employee.connection
161
+ cxn = Employee.connection
155
162
  exec_count = cxn.execution_log.size
156
163
  @employee.save!
157
164
  cxn.execution_log.size.should == (exec_count + 1)
158
165
  end
159
166
 
160
167
  it "should have the adapter name 'NullDB'" do
161
- @employee.connection.adapter_name.should == "NullDB"
168
+ Employee.connection.adapter_name.should == "NullDB"
162
169
  end
163
170
 
164
171
  it "should support migrations" do
165
- @employee.connection.supports_migrations?.should be_true
172
+ Employee.connection.supports_migrations?.should be_true
166
173
  end
167
174
 
168
175
  it "should always have a schema_info table definition" do
169
- @employee.connection.tables.should include("schema_info")
176
+ Employee.connection.tables.should include("schema_info")
170
177
  end
171
178
 
172
179
  it "should return an empty array from #select" do
173
- @employee.connection.select_all("who cares", "blah").should == []
180
+ Employee.connection.select_all("who cares", "blah").should == []
174
181
  end
175
182
 
176
183
  it "should provide a way to set log checkpoints" do
177
- cxn = @employee.connection
184
+ cxn = Employee.connection
178
185
  @employee.save!
179
186
  cxn.execution_log_since_checkpoint.size.should > 0
180
187
  cxn.checkpoint!
@@ -195,7 +202,7 @@ describe "NullDB" do
195
202
  end
196
203
 
197
204
  it "should tag logged statements with their entry point" do
198
- cxn = @employee.connection
205
+ cxn = Employee.connection
199
206
 
200
207
  should_not_contain_statement(cxn, :insert)
201
208
  @employee.save
@@ -214,17 +221,28 @@ describe "NullDB" do
214
221
 
215
222
  cxn.checkpoint!
216
223
  should_not_contain_statement(cxn, :select_all)
217
- Employee.find(:all)
224
+ Employee.all.each do |emp|; end
218
225
  should_contain_statement(cxn, :select_all)
219
226
 
220
227
  cxn.checkpoint!
221
228
  should_not_contain_statement(cxn, :select_value)
222
229
  Employee.count_by_sql("frobozz")
223
230
  should_contain_statement(cxn, :select_value)
231
+
232
+ cxn.checkpoint!
233
+ should_not_contain_statement(cxn, :select_values)
234
+ cxn.select_values("")
235
+ should_contain_statement(cxn, :select_values)
224
236
  end
225
237
 
226
238
  it "should allow #finish to be called on the result of #execute" do
227
- @employee.connection.execute("blah").finish
239
+ Employee.connection.execute("blah").finish
240
+ end
241
+
242
+ it "should #to_a return empty array on the result of #execute" do
243
+ result = Employee.connection.execute("blah")
244
+ result.to_a.should be_a Array
245
+ result.to_a.should be_empty
228
246
  end
229
247
 
230
248
  def should_have_column(klass, col_name, col_type)
@@ -233,28 +251,28 @@ describe "NullDB" do
233
251
  col.type.should == col_type
234
252
  end
235
253
 
236
-
254
+
237
255
  it "should support adding indexes" do
238
256
  Employee.connection.indexes('employees').size.should == 2
239
257
  Employee.connection.indexes('employees_widgets').size.should == 1
240
258
  end
241
-
259
+
242
260
  it "should support unique indexes" do
243
261
  Employee.connection.indexes('employees').detect{|idx| idx.columns == ["name"]}.unique.should be_false
244
262
  Employee.connection.indexes('employees').detect{|idx| idx.columns == ["employee_number"]}.unique.should be_true
245
263
  end
246
-
264
+
247
265
  it "should support multi-column indexes" do
248
266
  Employee.connection.indexes('employees_widgets').first.columns.should == ["employee_id", "widget_id"]
249
267
  end
250
-
268
+
251
269
  it "should support custom index names" do
252
270
  Employee.connection.indexes('employees_widgets').first.name.should == 'my_index'
253
271
  end
254
272
 
255
273
  it 'should handle ActiveRecord::ConnectionNotEstablished' do
256
274
  ActiveRecord::Base.should_receive(:connection_pool).and_raise(ActiveRecord::ConnectionNotEstablished)
257
- lambda { NullDB.nullify }.should_not raise_error(ActiveRecord::ConnectionNotEstablished)
275
+ lambda { NullDB.nullify }.should_not raise_error
258
276
  end
259
277
  end
260
278
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-nulldb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Avdi Grimm
@@ -10,40 +9,106 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2011-09-12 00:00:00.000000000 Z
12
+ date: 2014-01-31 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: 2.0.0
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: 2.0.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: iconv
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: spec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
31
56
  - !ruby/object:Gem::Dependency
32
57
  name: rspec
33
58
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
59
  requirements:
36
- - - ! '>='
60
+ - - '>='
37
61
  - !ruby/object:Gem::Version
38
62
  version: 1.2.9
39
63
  type: :development
40
64
  prerelease: false
41
65
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
66
  requirements:
44
- - - ! '>='
67
+ - - '>='
45
68
  - !ruby/object:Gem::Version
46
69
  version: 1.2.9
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: jeweler
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: appraisal
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
47
112
  description: A database backend that translates database interactions into no-ops.
48
113
  Using NullDB enables you to test your model business logic - including after_save
49
114
  hooks - without ever touching a real database.
@@ -54,49 +119,52 @@ extra_rdoc_files:
54
119
  - LICENSE
55
120
  - README.rdoc
56
121
  files:
57
- - .gitignore
122
+ - .travis.yml
123
+ - Appraisals
124
+ - CHANGES.md
58
125
  - Gemfile
59
- - Gemfile.lock
60
126
  - LICENSE
61
127
  - README.rdoc
62
128
  - Rakefile
63
129
  - VERSION
64
130
  - activerecord-nulldb-adapter.gemspec
65
- - lib/nulldb.rb
66
- - lib/activerecord-nulldb-adapter.rb
131
+ - gemfiles/activerecord_2.3.gemfile
132
+ - gemfiles/activerecord_3.0.gemfile
133
+ - gemfiles/activerecord_3.1.gemfile
134
+ - gemfiles/activerecord_3.2.gemfile
135
+ - gemfiles/activerecord_4.0.gemfile
67
136
  - lib/active_record/connection_adapters/nulldb_adapter.rb
137
+ - lib/activerecord-nulldb-adapter.rb
138
+ - lib/nulldb.rb
68
139
  - lib/nulldb/arel_compiler.rb
69
- - lib/nulldb/rails.rb
70
140
  - lib/nulldb/core.rb
141
+ - lib/nulldb/rails.rb
71
142
  - lib/nulldb_rspec.rb
72
143
  - lib/tasks/database.rake
73
144
  - spec/nulldb_spec.rb
74
145
  - spec/spec.opts
75
146
  homepage: http://github.com/nulldb/nulldb
76
- licenses: []
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
77
150
  post_install_message:
78
- rdoc_options:
79
- - --charset=UTF-8
151
+ rdoc_options: []
80
152
  require_paths:
81
153
  - lib
82
154
  required_ruby_version: !ruby/object:Gem::Requirement
83
- none: false
84
155
  requirements:
85
- - - ! '>='
156
+ - - '>='
86
157
  - !ruby/object:Gem::Version
87
158
  version: '0'
88
159
  required_rubygems_version: !ruby/object:Gem::Requirement
89
- none: false
90
160
  requirements:
91
- - - ! '>='
161
+ - - '>='
92
162
  - !ruby/object:Gem::Version
93
163
  version: '0'
94
164
  requirements: []
95
165
  rubyforge_project: nulldb
96
- rubygems_version: 1.8.24
166
+ rubygems_version: 2.2.0
97
167
  signing_key:
98
- specification_version: 3
168
+ specification_version: 4
99
169
  summary: The Null Object pattern as applied to ActiveRecord database adapters
100
- test_files:
101
- - spec/nulldb_spec.rb
102
- has_rdoc:
170
+ test_files: []
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- pkg
2
- html
3
- *.gem
4
- .ginger
5
- .rvmrc
@@ -1,46 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- activerecord-nulldb-adapter (0.2.1)
5
- activerecord (>= 2.0.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.2.3)
11
- activesupport (= 3.2.3)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.3)
14
- activemodel (= 3.2.3)
15
- activesupport (= 3.2.3)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.3)
19
- i18n (~> 0.6)
20
- multi_json (~> 1.0)
21
- appraisal (0.4.1)
22
- bundler
23
- rake
24
- arel (3.0.2)
25
- builder (3.0.0)
26
- diff-lcs (1.1.3)
27
- i18n (0.6.0)
28
- multi_json (1.3.4)
29
- rake (0.9.2.2)
30
- rspec (2.10.0)
31
- rspec-core (~> 2.10.0)
32
- rspec-expectations (~> 2.10.0)
33
- rspec-mocks (~> 2.10.0)
34
- rspec-core (2.10.0)
35
- rspec-expectations (2.10.0)
36
- diff-lcs (~> 1.1.3)
37
- rspec-mocks (2.10.1)
38
- tzinfo (0.3.33)
39
-
40
- PLATFORMS
41
- ruby
42
-
43
- DEPENDENCIES
44
- activerecord-nulldb-adapter!
45
- appraisal
46
- rspec (>= 1.2.9)