surgical_strike 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/Gemfile.lock +163 -0
  2. data/History.txt +210 -0
  3. data/LICENSE +20 -0
  4. data/README.textile +229 -0
  5. data/TODO +3 -0
  6. data/VERSION.yml +5 -0
  7. data/cucumber.yml +1 -0
  8. data/examples/Gemfile +1 -0
  9. data/examples/Gemfile.lock +1 -0
  10. data/examples/config/database.yml.example +8 -0
  11. data/examples/db/sqlite_databases_go_here +0 -0
  12. data/examples/features/example.feature +11 -0
  13. data/examples/features/example_multiple_db.feature +23 -0
  14. data/examples/features/example_multiple_orm.feature +22 -0
  15. data/examples/features/step_definitions/activerecord_steps.rb +31 -0
  16. data/examples/features/step_definitions/couchpotato_steps.rb +31 -0
  17. data/examples/features/step_definitions/datamapper_steps.rb +37 -0
  18. data/examples/features/step_definitions/mongoid_steps.rb +23 -0
  19. data/examples/features/step_definitions/mongomapper_steps.rb +31 -0
  20. data/examples/features/step_definitions/translation_steps.rb +55 -0
  21. data/examples/features/support/env.rb +62 -0
  22. data/examples/lib/activerecord_models.rb +41 -0
  23. data/examples/lib/couchpotato_models.rb +61 -0
  24. data/examples/lib/datamapper_models.rb +50 -0
  25. data/examples/lib/mongoid_models.rb +49 -0
  26. data/examples/lib/mongomapper_models.rb +51 -0
  27. data/features/cleaning.feature +22 -0
  28. data/features/cleaning_default_strategy.feature +19 -0
  29. data/features/cleaning_multiple_dbs.feature +21 -0
  30. data/features/cleaning_multiple_orms.feature +29 -0
  31. data/features/step_definitions/database_cleaner_steps.rb +32 -0
  32. data/features/support/env.rb +7 -0
  33. data/features/support/feature_runner.rb +39 -0
  34. data/lib/database_cleaner/active_record/base.rb +53 -0
  35. data/lib/database_cleaner/active_record/deletion.rb +67 -0
  36. data/lib/database_cleaner/active_record/surgicalstrike.rb +65 -0
  37. data/lib/database_cleaner/active_record/transaction.rb +28 -0
  38. data/lib/database_cleaner/active_record/truncation.rb +152 -0
  39. data/lib/database_cleaner/base.rb +138 -0
  40. data/lib/database_cleaner/configuration.rb +94 -0
  41. data/lib/database_cleaner/couch_potato/base.rb +7 -0
  42. data/lib/database_cleaner/couch_potato/truncation.rb +28 -0
  43. data/lib/database_cleaner/cucumber.rb +11 -0
  44. data/lib/database_cleaner/data_mapper/base.rb +21 -0
  45. data/lib/database_cleaner/data_mapper/transaction.rb +26 -0
  46. data/lib/database_cleaner/data_mapper/truncation.rb +175 -0
  47. data/lib/database_cleaner/generic/base.rb +12 -0
  48. data/lib/database_cleaner/generic/surgicalstrike.rb +47 -0
  49. data/lib/database_cleaner/generic/truncation.rb +37 -0
  50. data/lib/database_cleaner/mongo/truncation.rb +22 -0
  51. data/lib/database_cleaner/mongo_mapper/base.rb +20 -0
  52. data/lib/database_cleaner/mongo_mapper/truncation.rb +19 -0
  53. data/lib/database_cleaner/mongoid/base.rb +20 -0
  54. data/lib/database_cleaner/mongoid/truncation.rb +20 -0
  55. data/lib/database_cleaner/null_strategy.rb +15 -0
  56. data/lib/database_cleaner/sequel/base.rb +22 -0
  57. data/lib/database_cleaner/sequel/transaction.rb +25 -0
  58. data/lib/database_cleaner/sequel/truncation.rb +50 -0
  59. data/lib/surgical_strike.rb +3 -0
  60. data/spec/database_cleaner/active_record/base_spec.rb +144 -0
  61. data/spec/database_cleaner/active_record/transaction_spec.rb +77 -0
  62. data/spec/database_cleaner/active_record/truncation_spec.rb +76 -0
  63. data/spec/database_cleaner/base_spec.rb +493 -0
  64. data/spec/database_cleaner/configuration_spec.rb +294 -0
  65. data/spec/database_cleaner/couch_potato/truncation_spec.rb +41 -0
  66. data/spec/database_cleaner/data_mapper/base_spec.rb +30 -0
  67. data/spec/database_cleaner/data_mapper/transaction_spec.rb +23 -0
  68. data/spec/database_cleaner/data_mapper/truncation_spec.rb +11 -0
  69. data/spec/database_cleaner/generic/base_spec.rb +22 -0
  70. data/spec/database_cleaner/generic/truncation_spec.rb +78 -0
  71. data/spec/database_cleaner/mongo_mapper/base_spec.rb +33 -0
  72. data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +8 -0
  73. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +74 -0
  74. data/spec/database_cleaner/sequel/base_spec.rb +32 -0
  75. data/spec/database_cleaner/sequel/transaction_spec.rb +21 -0
  76. data/spec/database_cleaner/sequel/truncation_spec.rb +13 -0
  77. data/spec/database_cleaner/shared_strategy_spec.rb +13 -0
  78. data/spec/rcov.opts +1 -0
  79. data/spec/spec.opts +7 -0
  80. data/spec/spec_helper.rb +19 -0
  81. metadata +162 -0
