database_cleaner 0.8.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/Gemfile.lock +150 -82
  2. data/History.txt +19 -1
  3. data/README.textile +61 -59
  4. data/Rakefile +7 -17
  5. data/VERSION.yml +3 -3
  6. data/examples/Gemfile +14 -20
  7. data/examples/Gemfile.lock +150 -82
  8. data/examples/features/step_definitions/translation_steps.rb +14 -14
  9. data/examples/features/support/env.rb +6 -2
  10. data/features/cleaning.feature +1 -1
  11. data/features/cleaning_default_strategy.feature +1 -1
  12. data/features/cleaning_multiple_dbs.feature +1 -2
  13. data/features/cleaning_multiple_orms.feature +7 -7
  14. data/features/support/env.rb +1 -1
  15. data/lib/database_cleaner/active_record/base.rb +26 -6
  16. data/lib/database_cleaner/active_record/deletion.rb +2 -2
  17. data/lib/database_cleaner/active_record/transaction.rb +9 -9
  18. data/lib/database_cleaner/active_record/truncation.rb +157 -50
  19. data/lib/database_cleaner/base.rb +2 -2
  20. data/lib/database_cleaner/configuration.rb +26 -3
  21. data/lib/database_cleaner/data_mapper/truncation.rb +2 -2
  22. data/lib/database_cleaner/generic/truncation.rb +7 -5
  23. data/lib/database_cleaner/mongo/base.rb +16 -0
  24. data/lib/database_cleaner/mongo/truncation.rb +9 -14
  25. data/lib/database_cleaner/mongo/truncation_mixin.rb +22 -0
  26. data/lib/database_cleaner/mongo_mapper/truncation.rb +2 -2
  27. data/lib/database_cleaner/mongoid/truncation.rb +2 -2
  28. data/lib/database_cleaner/moped/truncation.rb +6 -2
  29. data/lib/database_cleaner/sequel/truncation.rb +6 -6
  30. data/spec/database_cleaner/active_record/base_spec.rb +27 -15
  31. data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +40 -0
  32. data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +40 -0
  33. data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +48 -0
  34. data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +40 -0
  35. data/spec/database_cleaner/active_record/truncation_spec.rb +102 -33
  36. data/spec/database_cleaner/base_spec.rb +14 -14
  37. data/spec/database_cleaner/configuration_spec.rb +15 -10
  38. data/spec/database_cleaner/data_mapper/base_spec.rb +1 -1
  39. data/spec/database_cleaner/data_mapper/transaction_spec.rb +1 -1
  40. data/spec/database_cleaner/data_mapper/truncation_spec.rb +1 -1
  41. data/spec/database_cleaner/generic/base_spec.rb +1 -1
  42. data/spec/database_cleaner/generic/truncation_spec.rb +35 -5
  43. data/spec/database_cleaner/mongo/mongo_examples.rb +26 -0
  44. data/spec/database_cleaner/mongo/truncation_spec.rb +72 -0
  45. data/spec/database_cleaner/mongo_mapper/base_spec.rb +1 -1
  46. data/spec/database_cleaner/sequel/base_spec.rb +1 -1
  47. data/spec/database_cleaner/sequel/transaction_spec.rb +1 -1
  48. data/spec/database_cleaner/sequel/truncation_spec.rb +1 -1
  49. data/spec/database_cleaner/{shared_strategy_spec.rb → shared_strategy.rb} +0 -0
  50. data/spec/spec_helper.rb +6 -4
  51. data/spec/support/active_record/database_setup.rb +4 -0
  52. data/spec/support/active_record/mysql2_setup.rb +38 -0
  53. data/spec/support/active_record/mysql_setup.rb +38 -0
  54. data/spec/support/active_record/postgresql_setup.rb +41 -0
  55. data/spec/support/active_record/schema_setup.rb +10 -0
  56. metadata +313 -46
  57. data/spec/spec.opts +0 -7
