bitfluent-database_cleaner 0.5.2
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/History.txt +100 -0
- data/LICENSE +20 -0
- data/README.textile +118 -0
- data/Rakefile +46 -0
- data/TODO +0 -0
- data/VERSION.yml +5 -0
- data/cucumber.yml +1 -0
- data/examples/features/example.feature +11 -0
- data/examples/features/step_definitions/example_steps.rb +8 -0
- data/examples/features/support/env.rb +23 -0
- data/examples/lib/activerecord_models.rb +12 -0
- data/examples/lib/couchpotato_models.rb +21 -0
- data/examples/lib/datamapper_models.rb +16 -0
- data/examples/lib/mongoid_models.rb +23 -0
- data/examples/lib/mongomapper_models.rb +17 -0
- data/features/cleaning.feature +21 -0
- data/features/step_definitions/database_cleaner_steps.rb +25 -0
- data/features/support/env.rb +7 -0
- data/lib/database_cleaner.rb +3 -0
- data/lib/database_cleaner/active_record/transaction.rb +26 -0
- data/lib/database_cleaner/active_record/truncation.rb +106 -0
- data/lib/database_cleaner/configuration.rb +129 -0
- data/lib/database_cleaner/couch_potato/truncation.rb +26 -0
- data/lib/database_cleaner/cucumber.rb +8 -0
- data/lib/database_cleaner/data_mapper/transaction.rb +23 -0
- data/lib/database_cleaner/data_mapper/truncation.rb +142 -0
- data/lib/database_cleaner/mongo_mapper/truncation.rb +30 -0
- data/lib/database_cleaner/mongoid/truncation.rb +23 -0
- data/lib/database_cleaner/truncation_base.rb +41 -0
- data/spec/database_cleaner/active_record/transaction_spec.rb +65 -0
- data/spec/database_cleaner/active_record/truncation_spec.rb +66 -0
- data/spec/database_cleaner/configuration_spec.rb +107 -0
- data/spec/database_cleaner/couch_potato/truncation_spec.rb +40 -0
- data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +81 -0
- data/spec/database_cleaner/mongoid/truncation_spec.rb +84 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +12 -0
- metadata +118 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
require 'mongoid'
|
|
3
|
+
require 'database_cleaner/mongoid/truncation'
|
|
4
|
+
|
|
5
|
+
TEST_DATABASE = 'database_cleaner_specs'
|
|
6
|
+
Mongoid.configure do |config|
|
|
7
|
+
name = TEST_DATABASE
|
|
8
|
+
config.master = Mongo::Connection.new.db(name)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class TestClassA
|
|
12
|
+
include Mongoid::Document
|
|
13
|
+
field :name
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class TestClassB
|
|
17
|
+
include Mongoid::Document
|
|
18
|
+
field :name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
module DatabaseCleaner
|
|
23
|
+
module Mongoid
|
|
24
|
+
|
|
25
|
+
describe Truncation do
|
|
26
|
+
before(:each) do
|
|
27
|
+
::Mongoid.database.connection.drop_database(TEST_DATABASE)
|
|
28
|
+
#::MongoMapper.connection.db(TEST_DATABASE).collections.each {|c| c.remove }
|
|
29
|
+
#::MongoMapper.database = TEST_DATABASE
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def ensure_counts(expected_counts)
|
|
33
|
+
# I had to add this sanity_check garbage because I was getting non-determinisc results from mongomapper at times..
|
|
34
|
+
# very odd and disconcerting...
|
|
35
|
+
sanity_check = expected_counts.delete(:sanity_check)
|
|
36
|
+
begin
|
|
37
|
+
expected_counts.each do |model_class, expected_count|
|
|
38
|
+
model_class.count.should equal(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
|
|
39
|
+
end
|
|
40
|
+
rescue Spec::Expectations::ExpectationNotMetError => e
|
|
41
|
+
raise !sanity_check ? e : Spec::ExpectationNotMetError::ExpectationNotMetError.new("SANITY CHECK FAILURE! This should never happen here: #{e.message}")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def create_testclassa(attrs={})
|
|
46
|
+
TestClassA.new({:name => 'some testclassa'}.merge(attrs)).save!
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def create_testclassb(attrs={})
|
|
50
|
+
TestClassB.new({:name => 'some testclassb'}.merge(attrs)).save!
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "truncates all collections by default" do
|
|
54
|
+
create_testclassa
|
|
55
|
+
create_testclassb
|
|
56
|
+
ensure_counts(TestClassA => 1, TestClassB => 1, :sanity_check => true)
|
|
57
|
+
Truncation.new.clean
|
|
58
|
+
ensure_counts(TestClassA => 0, TestClassB => 0)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context "when collections are provided to the :only option" do
|
|
62
|
+
it "only truncates the specified collections" do
|
|
63
|
+
create_testclassa
|
|
64
|
+
create_testclassb
|
|
65
|
+
ensure_counts(TestClassA => 1, TestClassB => 1, :sanity_check => true)
|
|
66
|
+
Truncation.new(:only => ['test_class_as']).clean
|
|
67
|
+
ensure_counts(TestClassA => 0, TestClassB => 1)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context "when collections are provided to the :except option" do
|
|
72
|
+
it "truncates all but the specified collections" do
|
|
73
|
+
create_testclassa
|
|
74
|
+
create_testclassb
|
|
75
|
+
ensure_counts(TestClassA => 1, TestClassB => 1, :sanity_check => true)
|
|
76
|
+
Truncation.new(:except => ['test_class_as']).clean
|
|
77
|
+
ensure_counts(TestClassA => 1, TestClassB => 0)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bitfluent-database_cleaner
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 15
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 5
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.5.2
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Ben Mabey
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-04-15 00:00:00 +09:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description: Strategies for cleaning databases. Can be used to ensure a clean state for testing.
|
|
23
|
+
email: ben@benmabey.com
|
|
24
|
+
executables: []
|
|
25
|
+
|
|
26
|
+
extensions: []
|
|
27
|
+
|
|
28
|
+
extra_rdoc_files:
|
|
29
|
+
- LICENSE
|
|
30
|
+
- README.textile
|
|
31
|
+
- TODO
|
|
32
|
+
files:
|
|
33
|
+
- History.txt
|
|
34
|
+
- README.textile
|
|
35
|
+
- Rakefile
|
|
36
|
+
- VERSION.yml
|
|
37
|
+
- cucumber.yml
|
|
38
|
+
- examples/features/example.feature
|
|
39
|
+
- examples/features/step_definitions/example_steps.rb
|
|
40
|
+
- examples/features/support/env.rb
|
|
41
|
+
- examples/lib/activerecord_models.rb
|
|
42
|
+
- examples/lib/couchpotato_models.rb
|
|
43
|
+
- examples/lib/datamapper_models.rb
|
|
44
|
+
- examples/lib/mongoid_models.rb
|
|
45
|
+
- examples/lib/mongomapper_models.rb
|
|
46
|
+
- features/cleaning.feature
|
|
47
|
+
- features/step_definitions/database_cleaner_steps.rb
|
|
48
|
+
- features/support/env.rb
|
|
49
|
+
- lib/database_cleaner.rb
|
|
50
|
+
- lib/database_cleaner/active_record/transaction.rb
|
|
51
|
+
- lib/database_cleaner/active_record/truncation.rb
|
|
52
|
+
- lib/database_cleaner/configuration.rb
|
|
53
|
+
- lib/database_cleaner/couch_potato/truncation.rb
|
|
54
|
+
- lib/database_cleaner/cucumber.rb
|
|
55
|
+
- lib/database_cleaner/data_mapper/transaction.rb
|
|
56
|
+
- lib/database_cleaner/data_mapper/truncation.rb
|
|
57
|
+
- lib/database_cleaner/mongo_mapper/truncation.rb
|
|
58
|
+
- lib/database_cleaner/mongoid/truncation.rb
|
|
59
|
+
- lib/database_cleaner/truncation_base.rb
|
|
60
|
+
- spec/database_cleaner/active_record/transaction_spec.rb
|
|
61
|
+
- spec/database_cleaner/active_record/truncation_spec.rb
|
|
62
|
+
- spec/database_cleaner/configuration_spec.rb
|
|
63
|
+
- spec/database_cleaner/couch_potato/truncation_spec.rb
|
|
64
|
+
- spec/database_cleaner/mongo_mapper/truncation_spec.rb
|
|
65
|
+
- spec/database_cleaner/mongoid/truncation_spec.rb
|
|
66
|
+
- spec/spec.opts
|
|
67
|
+
- spec/spec_helper.rb
|
|
68
|
+
- LICENSE
|
|
69
|
+
- TODO
|
|
70
|
+
has_rdoc: true
|
|
71
|
+
homepage: http://github.com/bmabey/database_cleaner
|
|
72
|
+
licenses: []
|
|
73
|
+
|
|
74
|
+
post_install_message:
|
|
75
|
+
rdoc_options:
|
|
76
|
+
- --charset=UTF-8
|
|
77
|
+
require_paths:
|
|
78
|
+
- lib
|
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
|
+
none: false
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
hash: 3
|
|
85
|
+
segments:
|
|
86
|
+
- 0
|
|
87
|
+
version: "0"
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
none: false
|
|
90
|
+
requirements:
|
|
91
|
+
- - ">="
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
hash: 3
|
|
94
|
+
segments:
|
|
95
|
+
- 0
|
|
96
|
+
version: "0"
|
|
97
|
+
requirements: []
|
|
98
|
+
|
|
99
|
+
rubyforge_project:
|
|
100
|
+
rubygems_version: 1.3.7
|
|
101
|
+
signing_key:
|
|
102
|
+
specification_version: 3
|
|
103
|
+
summary: Strategies for cleaning databases. Can be used to ensure a clean state for testing.
|
|
104
|
+
test_files:
|
|
105
|
+
- spec/database_cleaner/active_record/transaction_spec.rb
|
|
106
|
+
- spec/database_cleaner/active_record/truncation_spec.rb
|
|
107
|
+
- spec/database_cleaner/configuration_spec.rb
|
|
108
|
+
- spec/database_cleaner/couch_potato/truncation_spec.rb
|
|
109
|
+
- spec/database_cleaner/mongo_mapper/truncation_spec.rb
|
|
110
|
+
- spec/database_cleaner/mongoid/truncation_spec.rb
|
|
111
|
+
- spec/spec_helper.rb
|
|
112
|
+
- examples/features/step_definitions/example_steps.rb
|
|
113
|
+
- examples/features/support/env.rb
|
|
114
|
+
- examples/lib/activerecord_models.rb
|
|
115
|
+
- examples/lib/couchpotato_models.rb
|
|
116
|
+
- examples/lib/datamapper_models.rb
|
|
117
|
+
- examples/lib/mongoid_models.rb
|
|
118
|
+
- examples/lib/mongomapper_models.rb
|