database_cleaner 1.6.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +5 -5
  2. data/lib/database_cleaner.rb +1 -8
  3. metadata +18 -498
  4. data/CONTRIBUTE.markdown +0 -28
  5. data/Gemfile.lock +0 -286
  6. data/History.rdoc +0 -430
  7. data/LICENSE +0 -20
  8. data/README.markdown +0 -518
  9. data/Rakefile +0 -40
  10. data/TODO +0 -3
  11. data/VERSION.yml +0 -4
  12. data/cucumber.yml +0 -1
  13. data/examples/Gemfile +0 -1
  14. data/examples/Gemfile.lock +0 -1
  15. data/examples/config/database.yml.example +0 -8
  16. data/examples/config/redis.yml +0 -8
  17. data/examples/db/sqlite_databases_go_here +0 -0
  18. data/examples/features/example.feature +0 -11
  19. data/examples/features/example_multiple_db.feature +0 -23
  20. data/examples/features/example_multiple_orm.feature +0 -22
  21. data/examples/features/step_definitions/activerecord_steps.rb +0 -31
  22. data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
  23. data/examples/features/step_definitions/datamapper_steps.rb +0 -37
  24. data/examples/features/step_definitions/mongoid_steps.rb +0 -23
  25. data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
  26. data/examples/features/step_definitions/neo4j_steps.rb +0 -23
  27. data/examples/features/step_definitions/ohm_steps.rb +0 -31
  28. data/examples/features/step_definitions/redis_steps.rb +0 -31
  29. data/examples/features/step_definitions/translation_steps.rb +0 -55
  30. data/examples/features/support/env.rb +0 -61
  31. data/examples/lib/activerecord_models.rb +0 -41
  32. data/examples/lib/couchpotato_models.rb +0 -61
  33. data/examples/lib/datamapper_models.rb +0 -50
  34. data/examples/lib/mongoid_models.rb +0 -44
  35. data/examples/lib/mongomapper_models.rb +0 -51
  36. data/examples/lib/neo4j_models.rb +0 -17
  37. data/examples/lib/ohm_models.rb +0 -43
  38. data/examples/lib/redis_models.rb +0 -65
  39. data/examples/lib/sequel_models.rb +0 -9
  40. data/features/cleaning.feature +0 -30
  41. data/features/cleaning_default_strategy.feature +0 -23
  42. data/features/cleaning_multiple_dbs.feature +0 -22
  43. data/features/cleaning_multiple_orms.feature +0 -67
  44. data/features/step_definitions/database_cleaner_steps.rb +0 -33
  45. data/features/support/env.rb +0 -4
  46. data/features/support/feature_runner.rb +0 -39
  47. data/lib/database_cleaner/active_record/base.rb +0 -92
  48. data/lib/database_cleaner/active_record/deletion.rb +0 -106
  49. data/lib/database_cleaner/active_record/transaction.rb +0 -59
  50. data/lib/database_cleaner/active_record/truncation.rb +0 -275
  51. data/lib/database_cleaner/base.rb +0 -164
  52. data/lib/database_cleaner/configuration.rb +0 -131
  53. data/lib/database_cleaner/couch_potato/base.rb +0 -7
  54. data/lib/database_cleaner/couch_potato/truncation.rb +0 -28
  55. data/lib/database_cleaner/cucumber.rb +0 -3
  56. data/lib/database_cleaner/data_mapper/base.rb +0 -21
  57. data/lib/database_cleaner/data_mapper/transaction.rb +0 -28
  58. data/lib/database_cleaner/data_mapper/truncation.rb +0 -172
  59. data/lib/database_cleaner/generic/base.rb +0 -29
  60. data/lib/database_cleaner/generic/transaction.rb +0 -11
  61. data/lib/database_cleaner/generic/truncation.rb +0 -40
  62. data/lib/database_cleaner/mongo/base.rb +0 -16
  63. data/lib/database_cleaner/mongo/truncation.rb +0 -62
  64. data/lib/database_cleaner/mongo/truncation_mixin.rb +0 -26
  65. data/lib/database_cleaner/mongo2/base.rb +0 -16
  66. data/lib/database_cleaner/mongo2/truncation_mixin.rb +0 -39
  67. data/lib/database_cleaner/mongo_mapper/base.rb +0 -20
  68. data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
  69. data/lib/database_cleaner/mongoid/base.rb +0 -20
  70. data/lib/database_cleaner/mongoid/truncation.rb +0 -49
  71. data/lib/database_cleaner/moped/base.rb +0 -39
  72. data/lib/database_cleaner/moped/truncation.rb +0 -9
  73. data/lib/database_cleaner/moped/truncation_base.rb +0 -40
  74. data/lib/database_cleaner/neo4j/base.rb +0 -62
  75. data/lib/database_cleaner/neo4j/deletion.rb +0 -16
  76. data/lib/database_cleaner/neo4j/transaction.rb +0 -35
  77. data/lib/database_cleaner/neo4j/truncation.rb +0 -9
  78. data/lib/database_cleaner/null_strategy.rb +0 -20
  79. data/lib/database_cleaner/ohm/truncation.rb +0 -15
  80. data/lib/database_cleaner/redis/base.rb +0 -37
  81. data/lib/database_cleaner/redis/truncation.rb +0 -26
  82. data/lib/database_cleaner/sequel/base.rb +0 -22
  83. data/lib/database_cleaner/sequel/deletion.rb +0 -47
  84. data/lib/database_cleaner/sequel/transaction.rb +0 -40
  85. data/lib/database_cleaner/sequel/truncation.rb +0 -78
  86. data/spec/database_cleaner/active_record/base_spec.rb +0 -188
  87. data/spec/database_cleaner/active_record/transaction_spec.rb +0 -176
  88. data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +0 -38
  89. data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +0 -38
  90. data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +0 -75
  91. data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +0 -40
  92. data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +0 -40
  93. data/spec/database_cleaner/active_record/truncation_spec.rb +0 -180
  94. data/spec/database_cleaner/base_spec.rb +0 -617
  95. data/spec/database_cleaner/configuration_spec.rb +0 -345
  96. data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
  97. data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
  98. data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
  99. data/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb +0 -41
  100. data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
  101. data/spec/database_cleaner/generic/base_spec.rb +0 -61
  102. data/spec/database_cleaner/generic/truncation_spec.rb +0 -118
  103. data/spec/database_cleaner/mongo/mongo_examples.rb +0 -26
  104. data/spec/database_cleaner/mongo/truncation_spec.rb +0 -72
  105. data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
  106. data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
  107. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
  108. data/spec/database_cleaner/moped/moped_examples.rb +0 -32
  109. data/spec/database_cleaner/moped/truncation_spec.rb +0 -80
  110. data/spec/database_cleaner/neo4j/base_spec.rb +0 -43
  111. data/spec/database_cleaner/neo4j/transaction_spec.rb +0 -25
  112. data/spec/database_cleaner/null_strategy_spec.rb +0 -28
  113. data/spec/database_cleaner/ohm/truncation_spec.rb +0 -70
  114. data/spec/database_cleaner/redis/base_spec.rb +0 -43
  115. data/spec/database_cleaner/redis/truncation_spec.rb +0 -63
  116. data/spec/database_cleaner/sequel/base_spec.rb +0 -32
  117. data/spec/database_cleaner/sequel/deletion_spec.rb +0 -58
  118. data/spec/database_cleaner/sequel/transaction_spec.rb +0 -21
  119. data/spec/database_cleaner/sequel/truncation/sqlite3_spec.rb +0 -0
  120. data/spec/database_cleaner/sequel/truncation_spec.rb +0 -182
  121. data/spec/database_cleaner/shared_strategy.rb +0 -15
  122. data/spec/rcov.opts +0 -1
  123. data/spec/spec_helper.rb +0 -21
  124. data/spec/support/active_record/database_setup.rb +0 -6
  125. data/spec/support/active_record/migrations/20150101010000_create_users.rb +0 -14
  126. data/spec/support/active_record/migrations/20150101020000_create_agents.rb +0 -14
  127. data/spec/support/active_record/mysql2_setup.rb +0 -39
  128. data/spec/support/active_record/mysql_setup.rb +0 -38
  129. data/spec/support/active_record/postgresql_setup.rb +0 -48
  130. data/spec/support/active_record/schema_setup.rb +0 -17
  131. data/spec/support/active_record/sqlite3_setup.rb +0 -40
  132. data/spec/support/data_mapper/schema_setup.rb +0 -15
  133. data/spec/support/data_mapper/sqlite3_setup.rb +0 -39