data/Gemfile.lock ADDED
@@ -0,0 +1,163 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ ZenTest (4.3.3)
5
+ activerecord (2.3.8)
6
+ activesupport (= 2.3.8)
7
+ activesupport (2.3.8)
8
+ addressable (2.2.0)
9
+ bson (1.0.4)
10
+ builder (2.1.2)
11
+ columnize (0.3.1)
12
+ couch_potato (0.3.0)
13
+ couchrest (>= 0.24)
14
+ json
15
+ couchrest (1.0.1)
16
+ json (>= 1.4.6)
17
+ mime-types (>= 1.15)
18
+ rest-client (>= 1.5.1)
19
+ cucumber (0.8.5)
20
+ builder (~> 2.1.2)
21
+ diff-lcs (~> 1.1.2)
22
+ gherkin (~> 2.1.4)
23
+ json_pure (~> 1.4.3)
24
+ term-ansicolor (~> 1.0.4)
25
+ data_objects (0.10.2)
26
+ addressable (~> 2.1)
27
+ datamapper (1.0.0)
28
+ dm-aggregates (= 1.0.0)
29
+ dm-constraints (= 1.0.0)
30
+ dm-core (= 1.0.0)
31
+ dm-core (= 1.0.0)
32
+ dm-migrations (= 1.0.0)
33
+ dm-serializer (= 1.0.0)
34
+ dm-timestamps (= 1.0.0)
35
+ dm-transactions (= 1.0.0)
36
+ dm-types (= 1.0.0)
37
+ dm-validations (= 1.0.0)
38
+ diff-lcs (1.1.2)
39
+ dm-aggregates (1.0.0)
40
+ dm-core (~> 1.0.0)
41
+ dm-constraints (1.0.0)
42
+ dm-core (~> 1.0.0)
43
+ dm-migrations (~> 1.0.0)
44
+ dm-core (1.0.0)
45
+ addressable (~> 2.1)
46
+ extlib (~> 0.9.15)
47
+ dm-do-adapter (1.0.0)
48
+ data_objects (~> 0.10.1)
49
+ dm-core (~> 1.0.0)
50
+ dm-migrations (1.0.0)
51
+ dm-core (~> 1.0.0)
52
+ dm-serializer (1.0.0)
53
+ dm-core (~> 1.0.0)
54
+ fastercsv (~> 1.5.3)
55
+ json_pure (~> 1.4.3)
56
+ dm-sqlite-adapter (1.0.0)
57
+ dm-do-adapter (~> 1.0.0)
58
+ do_sqlite3 (~> 0.10.2)
59
+ dm-timestamps (1.0.0)
60
+ dm-core (~> 1.0.0)
61
+ dm-transactions (1.0.0)
62
+ dm-core (~> 1.0.0)
63
+ dm-types (1.0.0)
64
+ dm-core (~> 1.0.0)
65
+ fastercsv (~> 1.5.3)
66
+ json_pure (~> 1.4.3)
67
+ stringex (~> 1.1.0)
68
+ uuidtools (~> 2.1.1)
69
+ dm-validations (1.0.0)
70
+ dm-core (~> 1.0.0)
71
+ do_sqlite3 (0.10.2)
72
+ data_objects (= 0.10.2)
73
+ durran-validatable (2.0.1)
74
+ extlib (0.9.15)
75
+ fastercsv (1.5.3)
76
+ ffi (0.6.3)
77
+ rake (>= 0.8.7)
78
+ gemcutter (0.6.1)
79
+ gherkin (2.1.5)
80
+ trollop (~> 1.16.2)
81
+ git (1.2.5)
82
+ growl (1.0.3)
83
+ jeweler (1.4.0)
84
+ gemcutter (>= 0.1.0)
85
+ git (>= 1.2.5)
86
+ rubyforge (>= 2.0.0)
87
+ jnunemaker-validatable (1.8.4)
88
+ activesupport (>= 2.3.4)
89
+ json (1.4.6)
90
+ json_pure (1.4.6)
91
+ libnotify (0.2.0)
92
+ ffi (>= 0.6.2)
93
+ linecache (0.43)
94
+ mime-types (1.16)
95
+ mongo (1.0.7)
96
+ bson (>= 1.0.4)
97
+ mongo_mapper (0.8.2)
98
+ activesupport (>= 2.3.4)
99
+ jnunemaker-validatable (~> 1.8.4)
100
+ plucky (~> 0.3.1)
101
+ mongoid (1.9.1)
102
+ activesupport (<= 3.0.0)
103
+ bson (~> 1.0.1)
104
+ durran-validatable (>= 2.0.1)
105
+ mongo (~> 1.0.1)
106
+ will_paginate (< 2.9)
107
+ plucky (0.3.4)
108
+ mongo (~> 1.0.7)
109
+ rake (0.8.7)
110
+ rb-inotify (0.8.1)
111
+ ffi (>= 0.5.0)
112
+ rcov (0.9.8)
113
+ rest-client (1.6.0)
114
+ mime-types (>= 1.16)
115
+ rspactor (0.7.0.beta.6)
116
+ bundler (>= 1.0.0.rc.5)
117
+ growl (>= 1.0.3)
118
+ libnotify (>= 0.1.3)
119
+ rb-inotify
120
+ sys-uname (>= 0.8.4)
121
+ trollop (>= 1.16.2)
122
+ rspec (1.3.0)
123
+ ruby-debug (0.10.3)
124
+ columnize (>= 0.1)
125
+ ruby-debug-base (~> 0.10.3.0)
126
+ ruby-debug-base (0.10.3)
127
+ linecache (>= 0.3)
128
+ rubyforge (2.0.4)
129
+ json_pure (>= 1.1.7)
130
+ sequel (3.21.0)
131
+ sqlite3-ruby (1.3.1)
132
+ stringex (1.1.0)
133
+ sys-uname (0.8.4)
134
+ term-ansicolor (1.0.5)
135
+ trollop (1.16.2)
136
+ tzinfo (0.3.22)
137
+ uuidtools (2.1.1)
138
+ will_paginate (2.3.14)
139
+
140
+ PLATFORMS
141
+ ruby
142
+
143
+ DEPENDENCIES
144
+ ZenTest
145
+ activerecord (= 2.3.8)
146
+ bundler
147
+ couch_potato (= 0.3.0)
148
+ cucumber
149
+ datamapper (= 1.0.0)
150
+ dm-migrations (= 1.0.0)
151
+ dm-sqlite-adapter (= 1.0.0)
152
+ jeweler
153
+ json_pure
154
+ mongo_mapper (= 0.8.2)
155
+ mongoid (= 1.9.1)
156
+ rake
157
+ rcov
158
+ rspactor
159
+ rspec
160
+ ruby-debug
161
+ sequel (~> 3.21.0)
162
+ sqlite3-ruby
163
+ tzinfo (= 0.3.22)
data/History.txt ADDED
@@ -0,0 +1,210 @@
1
+ == 0.7.x (in git)
2
+
3
+ == 0.7.2 2012-03-21
4
+
5
+ * Proper Mysql2Adapter superclass fix. (Jonathan Viney)
6
+ * Sequel::Transaction works with latest Sequel. (David Barri)
7
+ * Postgres Adapter no longer generates invalid SQL when no tables provided. (Michael-Keith Bernard)
8
+ * Documenation fixes/improvements. (David Barri, Ben Mabey, Kevin Moore)
9
+
10
+ == 0.7.1 2012-01-15
11
+
12
+ === New Features
13
+
14
+ * Support for Rails 3.2. (David Demaree)
15
+
16
+ === Bugfixes
17
+
18
+ * Truncation resets the id count on SQLite. (Jordan Hollinger)
19
+ * AR delete strategy now disables referential integrity. (Ben Mabey)
20
+ * Fixes Postgres adapter for JRuby. (Dmytrii Nagirniak, Uģis Ozols)
21
+ * Documenation fixes. (Josh Rendek, Joshua Flanagan)
22
+ * Fixes bad error message when no database is specified for AR. (issue #72, Ben Mabey)
23
+
24
+
25
+ == 0.7.0 2011-11-12
26
+
27
+ === New Features
28
+
29
+ * Sequel Support (Corin Langosch)
30
+ * Updates DataMapper strategies to work with DataMapper 1.1 (Xavier Shay and Anthony Williams)
31
+ * for AR and PSQL, truncate all tables with one command, improving performance due to avoiding cascades (Leonid Shevtsov)
32
+
33
+ === Bugfixes
34
+
35
+ * Avoids trying to load the ':default' ActiveRecord config. #72 (Ben Mabey)
36
+
37
+
38
+ == 0.6.7 2011-04-21
39
+
40
+ === Bugfixes
41
+ * Explicity require ERB. (Vít Ondruch)
42
+ * Cache DB connections, fixes referential integrity bug when using multiple DBs. (John Ferlito)
43
+
44
+ == 0.6.6 2011-03-16
45
+
46
+ === Bugfixes
47
+ * Don't modify the array passed in with the :except key. (Eric Wollesen)
48
+ * Fixes version checking for postgresql. (Greg Barnett)
49
+
50
+ == 0.6.5 2011-03-08
51
+
52
+ === Bugfixes
53
+ * When truncating in postgresql (>= 8.4) sequences are now reset. (Greg Barnett)
54
+ * Fixes the MongoDB truncation so non system collections starting with 'system' are not excluded for truncation. (Dmitry Naumov)
55
+
56
+ == 0.6.4 2011-02-21
57
+
58
+ === Bugfixes
59
+ * Avoids trying to drop views in Postgres. (Bernerd Schaefer)
60
+
61
+ == 0.6.3 2011-02-09
62
+
63
+ === New Features
64
+ * Configurable logger to aid in debugging database cleaner. (Marty Haught)
65
+
66
+ == 0.6.2 2011-02-04
67
+
68
+ === New Features
69
+ * Support IBM_DB Adapter for table truncation. This is for DB2 >= 9.7 (GH-39 Samer Abukhait)
70
+
71
+ === Bugfixes
72
+ * Reversed GH-41 after larger community discussion. Mongo indexes are no longer dropped. (Ben Mabey)
73
+ * Truncation strategy works on SqlServer tables with FKs. (GH-33, Hugo Freire)
74
+
75
+ == 0.6.1 2011-01-27
76
+
77
+ === New Features
78
+ * Default strategies for all ORM libs are defined. (GH-36, GH-38 Prem Sichanugrist)
79
+ * Add a NullStrategy. (GH-6 Ben Mabey)
80
+
81
+ === Bugfixes
82
+ * Mongo colletion indexes are dropped for collections being removed. (GH-41 Ben Mabey)
83
+ * Exclude database views from tables_to_truncate, if the connection adapter
84
+ supports reading from the ANSI standard information_schema views. (GH-25 Samer Abukhait)
85
+ * ORM types can be specified in string format and not mysteriously blowup. (GH-26 Ben Mabey)
86
+ * Do not remove MongoDB reserved system collections. (GH-24 Ches Martin)
87
+
88
+ == 0.6.0 2010-10-25 - The Multi-ORM/Connection Release
89
+
90
+ This release has the often asked for functionality of being able to clean
91
+ multiple databases within the same project. This involves being able to
92
+ clean databases managed by the same ORM (i.e. different connections) and
93
+ also being able to clean databases managed by distinct ORMs. So, for
94
+ example you can now use DatabaseCleaner on a project that has ActiveRecord
95
+ and Mongoid to help ensure all DBs all in a clean state. Please see the
96
+ README for more information. The old API has been preserved so this release
97
+ is backwards compatible.
98
+
99
+ This release is a result of Jon Rowe's hard work. Many thanks to Jon for all
100
+ of the hours and effort he put into making this feature request a reality.
101
+
102
+ === New Features
103
+ * Ability to clean multiple database connections managed by the same ORM. (Jon Rowe)
104
+ * Ability to clean multiple DBs managed by different ORMs in same project. (Jon Rowe)
105
+ * Allows for the ActiveRecord config file (database.yml) to contain ERB and process it. (Fletcher Nichol)
106
+ * Mysql2Adapter support. (Kamal Fariz Mahyuddin and John Ferlito)
107
+ * Deletion strategy for ActiveRecord (Mikl Kurkov)
108
+
109
+ === Bugfixes
110
+ * Updates the DataMapper truncation strategy to version 0.10.3. (Robert Rouse)
111
+ * Addresses Ruby 1.9 and 1.8 differences causing a bug in the AR PostgreSQLAdapter truncation strategy. (GH-14, James B. Byrne)
112
+ * Fixes syntax error that MySQL was throwing during DataMapper truncation. (Blake Gentry)
113
+ * Fixes truncation for PostgreSQL (Bodaniel Jeanes and Gabriel Sobrinho)
114
+ * Workaround for superclass mismatches for the ActiveRecord-jdbc-adapter (Toms Mikoss)
115
+
116
+ == 0.5.2
117
+
118
+ === Bugfixes
119
+ * Removes extraneous puts call from configuration.rb. (Ben Mabey)
120
+
121
+ == 0.5.1 - The Mongoid Release
122
+
123
+ This release also attempts to fix AR for Rails 3 support. I have seen mixed reviews on this. Some people
124
+ claim the fixes allow for use in Rails3 while others have not had good luck with it. I plan on reworking
125
+ the way AR support is added so that it is more friendly with how Rails 3 uses autoload.
126
+
127
+ === New features
128
+ * Clean and clean_with methods are now aliased to clean! and clean_with!. (Ben Mabey)
129
+ * Mongoid Support! (Sidney Burks)
130
+
131
+ === Bugfixes
132
+ * Check PostgreSQL version >= 8.2 before using TRUNCATE CASCADE (James B. Byrne)
133
+ * Correct superclass is used in ActiveRecord connection adapters. (johnathan, Aslak Hellesoy, Ben Mabey)
134
+
135
+ == 0.5.0 2010-02-22 - The CouchPotato Release
136
+
137
+ === New features
138
+ * Basic truncation support for CouchPotato / CouchDB. (Martin Rehfeld)
139
+ * SQLite3 on JRuby will fall back to delete if truncate doesn't work. (Darrin Holst)
140
+ * JDBC is used for ActiveRecord automaticaly when JRuby is detected. (Darrin Holst)
141
+
142
+ === Bufixes
143
+ * MongoMapper truncation strategy now works with :only and :except options. (Ben Mabey)
144
+
145
+ == 0.4.3 2010-01-17
146
+
147
+ === New features
148
+ * Truncation for ActiveRecord oracle_enhanced adapter. (Edgars Beigarts)
149
+
150
+ == 0.4.2 2010-01-12
151
+
152
+ === Bufixes
153
+ * Datamapper truncation now uses 'select' instead of deprecated the 'query' method. (Steve Tooke)
154
+
155
+ == 0.4.1 2010-01-07
156
+
157
+ === Bufixes
158
+ * Postgres tables with FKs now truncate (added TRUNCADE CASCADE) using Datamapper. (Ben Mabey)
159
+
160
+ == 0.4.0 2009-12-23 (The MongoMapper Edition)
161
+
162
+ === New features
163
+ * MongoMapper support for the truncation strategy. (Aubrey Holland)
164
+
165
+ == 0.3.0 2009-12-20
166
+
167
+ === New features
168
+ * DataMapper 0.10.0 Compatible. (Martin Gamsjaeger)
169
+ === Bufixes
170
+ * Postgres tables with FKs now truncate (added TRUNCADE CASCADE). (Vika - yozhyk on github)
171
+
172
+ == 0.2.3 2009-05-30
173
+
174
+ === New features
175
+ * Support for SQL Server truncation (Adam Meehan)
176
+
177
+ == 0.2.2 2009-05-08
178
+ === Bufixes
179
+ * Added proper gemspec description and summary. (Ben Mabey, thanks to Martin Gamsjaeger)
180
+
181
+ === New features
182
+
183
+ == 0.2.1 2009-05-08
184
+ === Bufixes
185
+ * Removed extraneous TruncationBase class definition. (Ben Mabey)
186
+
187
+ == 0.2.0 2009-05-08 - The Datamapper Release
188
+
189
+ === New features
190
+ * DataMapper strategies (Martin Gamsjaeger)
191
+ * Transaction
192
+ * Truncation - working SQLite3, MySQL adapters. Experimental Postgres adapter (not tested).
193
+
194
+ == 0.1.3 2009-04-30
195
+
196
+ === New features
197
+ * PostgresSQLAdapter for AR to support the truncation strategy. (Alberto Perdomo)
198
+ === Bufixes
199
+ * Added missing quotes around table names in truncation calls. (Michael MacDonald)
200
+
201
+ == 0.1.2 2009-03-05
202
+ === New features
203
+ * JDBC Adapter to enable AR truncation strategy to work. (Kamal Fariz Mahyuddin)
204
+
205
+ == 0.1.1 2009-03-04 - Initial Release (Ben Mabey)
206
+ * Basic infrastructure
207
+ * Features, RSpec code examples
208
+ * ActiveRecord strategies
209
+ * Truncation - with MySQL, and SQLite3 adapters.
210
+ * Transaction - wrap your modifications and roll them back.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ben Mabey
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,229 @@
1
+ h1. Database Cleaner
2
+
3
+ Database Cleaner is a set of strategies for cleaning your database in Ruby.
4
+ The original use case was to ensure a clean state during tests. Each strategy
5
+ is a small amount of code but is code that is usually needed in any ruby app
6
+ that is testing with a database.
7
+
8
+ ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, and CouchPotato are supported.
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
+ | Mongoid | **Yes** | No | No |
18
+ | Sequel | **Yes** | Yes | No |
19
+
20
+ (Default strategy for each library is denoted in bold)
21
+
22
+ The ActiveRecord @:deletion@ strategy is useful for when the @:truncation@ strategy causes
23
+ locks (as reported by some Oracle DB users). The @:deletion@ option has been reported to
24
+ be faster than @:truncation@ in some cases as well. In general, the best approach is to use
25
+ @:transaction@ since it is the fastest.
26
+
27
+ Database Cleaner also includes a @null@ strategy (that does no cleaning at all) which can be used
28
+ with any ORM library. You can also explicitly use it by setting your strategy to @nil@.
29
+
30
+ For support or to discuss development please use the "Google Group":http://groups.google.com/group/database_cleaner.
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
+
38
+ h2. How to use
39
+
40
+ <pre>
41
+ require 'database_cleaner'
42
+ DatabaseCleaner.strategy = :truncation
43
+
44
+ # then, whenever you need to clean the DB
45
+ DatabaseCleaner.clean
46
+ </pre>
47
+
48
+ With the :truncation strategy you can also pass in options, for example:
49
+ <pre>
50
+ DatabaseCleaner.strategy = :truncation, {:only => %w[widgets dogs some_other_table]}
51
+ </pre>
52
+
53
+ <pre>
54
+ DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
55
+ </pre>
56
+
57
+ (I should point out the truncation strategy will never truncate your schema_migrations table.)
58
+
59
+ Some strategies require that you call DatabaseCleaner.start before calling clean
60
+ (for example the :transaction one needs to know to open up a transaction). So
61
+ you would have:
62
+
63
+ <pre>
64
+ require 'database_cleaner'
65
+ DatabaseCleaner.strategy = :transaction
66
+
67
+ DatabaseCleaner.start # usually this is called in setup of a test
68
+ dirty_the_db
69
+ DatabaseCleaner.clean # cleanup of the test
70
+ </pre>
71
+
72
+ At times you may want to do a single clean with one strategy. For example, you may want
73
+ to start the process by truncating all the tables, but then use the faster transaction
74
+ strategy the remaining time. To accomplish this you can say:
75
+
76
+ <pre>
77
+ require 'database_cleaner'
78
+ DatabaseCleaner.clean_with :truncation
79
+ DatabaseCleaner.strategy = :transaction
80
+ # then make the DatabaseCleaner.start and DatabaseCleaner.clean calls appropriately
81
+ </pre>
82
+
83
+ h3. RSpec Example
84
+
85
+ <pre>
86
+ RSpec.configure do |config|
87
+
88
+ config.before(:suite) do
89
+ DatabaseCleaner.strategy = :transaction
90
+ DatabaseCleaner.clean_with(:truncation)
91
+ end
92
+
93
+ config.before(:each) do
94
+ DatabaseCleaner.start
95
+ end
96
+
97
+ config.after(:each) do
98
+ DatabaseCleaner.clean
99
+ end
100
+
101
+ end
102
+ </pre>
103
+
104
+ h3. Cucumber Example
105
+
106
+ Add this to your features/support/env.rb file:
107
+
108
+ <pre>
109
+ begin
110
+ require 'database_cleaner'
111
+ require 'database_cleaner/cucumber'
112
+ DatabaseCleaner.strategy = :truncation
113
+ rescue NameError
114
+ raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
115
+ end
116
+ </pre>
117
+
118
+ A good idea is to create the before and after hooks to use the DatabaseCleaner.start and DatabaseCleaner.clean methods.
119
+
120
+ Inside features/support/hooks.rb:
121
+
122
+ <pre>
123
+ Before do
124
+ DatabaseCleaner.start
125
+ end
126
+
127
+ After do |scenario|
128
+ DatabaseCleaner.clean
129
+ end
130
+ </pre>
131
+
132
+ This should cover the basics of tear down between scenarios and keeping your database clean.
133
+ For more examples see the section "Why?"
134
+
135
+ h2. How to use with multiple ORM's
136
+
137
+ Sometimes you need to use multiple ORMs in your application. You can use DatabaseCleaner to clean multiple ORMs, and multiple connections for those ORMs.
138
+
139
+ <pre>
140
+ #How to specify particular orms
141
+ DatabaseCleaner[:active_record].strategy = :transaction
142
+ DatabaseCleaner[:mongo_mapper].strategy = :truncation
143
+
144
+ #How to specify particular connections
145
+ DatabaseCleaner[:active_record,{:connection => :two}]
146
+ </pre>
147
+
148
+ Usage beyond that remains the same with DatabaseCleaner.start calling any setup on the different configured connections, and DatabaseCleaner.clean executing afterwards.
149
+
150
+ Configuration options
151
+
152
+
153
+ |_. ORM |_. How to access |_. Notes |
154
+ | Active Record | DatabaseCleaner[:active_record] | Connection specified as :symbol keys, loaded from config/database.yml |
155
+ | Data Mapper | DatabaseCleaner[:data_mapper] | Connection specified as :symbol keys, loaded via Datamapper repositories |
156
+ | Mongo Mapper | DatabaseCleaner[:mongo_mapper] | Multiple connections not yet supported |
157
+ | Mongoid | DatabaseCleaner[:mongoid] | Multiple connections not yet supported |
158
+ | Couch Potato | DatabaseCleaner[:couch_potato] | Multiple connections not yet supported |
159
+ | Sequel | DatabaseCleaner[:sequel] | ? |
160
+
161
+ h2. Why?
162
+
163
+ One of my motivations for writing this library was to have an easy way to
164
+ turn on what Rails calls "transactional_fixtures" in my non-rails
165
+ ActiveRecord projects. For example, Cucumber ships with a Rails world that
166
+ will wrap each scenario in a transaction. This is great, but what if you are
167
+ using ActiveRecord in a non-rails project? You used to have to copy-and-paste
168
+ the needed code, but with DatabaseCleaner you can now say:
169
+
170
+ <pre>
171
+ #env.rb
172
+ require 'database_cleaner'
173
+ require 'database_cleaner/cucumber'
174
+ DatabaseCleaner.strategy = :transaction
175
+ </pre>
176
+
177
+ Now lets say you are running your features and it requires that another process be
178
+ involved (i.e. Selenium running against your app's server.) You can simply change
179
+ your strategy type:
180
+
181
+ <pre>
182
+ #env.rb
183
+ require 'database_cleaner'
184
+ require 'database_cleaner/cucumber'
185
+ DatabaseCleaner.strategy = :truncation
186
+ </pre>
187
+
188
+ You can have the best of both worlds and use the best one for the job:
189
+ <pre>
190
+ #env.rb
191
+ require 'database_cleaner'
192
+ require 'database_cleaner/cucumber'
193
+ DatabaseCleaner.strategy = (ENV['SELENIUM'] == 'true') ? :truncation : :transaction
194
+ </pre>
195
+
196
+
197
+ h2. Common Errors
198
+
199
+ h4. DatabaseCleaner is trying to use the wrong ORM
200
+
201
+ 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:
202
+
203
+ <pre>
204
+ # How to setup your ORM explicitly
205
+ DatabaseCleaner[:mongoid].strategy = :truncation
206
+ </pre>
207
+
208
+ h4. STDERR is being flooded when using Postgres
209
+
210
+ 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
211
+ the form of "NOTICE truncate cascades" messages). To silence these warnings set the following log level in your postgresql.conf file:
212
+
213
+ <pre>
214
+ client_min_messages = warning
215
+ </pre>
216
+
217
+
218
+ h2. Debugging
219
+
220
+ 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:
221
+
222
+ <pre>
223
+ DatabaseCleaner.logger = Rails.logger
224
+ </pre>
225
+
226
+
227
+ h2. COPYRIGHT
228
+
229
+ Copyright (c) 2009 Ben Mabey. See LICENSE for details.
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ Could be more Datamapper
2
+ MongoMapper multiple db support
3
+ CouchDB multiple db support
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :major: 0
3
+ :build:
4
+ :minor: 7
5
+ :patch: 2
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: features
data/examples/Gemfile ADDED
@@ -0,0 +1 @@
1
+ ../Gemfile
@@ -0,0 +1 @@
1
+ ../Gemfile.lock
@@ -0,0 +1,8 @@
1
+ #This is an example of what database.yml *should* look like (when I wrote it)
2
+ #The real database.yml is generated automatically by the active record model lib (so it can be correct)
3
+ two:
4
+ adapter: sqlite3
5
+ database: /path/to/examples/features/support/../../db/activerecord_two.db
6
+ one:
7
+ adapter: sqlite3
8
+ database: /path/to/examples/features/support/../../db/activerecord_one.db
File without changes
@@ -0,0 +1,11 @@
1
+ Feature: example
2
+ In order to test DataBase Cleaner
3
+ Here are some scenarios that rely on the DB being clean!
4
+
5
+ Scenario: dirty the db
6
+ When I create a widget
7
+ Then I should see 1 widget
8
+
9
+ Scenario: assume a clean db
10
+ When I create a widget
11
+ Then I should see 1 widget
@@ -0,0 +1,23 @@
1
+ Feature: example
2
+ In order to test DataBase Cleaner
3
+ Here are some scenarios that rely on the DB being clean!
4
+
5
+ # Background:
6
+ # Given I have setup DatabaseCleaner to clean multiple databases
7
+ #
8
+ Scenario: dirty the db
9
+ When I create a widget in one db
10
+ And I create a widget in another db
11
+ Then I should see 1 widget in one db
12
+ And I should see 1 widget in another db
13
+
14
+ Scenario: assume a clean db
15
+ When I create a widget in one db
16
+ Then I should see 1 widget in one db
17
+ And I should see 0 widget in another db
18
+
19
+ Scenario: assume a clean db
20
+ When I create a widget in another db
21
+ Then I should see 0 widget in one db
22
+ And I should see 1 widget in another db
23
+