database_cleaner 0.6.0.rc.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  == 0.6.x (In Git)
2
2
 
3
- == 0.6.0 2010-08-2x - The Multi-ORM/Connection Release
3
+ == 0.6.0 2010-10-25 - The Multi-ORM/Connection Release
4
4
 
5
5
  This release has the often asked for functionality of being able to clean
6
6
  multiple databases within the same project. This involves being able to
@@ -19,11 +19,14 @@ of the hours and effort he put into making this feature request a reality.
19
19
  * Ability to clean multiple DBs managed by different ORMs in same project. (Jon Rowe)
20
20
  * Allows for the ActiveRecord config file (database.yml) to contain ERB and process it. (Fletcher Nichol)
21
21
  * Mysql2Adapter support. (Kamal Fariz Mahyuddin and John Ferlito)
22
+ * Deletion strategy for ActiveRecord (Mikl Kurkov)
22
23
 
23
24
  === Bugfixes
24
25
  * Updates the DataMapper truncation strategy to version 0.10.3. (Robert Rouse)
25
26
  * Addresses Ruby 1.9 and 1.8 differences causing a bug in the AR PostgreSQLAdapter truncation strategy. (GH-14, James B. Byrne)
26
27
  * Fixes syntax error that MySQL was throwing during DataMapper truncation. (Blake Gentry)
28
+ * Fixes truncation for PostgreSQL (Bodaniel Jeanes and Gabriel Sobrinho)
29
+ * Workaround for superclass mismatches for the ActiveRecord-jdbc-adapter (Toms Mikoss)
27
30
 
28
31
  == 0.5.2
29
32
 
data/README.textile CHANGED
@@ -7,6 +7,19 @@ that is testing with a database.
7
7
 
8
8
  ActiveRecord, DataMapper, MongoMapper, Mongoid, and CouchPotato are supported.
9
9
 
10
+ Here is an overview of the strategies supported for each library:
11
+
12
+ |_. ORM |_. Truncation |_. Transaction |_. Deletion |
13
+ | ActiveRecord | Yes | Yes | Yes |
14
+ | DataMapper | Yes | Yes | No |
15
+ | CouchPotato | Yes | No | No |
16
+ | MongoMapper | Yes | No | No |
17
+ | Mongiod | Yes | No | No |
18
+
19
+ The ActiveRecord @:deletion@ strategy is only useful for when the @:truncation@ strategy causes
20
+ locks (as reported by some Oracle DB users). The @:truncation@ strategy is the preferred option
21
+ since it is much faster.
22
+
10
23
  h2. How to use
11
24
 
12
25
  <pre>
@@ -28,7 +41,6 @@ With the :truncation strategy you can also pass in options, for example:
28
41
 
29
42
  (I should point out the truncation strategy will never truncate your schema_migrations table.)
30
43
 
31
-
32
44
  Some strategies require that you call DatabaseCleaner.start before calling clean
33
45
  (for example the :transaction one needs to know to open up a transaction). So
34
46
  you would have:
@@ -93,38 +105,13 @@ Usage beyond that remains the same with DatabaseCleaner.start calling any setup
93
105
 
94
106
  Configuration options
95
107
 
