database_cleaner 0.6.7 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/lib/database_cleaner.rb +1 -3
  3. metadata +48 -154
  4. data/Gemfile.lock +0 -161
  5. data/History.txt +0 -173
  6. data/LICENSE +0 -20
  7. data/README.textile +0 -165
  8. data/Rakefile +0 -65
  9. data/TODO +0 -3
  10. data/VERSION.yml +0 -5
  11. data/cucumber.yml +0 -1
  12. data/examples/Gemfile +0 -48
  13. data/examples/Gemfile.lock +0 -161
  14. data/examples/config/database.yml.example +0 -8
  15. data/examples/db/sqlite_databases_go_here +0 -0
  16. data/examples/features/example.feature +0 -11
  17. data/examples/features/example_multiple_db.feature +0 -23
  18. data/examples/features/example_multiple_orm.feature +0 -22
  19. data/examples/features/step_definitions/activerecord_steps.rb +0 -31
  20. data/examples/features/step_definitions/couchpotato_steps.rb +0 -31
  21. data/examples/features/step_definitions/datamapper_steps.rb +0 -37
  22. data/examples/features/step_definitions/mongoid_steps.rb +0 -23
  23. data/examples/features/step_definitions/mongomapper_steps.rb +0 -31
  24. data/examples/features/step_definitions/translation_steps.rb +0 -55
  25. data/examples/features/support/env.rb +0 -62
  26. data/examples/lib/activerecord_models.rb +0 -41
  27. data/examples/lib/couchpotato_models.rb +0 -61
  28. data/examples/lib/datamapper_models.rb +0 -50
  29. data/examples/lib/mongoid_models.rb +0 -49
  30. data/examples/lib/mongomapper_models.rb +0 -51
  31. data/features/cleaning.feature +0 -22
  32. data/features/cleaning_default_strategy.feature +0 -19
  33. data/features/cleaning_multiple_dbs.feature +0 -21
  34. data/features/cleaning_multiple_orms.feature +0 -29
  35. data/features/step_definitions/database_cleaner_steps.rb +0 -32
  36. data/features/support/env.rb +0 -7
  37. data/features/support/feature_runner.rb +0 -39
  38. data/lib/database_cleaner/active_record/#transaction.rb# +0 -34
  39. data/lib/database_cleaner/active_record/base.rb +0 -53
  40. data/lib/database_cleaner/active_record/deletion.rb +0 -64
  41. data/lib/database_cleaner/active_record/transaction.rb +0 -26
  42. data/lib/database_cleaner/active_record/truncation.rb +0 -134
  43. data/lib/database_cleaner/base.rb +0 -136
  44. data/lib/database_cleaner/configuration.rb +0 -92
  45. data/lib/database_cleaner/couch_potato/base.rb +0 -7
  46. data/lib/database_cleaner/couch_potato/truncation.rb +0 -28
  47. data/lib/database_cleaner/cucumber.rb +0 -11
  48. data/lib/database_cleaner/data_mapper/base.rb +0 -21
  49. data/lib/database_cleaner/data_mapper/transaction.rb +0 -28
  50. data/lib/database_cleaner/data_mapper/truncation.rb +0 -175
  51. data/lib/database_cleaner/generic/base.rb +0 -23
  52. data/lib/database_cleaner/generic/truncation.rb +0 -43
  53. data/lib/database_cleaner/mongo/truncation.rb +0 -22
  54. data/lib/database_cleaner/mongo_mapper/base.rb +0 -20
  55. data/lib/database_cleaner/mongo_mapper/truncation.rb +0 -19
  56. data/lib/database_cleaner/mongoid/base.rb +0 -20
  57. data/lib/database_cleaner/mongoid/truncation.rb +0 -20
  58. data/lib/database_cleaner/null_strategy.rb +0 -15
  59. data/spec/database_cleaner/active_record/base_spec.rb +0 -141
  60. data/spec/database_cleaner/active_record/transaction_spec.rb +0 -65
  61. data/spec/database_cleaner/active_record/truncation_spec.rb +0 -82
  62. data/spec/database_cleaner/base_spec.rb +0 -478
  63. data/spec/database_cleaner/configuration_spec.rb +0 -294
  64. data/spec/database_cleaner/couch_potato/truncation_spec.rb +0 -41
  65. data/spec/database_cleaner/data_mapper/base_spec.rb +0 -30
  66. data/spec/database_cleaner/data_mapper/transaction_spec.rb +0 -23
  67. data/spec/database_cleaner/data_mapper/truncation_spec.rb +0 -11
  68. data/spec/database_cleaner/generic/base_spec.rb +0 -22
  69. data/spec/database_cleaner/generic/truncation_spec.rb +0 -78
  70. data/spec/database_cleaner/mongo_mapper/base_spec.rb +0 -33
  71. data/spec/database_cleaner/mongo_mapper/mongo_examples.rb +0 -8
  72. data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +0 -74
  73. data/spec/database_cleaner/shared_strategy_spec.rb +0 -13
  74. data/spec/rcov.opts +0 -1
  75. data/spec/spec.opts +0 -7
  76. data/spec/spec_helper.rb +0 -19
