roqua-support 0.1.4 → 0.1.5
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62b713d3e5154df4114e38724df34637620903af
|
4
|
+
data.tar.gz: 9248b7cc7833517983955066fe280e5fda61a673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a34115a92fdc6f8b30dbd835b68e1921eb9c519e80122890df104428b7ea9f91f1decb9d1aff568cefd23ba8d7a2d3c55cb4d1effebd28f1cf39d014844114f1
|
7
|
+
data.tar.gz: 037d2ca3d79ae8d2cd722e5abfd88dde320fdb8698662af6dbec7cea04b7ed27c790306802243568e5dd9a16eae2a8a3a4f5654b626de5af3a49f6ba3812c9e4
|
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.5)
|
5
5
|
activesupport (>= 3.2, < 5.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -44,7 +44,7 @@ GEM
|
|
44
44
|
lumberjack (1.0.4)
|
45
45
|
method_source (0.8.2)
|
46
46
|
minitest (4.7.5)
|
47
|
-
multi_json (1.
|
47
|
+
multi_json (1.9.0)
|
48
48
|
nio4r (1.0.0)
|
49
49
|
pry (0.9.12.6)
|
50
50
|
coderay (~> 1.0)
|
@@ -9,16 +9,16 @@ module ActiveRecord
|
|
9
9
|
# containing the validation errors is returned instead.
|
10
10
|
def self.uniq_find_or_create_by(attributes, &block)
|
11
11
|
record = find_or_create_by(attributes, &block)
|
12
|
-
rescue ActiveRecord::RecordNotUnique
|
12
|
+
rescue ActiveRecord::RecordNotUnique => exception
|
13
13
|
ensure
|
14
|
-
return find_by(attributes) || record
|
14
|
+
return find_by(attributes) || record || raise(exception)
|
15
15
|
end
|
16
16
|
|
17
17
|
# Use this method if you want an exception to be raised when creating a new record fails due to some validation
|
18
18
|
# error other than uniqueness.
|
19
19
|
def self.uniq_find_or_create_by!(attributes, &block)
|
20
20
|
find_or_create_by!(attributes, &block)
|
21
|
-
rescue ActiveRecord::RecordNotUnique
|
21
|
+
rescue ActiveRecord::RecordNotUnique => exception
|
22
22
|
rescue ActiveRecord::RecordInvalid => exception
|
23
23
|
ensure
|
24
24
|
return find_by(attributes) || raise(exception)
|
@@ -20,7 +20,7 @@ describe ActiveRecord::Base do
|
|
20
20
|
|
21
21
|
describe '#uniq_find_or_create_by' do
|
22
22
|
it 'tries to find or create a record by the attributes provided' do
|
23
|
-
expect(ActiveRecord::Base).to receive(:find_or_create_by).with(attributes, &block)
|
23
|
+
expect(ActiveRecord::Base).to receive(:find_or_create_by).with(attributes, &block).and_return record
|
24
24
|
ActiveRecord::Base.uniq_find_or_create_by attributes, &block
|
25
25
|
end
|
26
26
|
|
@@ -36,6 +36,15 @@ describe ActiveRecord::Base do
|
|
36
36
|
expect(ActiveRecord::Base.uniq_find_or_create_by attributes, &block).to eq(record)
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'raises when a concurrent record is detected by the database but could not be queried for unknown reasons' do
|
40
|
+
allow(ActiveRecord::Base).to receive(:find_by).with(attributes).and_return nil
|
41
|
+
allow(ActiveRecord::Base).to receive(:find_or_create_by).with(attributes, &block)
|
42
|
+
.and_raise ActiveRecord::RecordNotUnique
|
43
|
+
expect do
|
44
|
+
ActiveRecord::Base.uniq_find_or_create_by attributes, &block
|
45
|
+
end.to raise_error ActiveRecord::RecordNotUnique
|
46
|
+
end
|
47
|
+
|
39
48
|
it 'returns the created record for inspection when validation fails' do
|
40
49
|
allow(ActiveRecord::Base).to receive(:find_or_create_by).with(attributes, &block).and_return record
|
41
50
|
expect(ActiveRecord::Base.uniq_find_or_create_by attributes, &block).to eq(record)
|
@@ -61,6 +70,15 @@ describe ActiveRecord::Base do
|
|
61
70
|
expect(ActiveRecord::Base.uniq_find_or_create_by! attributes, &block).to eq(record)
|
62
71
|
end
|
63
72
|
|
73
|
+
it 'raises when a concurrent record is detected by the database but could not be queried for unknown reasons' do
|
74
|
+
allow(ActiveRecord::Base).to receive(:find_by).with(attributes).and_return nil
|
75
|
+
allow(ActiveRecord::Base).to receive(:find_or_create_by!).with(attributes, &block)
|
76
|
+
.and_raise ActiveRecord::RecordNotUnique
|
77
|
+
expect do
|
78
|
+
ActiveRecord::Base.uniq_find_or_create_by! attributes, &block
|
79
|
+
end.to raise_error ActiveRecord::RecordNotUnique
|
80
|
+
end
|
81
|
+
|
64
82
|
it 'raises when creating a new record causes validation failures not due to concurrency' do
|
65
83
|
exception = ActiveRecord::RecordInvalid.new 'some_validation_error'
|
66
84
|
allow(ActiveRecord::Base).to receive(:find_or_create_by!).with(attributes, &block).and_raise exception
|
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.5
|
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-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|