database_cleaner 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,11 @@
1
1
  == 0.7.x (in git)
2
2
 
3
+ == 0.7.2 2012-03-21
4
+
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)
8
+
3
9
  == 0.7.1 2012-01-15
4
10
 
5
11
  === New Features
@@ -14,6 +14,7 @@ Here is an overview of the strategies supported for each library:
14
14
  | DataMapper | Yes | **Yes** | No |
15
15
  | CouchPotato | **Yes** | No | No |
16
16
  | MongoMapper | **Yes** | No | No |
17
+ | Mongoid | **Yes** | No | No |
17
18
  | Sequel | **Yes** | Yes | No |
18
19
 
19
20
  (Default strategy for each library is denoted in bold)
@@ -26,6 +27,8 @@ be faster than @:truncation@ in some cases as well. In general, the best approa
26
27
  Database Cleaner also includes a @null@ strategy (that does no cleaning at all) which can be used
27
28
  with any ORM library. You can also explicitly use it by setting your strategy to @nil@.
28
29
 
30
+ For support or to discuss development please use the "Google Group":http://groups.google.com/group/database_cleaner.
31
+
29
32
  h2. How to use
30
33
 
31
34
  <pre>
@@ -123,21 +126,6 @@ end
123
126
  This should cover the basics of tear down between scenarios and keeping your database clean.
124
127
  For more examples see the section "Why?"
125
128
 
126
- h2. Common Errors
127
-
128
- In rare cases DatabaseCleaner will encounter errors that it will log. By default it uses STDOUT set to the ERROR level but you can configure this to use whatever Logger you desire. Here's an example of using the Rails.logger in env.rb:
129
-
130
- <pre>
131
- DatabaseCleaner.logger = Rails.logger
132
- </pre>
133
-
134
- If you are using Postgres and have foreign key constraints, the truncation strategy will cause a lot of extra noise to appear on STDERR (in
135
- the form of "NOTICE truncate cascades" messages). To silence these warnings set the following log level in your postgresql.conf file:
136
-
137
- <pre>
138
- client_min_messages = warning
139
- </pre>
140
-
141
129
  h2. How to use with multiple ORM's
142
130
 
143
131
  Sometimes you need to use multiple ORMs in your application. You can use DatabaseCleaner to clean multiple ORMs, and multiple connections for those ORMs.
@@ -199,6 +187,37 @@ You can have the best of both worlds and use the best one for the job:
199
187
  DatabaseCleaner.strategy = (ENV['SELENIUM'] == 'true') ? :truncation : :transaction
200
188
  </pre>
201
189
 
190
+
191
+ h2. Common Errors
192
+
193
+ h4. DatabaseCleaner is trying to use the wrong ORM
194
+
195
+ DatabaseCleaner has an autodetect mechanism where if you do not explicitly define your ORM it will use the first ORM it can detect that is loaded. Since ActiveRecord is the most common ORM used that is the first one checked for. Sometimes other libraries (e.g. ActiveAdmin) will load other ORMs (e.g. ActiveRecord) even though you are using a different ORM. This will result in DatabaseCleaner trying to use the wrong ORM (e.g. ActiveRecord) unless you explicitly define your ORM like so:
196
+
197
+ <pre>
198
+ # How to setup your ORM explicitly
199
+ DatabaseCleaner[:mongoid].strategy = :truncation
200
+ </pre>
201
+
202
+ h4. STDERR is being flooded when using Postgres
203
+
204
+ If you are using Postgres and have foreign key constraints, the truncation strategy will cause a lot of extra noise to appear on STDERR (in
205
+ the form of "NOTICE truncate cascades" messages). To silence these warnings set the following log level in your postgresql.conf file:
206
+
207
+ <pre>
208
+ client_min_messages = warning
209
+ </pre>
210
+
211
+
212
+ h2. Debugging
213
+
214
+ In rare cases DatabaseCleaner will encounter errors that it will log. By default it uses STDOUT set to the ERROR level but you can configure this to use whatever Logger you desire. Here's an example of using the Rails.logger in env.rb:
215
+
216
+ <pre>
217
+ DatabaseCleaner.logger = Rails.logger
218
+ </pre>
219
+
220
+
202
221
  h2. COPYRIGHT
203
222
 
204
223
  Copyright (c) 2009 Ben Mabey. See LICENSE for details.
@@ -2,4 +2,4 @@
2
2
  :major: 0
3
3
  :build:
4
4
  :minor: 7
5
- :patch: 1
5
+ :patch: 2
@@ -15,7 +15,7 @@ module ActiveRecord
15
15
  end
16
16
  end
17
17
 
18
- class Mysql2Adapter < AbstractAdapter
18
+ class Mysql2Adapter < MYSQL2_ADAPTER_PARENT
19
19
  def delete_table(table_name)
20
20
  execute("DELETE FROM #{quote_table_name(table_name)};")
21
21
  end
@@ -5,15 +5,20 @@ module DatabaseCleaner
5
5
  include ::DatabaseCleaner::Sequel::Base
6
6
 
7
7
  def start
8
- @transactions ||= []
9
- db.send(:add_transaction)
10
- @transactions << db.send(:begin_transaction, db)
8
+ @fibers||= []
9
+ db= self.db
10
+ f= Fiber.new do
11
+ db.transaction(:rollback => :always, :savepoint => true) do
12
+ Fiber.yield
13
+ end
14
+ end
15
+ f.resume
16
+ @fibers<< f
11
17
  end
12
-
18
+
13
19
  def clean
14
- transaction = @transactions.pop
15
- db.send(:rollback_transaction, transaction)
16
- db.send(:remove_transaction, transaction)
20
+ f= @fibers.pop
21
+ f.resume
17
22
  end
18
23
  end
19
24
  end
@@ -8,8 +8,21 @@ module DatabaseCleaner
8
8
  include ::DatabaseCleaner::Generic::Truncation
9
9
 
10
10
  def clean
11
- each_table do |db, table|
12
- db[table].truncate
11
+ case db_type= db.url.sub(/:.+/,'').to_sym
12
+ when :postgres
13
+ # PostgreSQL requires all tables with FKs to be truncates in the same command, or have the CASCADE keyword
14
+ # appended. Bulk truncation without CASCADE is:
15
+ # * Safer. Tables outside of tables_to_truncate won't be affected.
16
+ # * Faster. Less roundtrips to the db.
17
+ unless (tables= tables_to_truncate(db)).empty?
18
+ all_tables= tables.map{|t| %["#{t}"]}.join ','
19
+ db.run "TRUNCATE TABLE #{all_tables};"
20
+ end
21
+ else
22
+ # Truncate each table normally
23
+ each_table do |db, table|
24
+ db[table].truncate
25
+ end
13
26
  end
14
27
  end
15
28
 
@@ -24,6 +37,12 @@ module DatabaseCleaner
24
37
  def tables_to_truncate(db)
25
38
  (@only || db.tables) - @tables_to_exclude
26
39
  end
40
+
41
+ # overwritten
42
+ def migration_storage_name
43
+ :schema_info
44
+ end
45
+
27
46
  end
28
47
  end
29
48
  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: 1
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 1
10
- version: 0.7.1
9
+ - 2
10
+ version: 0.7.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Mabey
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-15 00:00:00 Z
18
+ date: 2012-03-21 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Strategies for cleaning databases. Can be used to ensure a clean state for testing.