database_cleaner 1.6.2 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +3 -3
- data/History.rdoc +23 -0
- data/README.markdown +24 -1
- data/VERSION.yml +2 -2
- data/lib/database_cleaner.rb +6 -2
- data/lib/database_cleaner/active_record/base.rb +1 -1
- data/lib/database_cleaner/active_record/deletion.rb +9 -7
- data/lib/database_cleaner/base.rb +2 -0
- data/lib/database_cleaner/safeguard.rb +72 -0
- metadata +6 -86
- data/examples/Gemfile +0 -1
- data/examples/Gemfile.lock +0 -1
- data/examples/config/database.yml.example +0 -8
- data/examples/config/redis.yml +0 -8
- data/examples/db/sqlite_databases_go_here +0 -0
- data/examples/features/example.feature +0 -11
- data/examples/features/example_multiple_db.feature +0 -23
- data/examples/features/example_multiple_orm.feature +0 -22
- data/examples/features/step_definitions/activerecord_steps.rb +0 -31
- data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
- data/examples/features/step_definitions/datamapper_steps.rb +0 -37
- data/examples/features/step_definitions/mongoid_steps.rb +0 -23
- data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
- data/examples/features/step_definitions/neo4j_steps.rb +0 -23
- data/examples/features/step_definitions/ohm_steps.rb +0 -31
- data/examples/features/step_definitions/redis_steps.rb +0 -31
- data/examples/features/step_definitions/translation_steps.rb +0 -55
- data/examples/features/support/env.rb +0 -61
- data/examples/lib/activerecord_models.rb +0 -41
- data/examples/lib/couchpotato_models.rb +0 -61
- data/examples/lib/datamapper_models.rb +0 -50
- data/examples/lib/mongoid_models.rb +0 -44
- data/examples/lib/mongomapper_models.rb +0 -51
- data/examples/lib/neo4j_models.rb +0 -17
- data/examples/lib/ohm_models.rb +0 -43
- data/examples/lib/redis_models.rb +0 -65
- data/examples/lib/sequel_models.rb +0 -9
- data/features/cleaning.feature +0 -30
- data/features/cleaning_default_strategy.feature +0 -23
- data/features/cleaning_multiple_dbs.feature +0 -22
- data/features/cleaning_multiple_orms.feature +0 -67
- data/features/step_definitions/database_cleaner_steps.rb +0 -33
- data/features/support/env.rb +0 -4
- data/features/support/feature_runner.rb +0 -39
- data/spec/database_cleaner/active_record/base_spec.rb +0 -188
- data/spec/database_cleaner/active_record/transaction_spec.rb +0 -176
- data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +0 -38
- data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +0 -38
- data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +0 -75
- data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +0 -40
- data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +0 -40
- data/spec/database_cleaner/active_record/truncation_spec.rb +0 -180
- data/spec/database_cleaner/base_spec.rb +0 -617
- data/spec/database_cleaner/configuration_spec.rb +0 -345
- data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
- data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
- data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
- data/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +0 -41
- data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
- data/spec/database_cleaner/generic/base_spec.rb +0 -61
- data/spec/database_cleaner/generic/truncation_spec.rb +0 -118
- data/spec/database_cleaner/mongo/mongo_examples.rb +0 -26
- data/spec/database_cleaner/mongo/truncation_spec.rb +0 -72
- data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
- data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
- data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
- data/spec/database_cleaner/moped/moped_examples.rb +0 -32
- data/spec/database_cleaner/moped/truncation_spec.rb +0 -80
- data/spec/database_cleaner/neo4j/base_spec.rb +0 -43
- data/spec/database_cleaner/neo4j/transaction_spec.rb +0 -25
- data/spec/database_cleaner/null_strategy_spec.rb +0 -28
- data/spec/database_cleaner/ohm/truncation_spec.rb +0 -70
- data/spec/database_cleaner/redis/base_spec.rb +0 -43
- data/spec/database_cleaner/redis/truncation_spec.rb +0 -63
- data/spec/database_cleaner/sequel/base_spec.rb +0 -32
- data/spec/database_cleaner/sequel/deletion_spec.rb +0 -58
- data/spec/database_cleaner/sequel/transaction_spec.rb +0 -21
- data/spec/database_cleaner/sequel/truncation/sqlite3_spec.rb +0 -0
- data/spec/database_cleaner/sequel/truncation_spec.rb +0 -182
- data/spec/database_cleaner/shared_strategy.rb +0 -15
- data/spec/rcov.opts +0 -1
- data/spec/spec_helper.rb +0 -21
- data/spec/support/active_record/database_setup.rb +0 -6
- data/spec/support/active_record/migrations/20150101010000_create_users.rb +0 -14
- data/spec/support/active_record/migrations/20150101020000_create_agents.rb +0 -14
- data/spec/support/active_record/mysql2_setup.rb +0 -39
- data/spec/support/active_record/mysql_setup.rb +0 -38
- data/spec/support/active_record/postgresql_setup.rb +0 -48
- data/spec/support/active_record/schema_setup.rb +0 -17
- data/spec/support/active_record/sqlite3_setup.rb +0 -40
- data/spec/support/data_mapper/schema_setup.rb +0 -15
- data/spec/support/data_mapper/sqlite3_setup.rb +0 -39
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'database_cleaner/data_mapper/truncation'
|
2
|
-
require 'database_cleaner/shared_strategy'
|
3
|
-
|
4
|
-
module DatabaseCleaner
|
5
|
-
module DataMapper
|
6
|
-
describe Truncation do
|
7
|
-
it_should_behave_like "a generic strategy"
|
8
|
-
it_should_behave_like "a generic truncation strategy"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'database_cleaner/shared_strategy'
|
3
|
-
require 'database_cleaner/generic/base'
|
4
|
-
require 'active_record'
|
5
|
-
|
6
|
-
module ::DatabaseCleaner
|
7
|
-
module Generic
|
8
|
-
class ExampleStrategy
|
9
|
-
include ::DatabaseCleaner::Generic::Base
|
10
|
-
|
11
|
-
def start; end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe ExampleStrategy do
|
15
|
-
context "class methods" do
|
16
|
-
subject { ExampleStrategy }
|
17
|
-
|
18
|
-
describe "#available_strategies" do
|
19
|
-
it "should have available strategies" do
|
20
|
-
expect(subject.available_strategies).to be_empty
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it_should_behave_like "a generic strategy"
|
26
|
-
|
27
|
-
describe "#db" do
|
28
|
-
it "should be :default" do
|
29
|
-
expect(subject.db).to eql(:default)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#cleaning" do
|
34
|
-
let (:connection) { double("connection") }
|
35
|
-
let (:strategy) { ExampleStrategy.new }
|
36
|
-
before do
|
37
|
-
# DatabaseCleaner.strategy = :truncation
|
38
|
-
connection.stub(:disable_referential_integrity).and_yield
|
39
|
-
connection.stub(:database_cleaner_view_cache).and_return([])
|
40
|
-
connection.stub(:database_cleaner_table_cache).and_return([])
|
41
|
-
::ActiveRecord::Base.stub(:connection).and_return(connection)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "calls #clean even if there is an exception" do
|
45
|
-
strategy.should_receive :clean
|
46
|
-
expect do
|
47
|
-
strategy.cleaning do
|
48
|
-
raise NoMethodError
|
49
|
-
end
|
50
|
-
end.to raise_exception(NoMethodError)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "calls #clean after processing the block" do
|
54
|
-
strategy.should_receive :clean
|
55
|
-
strategy.cleaning do
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'database_cleaner/generic/truncation'
|
3
|
-
|
4
|
-
module ::DatabaseCleaner
|
5
|
-
module Generic
|
6
|
-
class TruncationExample
|
7
|
-
include ::DatabaseCleaner::Generic::Truncation
|
8
|
-
|
9
|
-
def only
|
10
|
-
@only
|
11
|
-
end
|
12
|
-
|
13
|
-
def except
|
14
|
-
@tables_to_exclude
|
15
|
-
end
|
16
|
-
|
17
|
-
def reset_ids?
|
18
|
-
!!@reset_ids
|
19
|
-
end
|
20
|
-
|
21
|
-
def pre_count?
|
22
|
-
!!@pre_count
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class MigrationExample < TruncationExample
|
27
|
-
def migration_storage_names
|
28
|
-
%w[migration_storage_name]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe TruncationExample do
|
33
|
-
subject(:truncation_example) { TruncationExample.new }
|
34
|
-
|
35
|
-
it "will start" do
|
36
|
-
expect { truncation_example.start }.to_not raise_error
|
37
|
-
end
|
38
|
-
|
39
|
-
it "expects clean to be implemented later" do
|
40
|
-
expect { truncation_example.clean }.to raise_error(NotImplementedError)
|
41
|
-
end
|
42
|
-
|
43
|
-
context "private methods" do
|
44
|
-
it { should_not respond_to(:tables_to_truncate) }
|
45
|
-
|
46
|
-
it 'expects #tables_to_truncate to be implemented later' do
|
47
|
-
expect{ truncation_example.send :tables_to_truncate }.to raise_error(NotImplementedError)
|
48
|
-
end
|
49
|
-
|
50
|
-
it { should_not respond_to(:migration_storage_names) }
|
51
|
-
its(:migration_storage_names) { should be_empty }
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "initialize" do
|
55
|
-
it { expect{ subject }.to_not raise_error }
|
56
|
-
|
57
|
-
it "should accept a hash of options" do
|
58
|
-
expect{ TruncationExample.new {} }.to_not raise_error
|
59
|
-
end
|
60
|
-
|
61
|
-
it { expect{ TruncationExample.new( { :a_random_param => "should raise ArgumentError" } ) }.to raise_error(ArgumentError) }
|
62
|
-
it { expect{ TruncationExample.new( { :except => "something",:only => "something else" } ) }.to raise_error(ArgumentError) }
|
63
|
-
it { expect{ TruncationExample.new( { :only => "something" } ) }.to_not raise_error }
|
64
|
-
it { expect{ TruncationExample.new( { :except => "something" } ) }.to_not raise_error }
|
65
|
-
it { expect{ TruncationExample.new( { :pre_count => "something" } ) }.to_not raise_error }
|
66
|
-
it { expect{ TruncationExample.new( { :reset_ids => "something" } ) }.to_not raise_error }
|
67
|
-
|
68
|
-
context "" do
|
69
|
-
subject { TruncationExample.new( { :only => ["something"] } ) }
|
70
|
-
its(:only) { should eq ["something"] }
|
71
|
-
its(:except) { should eq [] }
|
72
|
-
end
|
73
|
-
|
74
|
-
context "" do
|
75
|
-
subject { TruncationExample.new( { :except => ["something"] } ) }
|
76
|
-
its(:only) { should eq nil }
|
77
|
-
its(:except) { should include("something") }
|
78
|
-
end
|
79
|
-
|
80
|
-
context "" do
|
81
|
-
subject { TruncationExample.new( { :reset_ids => ["something"] } ) }
|
82
|
-
its(:reset_ids?) { should eq true }
|
83
|
-
end
|
84
|
-
|
85
|
-
context "" do
|
86
|
-
subject { TruncationExample.new( { :reset_ids => nil } ) }
|
87
|
-
its(:reset_ids?) { should eq false }
|
88
|
-
end
|
89
|
-
|
90
|
-
context "" do
|
91
|
-
subject { TruncationExample.new( { :pre_count => ["something"] } ) }
|
92
|
-
its(:pre_count?) { should eq true }
|
93
|
-
end
|
94
|
-
|
95
|
-
context "" do
|
96
|
-
subject { TruncationExample.new( { :pre_count => nil } ) }
|
97
|
-
its(:pre_count?) { should eq false }
|
98
|
-
end
|
99
|
-
|
100
|
-
context "" do
|
101
|
-
subject { MigrationExample.new }
|
102
|
-
its(:only) { should eq nil }
|
103
|
-
its(:except) { should eq %w[migration_storage_name] }
|
104
|
-
end
|
105
|
-
|
106
|
-
context "" do
|
107
|
-
EXCEPT_TABLES = ["something"]
|
108
|
-
subject { MigrationExample.new( { :except => EXCEPT_TABLES } ) }
|
109
|
-
|
110
|
-
it "should not modify the array of excepted tables" do
|
111
|
-
subject.except.should include("migration_storage_name")
|
112
|
-
EXCEPT_TABLES.should_not include("migration_storage_name")
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module MongoTest
|
2
|
-
class ThingBase
|
3
|
-
def self.collection
|
4
|
-
@connection ||= ::Mongo::Connection.new('127.0.0.1')
|
5
|
-
@db ||= @connection.db('database_cleaner_specs')
|
6
|
-
@mongo ||= @db.collection(name) || @db.create_collection(name)
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.count
|
10
|
-
@mongo.count
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(attrs={})
|
14
|
-
@attrs = attrs
|
15
|
-
end
|
16
|
-
|
17
|
-
def save!
|
18
|
-
self.class.collection.insert(@attrs)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Widget < ThingBase
|
23
|
-
end
|
24
|
-
class Gadget < ThingBase
|
25
|
-
end
|
26
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
require 'mongo'
|
3
|
-
require 'database_cleaner/mongo/truncation'
|
4
|
-
require File.dirname(__FILE__) + '/mongo_examples'
|
5
|
-
|
6
|
-
module DatabaseCleaner
|
7
|
-
module Mongo
|
8
|
-
|
9
|
-
describe Truncation do
|
10
|
-
let(:args) {{}}
|
11
|
-
let(:truncation) { described_class.new(args).tap { |t| t.db=@db } }
|
12
|
-
#doing this in the file root breaks autospec, doing it before(:all) just fails the specs
|
13
|
-
before(:all) do
|
14
|
-
@connection = ::Mongo::Connection.new('127.0.0.1')
|
15
|
-
@test_db = 'database_cleaner_specs'
|
16
|
-
@db = @connection.db(@test_db)
|
17
|
-
end
|
18
|
-
|
19
|
-
after(:each) do
|
20
|
-
@connection.drop_database(@test_db)
|
21
|
-
end
|
22
|
-
|
23
|
-
def ensure_counts(expected_counts)
|
24
|
-
# I had to add this sanity_check garbage because I was getting non-determinisc results from mongo at times..
|
25
|
-
# very odd and disconcerting...
|
26
|
-
expected_counts.each do |model_class, expected_count|
|
27
|
-
model_class.count.should equal(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def create_widget(attrs={})
|
32
|
-
MongoTest::Widget.new({:name => 'some widget'}.merge(attrs)).save!
|
33
|
-
end
|
34
|
-
|
35
|
-
def create_gadget(attrs={})
|
36
|
-
MongoTest::Gadget.new({:name => 'some gadget'}.merge(attrs)).save!
|
37
|
-
end
|
38
|
-
|
39
|
-
it "truncates all collections by default" do
|
40
|
-
create_widget
|
41
|
-
create_gadget
|
42
|
-
ensure_counts(MongoTest::Widget => 1, MongoTest::Gadget => 1)
|
43
|
-
truncation.clean
|
44
|
-
ensure_counts(MongoTest::Widget => 0, MongoTest::Gadget => 0)
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when collections are provided to the :only option" do
|
48
|
-
let(:args) {{:only => ['MongoTest::Widget']}}
|
49
|
-
it "only truncates the specified collections" do
|
50
|
-
create_widget
|
51
|
-
create_gadget
|
52
|
-
ensure_counts(MongoTest::Widget => 1, MongoTest::Gadget => 1)
|
53
|
-
truncation.clean
|
54
|
-
ensure_counts(MongoTest::Widget => 0, MongoTest::Gadget => 1)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "when collections are provided to the :except option" do
|
59
|
-
let(:args) {{:except => ['MongoTest::Widget']}}
|
60
|
-
it "truncates all but the specified collections" do
|
61
|
-
create_widget
|
62
|
-
create_gadget
|
63
|
-
ensure_counts(MongoTest::Widget => 1, MongoTest::Gadget => 1)
|
64
|
-
truncation.clean
|
65
|
-
ensure_counts(MongoTest::Widget => 1, MongoTest::Gadget => 0)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'database_cleaner/mongo_mapper/base'
|
3
|
-
require 'database_cleaner/shared_strategy'
|
4
|
-
|
5
|
-
module DatabaseCleaner
|
6
|
-
describe MongoMapper do
|
7
|
-
it { should respond_to(:available_strategies) }
|
8
|
-
end
|
9
|
-
|
10
|
-
module MongoMapper
|
11
|
-
class ExampleStrategy
|
12
|
-
include ::DatabaseCleaner::MongoMapper::Base
|
13
|
-
end
|
14
|
-
|
15
|
-
describe ExampleStrategy do
|
16
|
-
|
17
|
-
it_should_behave_like "a generic strategy"
|
18
|
-
|
19
|
-
describe "db" do
|
20
|
-
it { should respond_to(:db=) }
|
21
|
-
|
22
|
-
it "should store my desired db" do
|
23
|
-
subject.db = :my_db
|
24
|
-
subject.db.should eq :my_db
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should default to :default" do
|
28
|
-
subject.db.should eq :default
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
require 'mongo_mapper'
|
3
|
-
require 'database_cleaner/mongo_mapper/truncation'
|
4
|
-
require File.dirname(__FILE__) + '/mongo_examples'
|
5
|
-
|
6
|
-
module DatabaseCleaner
|
7
|
-
module MongoMapper
|
8
|
-
|
9
|
-
describe Truncation do
|
10
|
-
|
11
|
-
#doing this in the file root breaks autospec, doing it before(:all) just fails the specs
|
12
|
-
before(:all) do
|
13
|
-
::MongoMapper.connection = ::Mongo::Connection.new('127.0.0.1')
|
14
|
-
@test_db = 'database_cleaner_specs'
|
15
|
-
::MongoMapper.database = @test_db
|
16
|
-
end
|
17
|
-
|
18
|
-
before(:each) do
|
19
|
-
::MongoMapper.connection.drop_database(@test_db)
|
20
|
-
end
|
21
|
-
|
22
|
-
def ensure_counts(expected_counts)
|
23
|
-
# I had to add this sanity_check garbage because I was getting non-determinisc results from mongomapper at times..
|
24
|
-
# very odd and disconcerting...
|
25
|
-
sanity_check = expected_counts.delete(:sanity_check)
|
26
|
-
begin
|
27
|
-
expected_counts.each do |model_class, expected_count|
|
28
|
-
model_class.count.should equal(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
|
29
|
-
end
|
30
|
-
rescue RSpec::Expectations::ExpectationNotMetError => e
|
31
|
-
raise !sanity_check ? e : RSpec::ExpectationNotMetError::ExpectationNotMetError.new("SANITY CHECK FAILURE! This should never happen here: #{e.message}")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def create_widget(attrs={})
|
36
|
-
Widget.new({:name => 'some widget'}.merge(attrs)).save!
|
37
|
-
end
|
38
|
-
|
39
|
-
def create_gadget(attrs={})
|
40
|
-
Gadget.new({:name => 'some gadget'}.merge(attrs)).save!
|
41
|
-
end
|
42
|
-
|
43
|
-
it "truncates all collections by default" do
|
44
|
-
create_widget
|
45
|
-
create_gadget
|
46
|
-
ensure_counts(Widget => 1, Gadget => 1, :sanity_check => true)
|
47
|
-
Truncation.new.clean
|
48
|
-
ensure_counts(Widget => 0, Gadget => 0)
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when collections are provided to the :only option" do
|
52
|
-
it "only truncates the specified collections" do
|
53
|
-
create_widget
|
54
|
-
create_gadget
|
55
|
-
ensure_counts(Widget => 1, Gadget => 1, :sanity_check => true)
|
56
|
-
Truncation.new(:only => ['widgets']).clean
|
57
|
-
ensure_counts(Widget => 0, Gadget => 1)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when collections are provided to the :except option" do
|
62
|
-
it "truncates all but the specified collections" do
|
63
|
-
create_widget
|
64
|
-
create_gadget
|
65
|
-
ensure_counts(Widget => 1, Gadget => 1, :sanity_check => true)
|
66
|
-
Truncation.new(:except => ['widgets']).clean
|
67
|
-
ensure_counts(Widget => 1, Gadget => 0)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module MopedTest
|
2
|
-
class ThingBase
|
3
|
-
def self.collection
|
4
|
-
@db ||= 'database_cleaner_specs'
|
5
|
-
@session ||= ::Moped::Session.new(['127.0.0.1:27017'], database: @db)
|
6
|
-
@collection ||= @session[name]
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.count
|
10
|
-
@collection.find.count
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(attrs={})
|
14
|
-
@attrs = attrs
|
15
|
-
end
|
16
|
-
|
17
|
-
def save!
|
18
|
-
self.class.collection.insert(@attrs)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Widget < ThingBase
|
23
|
-
end
|
24
|
-
class Gadget < ThingBase
|
25
|
-
end
|
26
|
-
class System < ThingBase
|
27
|
-
def self.collection
|
28
|
-
super
|
29
|
-
@collection = @session['system_logs']
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
-
require 'moped'
|
3
|
-
require 'database_cleaner/moped/truncation'
|
4
|
-
require File.dirname(__FILE__) + '/moped_examples'
|
5
|
-
|
6
|
-
module DatabaseCleaner
|
7
|
-
module Moped
|
8
|
-
|
9
|
-
describe Truncation do
|
10
|
-
let(:args) {{}}
|
11
|
-
let(:truncation) { described_class.new(args) }
|
12
|
-
#doing this in the file root breaks autospec, doing it before(:all) just fails the specs
|
13
|
-
before(:all) do
|
14
|
-
@test_db = 'database_cleaner_specs'
|
15
|
-
@session = ::Moped::Session.new(['127.0.0.1:27017'], database: @test_db)
|
16
|
-
end
|
17
|
-
|
18
|
-
before(:each) do
|
19
|
-
truncation.db = @test_db
|
20
|
-
end
|
21
|
-
|
22
|
-
after(:each) do
|
23
|
-
@session.drop
|
24
|
-
end
|
25
|
-
|
26
|
-
def ensure_counts(expected_counts)
|
27
|
-
# I had to add this sanity_check garbage because I was getting non-determinisc results from mongo at times..
|
28
|
-
# very odd and disconcerting...
|
29
|
-
expected_counts.each do |model_class, expected_count|
|
30
|
-
model_class.count.should equal(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def create_widget(attrs={})
|
35
|
-
MopedTest::Widget.new({:name => 'some widget'}.merge(attrs)).save!
|
36
|
-
end
|
37
|
-
|
38
|
-
def create_gadget(attrs={})
|
39
|
-
MopedTest::Gadget.new({:name => 'some gadget'}.merge(attrs)).save!
|
40
|
-
end
|
41
|
-
|
42
|
-
def create_system(attrs={})
|
43
|
-
MopedTest::System.new({:name => 'some system'}.merge(attrs)).save!
|
44
|
-
end
|
45
|
-
|
46
|
-
it "truncates all collections by default" do
|
47
|
-
create_widget
|
48
|
-
create_gadget
|
49
|
-
create_system
|
50
|
-
ensure_counts(MopedTest::Widget => 1, MopedTest::Gadget => 1, MopedTest::System => 1)
|
51
|
-
truncation.clean
|
52
|
-
ensure_counts(MopedTest::Widget => 0, MopedTest::Gadget => 0, MopedTest::System => 0)
|
53
|
-
end
|
54
|
-
|
55
|
-
context "when collections are provided to the :only option" do
|
56
|
-
let(:args) {{:only => ['MopedTest::Widget']}}
|
57
|
-
it "only truncates the specified collections" do
|
58
|
-
create_widget
|
59
|
-
create_gadget
|
60
|
-
ensure_counts(MopedTest::Widget => 1, MopedTest::Gadget => 1)
|
61
|
-
truncation.clean
|
62
|
-
ensure_counts(MopedTest::Widget => 0, MopedTest::Gadget => 1)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "when collections are provided to the :except option" do
|
67
|
-
let(:args) {{:except => ['MopedTest::Widget']}}
|
68
|
-
it "truncates all but the specified collections" do
|
69
|
-
create_widget
|
70
|
-
create_gadget
|
71
|
-
ensure_counts(MopedTest::Widget => 1, MopedTest::Gadget => 1)
|
72
|
-
truncation.clean
|
73
|
-
ensure_counts(MopedTest::Widget => 1, MopedTest::Gadget => 0)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|