uuid_associations-active_record 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: 7e1538fc45bf664d391c0a3b2b335247bdf0a66cc1f9133d3936000850175e9c
4
- data.tar.gz: '092c5dad84a0a0ae487ecc61516b43b7d0b0e19fe7e3a2805f1811602dbbd5ee'
3
+ metadata.gz: 7bd48c49180664455d830bf4877bab4a57001cba97d710d0ec104753c71a456c
4
+ data.tar.gz: e6259cc8ef51b92bc456b00cf89839c088823567afc8de1d605440c85e79b5d7
5
5
  SHA512:
6
- metadata.gz: 40acb305ecca02b540d97161942ef0bcf9161b1b5b07c4160df0adcb76a039e576da7a3afe53882bcb7501684b394170137f0c5df54df3eecf04fddf61ab7726
7
- data.tar.gz: f064f70789721a9b789a76f096098548fa409ac69f63b818d8a232b3112a4ee58d524a72e2b7611c3a862596a7b22a17eb556655154cee828319aa7adbf59490
6
+ metadata.gz: 8e94d8ffa58e122b70e09f60b9031de98510cb9452fa4b98a11f5b8225cb7474e995eb8dd1cff8e40efbf43ea05ac4e45b34a8211ae9a28f749352f16a61764e
7
+ data.tar.gz: 510166b160fc1c19ce2ac78215d92169246f64e41c335583e905110f5ed3aa205101aea8f308bb65105a6643f162b84b2d31ffe107d4a9e66310e1dd32dd41d0
data/README.md CHANGED
@@ -218,14 +218,13 @@ Here are some things to take into account:
218
218
  1. If the nested model (Comment in the example) does not have a column named `uuid`, the gem will take no action, will
219
219
  just preserve the original behavior.
220
220
  1. If the hash has both the `:id` and `:uuid` keys, the record will be fetched by `id`, and `uuid` will be passed as an attribute.
221
- 1. When the hash has a `:uuid` key and no record is found for that key, a new record will be created using that UUID
222
- (this will change to raise a not found error instead).
221
+ 1. When the hash has a `:uuid` key and no record is found for that key, an `ActiveRecord::RecordNotFound` error will be raised.
223
222
 
224
223
  ## Future Work
225
224
 
226
225
  1. Not commonly used by me, but testing and adding these methods to a `has_one` relationship.
227
- 1. Raise not found error if the array of UUIDs is bigger that the array
228
- of IDs fetched with the `where` statement (ActiveRecord's behavior).
226
+ 1. Raise not found error if the array of UUIDs is bigger that the array of IDs fetched with the `where` statement (ActiveRecord's behavior).
227
+ 1. Allow `accepts_nested_attributes_for` to take a configuration to allow the creation of new records if not found by UUID.
229
228
 
230
229
  ## Development
231
230
 
@@ -26,11 +26,13 @@ module UuidAssociations
26
26
 
27
27
  record = found_records.find { |found_record| found_record.uuid == uuid }
28
28
 
29
- collection << if record.blank?
30
- attributes
31
- else
32
- attributes.merge(id: record.id)
29
+ if record.blank?
30
+ raise ::ActiveRecord::RecordNotFound.new(
31
+ "Couldn't find #{association_klass.name} with UUID=#{uuid}", association_klass, :id, uuid
32
+ )
33
33
  end
34
+
35
+ collection << attributes.merge(id: record.id)
34
36
  end
35
37
 
36
38
  to_keep + replaced
@@ -1,5 +1,5 @@
1
1
  module UuidAssociations
2
2
  module ActiveRecord
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
@@ -10,20 +10,19 @@ RSpec.describe 'nested attributes for collection' do
10
10
  end
11
11
 
12
12
  context 'when creating a new record' do
13
- it 'creates nested resources when not existing UUID is passed' do
13
+ let(:uuid) { SecureRandom.uuid }
14
+
15
+ it 'raises an expception if no record is found with the specified UUID' do
14
16
  expect do
15
17
  Post.create!(
16
18
  uuid: SecureRandom.uuid,
17
19
  content: 'post',
18
20
  comments_attributes: [
19
21
  body: 'New comment',
20
- uuid: SecureRandom.uuid
22
+ uuid: uuid
21
23
  ]
22
24
  )
23
- end.to change(Post, :count).from(0).to(1)
24
- .and change(Comment, :count).from(0).to(1)
25
-
26
- expect(Post.first.comments.count).to eq(1)
25
+ end.to raise_error(ActiveRecord::RecordNotFound, "Couldn't find Comment with UUID=#{uuid}")
27
26
  end
28
27
 
29
28
  it 'creates nested resources when no UUID or ID is passed' do
@@ -17,7 +17,9 @@ RSpec.describe UuidAssociations::ActiveRecord::NestedAttributes::UuidFinder do
17
17
  context 'when record with specified UUID does not exist on the sytem' do
18
18
  let(:attribute_collection) { [{ uuid: SecureRandom.uuid, body: 'new comment :/' }] }
19
19
 
20
- it { is_expected.to match_array(attribute_collection) }
20
+ it 'raises a not found error' do
21
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
22
+ end
21
23
  end
22
24
  end
23
25
 
@@ -47,7 +49,9 @@ RSpec.describe UuidAssociations::ActiveRecord::NestedAttributes::UuidFinder do
47
49
  context 'when record with specified UUID does not exist on the sytem' do
48
50
  let(:attribute_collection) { { first: { uuid: SecureRandom.uuid, body: 'new comment :/' } } }
49
51
 
50
- it { is_expected.to match_array(attribute_collection.values) }
52
+ it 'raises a not found error' do
53
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
54
+ end
51
55
  end
52
56
  end
53
57
 
@@ -12,6 +12,9 @@ Gem::Specification.new do |spec|
12
12
  spec.description = 'Adds association_uuids= method on has_many and has_and_belongs_to_many associations'
13
13
  spec.homepage = 'https://github.com/mcelicalderon/uuid_associations-active_record'
14
14
  spec.license = 'MIT'
15
+ spec.metadata = {
16
+ 'source_code_uri' => 'https://github.com/mcelicalderon/uuid_associations-active_record'
17
+ }
15
18
 
16
19
  spec.files = `git ls-files -z`.split("\x0")
17
20
  spec.test_files = spec.files.grep(%r{^spec\/})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uuid_associations-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Celi
@@ -165,7 +165,8 @@ files:
165
165
  homepage: https://github.com/mcelicalderon/uuid_associations-active_record
166
166
  licenses:
167
167
  - MIT
168
- metadata: {}
168
+ metadata:
169
+ source_code_uri: https://github.com/mcelicalderon/uuid_associations-active_record
169
170
  post_install_message:
170
171
  rdoc_options: []
171
172
  require_paths: