database_rewinder 0.5.1 → 0.5.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: b508301ffcd515a842bbaf9b69cb2f259f7d37bf
4
- data.tar.gz: 28006751946237e176b620e7bac07527cd99ebd0
3
+ metadata.gz: 3bf8192dabd4d1fb1fad33301a15a13ce5ee7488
4
+ data.tar.gz: 5ffe5087a213f1491dbe1927ef891e0497006370
5
5
  SHA512:
6
- metadata.gz: dd07c81ea30272bef5bc22eb0bdeaa1e043ed3eeeab8e5e34a7273ce0ed5bb6fab3876c774c1440a5b2fa10f8b155523ed094d7bc4f11b142f97a2a15bb36cd5
7
- data.tar.gz: c34c37f908f7b2e8a2a4181c395a0f23f74605a00005a4776bdc41c53cc65585d736bd4f9c54e0045715c12c66dfb0876398d68d69bd13c0475f7756a2617cb9
6
+ metadata.gz: e838b4cc0a35731019ff1c4cab84b651ff80bd240cd0958ec2c0893f26c09e3ad90761f8bf3620e7524bbe4491620ac9fe0690c47bf9717494162a706a2013f4
7
+ data.tar.gz: faf1091315a8592c5c2b94597d0e12d1629c493c04bddf2eb96c72ce43a7689dbfe7c70ddaaebe1e22393cb9e0b21d3189ff33c4bb1dd3ce0e02d9acf2da0bae
data/README.md CHANGED
@@ -71,7 +71,7 @@ RSpec.configure do |config|
71
71
  # you could give the DB name with connection: key if you like
72
72
  DatabaseRewinder[connection: 'yet_another_test_db']
73
73
 
74
- # also with a meaning less something first, then {connection: DB_NAME} as the second argument (DatabaseCleaner compatible)
74
+ # or with a meaningless something first, then {connection: DB_NAME} as the second argument (DatabaseCleaner compatible)
75
75
  DatabaseRewinder[:active_record, connection: 'an_active_record_db']
76
76
 
77
77
  DatabaseRewinder.clean_all
@@ -80,6 +80,7 @@ RSpec.configure do |config|
80
80
  config.after(:each) do
81
81
  DatabaseRewinder.clean
82
82
  end
83
+ end
83
84
  ```
84
85
 
85
86
  ### Pro Tip
@@ -91,11 +92,6 @@ So the following code will probably let your existing app work under database\_r
91
92
  DatabaseCleaner = DatabaseRewinder
92
93
  ```
93
94
 
94
- ## TODO
95
-
96
- Write documentation and specs about multiple databases.
97
-
98
-
99
95
  ## Contributing
100
96
 
101
97
  Send me your pull requests.
@@ -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.5.1'
7
+ spec.version = '0.5.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"
@@ -37,14 +37,7 @@ module DatabaseRewinder
37
37
  # DatabaseRewinder[:active_record, connection: 'the_db_name']
38
38
  #
39
39
  # You can cleanup multiple databases for each test using this configuration.
40
- def [](orm, connection: nil, **)
41
- if connection.nil?
42
- if orm.is_a? String
43
- connection = orm
44
- elsif orm.is_a?(Hash) && orm.has_key?(:connection)
45
- connection = orm[:connection]
46
- end
47
- end
40
+ def [](connection)
48
41
  @cleaners.detect {|c| c.connection_name == connection} || create_cleaner(connection)
49
42
  end
50
43
 
@@ -70,7 +63,7 @@ module DatabaseRewinder
70
63
  end
71
64
  end or return
72
65
 
73
- match = sql.match(/\AINSERT INTO (?:\.*[`"]?([^.\s`"]+)[`"]?)*/i)
66
+ match = sql.match(/\AINSERT(?: IGNORE)? INTO (?:\.*[`"]?([^.\s`"]+)[`"]?)*/i)
74
67
  return unless match
75
68
 
76
69
  table = match[1]
@@ -84,12 +77,12 @@ module DatabaseRewinder
84
77
  if @clean_all
85
78
  clean_all
86
79
  else
87
- cleaners.each {|c| c.clean}
80
+ cleaners.each(&:clean)
88
81
  end
89
82
  end
90
83
 
91
84
  def clean_all
92
- cleaners.each {|c| c.clean_all}
85
+ cleaners.each(&:clean_all)
93
86
  end
94
87
 
95
88
  # cache AR connection.tables
@@ -55,10 +55,10 @@ module DatabaseRewinder
55
55
  @inserted_tables = []
56
56
  end
57
57
 
58
- def with_automatic_reconnect(pool, &block)
58
+ def with_automatic_reconnect(pool)
59
59
  reconnect = pool.automatic_reconnect
60
60
  pool.automatic_reconnect = true
61
- block.call
61
+ yield
62
62
  ensure
63
63
  pool.automatic_reconnect = reconnect
64
64
  end
@@ -11,9 +11,20 @@ module DatabaseRewinder
11
11
  @only, @except = options[:only], options[:except]
12
12
  cleaners.each {|c| c.strategy = nil, options}
13
13
  end
14
+
15
+ def [](orm, connection: nil, **)
16
+ if connection.nil?
17
+ if orm.is_a? String
18
+ connection = orm
19
+ elsif orm.is_a?(Hash) && orm.has_key?(:connection)
20
+ connection = orm[:connection]
21
+ end
22
+ end
23
+ super connection
24
+ end
14
25
  end
15
26
  class << self
16
- include Compatibility
27
+ prepend Compatibility
17
28
  end
18
29
 
19
30
  class Cleaner
@@ -93,6 +93,11 @@ describe DatabaseRewinder do
93
93
  its(:inserted_tables) { should == ['foos'] }
94
94
  end
95
95
  end
96
+
97
+ context 'when database accepts INSERT IGNORE INTO statement' do
98
+ let(:sql) { "INSERT IGNORE INTO `foos` (`name`) VALUES ('alice'), ('bob') ON DUPLICATE KEY UPDATE `foos`.`updated_at`=VALUES(`updated_at`)" }
99
+ its(:inserted_tables) { should == ['foos'] }
100
+ end
96
101
  end
97
102
 
98
103
  describe '.clean' do
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_rewinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.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: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - <
45
+ - - "<"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.99'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - <
52
+ - - "<"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.99'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: A minimalist's tiny and ultra-fast database cleaner
@@ -87,8 +87,8 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
92
  - Gemfile
93
93
  - MIT_LICENSE
94
94
  - README.md
@@ -116,12 +116,12 @@ require_paths:
116
116
  - lib
117
117
  required_ruby_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - '>='
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - '>='
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []