activerecord-nulldb-adapter 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +4 -1
- data/Rakefile +36 -10
- data/VERSION +1 -1
- data/activerecord-nulldb-adapter.gemspec +8 -7
- data/ginger_scenarios.rb +4 -4
- data/lib/active_record/connection_adapters/nulldb_adapter.rb +32 -8
- data/lib/nulldb/arel_compiler.rb +6 -0
- data/lib/nulldb_rspec.rb +12 -8
- data/spec/nulldb_spec.rb +25 -1
- metadata +21 -4
data/README.rdoc
CHANGED
@@ -128,7 +128,7 @@ nothing will be saved.
|
|
128
128
|
== Version Compatibility
|
129
129
|
|
130
130
|
The specs pass against ruby {1.8.6}[http://integrity186.heroku.com/null-db], {1.8.7}[http://integrity187.heroku.com/null-db]
|
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.
|
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.
|
132
132
|
|
133
133
|
== Who
|
134
134
|
|
@@ -151,6 +151,9 @@ It is currently maintained by {Myron Marston}[http://github.com/myronmarston].
|
|
151
151
|
- Released as activerecord-nulldb-adapter gem.
|
152
152
|
* Version 0.2.0 (2010-03-20)
|
153
153
|
- Rails 3 support. All specs pass against ActiveRecord 3.0.0.beta.
|
154
|
+
* Version 0.2.1 (2010-09-01)
|
155
|
+
- Updated Rails 3 support so that nulldb works against AR 3.0.0.
|
156
|
+
- Add support for RSpec 2.
|
154
157
|
|
155
158
|
== License
|
156
159
|
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ begin
|
|
12
12
|
gem.authors = ["Avdi Grimm", "Myron Marston"]
|
13
13
|
gem.rubyforge_project = "nulldb"
|
14
14
|
|
15
|
-
gem.add_dependency 'activerecord', '>= 2.0.0'
|
15
|
+
gem.add_dependency 'activerecord', '>= 2.0.0', '< 3.1'
|
16
16
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
17
17
|
|
18
18
|
gem.files.exclude 'vendor/ginger'
|
@@ -26,16 +26,42 @@ rescue LoadError
|
|
26
26
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
# We want to test ActiveRecord 3 against RSpec 2.x, and
|
30
|
+
# prior versions of AR against RSpec 1.x. The task
|
31
|
+
# definitions are different, and in order to allow ginger
|
32
|
+
# to invoke a single task (:spec_for_ginger) that runs the
|
33
|
+
# specs against the right version of RSpec, we dynamically
|
34
|
+
# define the spec task with this method.
|
35
|
+
def define_specs_task
|
36
|
+
require 'active_record/version'
|
37
|
+
|
38
|
+
if ActiveRecord::VERSION::MAJOR > 2
|
39
|
+
# rspec 2
|
40
|
+
require "rspec/core/rake_task"
|
41
|
+
RSpec::Core::RakeTask.new(:specs) do |spec|
|
42
|
+
spec.pattern = "spec/*_spec.rb"
|
43
|
+
end
|
44
|
+
else
|
45
|
+
# rspec 1
|
46
|
+
require 'spec/rake/spectask'
|
47
|
+
Spec::Rake::SpecTask.new(:specs) do |spec|
|
48
|
+
spec.libs << 'lib' << 'spec'
|
49
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
50
|
+
end
|
51
|
+
end
|
33
52
|
end
|
34
53
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
54
|
+
desc "Run the specs"
|
55
|
+
task :spec do
|
56
|
+
define_specs_task
|
57
|
+
Rake::Task[:specs].invoke
|
58
|
+
end
|
59
|
+
|
60
|
+
task :spec_for_ginger do
|
61
|
+
$LOAD_PATH << File.join(*%w[vendor ginger lib])
|
62
|
+
require 'ginger'
|
63
|
+
define_specs_task
|
64
|
+
Rake::Task[:specs].invoke
|
39
65
|
end
|
40
66
|
|
41
67
|
task :spec => :check_dependencies if defined?(Jeweler)
|
@@ -44,7 +70,7 @@ desc 'Run ginger tests'
|
|
44
70
|
task :ginger do
|
45
71
|
$LOAD_PATH << File.join(*%w[vendor ginger lib])
|
46
72
|
ARGV.clear
|
47
|
-
ARGV << '
|
73
|
+
ARGV << 'spec_for_ginger'
|
48
74
|
load File.join(*%w[vendor ginger bin ginger])
|
49
75
|
end
|
50
76
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -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.2.
|
8
|
+
s.version = "0.2.1"
|
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-
|
12
|
+
s.date = %q{2010-09-01}
|
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 = [
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"activerecord-nulldb-adapter.gemspec",
|
26
26
|
"ginger_scenarios.rb",
|
27
27
|
"lib/active_record/connection_adapters/nulldb_adapter.rb",
|
28
|
+
"lib/nulldb/arel_compiler.rb",
|
28
29
|
"lib/nulldb_rspec.rb",
|
29
30
|
"lib/tasks/database.rake",
|
30
31
|
"spec/nulldb_spec.rb",
|
@@ -34,7 +35,7 @@ Gem::Specification.new do |s|
|
|
34
35
|
s.rdoc_options = ["--charset=UTF-8"]
|
35
36
|
s.require_paths = ["lib"]
|
36
37
|
s.rubyforge_project = %q{nulldb}
|
37
|
-
s.rubygems_version = %q{1.3.
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
38
39
|
s.summary = %q{The Null Object pattern as applied to ActiveRecord database adapters}
|
39
40
|
s.test_files = [
|
40
41
|
"spec/nulldb_spec.rb"
|
@@ -44,15 +45,15 @@ Gem::Specification.new do |s|
|
|
44
45
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
46
|
s.specification_version = 3
|
46
47
|
|
47
|
-
if Gem::Version.new(Gem::
|
48
|
-
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0"])
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0", "< 3.1"])
|
49
50
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
50
51
|
else
|
51
|
-
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
52
|
+
s.add_dependency(%q<activerecord>, [">= 2.0.0", "< 3.1"])
|
52
53
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
53
54
|
end
|
54
55
|
else
|
55
|
-
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
56
|
+
s.add_dependency(%q<activerecord>, [">= 2.0.0", "< 3.1"])
|
56
57
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
57
58
|
end
|
58
59
|
end
|
data/ginger_scenarios.rb
CHANGED
@@ -13,9 +13,9 @@ Ginger.configure do |config|
|
|
13
13
|
|
14
14
|
versions = []
|
15
15
|
|
16
|
-
# Rails 3
|
17
|
-
versions << '3.0.0
|
18
|
-
versions += %w( 2.3.5 2.3.4 2.3.3 2.3.2 )
|
16
|
+
# Rails 3 only works on Ruby 1.8.7 and 1.9.2
|
17
|
+
versions << '3.0.0' if %w[1.8.7 1.9.2].include?(RUBY_VERSION)
|
18
|
+
versions += %w( 2.3.8 2.3.5 2.3.4 2.3.3 2.3.2 )
|
19
19
|
versions += %w(
|
20
20
|
2.2.3 2.2.2
|
21
21
|
2.1.2 2.1.1 2.1.0
|
@@ -24,4 +24,4 @@ Ginger.configure do |config|
|
|
24
24
|
versions.each do |version|
|
25
25
|
config.scenarios << create_scenario(version)
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
@@ -2,7 +2,15 @@ require 'logger'
|
|
2
2
|
require 'stringio'
|
3
3
|
require 'singleton'
|
4
4
|
require 'active_record/connection_adapters/abstract_adapter'
|
5
|
-
|
5
|
+
|
6
|
+
unless respond_to?(:tap)
|
7
|
+
class Object
|
8
|
+
def tap
|
9
|
+
yield self
|
10
|
+
self
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
6
14
|
|
7
15
|
class ActiveRecord::Base
|
8
16
|
# Instantiate a new NullDB connection. Used by ActiveRecord internally.
|
@@ -25,6 +33,16 @@ end
|
|
25
33
|
class ActiveRecord::ConnectionAdapters::NullDBAdapter <
|
26
34
|
ActiveRecord::ConnectionAdapters::AbstractAdapter
|
27
35
|
|
36
|
+
class Column < ::ActiveRecord::ConnectionAdapters::Column
|
37
|
+
private
|
38
|
+
|
39
|
+
def simplified_type(field_type)
|
40
|
+
type = super
|
41
|
+
type = :integer if type.nil? && sql_type == :primary_key
|
42
|
+
type
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
28
46
|
class Statement
|
29
47
|
attr_reader :entry_point, :content
|
30
48
|
|
@@ -140,10 +158,12 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
|
|
140
158
|
|
141
159
|
if table = @tables[table_name]
|
142
160
|
table.columns.map do |col_def|
|
143
|
-
ActiveRecord::ConnectionAdapters::Column.new(
|
144
|
-
|
145
|
-
|
146
|
-
|
161
|
+
ActiveRecord::ConnectionAdapters::NullDBAdapter::Column.new(
|
162
|
+
col_def.name.to_s,
|
163
|
+
col_def.default,
|
164
|
+
col_def.type,
|
165
|
+
col_def.null
|
166
|
+
)
|
147
167
|
end
|
148
168
|
else
|
149
169
|
[]
|
@@ -156,13 +176,13 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
|
|
156
176
|
end
|
157
177
|
|
158
178
|
def select_rows(statement, name = nil)
|
159
|
-
|
179
|
+
[].tap do
|
160
180
|
self.execution_log << Statement.new(entry_point, statement)
|
161
181
|
end
|
162
182
|
end
|
163
183
|
|
164
184
|
def insert(statement, name = nil, primary_key = nil, object_id = nil, sequence_name = nil)
|
165
|
-
|
185
|
+
(object_id || next_unique_id).tap do
|
166
186
|
with_entry_point(:insert) do
|
167
187
|
super(statement, name, primary_key, object_id, sequence_name)
|
168
188
|
end
|
@@ -200,10 +220,14 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
|
|
200
220
|
end
|
201
221
|
end
|
202
222
|
|
223
|
+
def primary_key(table_name)
|
224
|
+
columns(table_name).detect { |col| col.sql_type == :primary_key }.name
|
225
|
+
end
|
226
|
+
|
203
227
|
protected
|
204
228
|
|
205
229
|
def select(statement, name)
|
206
|
-
|
230
|
+
[].tap do
|
207
231
|
self.execution_log << Statement.new(entry_point, statement)
|
208
232
|
end
|
209
233
|
end
|
data/lib/nulldb_rspec.rb
CHANGED
@@ -37,8 +37,11 @@ module NullDB::RSpec::NullifiedDatabase
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.globally_nullify_database
|
40
|
-
|
41
|
-
|
40
|
+
block = lambda { |config| nullify_database(config) }
|
41
|
+
if defined?(RSpec)
|
42
|
+
RSpec.configure(&block)
|
43
|
+
else
|
44
|
+
Spec::Runner.configure(&block)
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
@@ -78,13 +81,14 @@ module NullDB::RSpec::NullifiedDatabase
|
|
78
81
|
end
|
79
82
|
|
80
83
|
def self.nullify_contextually?(other)
|
81
|
-
|
82
|
-
|
84
|
+
rspec_root = defined?(RSpec) ? RSpec : Spec
|
85
|
+
if defined? rspec_root::Rails::RailsExampleGroup
|
86
|
+
other.ancestors.include?(rspec_root::Rails::RailsExampleGroup)
|
83
87
|
else
|
84
|
-
other.ancestors.include?(
|
85
|
-
other.ancestors.include?(
|
86
|
-
other.ancestors.include?(
|
87
|
-
other.ancestors.include?(
|
88
|
+
other.ancestors.include?(rspec_root::Rails::ModelExampleGroup) ||
|
89
|
+
other.ancestors.include?(rspec_root::Rails::ControllerExampleGroup) ||
|
90
|
+
other.ancestors.include?(rspec_root::Rails::ViewExampleGroup) ||
|
91
|
+
other.ancestors.include?(rspec_root::Rails::HelperExampleGroup)
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
data/spec/nulldb_spec.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
2
|
+
|
3
3
|
$LOAD_PATH << File.join(File.dirname(__FILE__), *%w[.. vendor ginger lib])
|
4
4
|
require 'ginger'
|
5
5
|
require 'active_record'
|
6
|
+
require 'active_record/version'
|
6
7
|
$: << File.join(File.dirname(__FILE__), "..", "lib")
|
7
8
|
|
9
|
+
if ActiveRecord::VERSION::MAJOR > 2
|
10
|
+
require 'rspec' # rspec 2
|
11
|
+
else
|
12
|
+
require 'spec' # rspec 1
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'nulldb_rspec'
|
16
|
+
|
8
17
|
class Employee < ActiveRecord::Base
|
9
18
|
after_save :on_save_finished
|
10
19
|
|
@@ -95,6 +104,10 @@ describe "NullDB" do
|
|
95
104
|
should_have_column(Employee, :salary, :decimal)
|
96
105
|
end
|
97
106
|
|
107
|
+
it "should return the appropriate primary key" do
|
108
|
+
ActiveRecord::Base.connection.primary_key('employees').should == 'id'
|
109
|
+
end
|
110
|
+
|
98
111
|
it "should return an empty array of columns for a table-less model" do
|
99
112
|
TablelessModel.columns.should == []
|
100
113
|
end
|
@@ -213,3 +226,14 @@ describe "NullDB" do
|
|
213
226
|
col.type.should == col_type
|
214
227
|
end
|
215
228
|
end
|
229
|
+
|
230
|
+
describe NullDB::RSpec::NullifiedDatabase do
|
231
|
+
describe '.globally_nullify_database' do
|
232
|
+
it 'nullifies the database' do
|
233
|
+
NullDB::RSpec::NullifiedDatabase.should respond_to(:nullify_database)
|
234
|
+
NullDB::RSpec::NullifiedDatabase.should_receive(:nullify_database)
|
235
|
+
NullDB::RSpec::NullifiedDatabase.globally_nullify_database
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-nulldb-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Avdi Grimm
|
@@ -15,30 +16,41 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-
|
19
|
+
date: 2010-09-01 00:00:00 -07:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: activerecord
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
25
27
|
requirements:
|
26
28
|
- - ">="
|
27
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 15
|
28
31
|
segments:
|
29
32
|
- 2
|
30
33
|
- 0
|
31
34
|
- 0
|
32
35
|
version: 2.0.0
|
36
|
+
- - <
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
hash: 5
|
39
|
+
segments:
|
40
|
+
- 3
|
41
|
+
- 1
|
42
|
+
version: "3.1"
|
33
43
|
type: :runtime
|
34
44
|
version_requirements: *id001
|
35
45
|
- !ruby/object:Gem::Dependency
|
36
46
|
name: rspec
|
37
47
|
prerelease: false
|
38
48
|
requirement: &id002 !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
39
50
|
requirements:
|
40
51
|
- - ">="
|
41
52
|
- !ruby/object:Gem::Version
|
53
|
+
hash: 13
|
42
54
|
segments:
|
43
55
|
- 1
|
44
56
|
- 2
|
@@ -64,6 +76,7 @@ files:
|
|
64
76
|
- activerecord-nulldb-adapter.gemspec
|
65
77
|
- ginger_scenarios.rb
|
66
78
|
- lib/active_record/connection_adapters/nulldb_adapter.rb
|
79
|
+
- lib/nulldb/arel_compiler.rb
|
67
80
|
- lib/nulldb_rspec.rb
|
68
81
|
- lib/tasks/database.rake
|
69
82
|
- spec/nulldb_spec.rb
|
@@ -78,23 +91,27 @@ rdoc_options:
|
|
78
91
|
require_paths:
|
79
92
|
- lib
|
80
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
81
95
|
requirements:
|
82
96
|
- - ">="
|
83
97
|
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
84
99
|
segments:
|
85
100
|
- 0
|
86
101
|
version: "0"
|
87
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
88
104
|
requirements:
|
89
105
|
- - ">="
|
90
106
|
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
91
108
|
segments:
|
92
109
|
- 0
|
93
110
|
version: "0"
|
94
111
|
requirements: []
|
95
112
|
|
96
113
|
rubyforge_project: nulldb
|
97
|
-
rubygems_version: 1.3.
|
114
|
+
rubygems_version: 1.3.7
|
98
115
|
signing_key:
|
99
116
|
specification_version: 3
|
100
117
|
summary: The Null Object pattern as applied to ActiveRecord database adapters
|