@@ -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,8 +0,0 @@
1
- class Widget
2
- include ::MongoMapper::Document
3
- key :name, String
4
- end
5
- class Gadget
6
- include ::MongoMapper::Document
7
- key :name, String
8
- 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
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/neo4j/base'
3
- require 'database_cleaner/shared_strategy'
4
-
5
- module DatabaseCleaner
6
- describe Neo4j do
7
- it { should respond_to(:available_strategies) }
8
- end
9
-
10
- module Neo4j
11
- class ExampleStrategy
12
- include ::DatabaseCleaner::Neo4j::Base
13
- end
14
-
15
- describe ExampleStrategy do
16
-
17
- it_should_behave_like "a generic strategy"
18
- it { should respond_to(:db) }
19
- it { should respond_to(:db=) }
20
-
21
- it "should store my describe db" do
22
- db_conf = {:connection => {:type => :server_db, :path => 'http://localhost:7474'}}
23
- subject.db = db_conf
24
- subject.db.should eq db_conf
25
- end
26
-
27
- it "should respect additional connection parameters" do
28
- db_conf = {:type => :server_db, :path => 'http://localhost:7474', basic_auth: {username: 'user', password: 'pass'}}
29
- subject.db = db_conf
30
- stub_const("Neo4j::Session", double()).should_receive(:open).with(:server_db, 'http://localhost:7474', {basic_auth: {username: 'user', password: 'pass'}}) { true }
31
- subject.start
32
- end
33
-
34
- it "should default to nil" do
35
- subject.db.should be_nil
36
- end
37
-
38
- it "should return default configuration" do
39
- subject.database.should eq(:type => :server_db, :path => 'http://localhost:7475/')
40
- end
41
- end
42
- end
43
- end
@@ -1,25 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'neo4j-core'
3
- require 'database_cleaner/neo4j/transaction'
4
-
5
- module DatabaseCleaner
6
- module Neo4j
7
-
8
- describe Transaction do
9
- before(:all) do
10
- DatabaseCleaner[:neo4j, :connection => {:type => :server_db, :path => 'http://localhost:7474'}]
11
- end
12
-
13
- it_should_behave_like "a generic strategy"
14
- it_should_behave_like "a generic transaction strategy"
15
-
16
- describe "start" do
17
- it "should start a transaction"
18
- end
19
-
20
- describe "clean" do
21
- it "should finish a transaction"
22
- end
23
- end
24
- end
25
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module DatabaseCleaner
4
- describe NullStrategy do
5
- it 'responds to .start' do
6
- expect { NullStrategy.start }.not_to raise_error(NoMethodError)
7
- end
8
-
9
- it 'responds to .clean' do
10
- expect { NullStrategy.clean }.not_to raise_error(NoMethodError)
11
- end
12
-
13
- describe '.cleaning' do
14
- it 'fails without a block' do
15
- expect { NullStrategy.cleaning }.to raise_error(LocalJumpError)
16
- end
17
-
18
- it 'no-ops with a block' do
19
- effect = double
20
- expect(effect).to receive(:occur).once
21
-
22
- NullStrategy.cleaning do
23
- effect.occur
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,70 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'ohm'
3
- require 'database_cleaner/ohm/truncation'
4
-
5
- module DatabaseCleaner
6
- module Ohm
7
-
8
- class Widget < ::Ohm::Model
9
- attribute :name
10
- end
11
-
12
- class Gadget < ::Ohm::Model
13
- attribute :name
14
- end
15
-
16
- describe Truncation do
17
- before(:all) do
18
- config = YAML::load(File.open("#{File.dirname(__FILE__)}/../../../examples/config/redis.yml"))
19
- ::Ohm.connect :url => config['test']['url']
20
- @redis = ::Ohm.redis
21
- end
22
-
23
- before(:each) do
24
- @redis.flushdb
25
- end
26
-
27
- it "should flush the database" do
28
- Truncation.new.clean
29
- end
30
-
31
- def create_widget(attrs={})
32
- Widget.new({:name => 'some widget'}.merge(attrs)).save
33
- end
34
-
35
- def create_gadget(attrs={})
36
- Gadget.new({:name => 'some gadget'}.merge(attrs)).save
37
- end
38
-
39
- it "truncates all keys by default" do
40
- create_widget
41
- create_gadget
42
- @redis.keys.size.should eq 6
43
- Truncation.new.clean
44
- @redis.keys.size.should eq 0
45
- end
46
-
47
- context "when keys are provided to the :only option" do
48
- it "only truncates the specified keys" do
49
- create_widget
50
- create_gadget
51
- @redis.keys.size.should eq 6
52
- Truncation.new(:only => ['*Widget*']).clean
53
- @redis.keys.size.should eq 3
54
- @redis.get('DatabaseCleaner::Ohm::Gadget:id').should eq '1'
55
- end
56
- end
57
-
58
- context "when keys are provided to the :except option" do
59
- it "truncates all but the specified keys" do
60
- create_widget
61
- create_gadget
62
- @redis.keys.size.should eq 6
63
- Truncation.new(:except => ['*Widget*']).clean
64
- @redis.keys.size.should eq 3
65
- @redis.get('DatabaseCleaner::Ohm::Widget:id').should eq '1'
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
- require 'redis'
3
- require 'database_cleaner/redis/base'
4
- require 'database_cleaner/shared_strategy'
5
-
6
- module DatabaseCleaner
7
- describe Redis do
8
- it { should respond_to(:available_strategies) }
9
- end
10
-
11
- module Redis
12
- class ExampleStrategy
13
- include ::DatabaseCleaner::Redis::Base
14
- end
15
-
16
- describe ExampleStrategy do
17
-
18
- it_should_behave_like "a generic strategy"
19
- it { should respond_to(:db) }
20
- it { should respond_to(:db=) }
21
-
22
- context "when passing url" do
23
- it "should store my describe db" do
24
- url = 'redis://localhost:6379/2'
25
- subject.db = 'redis://localhost:6379/2'
26
- subject.db.should eq url
27
- end
28
- end
29
-
30
- context "when passing connection" do
31
- it "should store my describe db" do
32
- connection = ::Redis.new :url => 'redis://localhost:6379/2'
33
- subject.db = connection
34
- subject.db.should eq connection
35
- end
36
- end
37
-
38
- it "should default to :default" do
39
- subject.db.should eq :default
40
- end
41
- end
42
- end
43
- end
@@ -1,63 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'redis'
3
- require 'database_cleaner/redis/truncation'
4
-
5
-
6
- module DatabaseCleaner
7
- module Redis
8
-
9
- describe Truncation do
10
- before(:all) do
11
- config = YAML::load(File.open("#{File.dirname(__FILE__)}/../../../examples/config/redis.yml"))
12
- @redis = ::Redis.new :url => config['test']['url']
13
- end
14
-
15
- before(:each) do
16
- @redis.flushdb
17
- end
18
-
19
- it "should flush the database" do
20
- Truncation.new.clean
21
- end
22
-
23
- def create_widget(attrs={})
24
- @redis.set 'Widget', 1
25
- end
26
-
27
- def create_gadget(attrs={})
28
- @redis.set 'Gadget', 1
29
- end
30
-
31
- it "truncates all keys by default" do
32
- create_widget
33
- create_gadget
34
- @redis.keys.size.should eq 2
35
- Truncation.new.clean
36
- @redis.keys.size.should eq 0
37
- end
38
-
39
- context "when keys are provided to the :only option" do
40
- it "only truncates the specified keys" do
41
- create_widget
42
- create_gadget
43
- @redis.keys.size.should eq 2
44
- Truncation.new(:only => ['Widge*']).clean
45
- @redis.keys.size.should eq 1
46
- @redis.get('Gadget').should eq '1'
47
- end
48
- end
49
-
50
- context "when keys are provided to the :except option" do
51
- it "truncates all but the specified keys" do
52
- create_widget
53
- create_gadget
54
- @redis.keys.size.should eq 2
55
- Truncation.new(:except => ['Widg*']).clean
56
- @redis.keys.size.should eq 1
57
- @redis.get('Widget').should eq '1'
58
- end
59
- end
60
- end
61
- end
62
- end
63
-
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/sequel/base'
3
- require 'database_cleaner/shared_strategy'
4
- require 'sequel'
5
-
6
- module DatabaseCleaner
7
- describe Sequel do
8
- it { should respond_to(:available_strategies) }
9
- end
10
-
11
- module Sequel
12
- class ExampleStrategy
13
- include ::DatabaseCleaner::Sequel::Base
14
- end
15
-
16
- describe ExampleStrategy do
17
- it_should_behave_like "a generic strategy"
18
- it { should respond_to(:db) }
19
- it { should respond_to(:db=) }
20
-
21
- it "should store my desired db" do
22
- subject.db = :my_db
23
- subject.db.should eq :my_db
24
- end
25
-
26
- it "should default to :default" do
27
- pending "I figure out how to use Sequel and write some real tests for it..."
28
- subject.db.should eq :default
29
- end
30
- end
31
- end
32
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/sequel/deletion'
3
- require 'database_cleaner/shared_strategy'
4
- require 'sequel'
5
- require 'support/active_record/database_setup'
6
-
7
- module DatabaseCleaner
8
- module Sequel
9
- describe Deletion do
10
- it_should_behave_like "a generic strategy"
11
- end
12
-
13
- shared_examples 'a Sequel deletion strategy' do
14
- let(:deletion) do
15
- d = Deletion.new
16
- d.db = db
17
- d
18
- end
19
-
20
- context 'when several tables have data' do
21
- before(:each) do
22
- db.create_table!(:precious_stones) { primary_key :id }
23
- db.create_table!(:replaceable_trifles) { primary_key :id }
24
- db.create_table!(:worthless_junk) { primary_key :id }
25
-
26
- db[:precious_stones].insert
27
- db[:replaceable_trifles].insert
28
- db[:worthless_junk].insert
29
- end
30
-
31
- context 'by default' do
32
- it 'deletes all the tables' do
33
- d = Deletion.new
34
- d.db = db
35
- d.clean
36
-
37
- expect(db[:replaceable_trifles]).to have(0).rows
38
- expect(db[:worthless_junk]).to have(0).rows
39
- expect(db[:precious_stones]).to have(0).rows
40
- end
41
- end
42
- end
43
- end
44
-
45
- supported_configurations = [
46
- { :url => 'mysql:///', :connection_options => db_config['mysql'] },
47
- { :url => 'postgres:///', :connection_options => db_config['postgres'] }
48
- ]
49
-
50
- supported_configurations.each do |config|
51
- describe "Sequel deletion (using a #{config[:url]} connection)" do
52
- let(:db) { ::Sequel.connect(config[:url], config[:connection_options]) }
53
-
54
- it_behaves_like 'a Sequel deletion strategy'
55
- end
56
- end
57
- end
58
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/sequel/transaction'
3
- require 'database_cleaner/shared_strategy'
4
- require 'sequel'
5
-
6
- module DatabaseCleaner
7
- module Sequel
8
- describe Transaction do
9
- it_should_behave_like "a generic strategy"
10
- it_should_behave_like "a generic transaction strategy"
11
-
12
- describe "start" do
13
- it "should start a transaction"
14
- end
15
-
16
- describe "clean" do
17
- it "should finish a transaction"
18
- end
19
- end
20
- end
21
- end