data/Gemfile.lock CHANGED
@@ -1,28 +1,49 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
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)
4
+ ZenTest (4.8.1)
5
+ actionpack (3.2.6)
6
+ activemodel (= 3.2.6)
7
+ activesupport (= 3.2.6)
8
+ builder (~> 3.0.0)
9
+ erubis (~> 2.7.0)
10
+ journey (~> 1.0.1)
11
+ rack (~> 1.4.0)
12
+ rack-cache (~> 1.2)
13
+ rack-test (~> 0.6.1)
14
+ sprockets (~> 2.1.3)
15
+ activemodel (3.2.6)
16
+ activesupport (= 3.2.6)
17
+ builder (~> 3.0.0)
18
+ activerecord (3.2.6)
19
+ activemodel (= 3.2.6)
20
+ activesupport (= 3.2.6)
21
+ arel (~> 3.0.2)
22
+ tzinfo (~> 0.3.29)
23
+ activesupport (3.2.6)
24
+ i18n (~> 0.6)
25
+ multi_json (~> 1.0)
26
+ addressable (2.2.8)
27
+ arel (3.0.2)
28
+ bson (1.6.4)
29
+ bson_ext (1.6.4)
30
+ bson (~> 1.6.4)
31
+ builder (3.0.0)
32
+ columnize (0.3.6)
33
+ couch_potato (0.5.7)
34
+ activemodel
35
+ couchrest (>= 1.0.1)
14
36
  json
15
37
  couchrest (1.0.1)
16
38
  json (>= 1.4.6)
17
39
  mime-types (>= 1.15)
18
40
  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)
41
+ cucumber (1.2.1)
42
+ builder (>= 2.1.2)
43
+ diff-lcs (>= 1.1.3)
44
+ gherkin (~> 2.11.0)
45
+ json (>= 1.4.6)
46
+ data_objects (0.10.8)
26
47
  addressable (~> 2.1)
27
48
  datamapper (1.0.0)
28
49
  dm-aggregates (= 1.0.0)
@@ -35,7 +56,7 @@ GEM
35
56
  dm-transactions (= 1.0.0)
36
57
  dm-types (= 1.0.0)
37
58
  dm-validations (= 1.0.0)
38
- diff-lcs (1.1.2)
59
+ diff-lcs (1.1.3)
39
60
  dm-aggregates (1.0.0)
40
61
  dm-core (~> 1.0.0)
41
62
  dm-constraints (1.0.0)
@@ -68,96 +89,143 @@ GEM
68
89
  uuidtools (~> 2.1.1)
69
90
  dm-validations (1.0.0)
70
91
  dm-core (~> 1.0.0)
71
- do_sqlite3 (0.10.2)
72
- data_objects (= 0.10.2)
73
- durran-validatable (2.0.1)
92
+ do_sqlite3 (0.10.8)
93
+ data_objects (= 0.10.8)
94
+ erubis (2.7.0)
74
95
  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)
96
+ fastercsv (1.5.5)
97
+ ffi (1.1.4)
98
+ gherkin (2.11.1)
99
+ json (>= 1.4.6)
81
100
  git (1.2.5)
82
- growl (1.0.3)
83
- jeweler (1.4.0)
84
- gemcutter (>= 0.1.0)
101
+ guard (1.3.0)
102
+ listen (>= 0.4.2)
103
+ thor (>= 0.14.6)
104
+ guard-rspec (1.2.1)
105
+ guard (>= 1.1)
106
+ hike (1.2.1)
107
+ i18n (0.6.0)
108
+ jeweler (1.8.4)
109
+ bundler (~> 1.0)
85
110
  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)
111
+ rake
112
+ rdoc
113
+ journey (1.0.4)
114
+ json (1.7.3)
90
115
  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)