96
- <table>
97
- <tr>
98
- <th>ORM</th>
99
- <th>How to access</th>
100
- <th>Notes</th>
101
- </tr>
102
- <tr>
103
- <td>Active Record</td>
104
- <td>DatabaseCleaner[:active_record]</td>
105
- <td>Connection specified as :symbol keys, loaded from config/database.yml</td>
106
- </th>
107
- <tr>
108
- <td>Data Mapper</td>
109
- <td>DatabaseCleaner[:data_mapper]</td>
110
- <td>Connection specified as :symbol keys, loaded via Datamapper repositories</td>
111
- </th>
112
- <tr>
113
- <td>Mongo Mapper</td>
114
- <td>DatabaseCleaner[:mongo_mapper]</td>
115
- <td>Multiple connections not yet supported</td>
116
- </th>
117
- <tr>
118
- <td>Mongoid</td>
119
- <td>DatabaseCleaner[:mongoid]</td>
120
- <td>Multiple connections not yet supported</td>
121
- </th>
122
- <tr>
123
- <td>Couch Potato</td>
124
- <td>DatabaseCleaner[:couch_potato]</td>
125
- <td>Multiple connections not yet supported</td>
126
- </tr>
127
- </table>
108
+
109
+ |_. ORM |_. How to access |_. Notes |
110
+ | Active Record | DatabaseCleaner[:active_record] | Connection specified as :symbol keys, loaded from config/database.yml |
111
+ | Data Mapper | DatabaseCleaner[:data_mapper] | Connection specified as :symbol keys, loaded via Datamapper repositories |
112
+ | Mongo Mapper | DatabaseCleaner[:mongo_mapper] | Multiple connections not yet supported |
113
+ | Mongoid | DatabaseCleaner[:mongoid] | Multiple connections not yet supported |
114
+ | Couch Potato | DatabaseCleaner[:couch_potato] | Multiple connections not yet supported |
128
115
 
129
116
  h2. Why?
130
117
 
@@ -14,6 +14,7 @@ Feature: database cleaning
14
14
  | ORM | Strategy |
15
15
  | ActiveRecord | transaction |
16
16
  | ActiveRecord | truncation |
17
+ | ActiveRecord | deletion |
17
18
  | DataMapper | transaction |
18
19
  | DataMapper | truncation |
19
20
  | MongoMapper | truncation |
@@ -13,6 +13,7 @@ Feature: multiple database cleaning
13
13
  Examples:
14
14
  | ORM | Strategy |
15
15
  | ActiveRecord | truncation |
16
+ | ActiveRecord | deletion |
16
17
  | DataMapper | truncation |
17
18
  | MongoMapper | truncation |
18
19
  | DataMapper | transaction |
@@ -5,7 +5,7 @@ module DatabaseCleaner
5
5
  module ActiveRecord
6
6
 
7
7
  def self.available_strategies
8
- %w[truncation transaction]
8
+ %w[truncation transaction deletion]
9
9
  end
10
10
 
11
11
  def self.config_file_location
@@ -0,0 +1,66 @@
1
+ require 'active_record/base'
2
+ require 'active_record/connection_adapters/abstract_adapter'
3
+ require "database_cleaner/generic/truncation"
4
+ require 'database_cleaner/active_record/base'
5
+ require 'database_cleaner/active_record/truncation'
6
+ # This file may seem to have duplication with that of truncation, but by keeping them separate
7
+ # we avoiding loading this code when it is not being used (which is the common case).
8
+
9
+ module ActiveRecord
10
+ module ConnectionAdapters
11
+
12
+ class MysqlAdapter < MYSQL_ADAPTER_PARENT
13
+ def delete_table(table_name)
14
+ execute("DELETE FROM #{quote_table_name(table_name)};")
15
+ end
16
+ end
17
+
18
+ class Mysql2Adapter < AbstractAdapter
19
+ def delete_table(table_name)
20
+ execute("DELETE FROM #{quote_table_name(table_name)};")
21
+ end
22
+ end
23
+
24
+ class JdbcAdapter < AbstractAdapter
25
+ def delete_table(table_name)
26
+ execute("DELETE FROM #{quote_table_name(table_name)};")
27
+ end
28
+ end
29
+
30
+ class PostgreSQLAdapter < AbstractAdapter
31
+ def delete_table(table_name)
32
+ execute("DELETE FROM #{quote_table_name(table_name)};")
33
+ end
34
+ end
35
+
36
+ class SQLServerAdapter < AbstractAdapter
37
+ def delete_table(table_name)
38
+ execute("DELETE FROM #{quote_table_name(table_name)};")
39
+ end
40
+ end
41
+
42
+ class OracleEnhancedAdapter < AbstractAdapter
43
+ def delete_table(table_name)
44
+ execute("DELETE FROM #{quote_table_name(table_name)}")
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+
51
+
52
+ module DatabaseCleaner::ActiveRecord
53
+ class Deletion < Truncation
54
+
55
+ def clean
56
+ connection.disable_referential_integrity do
57
+ tables_to_truncate.each do |table_name|
58
+ connection.delete_table table_name
59
+ end
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+
66
+
@@ -5,14 +5,21 @@ require 'database_cleaner/active_record/base'
5
5
 
