roqua-support 0.1.7 → 0.1.8
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +2 -2
- data/circle.yml +3 -0
- data/lib/roqua-support/version.rb +1 -1
- data/lib/roqua/core_ext/activerecord/uniq_find_or_create.rb +12 -0
- data/spec/roqua/core_ext/activerecord/uniq_find_or_create_spec.rb +20 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d04050aedf6fdfafa5b9a9a6cabc22b11f57f215
|
4
|
+
data.tar.gz: 06c935c3e34b4d9b402d63717a4800d398d0d127
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4d6e986f2ab7560d71eba134b8f2b2b5dc8407c7ce01fa59af20f6ca828b9646fe5551e370289e03efd0ce3f702ce9feff6df7e5f887905d695446031c8870b
|
7
|
+
data.tar.gz: 1a33aae58fd341f06e1695de7e1af81f8f170dde10fdd804fa48eff30235462279fdd3a6f3d97e629a620912fa5909363d9dbb57ef2d0b1ee675eb5199bfc8df
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
roqua-support (0.1.
|
4
|
+
roqua-support (0.1.8)
|
5
5
|
activesupport (>= 3.2, < 5.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -64,7 +64,7 @@ GEM
|
|
64
64
|
ruby-progressbar (1.4.1)
|
65
65
|
slop (3.4.7)
|
66
66
|
thor (0.18.1)
|
67
|
-
thread_safe (0.3.
|
67
|
+
thread_safe (0.3.4)
|
68
68
|
timers (1.1.0)
|
69
69
|
tzinfo (1.1.0)
|
70
70
|
thread_safe (~> 0.1)
|
data/circle.yml
ADDED
@@ -9,6 +9,12 @@ module ActiveRecord
|
|
9
9
|
# containing the validation errors is returned instead.
|
10
10
|
def self.uniq_find_or_create_by(attributes, &block)
|
11
11
|
find_or_create_by(attributes, &block)
|
12
|
+
# When a real race condition occurs, activerecord has no clue about a uniqueness constraint
|
13
|
+
# being violated (this is exactly why validates :attribute, uniqueness: true does not work
|
14
|
+
# for these cases) and a plain Mysql2::Error exception is raised instead of
|
15
|
+
# ActiveRecord::RecordNotUnique
|
16
|
+
rescue Mysql2::Error => exception
|
17
|
+
find_by(attributes) || raise(exception)
|
12
18
|
rescue ActiveRecord::RecordNotUnique => exception
|
13
19
|
find_by(attributes) || raise(exception)
|
14
20
|
end
|
@@ -17,6 +23,12 @@ module ActiveRecord
|
|
17
23
|
# error other than uniqueness.
|
18
24
|
def self.uniq_find_or_create_by!(attributes, &block)
|
19
25
|
find_or_create_by!(attributes, &block)
|
26
|
+
# When a real race condition occurs, activerecord has no clue about a uniqueness constraint
|
27
|
+
# being violated (this is exactly why validates :attribute, uniqueness: true does not work
|
28
|
+
# for these cases) and a plain Mysql2::Error exception is raised instead of
|
29
|
+
# ActiveRecord::RecordNotUnique
|
30
|
+
rescue Mysql2::Error => exception
|
31
|
+
find_by(attributes) || raise(exception)
|
20
32
|
rescue ActiveRecord::RecordNotUnique => exception
|
21
33
|
find_by(attributes) || raise(exception)
|
22
34
|
rescue ActiveRecord::RecordInvalid => exception
|
@@ -13,9 +13,14 @@ module ActiveRecord
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
module Mysql2
|
17
|
+
class Error < StandardError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
16
21
|
describe ActiveRecord::Base do
|
17
22
|
let(:attributes) { double('attributes') }
|
18
|
-
let(:block) { -> {} }
|
23
|
+
let(:block) { -> (*args){} }
|
19
24
|
let(:record) { double('record') }
|
20
25
|
|
21
26
|
describe '#uniq_find_or_create_by' do
|
@@ -36,6 +41,13 @@ describe ActiveRecord::Base do
|
|
36
41
|
expect(ActiveRecord::Base.uniq_find_or_create_by attributes, &block).to eq(record)
|
37
42
|
end
|
38
43
|
|
44
|
+
it 'returns a concurrenlty created record when activerecord is unaware of the uniqueness violation' do
|
45
|
+
allow(ActiveRecord::Base).to receive(:find_by).with(attributes).and_return record
|
46
|
+
allow(ActiveRecord::Base).to receive(:find_or_create_by).with(attributes, &block)
|
47
|
+
.and_raise Mysql2::Error
|
48
|
+
expect(ActiveRecord::Base.uniq_find_or_create_by attributes, &block).to eq(record)
|
49
|
+
end
|
50
|
+
|
39
51
|
it 'raises when a concurrent record is detected by the database but could not be queried for unknown reasons' do
|
40
52
|
allow(ActiveRecord::Base).to receive(:find_by).with(attributes).and_return nil
|
41
53
|
allow(ActiveRecord::Base).to receive(:find_or_create_by).with(attributes, &block)
|
@@ -70,6 +82,13 @@ describe ActiveRecord::Base do
|
|
70
82
|
expect(ActiveRecord::Base.uniq_find_or_create_by! attributes, &block).to eq(record)
|
71
83
|
end
|
72
84
|
|
85
|
+
it 'returns a concurrenlty created record when activerecord is unaware of the uniqueness violation' do
|
86
|
+
allow(ActiveRecord::Base).to receive(:find_by).with(attributes).and_return record
|
87
|
+
allow(ActiveRecord::Base).to receive(:find_or_create_by!).with(attributes, &block)
|
88
|
+
.and_raise Mysql2::Error
|
89
|
+
expect(ActiveRecord::Base.uniq_find_or_create_by! attributes, &block).to eq(record)
|
90
|
+
end
|
91
|
+
|
73
92
|
it 'raises when a concurrent record is detected by the database but could not be queried for unknown reasons' do
|
74
93
|
allow(ActiveRecord::Base).to receive(:find_by).with(attributes).and_return nil
|
75
94
|
allow(ActiveRecord::Base).to receive(:find_or_create_by!).with(attributes, &block)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roqua-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- LICENSE.txt
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
|
+
- circle.yml
|
97
98
|
- lib/roqua-support.rb
|
98
99
|
- lib/roqua-support/version.rb
|
99
100
|
- lib/roqua/core_ext/activerecord/uniq_find_or_create.rb
|
@@ -137,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
140
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.2.
|
141
|
+
rubygems_version: 2.2.1
|
141
142
|
signing_key:
|
142
143
|
specification_version: 4
|
143
144
|
summary: Helper objects and proxies used by a lot of RoQua applications
|