116
+ linecache (0.46)
117
+ rbx-require-relative (> 0.0.4)
118
+ listen (0.4.7)
119
+ rb-fchange (~> 0.0.5)
120
+ rb-fsevent (~> 0.9.1)
121
+ rb-inotify (~> 0.8.8)
122
+ mime-types (1.19)
123
+ mongo (1.6.4)
124
+ bson (~> 1.6.4)
125
+ mongo_ext (0.19.3)
126
+ mongo_mapper (0.11.1)
127
+ activemodel (~> 3.0)
128
+ activesupport (~> 3.0)
129
+ plucky (~> 0.4.0)
130
+ mongoid (3.0.1)
131
+ activemodel (~> 3.1)
132
+ moped (~> 1.1.1)
133
+ origin (~> 1.0.3)
134
+ tzinfo (~> 0.3.22)
135
+ moped (1.1.2)
136
+ multi_json (1.3.6)
137
+ mysql (2.8.1)
138
+ mysql2 (0.3.11)
139
+ origin (1.0.4)
140
+ pg (0.14.0)
141
+ plucky (0.4.4)
142
+ mongo (~> 1.5)
143
+ rack (1.4.1)
144
+ rack-cache (1.2)
145
+ rack (>= 0.4)
146
+ rack-ssl (1.3.2)
147
+ rack
148
+ rack-test (0.6.1)
149
+ rack (>= 1.0)
150
+ railties (3.2.6)
151
+ actionpack (= 3.2.6)
152
+ activesupport (= 3.2.6)
153
+ rack-ssl (~> 1.3.2)
154
+ rake (>= 0.8.7)
155
+ rdoc (~> 3.4)
156
+ thor (>= 0.14.6, < 2.0)
157
+ rake (0.9.2.2)
158
+ rb-fchange (0.0.5)
159
+ ffi
160
+ rb-fsevent (0.9.1)
161
+ rb-inotify (0.8.8)
111
162
  ffi (>= 0.5.0)
112
- rcov (0.9.8)
113
- rest-client (1.6.0)
163
+ rbx-require-relative (0.0.9)
164
+ rcov (1.0.0)
165
+ rdoc (3.12)
166
+ json (~> 1.4)
167
+ rest-client (1.6.7)
114
168
  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)
169
+ rspactor (0.6.4)
170
+ rspec (2.11.0)
171
+ rspec-core (~> 2.11.0)
172
+ rspec-expectations (~> 2.11.0)
173
+ rspec-mocks (~> 2.11.0)
174
+ rspec-core (2.11.1)
175
+ rspec-expectations (2.11.1)
176
+ diff-lcs (~> 1.1.3)
177
+ rspec-mocks (2.11.1)
178
+ rspec-rails (2.11.0)
179
+ actionpack (>= 3.0)
180
+ activesupport (>= 3.0)
181
+ railties (>= 3.0)
182
+ rspec (~> 2.11.0)
183
+ ruby-debug (0.10.4)
124
184
  columnize (>= 0.1)
125
- ruby-debug-base (~> 0.10.3.0)
126
- ruby-debug-base (0.10.3)
185
+ ruby-debug-base (~> 0.10.4.0)
186
+ ruby-debug-base (0.10.4)
127
187
  linecache (>= 0.3)
128
- rubyforge (2.0.4)
129
- json_pure (>= 1.1.7)
130
188
  sequel (3.21.0)
131
- sqlite3-ruby (1.3.1)
189
+ sprockets (2.1.3)
190
+ hike (~> 1.2)
191
+ rack (~> 1.0)
192
+ tilt (~> 1.1, != 1.3.0)
193
+ sqlite3 (1.3.6)
194
+ sqlite3-ruby (1.3.3)
195
+ sqlite3 (>= 1.3.3)
132
196
  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)
197
+ thor (0.15.4)
198
+ tilt (1.3.3)
199
+ tzinfo (0.3.33)
200
+ uuidtools (2.1.3)
139
201
 
140
202
  PLATFORMS
141
203
  ruby
142
204
 
143
205
  DEPENDENCIES
144
206
  ZenTest