6
6
  module ActiveRecord
7
7
  module ConnectionAdapters
8
+ # Activerecord-jdbc-adapter defines class dependencies a bit differently - if it is present, confirm to ArJdbc hierarchy to avoid 'superclass mismatch' errors.
9
+ USE_ARJDBC_WORKAROUND = defined?(ArJdbc)
8
10
 
9
11
  class AbstractAdapter
10
12
  end
11
13
 
12
- class SQLiteAdapter < AbstractAdapter
14
+ unless USE_ARJDBC_WORKAROUND
15
+ class SQLiteAdapter < AbstractAdapter
16
+ end
13
17
  end
14
18
 
15
- class MysqlAdapter < AbstractAdapter
19
+ MYSQL_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
20
+ SQLITE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : SQLiteAdapter
21
+
22
+ class MysqlAdapter < MYSQL_ADAPTER_PARENT
16
23
  def truncate_table(table_name)
17
24
  execute("TRUNCATE TABLE #{quote_table_name(table_name)};")
18
25
  end
@@ -24,10 +31,11 @@ module ActiveRecord
24
31
  end
25
32
  end
26
33
 
27
- class SQLite3Adapter < SQLiteAdapter
28
- def truncate_table(table_name)
34
+ class SQLite3Adapter < SQLITE_ADAPTER_PARENT
35
+ def delete_table(table_name)
29
36
  execute("DELETE FROM #{quote_table_name(table_name)};")
30
37
  end
38
+ alias truncate_table delete_table
31
39
  end
32
40
 
33
41
  class JdbcAdapter < AbstractAdapter
@@ -42,19 +50,19 @@ module ActiveRecord
42
50
 
43
51
  class PostgreSQLAdapter < AbstractAdapter
44
52
 
45
- def self.db_version
46
- @db_version ||= connection.select_values(
53
+ def db_version
54
+ @db_version ||= select_values(
47
55
  "SELECT CHARACTER_VALUE
48
56
  FROM INFORMATION_SCHEMA.SQL_IMPLEMENTATION_INFO
49
57
  WHERE IMPLEMENTATION_INFO_NAME = 'DBMS VERSION' ").join.to_s
50
58
  end
51
59
 
52
- def self.cascade
60
+ def cascade
53
61
  @cascade ||= db_version >= "08.02" ? "CASCADE" : ""
54
62
  end
55
63
 
56
64
  def truncate_table(table_name)
57
- execute("TRUNCATE TABLE #{quote_table_name(table_name)} #{self.class.cascade};")
65
+ execute("TRUNCATE TABLE #{quote_table_name(table_name)} #{cascade};")
58
66
  end
59
67
 
60
68
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_cleaner
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15424115
5
- prerelease: true
4
+ hash: 7
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
9
  - 0
10
- - rc
11
- - 3
12
- version: 0.6.0.rc.3
10
+ version: 0.6.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - Ben Mabey
@@ -17,7 +15,7 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2010-08-22 00:00:00 -06:00
18
+ date: 2010-10-25 00:00:00 -06:00
21
19
  default_executable:
22
20
  dependencies: []
23
21
 
@@ -65,6 +63,7 @@ files:
65
63
  - features/support/feature_runner.rb
66
64
  - lib/database_cleaner.rb
67
65
  - lib/database_cleaner/active_record/base.rb
66
+ - lib/database_cleaner/active_record/deletion.rb
68
67
  - lib/database_cleaner/active_record/transaction.rb
69
68
  - lib/database_cleaner/active_record/truncation.rb
70
69
  - lib/database_cleaner/base.rb