activerecord-nulldb-adapter 0.0.3 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/{README → README.rdoc} +9 -1
- data/Rakefile +49 -40
- data/VERSION +1 -1
- data/activerecord-nulldb-adapter.gemspec +20 -12
- data/ginger_scenarios.rb +23 -0
- data/lib/active_record/connection_adapters/nulldb_adapter.rb +14 -7
- data/lib/nulldb_rspec.rb +12 -1
- data/spec/nulldb_spec.rb +22 -0
- data/spec/spec.opts +1 -0
- metadata +51 -14
- data/init.rb +0 -1
data/.gitignore
ADDED
data/{README → README.rdoc}
RENAMED
@@ -121,9 +121,15 @@ nothing will be saved.
|
|
121
121
|
migrations will probably break it.
|
122
122
|
* Lots of other things probably don't work. Patches welcome!
|
123
123
|
|
124
|
+
== Version Compatibility
|
125
|
+
|
126
|
+
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.
|
128
|
+
|
124
129
|
== Who
|
125
130
|
|
126
|
-
NullDB was written by Avdi Grimm <mailto:avdi@avdi.org
|
131
|
+
NullDB was originally written by Avdi Grimm <mailto:avdi@avdi.org>.
|
132
|
+
It is currently maintained by {Myron Marston}[http://github.com/myronmarston].
|
127
133
|
|
128
134
|
== Where
|
129
135
|
|
@@ -137,6 +143,8 @@ NullDB was written by Avdi Grimm <mailto:avdi@avdi.org>
|
|
137
143
|
- Initial Release
|
138
144
|
* Version 0.0.2 (2007-05-31)
|
139
145
|
- Moved to Rubyforge
|
146
|
+
* Version 0.1.0 (2010-03-02)
|
147
|
+
- Released as a gem, with some bug fixes.
|
140
148
|
|
141
149
|
== License
|
142
150
|
|
data/Rakefile
CHANGED
@@ -1,53 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'rake'
|
2
|
-
require 'rake/rdoctask'
|
3
|
-
require 'spec/rake/spectask'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = 'activerecord-nulldb-adapter'
|
8
|
+
gem.summary = %Q{The Null Object pattern as applied to ActiveRecord database adapters}
|
9
|
+
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.}
|
10
|
+
gem.email = "myron.marston@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/nulldb/nulldb"
|
12
|
+
gem.authors = ["Avdi Grimm", "Myron Marston"]
|
13
|
+
gem.rubyforge_project = "nulldb"
|
14
|
+
|
15
|
+
gem.add_dependency 'activerecord', '>= 2.0.0'
|
16
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
17
|
+
|
18
|
+
gem.files.exclude 'vendor/ginger'
|
19
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
23
|
+
rubyforge.doc_task = "rdoc"
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
11
27
|
end
|
12
28
|
|
13
|
-
|
14
|
-
|
15
|
-
|
29
|
+
require 'spec/rake/spectask'
|
30
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
16
33
|
end
|
17
34
|
|
18
|
-
|
19
|
-
|
20
|
-
|
35
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
36
|
+
spec.libs << 'lib' << 'spec'
|
37
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
+
spec.rcov = true
|
21
39
|
end
|
22
40
|
|
23
|
-
|
24
|
-
task :tag do
|
25
|
-
warn "This needs to be updated for git"
|
26
|
-
exit 1
|
27
|
-
repos = "http://svn.avdi.org/nulldb"
|
28
|
-
version = ENV["VERSION"]
|
29
|
-
raise "No version specified" unless version
|
30
|
-
sh "svn cp #{repos}/trunk #{repos}/tags/nulldb-#{version}"
|
31
|
-
end
|
41
|
+
task :spec => :check_dependencies if defined?(Jeweler)
|
32
42
|
|
33
|
-
desc
|
34
|
-
task :
|
35
|
-
|
36
|
-
|
43
|
+
desc 'Run ginger tests'
|
44
|
+
task :ginger do
|
45
|
+
$LOAD_PATH << File.join(*%w[vendor ginger lib])
|
46
|
+
ARGV.clear
|
47
|
+
ARGV << 'spec'
|
48
|
+
load File.join(*%w[vendor ginger bin ginger])
|
37
49
|
end
|
38
50
|
|
39
|
-
|
40
|
-
require 'jeweler'
|
41
|
-
Jeweler::Tasks.new do |gem|
|
42
|
-
gem.name = GEM_NAME
|
43
|
-
gem.summary = %Q{NullDB lets you to test your models without ever touching a real database.}
|
44
|
-
gem.email = "avdi@avdi.org"
|
45
|
-
gem.homepage = 'http://nulldb.rubyforge.org'
|
46
|
-
gem.description = "An ActiveRecord null database adapter for greater speed and isolation in unit tests"
|
47
|
-
gem.rubyforge_project = 'nulldb'
|
48
|
-
gem.authors = ['Avdi Grimm']
|
49
|
-
end
|
51
|
+
task :default => :ginger
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
+
require 'rake/rdoctask'
|
54
|
+
Rake::RDocTask.new do |rd|
|
55
|
+
rd.main = "README.rdoc"
|
56
|
+
rd.rdoc_files.include("README.rdoc", "LICENSE", "lib/**/*.rb")
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Publish project home page"
|
60
|
+
task :publish => ["rdoc"] do
|
61
|
+
sh "scp -r html/* myronmarston@rubyforge.org:/var/www/gforge-projects/nulldb"
|
53
62
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.1
|
@@ -5,35 +5,37 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{activerecord-nulldb-adapter}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Avdi Grimm"]
|
12
|
-
s.date = %q{
|
13
|
-
s.description = %q{
|
14
|
-
s.email = %q{
|
11
|
+
s.authors = ["Avdi Grimm", "Myron Marston"]
|
12
|
+
s.date = %q{2010-03-15}
|
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
|
+
s.email = %q{myron.marston@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README"
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
21
|
-
"
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
22
23
|
"Rakefile",
|
23
24
|
"VERSION",
|
24
25
|
"activerecord-nulldb-adapter.gemspec",
|
25
|
-
"
|
26
|
+
"ginger_scenarios.rb",
|
26
27
|
"lib/active_record/connection_adapters/nulldb_adapter.rb",
|
27
28
|
"lib/nulldb_rspec.rb",
|
28
29
|
"spec/nulldb_spec.rb",
|
30
|
+
"spec/spec.opts",
|
29
31
|
"tasks/database.rake"
|
30
32
|
]
|
31
|
-
s.homepage = %q{http://nulldb
|
33
|
+
s.homepage = %q{http://github.com/nulldb/nulldb}
|
32
34
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
35
|
s.require_paths = ["lib"]
|
34
36
|
s.rubyforge_project = %q{nulldb}
|
35
|
-
s.rubygems_version = %q{1.3.
|
36
|
-
s.summary = %q{
|
37
|
+
s.rubygems_version = %q{1.3.6}
|
38
|
+
s.summary = %q{The Null Object pattern as applied to ActiveRecord database adapters}
|
37
39
|
s.test_files = [
|
38
40
|
"spec/nulldb_spec.rb"
|
39
41
|
]
|
@@ -43,9 +45,15 @@ Gem::Specification.new do |s|
|
|
43
45
|
s.specification_version = 3
|
44
46
|
|
45
47
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 2.0.0"])
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
46
50
|
else
|
51
|
+
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
52
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
47
53
|
end
|
48
54
|
else
|
55
|
+
s.add_dependency(%q<activerecord>, [">= 2.0.0"])
|
56
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
49
57
|
end
|
50
58
|
end
|
51
59
|
|
data/ginger_scenarios.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'ginger'
|
2
|
+
|
3
|
+
def create_scenario(version)
|
4
|
+
scenario = Ginger::Scenario.new("Rails #{version}")
|
5
|
+
scenario[/^active_?record$/] = version
|
6
|
+
scenario[/^active_?support$/] = version
|
7
|
+
scenario
|
8
|
+
end
|
9
|
+
|
10
|
+
Ginger.configure do |config|
|
11
|
+
config.aliases["active_record"] = "activerecord"
|
12
|
+
config.aliases["active_support"] = "activesupport"
|
13
|
+
|
14
|
+
versions = %w( 2.3.5 2.3.4 2.3.3 2.3.2 )
|
15
|
+
versions += %w(
|
16
|
+
2.2.3 2.2.2
|
17
|
+
2.1.2 2.1.1 2.1.0
|
18
|
+
2.0.5 2.0.4 2.0.2 2.0.1 2.0.0
|
19
|
+
) if RUBY_VERSION =~ /^1\.8/
|
20
|
+
versions.each do |version|
|
21
|
+
config.scenarios << create_scenario(version)
|
22
|
+
end
|
23
|
+
end
|
@@ -10,6 +10,7 @@ class ActiveRecord::Base
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
|
13
14
|
module ActiveRecord
|
14
15
|
# Just make sure you have the latest version of your schema
|
15
16
|
class Schema < Migration
|
@@ -19,6 +20,7 @@ module ActiveRecord
|
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
23
|
+
|
22
24
|
class ActiveRecord::ConnectionAdapters::NullDBAdapter <
|
23
25
|
ActiveRecord::ConnectionAdapters::AbstractAdapter
|
24
26
|
|
@@ -73,6 +75,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
|
|
73
75
|
@last_unique_id = 0
|
74
76
|
@tables = {'schema_info' => TableDefinition.new(nil)}
|
75
77
|
@schema_path = config.fetch(:schema){ "db/schema.rb" }
|
78
|
+
@config = config.merge(:adapter => :nulldb)
|
76
79
|
super(nil, @logger)
|
77
80
|
end
|
78
81
|
|
@@ -109,7 +112,7 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
|
|
109
112
|
table_definition.primary_key(options[:primary_key] || "id")
|
110
113
|
end
|
111
114
|
|
112
|
-
yield table_definition
|
115
|
+
yield table_definition if block_given?
|
113
116
|
|
114
117
|
@tables[table_name] = table_definition
|
115
118
|
end
|
@@ -133,12 +136,16 @@ class ActiveRecord::ConnectionAdapters::NullDBAdapter <
|
|
133
136
|
ActiveRecord::Migration.verbose = false
|
134
137
|
Kernel.load(File.join(RAILS_ROOT, @schema_path))
|
135
138
|
end
|
136
|
-
|
137
|
-
table
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
139
|
+
|
140
|
+
if table = @tables[table_name]
|
141
|
+
table.columns.map do |col_def|
|
142
|
+
ActiveRecord::ConnectionAdapters::Column.new(col_def.name.to_s,
|
143
|
+
col_def.default,
|
144
|
+
col_def.type,
|
145
|
+
col_def.null)
|
146
|
+
end
|
147
|
+
else
|
148
|
+
[]
|
142
149
|
end
|
143
150
|
end
|
144
151
|
|
data/lib/nulldb_rspec.rb
CHANGED
@@ -70,13 +70,24 @@ module NullDB::RSpec::NullifiedDatabase
|
|
70
70
|
private
|
71
71
|
|
72
72
|
def self.included(other)
|
73
|
-
if
|
73
|
+
if nullify_contextually?(other)
|
74
74
|
contextually_nullify_database(other)
|
75
75
|
else
|
76
76
|
globally_nullify_database
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
def self.nullify_contextually?(other)
|
81
|
+
if defined? Spec::Rails::Example::RailsExampleGroup
|
82
|
+
other.ancestors.include?(Spec::Rails::Example::RailsExampleGroup)
|
83
|
+
else
|
84
|
+
other.ancestors.include?(Spec::Rails::Example::ModelExampleGroup) ||
|
85
|
+
other.ancestors.include?(Spec::Rails::Example::ControllerExampleGroup) ||
|
86
|
+
other.ancestors.include?(Spec::Rails::Example::ViewExampleGroup) ||
|
87
|
+
other.ancestors.include?(Spec::Rails::Example::HelperExampleGroup)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
80
91
|
def self.nullify_database(receiver)
|
81
92
|
receiver.before :all do
|
82
93
|
ActiveRecord::Base.establish_connection(:adapter => :nulldb)
|
data/spec/nulldb_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'spec'
|
3
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), *%w[.. vendor ginger lib])
|
4
|
+
require 'ginger'
|
3
5
|
require 'active_record'
|
4
6
|
$: << File.join(File.dirname(__FILE__), "..", "lib")
|
5
7
|
|
@@ -10,6 +12,9 @@ class Employee < ActiveRecord::Base
|
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
15
|
+
class TablelessModel < ActiveRecord::Base
|
16
|
+
end
|
17
|
+
|
13
18
|
RAILS_ROOT = "RAILS_ROOT"
|
14
19
|
|
15
20
|
describe "NullDB with no schema pre-loaded" do
|
@@ -37,6 +42,13 @@ describe "NullDB with no schema pre-loaded" do
|
|
37
42
|
:schema => "foo/myschema.rb"
|
38
43
|
ActiveRecord::Base.connection.columns('schema_info')
|
39
44
|
end
|
45
|
+
|
46
|
+
it "should allow creating a table without passing a block" do
|
47
|
+
ActiveRecord::Base.establish_connection :adapter => :nulldb
|
48
|
+
ActiveRecord::Schema.define do
|
49
|
+
create_table(:employees)
|
50
|
+
end
|
51
|
+
end
|
40
52
|
end
|
41
53
|
|
42
54
|
describe "NullDB" do
|
@@ -63,6 +75,10 @@ describe "NullDB" do
|
|
63
75
|
:salary => 56000.00)
|
64
76
|
end
|
65
77
|
|
78
|
+
it "should set the @config instance variable so plugins that assume its there can use it" do
|
79
|
+
Employee.connection.instance_variable_get(:@config)[:adapter].should == :nulldb
|
80
|
+
end
|
81
|
+
|
66
82
|
it "should enable instantiation of AR objects without a database" do
|
67
83
|
@employee.should_not be_nil
|
68
84
|
@employee.should be_a_kind_of(ActiveRecord::Base)
|
@@ -75,6 +91,10 @@ describe "NullDB" do
|
|
75
91
|
should_have_column(Employee, :salary, :decimal)
|
76
92
|
end
|
77
93
|
|
94
|
+
it "should return an empty array of columns for a table-less model" do
|
95
|
+
TablelessModel.columns.should == []
|
96
|
+
end
|
97
|
+
|
78
98
|
it "should enable simulated saving of AR objects" do
|
79
99
|
lambda { @employee.save! }.should_not raise_error
|
80
100
|
end
|
@@ -135,6 +155,7 @@ describe "NullDB" do
|
|
135
155
|
cxn.execution_log_since_checkpoint.size.should > 0
|
136
156
|
cxn.checkpoint!
|
137
157
|
cxn.execution_log_since_checkpoint.size.should == 0
|
158
|
+
@employee.salary = @employee.salary + 1
|
138
159
|
@employee.save!
|
139
160
|
cxn.execution_log_since_checkpoint.size.should == 1
|
140
161
|
end
|
@@ -158,6 +179,7 @@ describe "NullDB" do
|
|
158
179
|
|
159
180
|
cxn.checkpoint!
|
160
181
|
should_not_contain_statement(cxn, :update)
|
182
|
+
@employee.salary = @employee.salary + 1
|
161
183
|
@employee.save
|
162
184
|
should_contain_statement(cxn, :update)
|
163
185
|
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format nested
|
metadata
CHANGED
@@ -1,40 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-nulldb-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Avdi Grimm
|
13
|
+
- Myron Marston
|
8
14
|
autorequire:
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-03-15 00:00:00 -07:00
|
13
19
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activerecord
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 2.0.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 2
|
45
|
+
- 9
|
46
|
+
version: 1.2.9
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
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.
|
50
|
+
email: myron.marston@gmail.com
|
18
51
|
executables: []
|
19
52
|
|
20
53
|
extensions: []
|
21
54
|
|
22
55
|
extra_rdoc_files:
|
23
56
|
- LICENSE
|
24
|
-
- README
|
57
|
+
- README.rdoc
|
25
58
|
files:
|
59
|
+
- .gitignore
|
26
60
|
- LICENSE
|
27
|
-
- README
|
61
|
+
- README.rdoc
|
28
62
|
- Rakefile
|
29
63
|
- VERSION
|
30
64
|
- activerecord-nulldb-adapter.gemspec
|
31
|
-
-
|
65
|
+
- ginger_scenarios.rb
|
32
66
|
- lib/active_record/connection_adapters/nulldb_adapter.rb
|
33
67
|
- lib/nulldb_rspec.rb
|
34
68
|
- spec/nulldb_spec.rb
|
69
|
+
- spec/spec.opts
|
35
70
|
- tasks/database.rake
|
36
71
|
has_rdoc: true
|
37
|
-
homepage: http://nulldb
|
72
|
+
homepage: http://github.com/nulldb/nulldb
|
38
73
|
licenses: []
|
39
74
|
|
40
75
|
post_install_message:
|
@@ -46,20 +81,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
81
|
requirements:
|
47
82
|
- - ">="
|
48
83
|
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
49
86
|
version: "0"
|
50
|
-
version:
|
51
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
88
|
requirements:
|
53
89
|
- - ">="
|
54
90
|
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
55
93
|
version: "0"
|
56
|
-
version:
|
57
94
|
requirements: []
|
58
95
|
|
59
96
|
rubyforge_project: nulldb
|
60
|
-
rubygems_version: 1.3.
|
97
|
+
rubygems_version: 1.3.6
|
61
98
|
signing_key:
|
62
99
|
specification_version: 3
|
63
|
-
summary:
|
100
|
+
summary: The Null Object pattern as applied to ActiveRecord database adapters
|
64
101
|
test_files:
|
65
102
|
- spec/nulldb_spec.rb
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
#require 'active_record/connection_adapters/nulldb_adapter'
|