145
- activerecord (= 2.3.8)
207
+ activerecord
208
+ bson_ext
146
209
  bundler
147
- couch_potato (= 0.3.0)
210
+ couch_potato
148
211
  cucumber
149
212
  datamapper (= 1.0.0)
150
213
  dm-migrations (= 1.0.0)
151
214
  dm-sqlite-adapter (= 1.0.0)
215
+ guard-rspec
152
216
  jeweler
153
217
  json_pure
154
- mongo_mapper (= 0.8.2)
155
- mongoid (= 1.9.1)
218
+ mongo_ext
219
+ mongo_mapper
220
+ mongoid
221
+ mysql
222
+ mysql2
223
+ pg
156
224
  rake
157
225
  rcov
158
226
  rspactor
159
- rspec
227
+ rspec-rails
160
228
  ruby-debug
161
229
  sequel (~> 3.21.0)
162
230
  sqlite3-ruby
163
- tzinfo (= 0.3.22)
231
+ tzinfo
data/History.txt CHANGED
@@ -1,7 +1,25 @@
1
- == 0.8.x (in git)
1
+ == 0.9.0 2012-10-11
2
+
3
+ === New Features
4
+
5
+ * New options for AR :truncation for speed. See README for details. (Stanislaw Pankevich)
6
+ * view caching works with the schema_plus gem loaded
7
+ * ActiveRecord::ConnectionAdapters::AbstractAdapter#views was renamed to an internal name
8
+ * ActiveRecord truncation strategy caches the list of tables #130 (Petteri Räty)
9
+ * Caches AR DB connections which speeds up cleaning with multiple DBs and allows for transation strategy.
10
+ * MongoDB :truncation strategy (wihtout use of additional library like Mogoid). #138 (Christopher Darrell & Richard Luther/@sidereel)
11
+ * Add Sequel support for multiple migration storage names in #148 (Jack Chu)
12
+ * Multiple database support for Mongoid 3 #149 (Luke Francl)
13
+
14
+ === Bug Fixes
15
+ * :deletion for AR Postgres in JRuby now works #140 (Heiko Seebach)
16
+ * Rescue LoadError when AR adapters not available. #145 (Garrow Bedrossian)
17
+ * Fixes DatabaseCleaner::[] to cache cleaners.
2
18
 
3
19
  == 0.8.0 2012-06-02
4
20
 
21
+ * Faster truncation strategy for ActiveRecord with MySQL or PostgreSQL
22
+ * Upgrade to RSpec 2
5
23
  * Support for Mongoid 3/Moped (Andrew Bennett)
6
24
  * Postgres Adapter no longer generates invalid SQL when no tables provided. (Michael-Keith Bernard)
7
25
 
data/README.textile CHANGED
@@ -7,6 +7,8 @@ that is testing with a database.
7
7
 
8
8
  ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, and CouchPotato are supported.
9
9
 
10
+ !https://secure.travis-ci.org/bmabey/database_cleaner.png(Build Status)!:http://travis-ci.org/bmabey/database_cleaner
11
+
10
12
  Here is an overview of the strategies supported for each library:
11
13
 
12
14
  |_. ORM |_. Truncation |_. Transaction |_. Deletion |
@@ -17,18 +19,36 @@ Here is an overview of the strategies supported for each library:
17
19
  | Mongoid | **Yes** | No | No |
18
20
  | Sequel | **Yes** | Yes | No |
19
21
 
20
- (Default strategy for each library is denoted in bold)
22
+ |_. Driver |_. Truncation |_. Transaction |_. Deletion |
23
+ | Mongo | Yes | No | No |
21
24
 
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.
25
+ (Default strategy for each library is denoted in bold)
26
26
 
27
27
  Database Cleaner also includes a @null@ strategy (that does no cleaning at all) which can be used
