database_rewinder 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7eb09a5bfe857d34118e354730f3f49cb4a6fb4
4
- data.tar.gz: 4c49a5891c8585ae6896b0137f34a05e397aeb9b
3
+ metadata.gz: db7ed1dc6ce9a93cb75fcbb82baf3e02654f9242
4
+ data.tar.gz: 5be39f4a597442871bc8e70d1d9fd2a5a4dceaf3
5
5
  SHA512:
6
- metadata.gz: aaf1352df853e3894d2cb777ebf4fd90bab61659e94577f61afce4eac41585df825fdfa22df10c5bf971b5d854e81851793a63cdc18139fe8ac377f6558684fd
7
- data.tar.gz: 31f04525cdb310b9bfe303f38578a94749f9a61ad7d22344460401804e2c6269bd5d032b62262610160f30dca220614f687ae37387be32a759a7a18c56287300
6
+ metadata.gz: 0f8b1ffbc5cc58969aaf7f028e70e1d87f67a6bf48597d2b97b9e80f2ee06fd0d1e1f2f490a7b12860bf7d4c04f58323606f579c5e019c515ae655785829cccd
7
+ data.tar.gz: ecf4ec4b7450800d551965fe1bf213023b11ed3bbf41ae7be3d9780fc088d5ba9c5b03db7bc235f9a8d6d451e18c376f6e1fdc7b44ba5059fd8ae3e0631178b7
data/README.md CHANGED
@@ -12,7 +12,11 @@ database\_rewinder is a minimalist's tiny and ultra-fast database cleaner.
12
12
 
13
13
  database\_rewinder memorizes every table name into which `INSERT` SQL was performed during each test case.
14
14
  Then it executes `DELETE` SQL only against these tables when cleaning.
15
- So, the more you have number of tables in your database, the more benefit you will get.
15
+ So, the more number of tables you have in your database, the more benefit you will get.
16
+
17
+ ### Credit
18
+
19
+ This strategy was originally devised and implemented by @eudoxa.
16
20
 
17
21
  ## Supported versions
18
22
 
@@ -32,12 +36,14 @@ And then execute:
32
36
 
33
37
  ## Usage
34
38
 
35
- Do `clean_all` in `before(:suite)`, and `clean` in `after(:each)`.
39
+ Do `clean` in `after(:each)`. And do `clean_all` or `clean_with` in `before(:suite)` if you'd like to.
36
40
 
37
41
  ```ruby
38
42
  RSpec.configure do |config|
39
43
  config.before :suite do
40
44
  DatabaseRewinder.clean_all
45
+ # or
46
+ # DatabaseRewinder.clean_with :any_arg_that_would_be_actually_ignored_anyway
41
47
  end
42
48
 
43
49
  config.after :each do
@@ -49,7 +55,7 @@ end
49
55
  ### Pro Tip
50
56
 
51
57
  database\_rewinder is designed to be almost compatible with database\_cleaner.
52
- So the following code will probably let your existing app work under database\_rewinder without making any change on your cofiguration.
58
+ So the following code will probably let your existing app work under database\_rewinder without making any change on your configuration.
53
59
 
54
60
  ```ruby
55
61
  DatabaseCleaner = DatabaseRewinder
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "database_rewinder"
7
- spec.version = '0.0.1'
7
+ spec.version = '0.0.2'
8
8
  spec.authors = ["Akira Matsuda"]
9
9
  spec.email = ["ronnie@dio.jp"]
10
10
  spec.description = "A minimalist's tiny and ultra-fast database cleaner"
@@ -34,10 +34,17 @@ module DatabaseRewinder
34
34
  end
35
35
 
36
36
  def record_inserted_table(connection, sql)
37
- database = connection.instance_variable_get(:'@config')[:database]
38
- cleaner = cleaners.detect {|c| c.db == database} or return
37
+ config = connection.instance_variable_get(:'@config')
38
+ database = config[:database]
39
+ cleaner = cleaners.detect do |c|
40
+ if (config[:adapter] == 'sqlite3') && (config[:database] != ':memory:')
41
+ File.expand_path(c.db, Rails.root) == File.expand_path(database, Rails.root)
42
+ else
43
+ c.db == database
44
+ end
45
+ end or return
39
46
 
40
- match = sql.match(/\AINSERT INTO [`"]?([^\s`"]+)[`"]?/)
47
+ match = sql.match(/\AINSERT INTO [`"]?([^\s`"]+)[`"]?/i)
41
48
  table = match[1] if match
42
49
  if table
43
50
  cleaner.inserted_tables << table unless cleaner.inserted_tables.include? table
@@ -4,7 +4,7 @@ describe 'DatabaseRewinder::InsertRecorder#execute' do
4
4
  before do
5
5
  DatabaseRewinder.init
6
6
  Foo.create! name: 'foo1'
7
- Bar.create! name: 'bar1'
7
+ Bar.connection.execute "insert into bars (name) values ('bar1')"
8
8
  DatabaseRewinder.cleaners
9
9
  end
10
10
  subject { DatabaseRewinder.instance_variable_get(:'@cleaners').detect {|c| c.db == ':memory:'} }
@@ -12,6 +12,19 @@ describe DatabaseRewinder do
12
12
  it { should == ['foo'] }
13
13
  end
14
14
 
15
+ describe '.record_inserted_table' do
16
+ before do
17
+ DatabaseRewinder.instance_variable_set :'@db_config', {'foo' => {'adapter' => 'sqlite3', 'database' => 'db/test.sqlite3'}}
18
+ @cleaner = DatabaseRewinder.create_cleaner 'foo'
19
+ connection = double('connection').as_null_object
20
+ connection.instance_variable_set :'@config', {adapter: 'sqlite3', database: File.expand_path('db/test.sqlite3', Rails.root) }
21
+ DatabaseRewinder.record_inserted_table(connection, 'INSERT INTO "foos" ("name") VALUES (?)')
22
+ end
23
+ subject { @cleaner }
24
+
25
+ its(:inserted_tables) { should == ['foos'] }
26
+ end
27
+
15
28
  describe '.clean' do
16
29
  before do
17
30
  Foo.create! name: 'foo1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_rewinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-13 00:00:00.000000000 Z
11
+ date: 2013-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,3 +132,4 @@ test_files:
132
132
  - spec/database_rewinder_spec.rb
133
133
  - spec/fake_app.rb
134
134
  - spec/spec_helper.rb
135
+ has_rdoc: