database_cleaner 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +12 -12
- data/History.rdoc +17 -0
- data/README.markdown +4 -0
- data/Rakefile +1 -0
- data/VERSION.yml +2 -2
- data/examples/Gemfile.lock +12 -12
- data/lib/database_cleaner/active_record/base.rb +3 -3
- data/lib/database_cleaner/active_record/deletion.rb +19 -36
- data/lib/database_cleaner/active_record/truncation.rb +40 -67
- data/lib/database_cleaner/base.rb +3 -3
- data/lib/database_cleaner/configuration.rb +1 -1
- data/lib/database_cleaner/data_mapper/base.rb +1 -1
- data/lib/database_cleaner/data_mapper/truncation.rb +22 -2
- data/lib/database_cleaner/generic/truncation.rb +4 -3
- data/lib/database_cleaner/mongo_mapper/base.rb +1 -1
- data/lib/database_cleaner/moped/base.rb +2 -2
- data/lib/database_cleaner/redis/base.rb +1 -1
- data/spec/database_cleaner/active_record/base_spec.rb +10 -10
- data/spec/database_cleaner/active_record/transaction_spec.rb +1 -1
- data/spec/database_cleaner/active_record/truncation/mysql2_spec.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/mysql_spec.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/postgresql_spec.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb +2 -2
- data/spec/database_cleaner/active_record/truncation/sqlite3_spec.rb +42 -0
- data/spec/database_cleaner/active_record/truncation_spec.rb +50 -29
- data/spec/database_cleaner/base_spec.rb +44 -48
- data/spec/database_cleaner/configuration_spec.rb +74 -74
- data/spec/database_cleaner/couch_potato/truncation_spec.rb +2 -2
- data/spec/database_cleaner/data_mapper/base_spec.rb +2 -2
- data/spec/database_cleaner/generic/base_spec.rb +1 -1
- data/spec/database_cleaner/generic/truncation_spec.rb +26 -16
- data/spec/database_cleaner/mongo_mapper/base_spec.rb +2 -2
- data/spec/database_cleaner/moped/truncation_spec.rb +1 -1
- data/spec/database_cleaner/ohm/truncation_spec.rb +8 -8
- data/spec/database_cleaner/redis/base_spec.rb +2 -2
- data/spec/database_cleaner/redis/truncation_spec.rb +8 -8
- data/spec/database_cleaner/sequel/base_spec.rb +2 -2
- data/spec/support/active_record/sqlite3_setup.rb +40 -0
- metadata +4 -2
@@ -6,10 +6,10 @@ module DatabaseCleaner
|
|
6
6
|
module CouchPotato
|
7
7
|
|
8
8
|
describe Truncation do
|
9
|
-
let(:database) {
|
9
|
+
let(:database) { double('database') }
|
10
10
|
|
11
11
|
before(:each) do
|
12
|
-
::CouchPotato.stub
|
12
|
+
::CouchPotato.stub(:couchrest_database).and_return(database)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should re-create the database" do
|
@@ -19,11 +19,11 @@ module DatabaseCleaner
|
|
19
19
|
|
20
20
|
it "should store my desired db" do
|
21
21
|
subject.db = :my_db
|
22
|
-
subject.db.should
|
22
|
+
subject.db.should eq :my_db
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should default to :default" do
|
26
|
-
subject.db.should
|
26
|
+
subject.db.should eq :default
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -30,12 +30,22 @@ module ::DatabaseCleaner
|
|
30
30
|
end
|
31
31
|
|
32
32
|
describe TruncationExample do
|
33
|
-
|
34
|
-
|
33
|
+
subject(:truncation_example) { TruncationExample.new }
|
34
|
+
|
35
|
+
it "will start" do
|
36
|
+
expect { truncation_example.start }.to_not raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "expects clean to be implemented later" do
|
40
|
+
expect { truncation_example.clean }.to raise_error(NotImplementedError)
|
41
|
+
end
|
35
42
|
|
36
43
|
context "private methods" do
|
37
44
|
it { should_not respond_to(:tables_to_truncate) }
|
38
|
-
|
45
|
+
|
46
|
+
it 'expects #tables_to_truncate to be implemented later' do
|
47
|
+
expect{ truncation_example.send :tables_to_truncate }.to raise_error(NotImplementedError)
|
48
|
+
end
|
39
49
|
|
40
50
|
it { should_not respond_to(:migration_storage_names) }
|
41
51
|
its(:migration_storage_names) { should be_empty }
|
@@ -50,47 +60,47 @@ module ::DatabaseCleaner
|
|
50
60
|
|
51
61
|
it { expect{ TruncationExample.new( { :a_random_param => "should raise ArgumentError" } ) }.to raise_error(ArgumentError) }
|
52
62
|
it { expect{ TruncationExample.new( { :except => "something",:only => "something else" } ) }.to raise_error(ArgumentError) }
|
53
|
-
it { expect{ TruncationExample.new( { :only => "something" } ) }.to_not raise_error
|
54
|
-
it { expect{ TruncationExample.new( { :except => "something" } ) }.to_not raise_error
|
55
|
-
it { expect{ TruncationExample.new( { :pre_count => "something"
|
56
|
-
it { expect{ TruncationExample.new( { :reset_ids => "something"
|
63
|
+
it { expect{ TruncationExample.new( { :only => "something" } ) }.to_not raise_error }
|
64
|
+
it { expect{ TruncationExample.new( { :except => "something" } ) }.to_not raise_error }
|
65
|
+
it { expect{ TruncationExample.new( { :pre_count => "something" } ) }.to_not raise_error }
|
66
|
+
it { expect{ TruncationExample.new( { :reset_ids => "something" } ) }.to_not raise_error }
|
57
67
|
|
58
68
|
context "" do
|
59
69
|
subject { TruncationExample.new( { :only => ["something"] } ) }
|
60
|
-
its(:only) { should
|
61
|
-
its(:except) { should
|
70
|
+
its(:only) { should eq ["something"] }
|
71
|
+
its(:except) { should eq [] }
|
62
72
|
end
|
63
73
|
|
64
74
|
context "" do
|
65
75
|
subject { TruncationExample.new( { :except => ["something"] } ) }
|
66
|
-
its(:only) { should
|
76
|
+
its(:only) { should eq nil }
|
67
77
|
its(:except) { should include("something") }
|
68
78
|
end
|
69
79
|
|
70
80
|
context "" do
|
71
81
|
subject { TruncationExample.new( { :reset_ids => ["something"] } ) }
|
72
|
-
its(:reset_ids?) { should
|
82
|
+
its(:reset_ids?) { should eq true }
|
73
83
|
end
|
74
84
|
|
75
85
|
context "" do
|
76
86
|
subject { TruncationExample.new( { :reset_ids => nil } ) }
|
77
|
-
its(:reset_ids?) { should
|
87
|
+
its(:reset_ids?) { should eq false }
|
78
88
|
end
|
79
89
|
|
80
90
|
context "" do
|
81
91
|
subject { TruncationExample.new( { :pre_count => ["something"] } ) }
|
82
|
-
its(:pre_count?) { should
|
92
|
+
its(:pre_count?) { should eq true }
|
83
93
|
end
|
84
94
|
|
85
95
|
context "" do
|
86
96
|
subject { TruncationExample.new( { :pre_count => nil } ) }
|
87
|
-
its(:pre_count?) { should
|
97
|
+
its(:pre_count?) { should eq false }
|
88
98
|
end
|
89
99
|
|
90
100
|
context "" do
|
91
101
|
subject { MigrationExample.new }
|
92
|
-
its(:only) { should
|
93
|
-
its(:except) { should
|
102
|
+
its(:only) { should eq nil }
|
103
|
+
its(:except) { should eq %w[migration_storage_name] }
|
94
104
|
end
|
95
105
|
|
96
106
|
context "" do
|
@@ -21,11 +21,11 @@ module DatabaseCleaner
|
|
21
21
|
|
22
22
|
it "should store my desired db" do
|
23
23
|
subject.db = :my_db
|
24
|
-
subject.db.should
|
24
|
+
subject.db.should eq :my_db
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should default to :default" do
|
28
|
-
subject.db.should
|
28
|
+
subject.db.should eq :default
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -8,7 +8,7 @@ module DatabaseCleaner
|
|
8
8
|
|
9
9
|
describe Truncation do
|
10
10
|
let(:args) {{}}
|
11
|
-
let(:truncation) { described_class.new(args)
|
11
|
+
let(:truncation) { described_class.new(args) }
|
12
12
|
#doing this in the file root breaks autospec, doing it before(:all) just fails the specs
|
13
13
|
before(:all) do
|
14
14
|
@test_db = 'database_cleaner_specs'
|
@@ -39,19 +39,19 @@ module DatabaseCleaner
|
|
39
39
|
it "truncates all keys by default" do
|
40
40
|
create_widget
|
41
41
|
create_gadget
|
42
|
-
@redis.keys.size.should
|
42
|
+
@redis.keys.size.should eq 6
|
43
43
|
Truncation.new.clean
|
44
|
-
@redis.keys.size.should
|
44
|
+
@redis.keys.size.should eq 0
|
45
45
|
end
|
46
46
|
|
47
47
|
context "when keys are provided to the :only option" do
|
48
48
|
it "only truncates the specified keys" do
|
49
49
|
create_widget
|
50
50
|
create_gadget
|
51
|
-
@redis.keys.size.should
|
51
|
+
@redis.keys.size.should eq 6
|
52
52
|
Truncation.new(:only => ['*Widget*']).clean
|
53
|
-
@redis.keys.size.should
|
54
|
-
@redis.get('DatabaseCleaner::Ohm::Gadget:id').should
|
53
|
+
@redis.keys.size.should eq 3
|
54
|
+
@redis.get('DatabaseCleaner::Ohm::Gadget:id').should eq '1'
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,10 +59,10 @@ module DatabaseCleaner
|
|
59
59
|
it "truncates all but the specified keys" do
|
60
60
|
create_widget
|
61
61
|
create_gadget
|
62
|
-
@redis.keys.size.should
|
62
|
+
@redis.keys.size.should eq 6
|
63
63
|
Truncation.new(:except => ['*Widget*']).clean
|
64
|
-
@redis.keys.size.should
|
65
|
-
@redis.get('DatabaseCleaner::Ohm::Widget:id').should
|
64
|
+
@redis.keys.size.should eq 3
|
65
|
+
@redis.get('DatabaseCleaner::Ohm::Widget:id').should eq '1'
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -21,11 +21,11 @@ module DatabaseCleaner
|
|
21
21
|
it "should store my describe db" do
|
22
22
|
url = 'redis://localhost:6379/2'
|
23
23
|
subject.db = 'redis://localhost:6379/2'
|
24
|
-
subject.db.should
|
24
|
+
subject.db.should eq url
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should default to :default" do
|
28
|
-
subject.db.should
|
28
|
+
subject.db.should eq :default
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -31,19 +31,19 @@ module DatabaseCleaner
|
|
31
31
|
it "truncates all keys by default" do
|
32
32
|
create_widget
|
33
33
|
create_gadget
|
34
|
-
@redis.keys.size.should
|
34
|
+
@redis.keys.size.should eq 2
|
35
35
|
Truncation.new.clean
|
36
|
-
@redis.keys.size.should
|
36
|
+
@redis.keys.size.should eq 0
|
37
37
|
end
|
38
38
|
|
39
39
|
context "when keys are provided to the :only option" do
|
40
40
|
it "only truncates the specified keys" do
|
41
41
|
create_widget
|
42
42
|
create_gadget
|
43
|
-
@redis.keys.size.should
|
43
|
+
@redis.keys.size.should eq 2
|
44
44
|
Truncation.new(:only => ['Widge*']).clean
|
45
|
-
@redis.keys.size.should
|
46
|
-
@redis.get('Gadget').should
|
45
|
+
@redis.keys.size.should eq 1
|
46
|
+
@redis.get('Gadget').should eq '1'
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,10 +51,10 @@ module DatabaseCleaner
|
|
51
51
|
it "truncates all but the specified keys" do
|
52
52
|
create_widget
|
53
53
|
create_gadget
|
54
|
-
@redis.keys.size.should
|
54
|
+
@redis.keys.size.should eq 2
|
55
55
|
Truncation.new(:except => ['Widg*']).clean
|
56
|
-
@redis.keys.size.should
|
57
|
-
@redis.get('Widget').should
|
56
|
+
@redis.keys.size.should eq 1
|
57
|
+
@redis.get('Widget').should eq '1'
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -20,12 +20,12 @@ module DatabaseCleaner
|
|
20
20
|
|
21
21
|
it "should store my desired db" do
|
22
22
|
subject.db = :my_db
|
23
|
-
subject.db.should
|
23
|
+
subject.db.should eq :my_db
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should default to :default" do
|
27
27
|
pending "I figure out how to use Sequel and write some real tests for it..."
|
28
|
-
subject.db.should
|
28
|
+
subject.db.should eq :default
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'support/active_record/database_setup'
|
2
|
+
require 'support/active_record/schema_setup'
|
3
|
+
|
4
|
+
module SQLite3Helper
|
5
|
+
puts "Active Record #{ActiveRecord::VERSION::STRING}, sqlite3"
|
6
|
+
|
7
|
+
# ActiveRecord::Base.logger = Logger.new(STDERR)
|
8
|
+
|
9
|
+
def config
|
10
|
+
db_config['sqlite3']
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_db
|
14
|
+
@encoding = config['encoding'] || ENV['CHARSET'] || 'utf8'
|
15
|
+
begin
|
16
|
+
establish_connection(config.merge('database' => 'sqlite3', 'schema_search_path' => 'public'))
|
17
|
+
rescue Exception => e
|
18
|
+
$stderr.puts e, *(e.backtrace)
|
19
|
+
$stderr.puts "Couldn't create database for #{config.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def establish_connection config = config
|
24
|
+
ActiveRecord::Base.establish_connection(config)
|
25
|
+
end
|
26
|
+
|
27
|
+
def active_record_sqlite3_setup
|
28
|
+
create_db
|
29
|
+
establish_connection
|
30
|
+
load_schema
|
31
|
+
end
|
32
|
+
|
33
|
+
def active_record_sqlite3_connection
|
34
|
+
ActiveRecord::Base.connection
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec.configure do |c|
|
39
|
+
c.include SQLite3Helper
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Strategies for cleaning databases. Can be used to ensure a clean state
|
15
15
|
for testing.
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- spec/database_cleaner/active_record/truncation/mysql_spec.rb
|
98
98
|
- spec/database_cleaner/active_record/truncation/postgresql_spec.rb
|
99
99
|
- spec/database_cleaner/active_record/truncation/shared_fast_truncation.rb
|
100
|
+
- spec/database_cleaner/active_record/truncation/sqlite3_spec.rb
|
100
101
|
- spec/database_cleaner/active_record/truncation_spec.rb
|
101
102
|
- spec/database_cleaner/base_spec.rb
|
102
103
|
- spec/database_cleaner/configuration_spec.rb
|
@@ -127,6 +128,7 @@ files:
|
|
127
128
|
- spec/support/active_record/mysql_setup.rb
|
128
129
|
- spec/support/active_record/postgresql_setup.rb
|
129
130
|
- spec/support/active_record/schema_setup.rb
|
131
|
+
- spec/support/active_record/sqlite3_setup.rb
|
130
132
|
- LICENSE
|
131
133
|
- TODO
|
132
134
|
homepage: http://github.com/bmabey/database_cleaner
|