28
28
  with any ORM library. You can also explicitly use it by setting your strategy to @nil@.
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(fastest). What strategy is fastest?
33
+
34
+ For the SQL libraries the fastest option will be to use @:transaction@ as transactions are
35
+ simply rolled back. If you can use this strategy you should. However, if you wind up needing
36
+ to use multiple database connections in your tests (i.e. your tests run in a different proceess
37
+ than your application) then using this strategy becomes a bit more difficult. You can get around the
38
+ problem a number of ways. One common approach is to force all processes to use the same database
39
+ connection ("common ActiveRecord hack":http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/) however this approach has been reported to result in
40
+ non-deterministic failures. Another approach is to have the transactions rolled back in the
41
+ application's process and relax the isolation level of the database (so the tests can read the
42
+ uncommited transactions). An easier, but slower, solution is to use the @:truncation@ or
43
+ @:deletion@ strategy.
44
+
45
+ So what is fastest out of @:deletion@ and @:truncation@? Well, it depends on your table structure
46
+ and what percentage of tables you populate in an average test. The reasoning is out the the
47
+ scope of this README but here is a "good SO answer on this topic for Postgres":http://stackoverflow.com/questions/11419536/postgresql-truncation-speed/11423886#11423886. Some people report
48
+ much faster speeds with @:deletion@ while others say @:truncation@ is faster for them. The best approach therefore
49
+ is it try all options on your test suite and see what is faster. If you are using ActiveRecord then take a look
50
+ at the "additional options":#ar_truncation available for @:truncation@.
51
+
32
52
  h2. Dependencies
33
53
 
34
54
  Because database_cleaner supports multiple ORMs, it doesn't make sense to include all the dependencies
@@ -80,21 +100,18 @@ strategy the remaining time. To accomplish this you can say:
80
100
  # then make the DatabaseCleaner.start and DatabaseCleaner.clean calls appropriately
81
101
  </pre>
82
102
 
