database_cleaner 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,15 @@
1
- == 0.7.x (in git)
1
+ == 0.8.x (in git)
2
+
3
+ == 0.8.0 2012-06-02
4
+
5
+ * Support for Mongoid 3/Moped (Andrew Bennett)
6
+ * Postgres Adapter no longer generates invalid SQL when no tables provided. (Michael-Keith Bernard)
2
7
 
3
8
  == 0.7.2 2012-03-21
4
9
 
5
- * Proper Mysql2Adapter fix (Jonathan Viney)
6
- * Sequel::Transaction works with latest Sequel (David Barri)
7
- * Documenation fixes/improvements (David Barri, Ben Mabey, Kevin Moore)
10
+ * Proper Mysql2Adapter superclass fix. (Jonathan Viney)
11
+ * Sequel::Transaction works with latest Sequel. (David Barri)
12
+ * Documenation fixes/improvements. (David Barri, Ben Mabey, Kevin Moore)
8
13
 
9
14
  == 0.7.1 2012-01-15
10
15
 
@@ -29,6 +29,12 @@ with any ORM library. You can also explicitly use it by setting your strategy to
29
29
 
30
30
  For support or to discuss development please use the "Google Group":http://groups.google.com/group/database_cleaner.
31
31
 
32
+ h2. Dependencies
33
+
34
+ Because database_cleaner supports multiple ORMs, it doesn't make sense to include all the dependencies
35
+ for each one in the gemspec. However, the DataMapper adapter does depend on dm-transactions. Therefore,
36
+ if you use DataMapper, you must include dm-transactions in your Gemfile/bundle/gemset manually.
37
+
32
38
  h2. How to use
33
39
 
34
40
  <pre>
@@ -74,6 +80,22 @@ strategy the remaining time. To accomplish this you can say:
74
80
  # then make the DatabaseCleaner.start and DatabaseCleaner.clean calls appropriately
75
81
  </pre>
76
82
 
83
+ h3. Minitest Example
84
+
85
+ <pre>
86
+ DatabaseCleaner.strategy = :transaction
87
+
88
+ class MiniTest::Spec
89
+ before :each do
90
+ DatabaseCleaner.clean
91
+ end
92
+
93
+ after :each do
94
+ DatabaseCleaner.clean
95
+ end
96
+ end
97
+ </pre>
98
+
77
99
  h3. RSpec Example
78
100
 
79
101
  <pre>
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :build:
4
- :minor: 7
5
- :patch: 2
4
+ :minor: 8
5
+ :patch: 0
@@ -19,4 +19,4 @@ Feature: database cleaning
19
19
  | DataMapper | truncation |
20
20
  | MongoMapper | truncation |
21
21
  | Mongoid | truncation |
22
- | CouchPotato | truncation |
22
+ # | CouchPotato | truncation |
@@ -16,4 +16,4 @@ Feature: database cleaning
16
16
  | DataMapper |
17
17
  | MongoMapper |
18
18
  | Mongoid |
19
- | CouchPotato |
19
+ # | CouchPotato |
@@ -14,16 +14,16 @@ Feature: database cleaning using multiple ORMs
14
14
  | ActiveRecord | DataMapper |
15
15
  | ActiveRecord | MongoMapper |
16
16
  | ActiveRecord | Mongoid |
17
- | ActiveRecord | CouchPotato |
17
+ #| ActiveRecord | CouchPotato |
18
18
  | DataMapper | ActiveRecord |
19
19
  | DataMapper | MongoMapper |
20
20
  | DataMapper | Mongoid |
21
- | DataMapper | CouchPotato |
21
+ #| DataMapper | CouchPotato |
22
22
  | MongoMapper | ActiveRecord |
23
23
  | MongoMapper | DataMapper |
24
24
  | MongoMapper | Mongoid |
25
- | MongoMapper | CouchPotato |
26
- | CouchPotato | ActiveRecord |
27
- | CouchPotato | DataMapper |
28
- | CouchPotato | MongoMapper |
29
- | CouchPotato | Mongoid |
25
+ #| MongoMapper | CouchPotato |
26
+ # | CouchPotato | ActiveRecord |
27
+ #| CouchPotato | DataMapper |
28
+ #| CouchPotato | MongoMapper |
29
+ #| CouchPotato | Mongoid |
@@ -1,7 +1,10 @@
1
1
  require 'database_cleaner/active_record/base'
2
+ require 'database_cleaner/generic/transaction'
3
+
2
4
  module DatabaseCleaner::ActiveRecord
3
5
  class Transaction
4
6
  include ::DatabaseCleaner::ActiveRecord::Base
7
+ include ::DatabaseCleaner::Generic::Transaction
5
8
 
6
9
  def start
7
10
  if connection_klass.connection.respond_to?(:increment_open_transactions)
@@ -96,6 +96,7 @@ module ActiveRecord
96
96
  end
97
97
 
98
98
  def truncate_tables(table_names)
99
+ return if table_names.nil? || table_names.empty?
99
100
  execute("TRUNCATE TABLE #{table_names.map{|name| quote_table_name(name)}.join(', ')} #{restart_identity} #{cascade};")