@@ -1,294 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- module DatabaseCleaner
4
- class << self
5
- def reset
6
- @connections = nil
7
- end
8
-
9
- def connections_stub!(array)
10
- @connections = array
11
- end
12
- end
13
- end
14
-
15
- describe ::DatabaseCleaner do
16
- before(:each) { ::DatabaseCleaner.reset }
17
-
18
- context "orm specification" do
19
- it "should not accept unrecognised orms" do
20
- expect { ::DatabaseCleaner[nil] }.should raise_error(::DatabaseCleaner::NoORMDetected)
21
- end
22
-
23
- it "should accept :active_record" do
24
- cleaner = ::DatabaseCleaner[:active_record]
25
- cleaner.should be_a(::DatabaseCleaner::Base)
26
- cleaner.orm.should == :active_record
27
- ::DatabaseCleaner.connections.size.should == 1
28
- end
29
-
30
- it "should accept :data_mapper" do
31
- cleaner = ::DatabaseCleaner[:data_mapper]
32
- cleaner.should be_a(::DatabaseCleaner::Base)
33
- cleaner.orm.should == :data_mapper
34
- ::DatabaseCleaner.connections.size.should == 1
35
- end
36
-
37
- it "should accept :mongo_mapper" do
38
- cleaner = ::DatabaseCleaner[:mongo_mapper]
39
- cleaner.should be_a(::DatabaseCleaner::Base)
40
- cleaner.orm.should == :mongo_mapper
41
- ::DatabaseCleaner.connections.size.should == 1
42
- end
43
-
44
- it "should accept :couch_potato" do
45
- cleaner = ::DatabaseCleaner[:couch_potato]
46
- cleaner.should be_a(::DatabaseCleaner::Base)
47
- cleaner.orm.should == :couch_potato
48
- ::DatabaseCleaner.connections.size.should == 1
49
- end
50
- end
51
-
52
- it "should accept multiple orm's" do
53
- ::DatabaseCleaner[:couch_potato]
54
- ::DatabaseCleaner[:data_mapper]
55
- ::DatabaseCleaner.connections.size.should == 2
56
- ::DatabaseCleaner.connections[0].orm.should == :couch_potato
57
- ::DatabaseCleaner.connections[1].orm.should == :data_mapper
58
- end
59
-
60
- context "connection/db specification" do
61
- it "should accept a connection parameter and store it" do
62
- cleaner = ::DatabaseCleaner[:active_record, {:connection => :first_connection}]
63
- cleaner.should be_a(::DatabaseCleaner::Base)
64
- cleaner.orm.should == :active_record
65
- cleaner.db.should == :first_connection
66
- end
67
-
68
- it "should accept multiple connections for a single orm" do
69
- ::DatabaseCleaner[:data_mapper,{:connection => :first_db}]
70
- ::DatabaseCleaner[:data_mapper,{:connection => :second_db}]
71
- ::DatabaseCleaner.connections.size.should == 2
72
- ::DatabaseCleaner.connections[0].orm.should == :data_mapper
73
- ::DatabaseCleaner.connections[0].db.should == :first_db
74
- ::DatabaseCleaner.connections[1].orm.should == :data_mapper
75
- ::DatabaseCleaner.connections[1].db.should == :second_db
76
- end
77
-
78
- it "should accept multiple connections and multiple orms" do
79
- ::DatabaseCleaner[:data_mapper, {:connection => :first_db} ]
80
- ::DatabaseCleaner[:active_record,{:connection => :second_db}]
81
- ::DatabaseCleaner[:active_record,{:connection => :first_db} ]
82
- ::DatabaseCleaner[:data_mapper, {:connection => :second_db}]
83
-
84
- ::DatabaseCleaner.connections.size.should == 4
85
-
86
- ::DatabaseCleaner.connections[0].orm.should == :data_mapper
87
- ::DatabaseCleaner.connections[0].db.should == :first_db
88
-
89
- ::DatabaseCleaner.connections[1].orm.should == :active_record
90
- ::DatabaseCleaner.connections[1].db.should == :second_db
91
-
92
- ::DatabaseCleaner.connections[2].orm.should == :active_record
93
- ::DatabaseCleaner.connections[2].db.should == :first_db
94
-
95
- ::DatabaseCleaner.connections[3].orm.should == :data_mapper
96
- ::DatabaseCleaner.connections[3].db.should == :second_db
97
- end
98
- end
99
-
100
- context "connection/db retrieval" do
101
- it "should retrieve a db rather than create a new one" do
102
- pending
103
- connection = ::DatabaseCleaner[:active_record].strategy = :truncation
104
- ::DatabaseCleaner[:active_record].should == connection
105
- end
106
- end
107
-
108
- context "class methods" do
109
- subject { ::DatabaseCleaner }
110
-
111
- its(:connections) { should respond_to(:each) }
112
-
113
- it "should give me a default (autodetection) databasecleaner by default" do
114
- cleaner = mock("cleaner").as_null_object
115
- ::DatabaseCleaner::Base.should_receive(:new).with().and_return(cleaner)
116
-
117
- ::DatabaseCleaner.connections.should have(1).items
118
- ::DatabaseCleaner.connections.first.should == cleaner
119
- end
120
- end
121
-
122
- context "single orm single connection" do
123
- let(:connection) { ::DatabaseCleaner.connections.first }
124
-
125
- it "should proxy strategy=" do
126
- stratagum = mock("stratagum")
127
- connection.should_receive(:strategy=).with(stratagum)
128
- ::DatabaseCleaner.strategy = stratagum
129
- end
130
-
131
- it "should proxy orm=" do
132
- orm = mock("orm")
133
- connection.should_receive(:orm=).with(orm)
134
- ::DatabaseCleaner.orm = orm
135
- end
136
-
137
- it "should proxy start" do
138
- connection.should_receive(:start)
139
- ::DatabaseCleaner.start
140
- end
141
-
142
- it "should proxy clean" do
143
- connection.should_receive(:clean)
144
- ::DatabaseCleaner.clean
145
- end
146
-
147
- it "should proxy clean_with" do
148
- stratagem = mock("stratgem")
149
- connection.should_receive(:clean_with).with(stratagem, {})
150
- ::DatabaseCleaner.clean_with stratagem, {}
151
- end
152
- end
153
-
154
- context "multiple connections" do
155
-
156
- #these are relativly simple, all we need to do is make sure all connections are cleaned/started/cleaned_with appropriatly.
157
- context "simple proxy methods" do
158
-
159
- let(:active_record) { mock("active_mock") }
160
- let(:data_mapper) { mock("data_mock") }
161
-
162
- before(:each) do
163
- ::DatabaseCleaner.stub!(:connections).and_return([active_record,data_mapper])
164
- end
165
-
166
- it "should proxy orm to all connections" do
167
- active_record.should_receive(:orm=)
168
- data_mapper.should_receive(:orm=)
169
-
170
- ::DatabaseCleaner.orm = mock("orm")
171
- end
172
-
173
- it "should proxy start to all connections" do
174
- active_record.should_receive(:start)
175
- data_mapper.should_receive(:start)
176
-
177
- ::DatabaseCleaner.start
178
- end
179
-
180
- it "should proxy clean to all connections" do
181
- active_record.should_receive(:clean)
182
- data_mapper.should_receive(:clean)
183
-
184
- ::DatabaseCleaner.clean
185
- end
186
-
187
- it "should proxy clean_with to all connections" do
188
- stratagem = mock("stratgem")
189
- active_record.should_receive(:clean_with).with(stratagem)
190
- data_mapper.should_receive(:clean_with).with(stratagem)
191
-
192
- ::DatabaseCleaner.clean_with stratagem
193
- end
194
- end
195
-
196
- # ah now we have some difficulty, we mustn't allow duplicate connections to exist, but they could
197
- # plausably want to force orm/strategy change on two sets of orm that differ only on db
198
- context "multiple orm proxy methods" do
199
-
200
- it "should proxy orm to all connections and remove duplicate connections" do
201
- active_record_1 = mock("active_mock_on_db_one").as_null_object
202
- active_record_2 = mock("active_mock_on_db_two").as_null_object
203
- data_mapper_1 = mock("data_mock_on_db_one").as_null_object
204
-
205
- ::DatabaseCleaner.connections_stub! [active_record_1,active_record_2,data_mapper_1]
206
-
207
- active_record_1.should_receive(:orm=).with(:data_mapper)
208
- active_record_2.should_receive(:orm=).with(:data_mapper)
209
- data_mapper_1.should_receive(:orm=).with(:data_mapper)
210
-
211
- active_record_1.should_receive(:==).with(data_mapper_1).and_return(true)
212
-
213
- ::DatabaseCleaner.connections.size.should == 3
214
- ::DatabaseCleaner.orm = :data_mapper
215
- ::DatabaseCleaner.connections.size.should == 2
216
- end
217
-
218
- it "should proxy strategy to all connections and remove duplicate connections" do
219
- active_record_1 = mock("active_mock_strategy_one").as_null_object
220
- active_record_2 = mock("active_mock_strategy_two").as_null_object
221
- strategy = mock("strategy")
222
-
223
- ::DatabaseCleaner.connections_stub! [active_record_1,active_record_2]
224
-
225
- active_record_1.should_receive(:strategy=).with(strategy)
226
- active_record_2.should_receive(:strategy=).with(strategy)
227
-
228
- active_record_1.should_receive(:==).with(active_record_2).and_return(true)
229
-
230
- ::DatabaseCleaner.connections.size.should == 2
231
- ::DatabaseCleaner.strategy = strategy
232
- ::DatabaseCleaner.connections.size.should == 1
233
- end
234
- end
235
- end
236
-
237
- describe "remove_duplicates" do
238
- it "should remove duplicates if they are identical" do
239
- orm = mock("orm")
240
- connection = mock("a datamapper connection", :orm => orm )
241
-
242
- ::DatabaseCleaner.connections_stub! [connection,connection,connection]
243
-
244
- ::DatabaseCleaner.remove_duplicates
245
- ::DatabaseCleaner.connections.size.should == 1
246
- end
247
- end
248
-
249
- describe "app_root" do
250
- it "should default to Dir.pwd" do
251
- DatabaseCleaner.app_root.should == Dir.pwd
252
- end
253
-
254
- it "should store specific paths" do
255
- DatabaseCleaner.app_root = '/path/to'
256
- DatabaseCleaner.app_root.should == '/path/to'
257
- end
258
- end
259
-
260
- describe "orm_module" do
261
- subject { ::DatabaseCleaner }
262
-
263
- it "should return DatabaseCleaner::ActiveRecord for :active_record" do
264
- ::DatabaseCleaner::ActiveRecord = mock("ar module") unless defined? ::DatabaseCleaner::ActiveRecord
265
- subject.orm_module(:active_record).should == DatabaseCleaner::ActiveRecord
266
- end
267
-
268
- it "should return DatabaseCleaner::DataMapper for :data_mapper" do
269
- ::DatabaseCleaner::DataMapper = mock("dm module") unless defined? ::DatabaseCleaner::DataMapper
270
- subject.orm_module(:data_mapper).should == DatabaseCleaner::DataMapper
271
- end
272
-
273
- it "should return DatabaseCleaner::MongoMapper for :mongo_mapper" do
274
- ::DatabaseCleaner::MongoMapper = mock("mm module") unless defined? ::DatabaseCleaner::MongoMapper
275
- subject.orm_module(:mongo_mapper).should == DatabaseCleaner::MongoMapper
276
- end
277
-
278
- it "should return DatabaseCleaner::Mongoid for :mongoid" do
279
- ::DatabaseCleaner::Mongoid = mock("mongoid module") unless defined? ::DatabaseCleaner::Mongoid
280
- subject.orm_module(:mongoid).should == DatabaseCleaner::Mongoid
281
- end
282
-
283
- it "should return DatabaseCleaner::Mongo for :mongo" do
284
- ::DatabaseCleaner::Mongo = mock("mongo module") unless defined? ::DatabaseCleaner::Mongo
285
- subject.orm_module(:mongo).should == DatabaseCleaner::Mongo
286
- end
287
-
288
- it "should return DatabaseCleaner::CouchPotato for :couch_potato" do
289
- ::DatabaseCleaner::CouchPotato = mock("cp module") unless defined? ::DatabaseCleaner::CouchPotato
290
- subject.orm_module(:couch_potato).should == DatabaseCleaner::CouchPotato
291
- end
292
-
293
- end
294
- end
@@ -1,41 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'database_cleaner/couch_potato/truncation'
3
- require 'couch_potato'
4
-
5
- module DatabaseCleaner
6
- module CouchPotato
7
-
8
- describe Truncation do
9
- let(:database) { mock('database') }
10
-
11
- before(:each) do
12
- ::CouchPotato.stub!(:couchrest_database).and_return(database)
13
- end
14
-
15
- it "should re-create the database" do
16
- database.should_receive(:recreate!)
17
-
18
- Truncation.new.clean
19
- end
20
-
21
- it "should raise an error when the :only option is used" do
22
- running {
23
- Truncation.new(:only => ['document-type'])
24
- }.should raise_error(ArgumentError)
25
- end
26
-
27
- it "should raise an error when the :except option is used" do
28
- running {
29
- Truncation.new(:except => ['document-type'])
30
- }.should raise_error(ArgumentError)
31
- end
32
-
33
- it "should raise an error when invalid options are provided" do
34
- running {
35
- Truncation.new(:foo => 'bar')
36
- }.should raise_error(ArgumentError)
37
- end
38
- end
39
-
40
- end
41
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/data_mapper/base'
3
- require 'database_cleaner/shared_strategy_spec'
4
-
5
- module DatabaseCleaner
6
- describe DataMapper do
7
- it { should respond_to(:available_strategies) }
8
- end
9
-
10
- module DataMapper
11
- class ExampleStrategy
12
- include ::DatabaseCleaner::DataMapper::Base
13
- end
14
-
15
- describe ExampleStrategy do
16
- it_should_behave_like "a generic strategy"
17
- it { should respond_to(:db) }
18
- it { should respond_to(:db=) }
19
-
20
- it "should store my desired db" do
21
- subject.db = :my_db
22
- subject.db.should == :my_db
23
- end
24
-
25
- it "should default to :default" do
26
- subject.db.should == :default
27
- end
28
- end
29
- end
30
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'database_cleaner/data_mapper/transaction'
3
- require 'database_cleaner/shared_strategy_spec'
4
- #require 'data_mapper'
5
-
6
- module DatabaseCleaner
7
- module DataMapper
8
-
9
- describe Transaction do
10
- it_should_behave_like "a generic strategy"
11
- it_should_behave_like "a generic transaction strategy"
12
-
13
- describe "start" do
14
- it "should start a transaction"
15
- end
16
-
17
- describe "clean" do
18
- it "should finish a transaction"
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,11 +0,0 @@
1
- require 'database_cleaner/data_mapper/truncation'
2
- require 'database_cleaner/shared_strategy_spec'
3
-
4
- module DatabaseCleaner
5
- module DataMapper
6
- describe Truncation do
7
- it_should_behave_like "a generic strategy"
8
- it_should_behave_like "a generic truncation strategy"
9
- end
10
- end
11
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/shared_strategy_spec'
3
- require 'database_cleaner/generic/base'
4
-
5
- module ::DatabaseCleaner
6
- module Generic
7
- class ExampleStrategy
8
- include ::DatabaseCleaner::Generic::Base
9
- end
10
-
11
- describe ExampleStrategy do
12
- context "class methods" do
13
- subject { ExampleStrategy }
14
- its(:available_strategies) { should be_empty }
15
- end
16
-
17
- it_should_behave_like "a generic strategy"
18
-
19
- its(:db) { should == :default }
20
- end
21
- end
22
- end
@@ -1,78 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/generic/truncation'
3
-
4
- module ::DatabaseCleaner
5
- module Generic
6
- class TruncationExample
7
- include ::DatabaseCleaner::Generic::Truncation
8
-
9
- def only
10
- @only
11
- end
12
-
13
- def except
14
- @tables_to_exclude
15
- end
16
- end
17
-
18
- class MigrationExample < TruncationExample
19
- def migration_storage_name
20
- "migration_storage_name"
21
- end
22
- end
23
-
24
- describe TruncationExample do
25
- its(:start) { expect{ subject }.to_not raise_error }
26
- its(:clean) { expect{ subject }.to raise_error(NotImplementedError) }
27
-
28
- context "private methods" do
29
- it { should_not respond_to(:tables_to_truncate) }
30
- its(:tables_to_truncate) { expect{ subject }.to raise_error(NotImplementedError) }
31
-
32
- it { should_not respond_to(:migration_storage_name) }
33
- its(:migration_storage_name) { should be_nil }
34
- end
35
-
36
- describe "initialize" do
37
- it { expect{ subject }.to_not raise_error }
38
-
39
- it "should accept a hash of options" do
40
- expect{ TruncationExample.new {} }.to_not raise_error
41
- end
42
-
43
- it { expect{ TruncationExample.new( { :a_random_param => "should raise ArgumentError" } ) }.to raise_error(ArgumentError) }
44
- it { expect{ TruncationExample.new( { :except => "something",:only => "something else" } ) }.to raise_error(ArgumentError) }
45
- it { expect{ TruncationExample.new( { :only => "something" } ) }.to_not raise_error(ArgumentError) }
46
- it { expect{ TruncationExample.new( { :except => "something" } ) }.to_not raise_error(ArgumentError) }
47
-
48
- context "" do
49
- subject { TruncationExample.new( { :only => ["something"] } ) }
50
- its(:only) { should == ["something"] }
51
- its(:except) { should == [] }
52
- end
53
-
54
- context "" do
55
- subject { TruncationExample.new( { :except => ["something"] } ) }
56
- its(:only) { should == nil }
57
- its(:except) { should include("something") }
58
- end
59
-
60
- context "" do
61
- subject { MigrationExample.new }
62
- its(:only) { should == nil }
63
- its(:except) { should == ["migration_storage_name"] }
64
- end
65
-
66
- context "" do
67
- EXCEPT_TABLES = ["something"]
68
- subject { MigrationExample.new( { :except => EXCEPT_TABLES } ) }
69
-
70
- it "should not modify the array of excepted tables" do
71
- subject.except.should include("migration_storage_name")
72
- EXCEPT_TABLES.should_not include("migration_storage_name")
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
- require 'database_cleaner/mongo_mapper/base'
3
- require 'database_cleaner/shared_strategy_spec'
4
-
5
- module DatabaseCleaner
6
- describe MongoMapper do
7
- it { should respond_to(:available_strategies) }
8
- end
9
-
10
- module MongoMapper
11
- class ExampleStrategy
12
- include ::DatabaseCleaner::MongoMapper::Base
13
- end
14
-
15
- describe ExampleStrategy do
16
-
17
- it_should_behave_like "a generic strategy"
18
-
19
- describe "db" do
20
- it { should respond_to(:db=) }
21
-
22
- it "should store my desired db" do
23
- subject.db = :my_db
24
- subject.db.should == :my_db
25
- end
26
-
27
- it "should default to :default" do
28
- subject.db.should == :default
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,8 +0,0 @@
1
- class Widget
2
- include ::MongoMapper::Document
3
- key :name, String
4
- end
5
- class Gadget
6
- include ::MongoMapper::Document
7
- key :name, String
8
- end
@@ -1,74 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
- require 'mongo_mapper'
3
- require 'database_cleaner/mongo_mapper/truncation'
4
- require File.dirname(__FILE__) + '/mongo_examples'
5
-
6
- module DatabaseCleaner
7
- module MongoMapper
8
-
9
- describe Truncation do
10
-
11
- #doing this in the file root breaks autospec, doing it before(:all) just fails the specs
12
- before(:all) do
13
- ::MongoMapper.connection = ::Mongo::Connection.new('127.0.0.1')
14
- @test_db = 'database_cleaner_specs'
15
- ::MongoMapper.database = @test_db
16
- end
17
-
18
- before(:each) do
19
- ::MongoMapper.connection.drop_database(@test_db)
20
- end
21
-
22
- def ensure_counts(expected_counts)
23
- # I had to add this sanity_check garbage because I was getting non-determinisc results from mongomapper at times..
24
- # very odd and disconcerting...
25
- sanity_check = expected_counts.delete(:sanity_check)
26
- begin
27
- expected_counts.each do |model_class, expected_count|
28
- model_class.count.should equal(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
29
- end
30
- rescue Spec::Expectations::ExpectationNotMetError => e
31
- raise !sanity_check ? e : Spec::ExpectationNotMetError::ExpectationNotMetError.new("SANITY CHECK FAILURE! This should never happen here: #{e.message}")
32
- end
33
- end
34
-
35
- def create_widget(attrs={})
36
- Widget.new({:name => 'some widget'}.merge(attrs)).save!
37
- end
38
-
39
- def create_gadget(attrs={})
40
- Gadget.new({:name => 'some gadget'}.merge(attrs)).save!
41
- end
42
-
43
- it "truncates all collections by default" do
44
- create_widget
45
- create_gadget
46
- ensure_counts(Widget => 1, Gadget => 1, :sanity_check => true)
47
- Truncation.new.clean
48
- ensure_counts(Widget => 0, Gadget => 0)
49
- end
50
-
51
- context "when collections are provided to the :only option" do
52
- it "only truncates the specified collections" do
53
- create_widget
54
- create_gadget
55
- ensure_counts(Widget => 1, Gadget => 1, :sanity_check => true)
56
- Truncation.new(:only => ['widgets']).clean
57
- ensure_counts(Widget => 0, Gadget => 1)
58
- end
59
- end
60
-
61
- context "when collections are provided to the :except option" do
62
- it "truncates all but the specified collections" do
63
- create_widget
64
- create_gadget
65
- ensure_counts(Widget => 1, Gadget => 1, :sanity_check => true)
66
- Truncation.new(:except => ['widgets']).clean
67
- ensure_counts(Widget => 1, Gadget => 0)
68
- end
69
- end
70
-
71
- end
72
-
73
- end
74
- end
@@ -1,13 +0,0 @@
1
- shared_examples_for "a generic strategy" do
2
- it { should respond_to(:db) }
3
- end
4
-
5
- shared_examples_for "a generic truncation strategy" do
6
- it { should respond_to(:start) }
7
- it { should respond_to(:clean) }
8
- end
9
-
10
- shared_examples_for "a generic transaction strategy" do
11
- it { should respond_to(:start) }
12
- it { should respond_to(:clean) }
13
- end
data/spec/rcov.opts DELETED
@@ -1 +0,0 @@
1
- --exclude "spec/*,vendor/*,examples/*,features/*,Users/*/.rvm/gems/*/gems/*"
data/spec/spec.opts DELETED
@@ -1,7 +0,0 @@
1
- --colour
2
- --format nested
3
- --loadby
4
- mtime
5
- --reverse
6
- --backtrace
7
- --debugger
data/spec/spec_helper.rb DELETED
@@ -1,19 +0,0 @@
1
- require "rubygems"
2
-
3
- require "bundler"
4
- Bundler.setup
5
-
6
-
7
- require 'spec'
8
- #require 'active_record'
9
- #require 'mongo_mapper'
10
- $:.unshift(File.dirname(__FILE__) + '/../lib')
11
- require 'database_cleaner'
12
-
13
-
14
-
15
- Spec::Runner.configure do |config|
16
-
17
- end
18
-
19
- alias running lambda