roqua-support 0.1.2.2 → 0.1.3

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: 0ac53c450b17e874859934e55be62b8ddc7ae00d
4
- data.tar.gz: 2f54b672a70529b33ee906ee88788c3f736e98ec
3
+ metadata.gz: 43a3414d9e81150939fa2856d06119486f2901e2
4
+ data.tar.gz: 0045f7cbe60fd4bf49ca7aea4eb53aaffcd5b1ad
5
5
  SHA512:
6
- metadata.gz: 144657fabc0578bd624c3e28a098da7c3f8623791c87cf1bb40dd5433bbb21e6179c663c201699bf9ef08f87a712363a54a522c1c7c3b765d567005fd2f4bdc6
7
- data.tar.gz: 9f26d2f6fb732c0fc89f54619371d12e45804cff76099f1b708ebfccf63c373c9426a51e89e984197ac64e8eaa890354621583e1e1d46f5a1ee4ce9608fa5bef
6
+ metadata.gz: 5598469b76b2db4761c05b40ba12d533dac4a85160537fd7c6da0b8eeeaefeead355fef69e7c6c9abc8566b28e090dcc3eb344e1b15541c06addadbe60524f15
7
+ data.tar.gz: d27f814a7fee1c1009656f386d547c0df7a05612dfba06c330513a4e4e5ace7ed5fefc90570975b0aca573273248ff05f7d0370a463867b12cc1e233f175e9c7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.3 / 2014-02-24
2
+
3
+ * Add ActiveRecord \#uniq\_find\_or\_create\_by method to find or create records with uniqueness constraints enforced by the database.
4
+
1
5
  ## 0.1.2.1
2
6
 
3
7
  * Bugfixes for Errors.
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- roqua-support (0.1.2.2)
4
+ roqua-support (0.1.3)
5
5
  activesupport (>= 3.2, < 5.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (4.0.2)
10
+ activesupport (4.0.3)
11
11
  i18n (~> 0.6, >= 0.6.4)
12
12
  minitest (~> 4.2)
13
13
  multi_json (~> 1.3)
@@ -24,9 +24,9 @@ GEM
24
24
  rspec-expectations (~> 2.14.0)
25
25
  rspec-mocks (~> 2.14.0)
26
26
  rspec-core (2.14.7)
27
- rspec-expectations (2.14.4)
27
+ rspec-expectations (2.14.5)
28
28
  diff-lcs (>= 1.1.3, < 2.0)
29
- rspec-mocks (2.14.4)
29
+ rspec-mocks (2.14.6)
30
30
  thread_safe (0.1.3)
31
31
  atomic
32
32
  tzinfo (0.3.38)
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module Support
3
- VERSION = "0.1.2.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ require 'active_support'
2
+
3
+ module ActiveRecord
4
+ class Base
5
+ def self.uniq_find_or_create_by(attributes, &block)
6
+ record = find_or_create_by(attributes, &block)
7
+ rescue ActiveRecord::RecordNotUnique
8
+ ensure
9
+ return find_by(attributes) || record
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ require 'roqua/core_ext/activerecord/uniq_find_or_create'
2
+
3
+ module ActiveRecord
4
+ class Base
5
+ def self.find_by(attributes)
6
+ end
7
+ end
8
+
9
+ class RecordNotUnique < StandardError
10
+ end
11
+ end
12
+
13
+ describe ActiveRecord::Base do
14
+ describe '#uniq_find_or_create_by' do
15
+ let(:attributes) { double('attributes') }
16
+ let(:block) { -> {} }
17
+ let(:record) { double('record') }
18
+
19
+ it 'tries to find or create a record by the attributes provided' do
20
+ expect(ActiveRecord::Base).to receive(:find_or_create_by).with(attributes, &block)
21
+ ActiveRecord::Base.uniq_find_or_create_by attributes, &block
22
+ end
23
+
24
+ it 'returns a preexisting or created record by querying it' do
25
+ allow(ActiveRecord::Base).to receive(:find_by).with(attributes).and_return record
26
+ expect(ActiveRecord::Base.uniq_find_or_create_by attributes, &block).to eq(record)
27
+ end
28
+
29
+ it 'returns a concurrenlty created record' do
30
+ allow(ActiveRecord::Base).to receive(:find_by).with(attributes).and_return record
31
+ allow(ActiveRecord::Base).to receive(:find_or_create_by).with(attributes, &block)
32
+ .and_raise ActiveRecord::RecordNotUnique
33
+ expect(ActiveRecord::Base.uniq_find_or_create_by attributes, &block).to eq(record)
34
+ end
35
+
36
+ it 'returns a created record for inspection when saving fails for some reason' do
37
+ allow(ActiveRecord::Base).to receive(:find_or_create_by).with(attributes, &block).and_return record
38
+ expect(ActiveRecord::Base.uniq_find_or_create_by attributes, &block).to eq(record)
39
+ end
40
+ end
41
+ end
@@ -36,6 +36,7 @@ describe 'Error reporting' do
36
36
 
37
37
  it 'sends notifications to appsignal' do
38
38
  stub_const("Appsignal", Module.new)
39
+ Appsignal.stub(active?: true)
39
40
  Appsignal.stub(is_ignored_exception?: false, agent: agent)
40
41
  stub_const("Appsignal::Transaction", double("Transaction", create: transaction))
41
42
 
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.2.2
4
+ version: 0.1.3
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-02-12 00:00:00.000000000 Z
11
+ date: 2014-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -95,6 +95,7 @@ files:
95
95
  - Rakefile
96
96
  - lib/roqua-support.rb
97
97
  - lib/roqua-support/version.rb
98
+ - lib/roqua/core_ext/activerecord/uniq_find_or_create.rb
98
99
  - lib/roqua/core_ext/array/stable_sort_by.rb
99
100
  - lib/roqua/core_ext/enumerable/sort_by_alphanum.rb
100
101
  - lib/roqua/core_ext/fabrication/singleton.rb
@@ -106,6 +107,7 @@ files:
106
107
  - lib/roqua/support/logging.rb
107
108
  - lib/roqua/support/request_logger.rb
108
109
  - roqua-support.gemspec
110
+ - spec/roqua/core_ext/activerecord/uniq_find_or_create_spec.rb
109
111
  - spec/roqua/core_ext/array/stable_sort_by_spec.rb
110
112
  - spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
111
113
  - spec/roqua/core_ext/fabrication/singleton_spec.rb
@@ -139,6 +141,7 @@ signing_key:
139
141
  specification_version: 4
140
142
  summary: Helper objects and proxies used by a lot of RoQua applications
141
143
  test_files:
144
+ - spec/roqua/core_ext/activerecord/uniq_find_or_create_spec.rb
142
145
  - spec/roqua/core_ext/array/stable_sort_by_spec.rb
143
146
  - spec/roqua/core_ext/enumerable/sort_by_alphanum_spec.rb
144
147
  - spec/roqua/core_ext/fabrication/singleton_spec.rb