100
101
  end
101
102
 
@@ -84,6 +84,8 @@ module DatabaseCleaner
84
84
  DatabaseCleaner::Mongoid
85
85
  when :mongo_mapper
86
86
  DatabaseCleaner::MongoMapper
87
+ when :moped
88
+ DatabaseCleaner::Moped
87
89
  when :couch_potato
88
90
  DatabaseCleaner::CouchPotato
89
91
  when :sequel
@@ -1,8 +1,10 @@
1
1
  require 'database_cleaner/data_mapper/base'
2
+ require 'database_cleaner/generic/transaction'
2
3
 
3
4
  module DatabaseCleaner::DataMapper
4
5
  class Transaction
5
6
  include ::DatabaseCleaner::DataMapper::Base
7
+ include ::DatabaseCleaner::Generic::Transaction
6
8
 
7
9
  def start(repository = self.db)
8
10
  ::DataMapper.repository(repository) do |r|
@@ -0,0 +1,11 @@
1
+ module DatabaseCleaner
2
+ module Generic
3
+ module Transaction
4
+ def initialize(opts = {})
5
+ if !opts.empty?
6
+ raise ArgumentError, "Options are not available for transaction strategies."
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,20 +1,37 @@
1
1
  require 'database_cleaner/mongoid/base'
2
2
  require 'database_cleaner/generic/truncation'
3
3
  require 'database_cleaner/mongo/truncation'
4
+ require 'database_cleaner/moped/truncation'
5
+ require 'mongoid/version'
4
6
 
5
7
  module DatabaseCleaner
6
8
  module Mongoid
7
9
  class Truncation
8
10
  include ::DatabaseCleaner::Mongoid::Base
9
11
  include ::DatabaseCleaner::Generic::Truncation
10
- include ::DatabaseCleaner::Mongo::Truncation
11
12
 
12
- private
13
+ if ::Mongoid::VERSION < '3'
14
+
15
+ include ::DatabaseCleaner::Mongo::Truncation
16
+
17
+ private
18
+
19
+ def database
20
+ ::Mongoid.database
21
+ end
22
+
23
+ else
24
+
25
+ include ::DatabaseCleaner::Moped::Truncation
26
+
27
+ private
28
+
29
+ def session
30
+ ::Mongoid.default_session
31
+ end
13
32
 
14
- def database
15
- ::Mongoid.database
16
33
  end
17
34
 
18
- end
35
+ end
19
36
  end
20
37
  end
@@ -0,0 +1,25 @@
1
+ module DatabaseCleaner
2
+ module Moped
3
+ module Truncation
4
+
5
+ def clean
6
+ if @only
7
+ collections.each { |c| session[c].drop if @only.include?(c.name) }
8
+ else
9
+ collections.each { |c| session[c].drop unless @tables_to_exclude.include?(c) }
10
+ end
11
+ true
12
+ end
13
+
14
+ private
15
+
16
+ def collections
17
+ session['system.namespaces'].find(:name => { '$not' => /system|\$/ }).to_a.map do |collection|
18
+ _, name = collection['name'].split('.', 2)
19
+ name
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_cleaner
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 2
10
- version: 0.7.2
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Mabey
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-21 00:00:00 Z
18
+ date: 2012-06-02 00:00:00 -06:00
19
+ default_executable:
19
20
  dependencies: []
20
21
 
21
22
  description: Strategies for cleaning databases. Can be used to ensure a clean state for testing.
@@ -75,12 +76,14 @@ files:
75
76
  - lib/database_cleaner/data_mapper/transaction.rb
76
77
  - lib/database_cleaner/data_mapper/truncation.rb
77
78
  - lib/database_cleaner/generic/base.rb
79
+ - lib/database_cleaner/generic/transaction.rb
78
80
  - lib/database_cleaner/generic/truncation.rb
79
81
  - lib/database_cleaner/mongo/truncation.rb
80
82
  - lib/database_cleaner/mongo_mapper/base.rb
81
83
  - lib/database_cleaner/mongo_mapper/truncation.rb
82
84
  - lib/database_cleaner/mongoid/base.rb
83
85
  - lib/database_cleaner/mongoid/truncation.rb
86
+ - lib/database_cleaner/moped/truncation.rb
84
87
  - lib/database_cleaner/null_strategy.rb
85
88
  - lib/database_cleaner/sequel/base.rb
86
89
  - lib/database_cleaner/sequel/transaction.rb
@@ -108,6 +111,7 @@ files:
108
111
  - spec/spec_helper.rb
109
112
  - LICENSE
110
113
  - TODO
114
+ has_rdoc: true
111
115
  homepage: http://github.com/bmabey/database_cleaner
112
116
  licenses: []
113
117
 
@@ -137,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
141
  requirements: []
138
142
 
139
143
  rubyforge_project:
140
- rubygems_version: 1.8.5
144
+ rubygems_version: 1.6.2
141
145
  signing_key:
142
146
  specification_version: 3
143
147
  summary: Strategies for cleaning databases. Can be used to ensure a clean state for testing.