database_cleaner 1.0.0.RC1 → 1.0.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.
Files changed (38) hide show
  1. data/Gemfile.lock +6 -0
  2. data/History.txt +11 -3
  3. data/README.markdown +39 -3
  4. data/VERSION.yml +2 -2
  5. data/examples/Gemfile +2 -0
  6. data/examples/Gemfile.lock +6 -0
  7. data/examples/config/redis.yml +8 -0
  8. data/examples/features/support/env.rb +8 -1
  9. data/examples/lib/mongoid_models.rb +1 -1
  10. data/examples/lib/ohm_models.rb +43 -0
  11. data/examples/lib/redis_models.rb +65 -0
  12. data/features/cleaning.feature +11 -9
  13. data/features/cleaning_default_strategy.feature +2 -0
  14. data/features/cleaning_multiple_orms.feature +19 -0
  15. data/features/step_definitions/database_cleaner_steps.rb +3 -2
  16. data/features/step_definitions/ohm_steps.rb +31 -0
  17. data/features/step_definitions/redis_steps.rb +31 -0
  18. data/lib/database_cleaner/active_record/base.rb +1 -7
  19. data/lib/database_cleaner/active_record/transaction.rb +4 -0
  20. data/lib/database_cleaner/base.rb +19 -3
  21. data/lib/database_cleaner/configuration.rb +5 -1
  22. data/lib/database_cleaner/mongoid/truncation.rb +2 -2
  23. data/lib/database_cleaner/moped/base.rb +35 -0
  24. data/lib/database_cleaner/moped/truncation.rb +4 -24
  25. data/lib/database_cleaner/moped/truncation_base.rb +34 -0
  26. data/lib/database_cleaner/ohm/truncation.rb +15 -0
  27. data/lib/database_cleaner/redis/base.rb +31 -0
  28. data/lib/database_cleaner/redis/truncation.rb +26 -0
  29. data/spec/database_cleaner/active_record/base_spec.rb +2 -19
  30. data/spec/database_cleaner/active_record/transaction_spec.rb +2 -0
  31. data/spec/database_cleaner/base_spec.rb +73 -7
  32. data/spec/database_cleaner/configuration_spec.rb +15 -1
  33. data/spec/database_cleaner/moped/moped_examples.rb +26 -0
  34. data/spec/database_cleaner/moped/truncation_spec.rb +75 -0
  35. data/spec/database_cleaner/ohm/truncation_spec.rb +70 -0
  36. data/spec/database_cleaner/redis/base_spec.rb +32 -0
  37. data/spec/database_cleaner/redis/truncation_spec.rb +63 -0
  38. metadata +20 -5
@@ -55,6 +55,20 @@ describe ::DatabaseCleaner do
55
55
  cleaner.orm.should == :couch_potato
56
56
  ::DatabaseCleaner.connections.size.should == 1
57
57
  end
58
+
59
+ it "should accept :moped" do
60
+ cleaner = ::DatabaseCleaner[:moped]
61
+ cleaner.should be_a(::DatabaseCleaner::Base)
62
+ cleaner.orm.should == :moped
63
+ ::DatabaseCleaner.connections.size.should == 1
64
+ end
65
+
66
+ it 'accepts :ohm' do
67
+ cleaner = ::DatabaseCleaner[:ohm]
68
+ cleaner.should be_a(::DatabaseCleaner::Base)
69
+ cleaner.orm.should == :ohm
70
+ ::DatabaseCleaner.connections.size.should == 1
71
+ end
58
72
  end
59
73
 
60
74
  it "should accept multiple orm's" do
@@ -119,7 +133,7 @@ describe ::DatabaseCleaner do
119
133
  it "should give me a default (autodetection) databasecleaner by default" do
120
134
  cleaner = mock("cleaner").as_null_object
121
135
  ::DatabaseCleaner::Base.stub!(:new).and_return(cleaner)
122
-
136
+
123
137
  ::DatabaseCleaner.connections.should == [cleaner]
124
138
  end
125
139
  end
