database_cleaner 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +19 -16
- data/History.rdoc +42 -0
- data/README.markdown +79 -9
- data/VERSION.yml +2 -2
- data/examples/Gemfile.lock +19 -16
- data/examples/lib/redis_models.rb +3 -3
- data/lib/database_cleaner/active_record/base.rb +8 -0
- data/lib/database_cleaner/active_record/deletion.rb +22 -2
- data/lib/database_cleaner/active_record/truncation.rb +3 -3
- data/lib/database_cleaner/base.rb +6 -5
- data/lib/database_cleaner/mongo/truncation_mixin.rb +6 -2
- data/lib/database_cleaner/mongo2/truncation_mixin.rb +6 -4
- data/lib/database_cleaner/mongoid/truncation.rb +1 -1
- data/lib/database_cleaner/null_strategy.rb +5 -0
- data/lib/database_cleaner/redis/base.rb +9 -3
- data/spec/database_cleaner/active_record/truncation_spec.rb +3 -3
- data/spec/database_cleaner/base_spec.rb +34 -21
- data/spec/database_cleaner/mongo_mapper/truncation_spec.rb +2 -2
- data/spec/database_cleaner/null_strategy_spec.rb +28 -0
- data/spec/database_cleaner/redis/base_spec.rb +15 -4
- data/spec/database_cleaner/redis/truncation_spec.rb +1 -1
- data/spec/support/active_record/postgresql_setup.rb +1 -1
- metadata +122 -203
- checksums.yaml +0 -7
- data/examples/config/database.yml +0 -7
- data/examples/db/activerecord_one.db +0 -0
- data/examples/db/activerecord_two.db +0 -0
- data/examples/db/datamapper_default.db +0 -0
- data/examples/db/datamapper_one.db +0 -0
- data/examples/db/datamapper_two.db +0 -0
- /data/{features → examples/features}/step_definitions/ohm_steps.rb +0 -0
- /data/{features → examples/features}/step_definitions/redis_steps.rb +0 -0
|
@@ -9,6 +9,12 @@ require 'database_cleaner/neo4j/transaction'
|
|
|
9
9
|
module DatabaseCleaner
|
|
10
10
|
describe Base do
|
|
11
11
|
|
|
12
|
+
let(:mock_strategy) {
|
|
13
|
+
double("strategy").tap{|strategy|
|
|
14
|
+
strategy.stub(:to_ary => [strategy])
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
describe "autodetect" do
|
|
13
19
|
|
|
14
20
|
#Cache all ORMs, we'll need them later but not now.
|
|
@@ -201,18 +207,38 @@ module DatabaseCleaner
|
|
|
201
207
|
|
|
202
208
|
describe "comparison" do
|
|
203
209
|
it "should be equal if orm, connection and strategy are the same" do
|
|
204
|
-
strategy = mock("strategy")
|
|
205
|
-
strategy.stub!(:to_ary => [strategy])
|
|
206
|
-
|
|
207
210
|
one = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
|
208
|
-
one.strategy =
|
|
211
|
+
one.strategy = mock_strategy
|
|
209
212
|
|
|
210
213
|
two = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
|
211
|
-
two.strategy =
|
|
214
|
+
two.strategy = mock_strategy
|
|
212
215
|
|
|
213
216
|
one.should eq two
|
|
214
217
|
two.should eq one
|
|
215
218
|
end
|
|
219
|
+
|
|
220
|
+
it "should not be equal if orm are not the same" do
|
|
221
|
+
one = DatabaseCleaner::Base.new(:mongo_id, :connection => :default)
|
|
222
|
+
one.strategy = mock_strategy
|
|
223
|
+
|
|
224
|
+
two = DatabaseCleaner::Base.new(:active_record, :connection => :default)
|
|
225
|
+
two.strategy = mock_strategy
|
|
226
|
+
|
|
227
|
+
one.should_not eq two
|
|
228
|
+
two.should_not eq one
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
it "should not be equal if connection are not the same" do
|
|
232
|
+
|
|
233
|
+
one = DatabaseCleaner::Base.new(:active_record, :connection => :default)
|
|
234
|
+
one.strategy = :truncation
|
|
235
|
+
|
|
236
|
+
two = DatabaseCleaner::Base.new(:active_record, :connection => :other)
|
|
237
|
+
two.strategy = :truncation
|
|
238
|
+
|
|
239
|
+
one.should_not eq two
|
|
240
|
+
two.should_not eq one
|
|
241
|
+
end
|
|
216
242
|
end
|
|
217
243
|
|
|
218
244
|
describe "initialization" do
|
|
@@ -269,11 +295,7 @@ module DatabaseCleaner
|
|
|
269
295
|
end
|
|
270
296
|
|
|
271
297
|
describe "strategy_db=" do
|
|
272
|
-
let(:strategy) {
|
|
273
|
-
mock("strategy").tap{|strategy|
|
|
274
|
-
strategy.stub!(:to_ary => [strategy])
|
|
275
|
-
}
|
|
276
|
-
}
|
|
298
|
+
let(:strategy) { mock_strategy }
|
|
277
299
|
|
|
278
300
|
before(:each) do
|
|
279
301
|
subject.strategy = strategy
|
|
@@ -373,12 +395,6 @@ module DatabaseCleaner
|
|
|
373
395
|
end
|
|
374
396
|
|
|
375
397
|
describe "strategy=" do
|
|
376
|
-
let(:mock_strategy) {
|
|
377
|
-
mock("strategy").tap{|strategy|
|
|
378
|
-
strategy.stub!(:to_ary => [strategy])
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
398
|
it "should proxy symbolised strategies to create_strategy" do
|
|
383
399
|
subject.should_receive(:create_strategy).with(:symbol)
|
|
384
400
|
subject.strategy = :symbol
|
|
@@ -417,11 +433,8 @@ module DatabaseCleaner
|
|
|
417
433
|
end
|
|
418
434
|
|
|
419
435
|
it "returns the set strategy" do
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
subject.strategy = strategum
|
|
424
|
-
subject.strategy.should eq strategum
|
|
436
|
+
subject.strategy = mock_strategy
|
|
437
|
+
subject.strategy.should eq mock_strategy
|
|
425
438
|
end
|
|
426
439
|
end
|
|
427
440
|
|
|
@@ -27,8 +27,8 @@ module DatabaseCleaner
|
|
|
27
27
|
expected_counts.each do |model_class, expected_count|
|
|
28
28
|
model_class.count.should equal(expected_count), "#{model_class} expected to have a count of #{expected_count} but was #{model_class.count}"
|
|
29
29
|
end
|
|
30
|
-
rescue
|
|
31
|
-
raise !sanity_check ? e :
|
|
30
|
+
rescue RSpec::Expectations::ExpectationNotMetError => e
|
|
31
|
+
raise !sanity_check ? e : RSpec::ExpectationNotMetError::ExpectationNotMetError.new("SANITY CHECK FAILURE! This should never happen here: #{e.message}")
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module DatabaseCleaner
|
|
4
|
+
describe NullStrategy do
|
|
5
|
+
it 'responds to .start' do
|
|
6
|
+
expect { NullStrategy.start }.not_to raise_error(NoMethodError)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'responds to .clean' do
|
|
10
|
+
expect { NullStrategy.clean }.not_to raise_error(NoMethodError)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '.cleaning' do
|
|
14
|
+
it 'fails without a block' do
|
|
15
|
+
expect { NullStrategy.cleaning }.to raise_error(LocalJumpError)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'no-ops with a block' do
|
|
19
|
+
effect = double
|
|
20
|
+
expect(effect).to receive(:occur).once
|
|
21
|
+
|
|
22
|
+
NullStrategy.cleaning do
|
|
23
|
+
effect.occur
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
+
require 'redis'
|
|
2
3
|
require 'database_cleaner/redis/base'
|
|
3
4
|
require 'database_cleaner/shared_strategy'
|
|
4
5
|
|
|
@@ -18,10 +19,20 @@ module DatabaseCleaner
|
|
|
18
19
|
it { should respond_to(:db) }
|
|
19
20
|
it { should respond_to(:db=) }
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
context "when passing url" do
|
|
23
|
+
it "should store my describe db" do
|
|
24
|
+
url = 'redis://localhost:6379/2'
|
|
25
|
+
subject.db = 'redis://localhost:6379/2'
|
|
26
|
+
subject.db.should eq url
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "when passing connection" do
|
|
31
|
+
it "should store my describe db" do
|
|
32
|
+
connection = ::Redis.new :url => 'redis://localhost:6379/2'
|
|
33
|
+
subject.db = connection
|
|
34
|
+
subject.db.should eq connection
|
|
35
|
+
end
|
|
25
36
|
end
|
|
26
37
|
|
|
27
38
|
it "should default to :default" do
|
|
@@ -9,7 +9,7 @@ module DatabaseCleaner
|
|
|
9
9
|
describe Truncation do
|
|
10
10
|
before(:all) do
|
|
11
11
|
config = YAML::load(File.open("#{File.dirname(__FILE__)}/../../../examples/config/redis.yml"))
|
|
12
|
-
@redis = ::Redis.
|
|
12
|
+
@redis = ::Redis.new :url => config['test']['url']
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
before(:each) do
|
|
@@ -14,6 +14,7 @@ module PostgreSQLHelper
|
|
|
14
14
|
@encoding = default_config['encoding'] || ENV['CHARSET'] || 'utf8'
|
|
15
15
|
begin
|
|
16
16
|
establish_connection(default_config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
|
17
|
+
ActiveRecord::Base.connection.drop_database(default_config['database']) rescue nil
|
|
17
18
|
ActiveRecord::Base.connection.create_database(default_config['database'], default_config.merge('encoding' => @encoding))
|
|
18
19
|
rescue Exception => e
|
|
19
20
|
$stderr.puts e, *(e.backtrace)
|
|
@@ -32,7 +33,6 @@ module PostgreSQLHelper
|
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
def active_record_pg_migrate
|
|
35
|
-
`dropdb #{default_config['database']}`
|
|
36
36
|
create_db
|
|
37
37
|
establish_connection
|
|
38
38
|
ActiveRecord::Migrator.migrate 'spec/support/active_record/migrations'
|