database_cleaner 0.6.1.rc → 0.6.1.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,7 @@
5
5
  * Add a NullStrategy. (GH-6 Ben Mabey)
6
6
 
7
7
  === Bugfixes
8
+ * Mongo colletion indexes are dropped for collections being removed. (GH-41 Ben Mabey)
8
9
  * Exclude database views from tables_to_truncate, if the connection adapter
9
10
  supports reading from the ANSI standard information_schema views. (GH-25 Samer Abukhait)
10
11
  * ORM types can be specified in string format and not mysteriously blowup. (GH-26 Ben Mabey)
@@ -0,0 +1,27 @@
1
+ module DatabaseCleaner
2
+ module Mongo
3
+ module Truncation
4
+
5
+ def clean
6
+ if @only
7
+ collections.each { |c| remove(c) if @only.include?(c.name) }
8
+ else
9
+ collections.each { |c| remove(c) unless @tables_to_exclude.include?(c.name) }
10
+ end
11
+ true
12
+ end
13
+
14
+ private
15
+
16
+ def remove(collection)
17
+ collection.drop_indexes
18
+ collection.remove
19
+ end
20
+
21
+ def collections
22
+ database.collections.select { |c| c.name !~ /^system/ }
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -1,35 +1,18 @@
1
1
  require 'database_cleaner/mongo_mapper/base'
2
2
  require 'database_cleaner/generic/truncation'
3
+ require 'database_cleaner/mongo/truncation'
3
4
 
4
5
  module DatabaseCleaner
5
6
  module MongoMapper
6
7
  class Truncation
7
8
  include ::DatabaseCleaner::MongoMapper::Base
8
9
  include ::DatabaseCleaner::Generic::Truncation
9
-
10
- def clean
11
- if @only
12
- collections.each { |c| c.remove if @only.include?(c.name) }
13
- elsif @tables_to_exclude
14
- collections.each { |c| c.remove unless @tables_to_exclude.include?(c.name) }
15
- else
16
- collections.each { |c| c.remove }
17
- end
18
- true
19
- end
20
-
10
+ include ::DatabaseCleaner::Mongo::Truncation
11
+
21
12
  private
22
13
 
23
- def connection
24
- ::MongoMapper.connection
25
- end
26
-
27
- def collections
28
- connection.db(database).collections.select { |c| c.name !~ /^system/ }
29
- end
30
-
31
14
  def database
32
- ::MongoMapper.database.name
15
+ ::MongoMapper.database
33
16
  end
34
17
  end
35
18
  end
@@ -1,25 +1,18 @@
1
1
  require 'database_cleaner/mongoid/base'
2
2
  require 'database_cleaner/generic/truncation'
3
+ require 'database_cleaner/mongo/truncation'
3
4
 
4
5
  module DatabaseCleaner
5
6
  module Mongoid
6
7
  class Truncation
7
8
  include ::DatabaseCleaner::Mongoid::Base
8
9
  include ::DatabaseCleaner::Generic::Truncation
9
-
10
- def clean
11
- if @only
12
- collections.each { |c| c.remove if @only.include?(c.name) }
13
- else
14
- collections.each { |c| c.remove unless @tables_to_exclude.include?(c.name) }
15
- end
16
- true
17
- end
10
+ include ::DatabaseCleaner::Mongo::Truncation
18
11
 
19
12
  private
20
13
 
21
- def collections
22
- ::Mongoid.database.collections.select { |c| c.name !~ /^system/ }
14
+ def database
15
+ ::Mongoid.database
23
16
  end
24
17
 
25
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_cleaner
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7712046
4
+ hash: 977940603
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
9
  - 1
10
- - rc
11
- version: 0.6.1.rc
10
+ - rc2
11
+ version: 0.6.1.rc2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Ben Mabey
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-01-16 00:00:00 -07:00
19
+ date: 2011-01-26 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies: []
22
22
 
@@ -84,6 +84,7 @@ files:
84
84
  - lib/database_cleaner/data_mapper/truncation.rb
85
85
  - lib/database_cleaner/generic/base.rb
86
86
  - lib/database_cleaner/generic/truncation.rb
87
+ - lib/database_cleaner/mongo/truncation.rb
87
88
  - lib/database_cleaner/mongo_mapper/base.rb
88
89
  - lib/database_cleaner/mongo_mapper/truncation.rb
89
90
  - lib/database_cleaner/mongoid/base.rb
@@ -103,7 +104,6 @@ files:
103
104
  - spec/database_cleaner/mongo_mapper/base_spec.rb
104
105
  - spec/database_cleaner/mongo_mapper/mongo_examples.rb
105
106
  - spec/database_cleaner/mongo_mapper/truncation_spec.rb
106
- - spec/database_cleaner/mongoid/truncation_spec.rb
107
107
  - spec/database_cleaner/shared_strategy_spec.rb
108
108
  - spec/rcov.opts
109
109
  - spec/spec.opts
@@ -159,7 +159,6 @@ test_files:
159
159
  - spec/database_cleaner/mongo_mapper/base_spec.rb
160
160
  - spec/database_cleaner/mongo_mapper/mongo_examples.rb
161
161
  - spec/database_cleaner/mongo_mapper/truncation_spec.rb
162
- - spec/database_cleaner/mongoid/truncation_spec.rb
163
162
  - spec/database_cleaner/shared_strategy_spec.rb
164
163
  - spec/spec_helper.rb
165
164
  - examples/features/step_definitions/activerecord_steps.rb
@@ -1,84 +0,0 @@
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