@@ -0,0 +1,26 @@
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
+ end
@@ -0,0 +1,75 @@
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).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
+ @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
+ it "truncates all collections by default" do
43
+ create_widget
44
+ create_gadget
45
+ ensure_counts(MopedTest::Widget => 1, MopedTest::Gadget => 1)
46
+ truncation.clean
47
+ ensure_counts(MopedTest::Widget => 0, MopedTest::Gadget => 0)
48
+ end
49
+
50
+ context "when collections are provided to the :only option" do
51
+ let(:args) {{:only => ['MopedTest::Widget']}}
52
+ it "only truncates the specified collections" do
53
+ create_widget
54
+ create_gadget
55
+ ensure_counts(MopedTest::Widget => 1, MopedTest::Gadget => 1)
56
+ truncation.clean
57
+ ensure_counts(MopedTest::Widget => 0, MopedTest::Gadget => 1)
58
+ end
59
+ end
60
+
61
+ context "when collections are provided to the :except option" do
62
+ let(:args) {{:except => ['MopedTest::Widget']}}
63
+ it "truncates all but the specified collections" do
64
+ create_widget
65
+ create_gadget
66
+ ensure_counts(MopedTest::Widget => 1, MopedTest::Gadget => 1)
67
+ truncation.clean
68
+ ensure_counts(MopedTest::Widget => 1, MopedTest::Gadget => 0)
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,70 @@
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 == 6
43
+ Truncation.new.clean
44
+ @redis.keys.size.should == 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 == 6
52
+ Truncation.new(:only => ['*Widget*']).clean
53
+ @redis.keys.size.should == 3
54
+ @redis.get('DatabaseCleaner::Ohm::Gadget:id').should == '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 == 6
63
+ Truncation.new(:except => ['*Widget*']).clean
64
+ @redis.keys.size.should == 3
65
+ @redis.get('DatabaseCleaner::Ohm::Widget:id').should == '1'
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'database_cleaner/redis/base'
3
+ require 'database_cleaner/shared_strategy'
4
+
5
+ module DatabaseCleaner
6
+ describe Redis do
7
+ it { should respond_to(:available_strategies) }
8
+ end
9
+
10
+ module Redis
11
+ class ExampleStrategy
12
+ include ::DatabaseCleaner::Redis::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
+ url = 'redis://localhost:6379/2'
23
+ subject.db = 'redis://localhost:6379/2'
24
+ subject.db.should == url
25
+ end
26
+
27
+ it "should default to :default" do
28
+ subject.db.should == :default
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,63 @@
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.connect :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 == 2
35
+ Truncation.new.clean
36
+ @redis.keys.size.should == 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 == 2
44
+ Truncation.new(:only => ['Widge*']).clean
45
+ @redis.keys.size.should == 1
46
+ @redis.get('Gadget').should == '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 == 2
55
+ Truncation.new(:except => ['Widg*']).clean
56
+ @redis.keys.size.should == 1
57
+ @redis.get('Widget').should == '1'
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.RC1
5
- prerelease: 6
4
+ version: 1.0.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Mabey
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-04 00:00:00.000000000 Z
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Strategies for cleaning databases. Can be used to ensure a clean state
15
15
  for testing.
@@ -30,6 +30,7 @@ files:
30
30
  - examples/Gemfile
31
31
  - examples/Gemfile.lock
32
32
  - examples/config/database.yml.example
33
+ - examples/config/redis.yml
33
34
  - examples/db/sqlite_databases_go_here
34
35
  - examples/features/example.feature
35
36
  - examples/features/example_multiple_db.feature
@@ -46,11 +47,15 @@ files:
46
47
  - examples/lib/datamapper_models.rb
47
48
  - examples/lib/mongoid_models.rb
48
49
  - examples/lib/mongomapper_models.rb
50
+ - examples/lib/ohm_models.rb
51
+ - examples/lib/redis_models.rb
49
52
  - features/cleaning.feature
50
53
  - features/cleaning_default_strategy.feature
51
54
  - features/cleaning_multiple_dbs.feature
52
55
  - features/cleaning_multiple_orms.feature
53
56
  - features/step_definitions/database_cleaner_steps.rb
57
+ - features/step_definitions/ohm_steps.rb
58
+ - features/step_definitions/redis_steps.rb
54
59
  - features/support/env.rb
55
60
  - features/support/feature_runner.rb
56
61
  - lib/database_cleaner.rb
@@ -76,8 +81,13 @@ files:
76
81
  - lib/database_cleaner/mongo_mapper/truncation.rb
77
82
  - lib/database_cleaner/mongoid/base.rb
78
83
  - lib/database_cleaner/mongoid/truncation.rb
84
+ - lib/database_cleaner/moped/base.rb
79
85
  - lib/database_cleaner/moped/truncation.rb
86
+ - lib/database_cleaner/moped/truncation_base.rb
80
87
  - lib/database_cleaner/null_strategy.rb
88
+ - lib/database_cleaner/ohm/truncation.rb
89
+ - lib/database_cleaner/redis/base.rb
90
+ - lib/database_cleaner/redis/truncation.rb
81
91
  - lib/database_cleaner/sequel/base.rb
82
92
  - lib/database_cleaner/sequel/transaction.rb
83
93
  - lib/database_cleaner/sequel/truncation.rb
@@ -101,6 +111,11 @@ files:
101
111
  - spec/database_cleaner/mongo_mapper/base_spec.rb
102
112
  - spec/database_cleaner/mongo_mapper/mongo_examples.rb
103
113
  - spec/database_cleaner/mongo_mapper/truncation_spec.rb
114
+ - spec/database_cleaner/moped/moped_examples.rb
115
+ - spec/database_cleaner/moped/truncation_spec.rb
116
+ - spec/database_cleaner/ohm/truncation_spec.rb
117
+ - spec/database_cleaner/redis/base_spec.rb
118
+ - spec/database_cleaner/redis/truncation_spec.rb
104
119
  - spec/database_cleaner/sequel/base_spec.rb
105
120
  - spec/database_cleaner/sequel/transaction_spec.rb
106
121
  - spec/database_cleaner/sequel/truncation_spec.rb
@@ -129,9 +144,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
144
  required_rubygems_version: !ruby/object:Gem::Requirement
130
145
  none: false
131
146
  requirements:
132
- - - ! '>'
147
+ - - ! '>='
133
148
  - !ruby/object:Gem::Version
134
- version: 1.3.1
149
+ version: '0'
135
150
  requirements: []
136
151
  rubyforge_project:
137
152
  rubygems_version: 1.8.23