83
- h3. Minitest Example
103
+ h3(#ar_truncation). Additional ActiveRecord options for Truncation
84
104
 
85
- <pre>
86
- DatabaseCleaner.strategy = :transaction
105
+ The following options are available for ActiveRecord's @:truncation@ strategy _only_ for
106
+ MySQL and Postgres.
87
107
 
88
- class MiniTest::Spec
89
- before :each do
90
- DatabaseCleaner.clean
91
- end
108
+ * @:pre_count@ - When set to @true@ this will check each table for existing rows before
109
+ truncating it. This can speed up test suites when many of the tables to be truncated
110
+ are never populated. Defaults to @:false@. (Also, see the section on "What strategy is fastest?":#fastest)
111
+ * @:reset_ids@ - This only matters when @:pre_count@ is used, and it will make sure that a
112
+ tables auto-incrementing id is reset even if there are no rows in the table (e.g. records
113
+ were created in the test but also removed before DatabaseCleaner gets to it). Defaults to @true@.
92
114
 
93
- after :each do
94
- DatabaseCleaner.clean
95
- end
96
- end
97
- </pre>
98
115
 
99
116
  h3. RSpec Example
100
117
 
@@ -117,9 +134,27 @@ RSpec.configure do |config|
117
134
  end
118
135
  </pre>
119
136
 
137
+ h3. Minitest Example
138
+
139
+ <pre>
140
+ DatabaseCleaner.strategy = :transaction
141
+
142
+ class MiniTest::Spec
143
+ before :each do
144
+ DatabaseCleaner.start
145
+ end
146
+
147
+ after :each do
148
+ DatabaseCleaner.clean
149
+ end
150
+ end
151
+ </pre>
152
+
120
153
  h3. Cucumber Example
121
154
 
122
- Add this to your features/support/env.rb file:
155
+ If you're using Cucumber with Rails, just use the generator that ships with cucumber-rails, and that will create all the code you need to integrate DatabaseCleaner into your Rails project.
156
+
157
+ Otherwise, to add DatabaseCleaner to your project by hand, create a file features/support/database_cleaner.rb that looks like this:
123
158
 
124
159
  <pre>
125
160
  begin
@@ -129,13 +164,7 @@ begin
129
164
  rescue NameError
130
165
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
131
166
  end
132
- </pre>
133
-
134
- A good idea is to create the before and after hooks to use the DatabaseCleaner.start and DatabaseCleaner.clean methods.
135
-
136
- Inside features/support/hooks.rb:
137
167
 
138
- <pre>
139
168
  Before do
140
169
  DatabaseCleaner.start
141
170
  end
@@ -159,6 +188,9 @@ Sometimes you need to use multiple ORMs in your application. You can use Databas
159
188
 
160
189
  #How to specify particular connections
161
190
  DatabaseCleaner[:active_record,{:connection => :two}]
191
+
192
+ # You may also pass in the model directly:
193
+ DatabaseCleaner[:active_record,{:model => ModelWithDifferentConnection}]
162
194
  </pre>
163
195
 
164
196
  Usage beyond that remains the same with DatabaseCleaner.start calling any setup on the different configured connections, and DatabaseCleaner.clean executing afterwards.
@@ -167,48 +199,18 @@ Configuration options
167
199
 
168
200
 
169
201
  |_. ORM |_. How to access |_. Notes |
170
- | Active Record | DatabaseCleaner[:active_record] | Connection specified as :symbol keys, loaded from config/database.yml |
202
+ | Active Record | DatabaseCleaner[:active_record] | Connection specified as :symbol keys, loaded from config/database.yml. You may also pass in the ActiveRecord model under the @:model@ key. |
171
203
  | Data Mapper | DatabaseCleaner[:data_mapper] | Connection specified as :symbol keys, loaded via Datamapper repositories |
172
204
  | Mongo Mapper | DatabaseCleaner[:mongo_mapper] | Multiple connections not yet supported |
173
- | Mongoid | DatabaseCleaner[:mongoid] | Multiple connections not yet supported |
205
+ | Mongoid | DatabaseCleaner[:mongoid] | Multiple databases supported for Mongoid 3. Specify DatabaseCleaner[:mongoid, {:connection => :db_name}] |
174
206
  | Couch Potato | DatabaseCleaner[:couch_potato] | Multiple connections not yet supported |
175
207
  | Sequel | DatabaseCleaner[:sequel] | ? |
176
208
 
177
209
  h2. Why?
178
210
 
179
- One of my motivations for writing this library was to have an easy way to
180
- turn on what Rails calls "transactional_fixtures" in my non-rails
181
- ActiveRecord projects. For example, Cucumber ships with a Rails world that
182
- will wrap each scenario in a transaction. This is great, but what if you are
183
- using ActiveRecord in a non-rails project? You used to have to copy-and-paste
184
- the needed code, but with DatabaseCleaner you can now say:
185
-
186
- <pre>
187
- #env.rb
188
- require 'database_cleaner'
189
- require 'database_cleaner/cucumber'
190
- DatabaseCleaner.strategy = :transaction
191
- </pre>
192
-
193
- Now lets say you are running your features and it requires that another process be
194
- involved (i.e. Selenium running against your app's server.) You can simply change
195
- your strategy type:
196
-
197
- <pre>
198
- #env.rb
199
- require 'database_cleaner'
200
- require 'database_cleaner/cucumber'
201
- DatabaseCleaner.strategy = :truncation
202
- </pre>
203
-
204
- You can have the best of both worlds and use the best one for the job:
205
- <pre>
206
- #env.rb
207
- require 'database_cleaner'
208
- require 'database_cleaner/cucumber'
209
- DatabaseCleaner.strategy = (ENV['SELENIUM'] == 'true') ? :truncation : :transaction
210
- </pre>
211
-
211
+ One of my motivations for writing this library was to have an easy way to turn on what Rails calls "transactional_fixtures"
212
+ in my non-rails ActiveRecord projects. After copying and pasting code to do this several times I decided to package it up
213
+ as a gem and same everyone a bit of time.
212
214
 
213
215
  h2. Common Errors
214
216