lhs 22.0.0 → 22.1.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: a749e7862bb20791a4a25fa5fdce92461ebfceaf6e30602c7e600f7342a69806
4
- data.tar.gz: eceb2d57d258630583394079f495474320354db45e15c205f66005b570abc448
3
+ metadata.gz: 6b42b1f0f10d4d0dcf31de3e65ed4ca0c3f7bcfded40e9897231b5ff09a9c472
4
+ data.tar.gz: 1c041ff80320d79d73ef02e9af30278d58e779c239044c3485eac9b5e047f8ee
5
5
  SHA512:
6
- metadata.gz: 9432edd5f7d4c2d76f873d21bb3e79c2bc54965e64d3a2df7aa8c06f64dbea479274adde5ea4d1f1acf3e128d4cc7af1fa8fb41bc801b6b3629e6ddbf1156667
7
- data.tar.gz: 719d291ec00314bf8061cbe72a6abab98e1466a7162dcd174588ffc57823b8509951eb2ed28a4be3d6b6e938bd0791ff26cab9f6d478dd49f50cf28139b3cdbf
6
+ metadata.gz: 1a33c68f7d0c82a6c54482fa3ba3986bac1dccc83d9284951fa0f95bf92c0cd17fe3283c62c1c9dee067769d0fe81daf5ca3c86b8c6f84c07ccc0c3977b108cc
7
+ data.tar.gz: fe26fa077139d670284ef136e6f702549bd1fd8e8d2c3bfd5f5d43dcd1dba3bf3ac72f7dca8ae70628184c85ff83908558353e0d835fa00052d21ab0539b88d8
data/README.md CHANGED
@@ -1607,6 +1607,21 @@ POST https://service.example.com/records/1z-5r1fkaj { body: "{ 'name': 'Starbuck
1607
1607
 
1608
1608
  ##### update
1609
1609
 
1610
+ ###### Directly via Record
1611
+
1612
+ ```ruby
1613
+ # app/controllers/some_controller.rb
1614
+
1615
+ Record.update(id: '1z-5r1fkaj', name: 'Steve')
1616
+
1617
+ ```
1618
+ ```
1619
+ GET https://service.example.com/records/1z-5r1fkaj
1620
+ { name: 'Steve' }
1621
+ ```
1622
+
1623
+ ###### per Instance
1624
+
1610
1625
  `update` persists the whole object after new parameters are applied through arguments.
1611
1626
 
1612
1627
  `update` will return false if persisting fails. `update!` instead will raise an exception.
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
5
+ class LHS::Record
6
+
7
+ module Update
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ class <<self
12
+ alias_method :update, :create
13
+ alias_method :update!, :create!
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class LHS::Record
4
+ autoload :AttributeAssignment,
5
+ 'lhs/concerns/record/attribute_assignment'
4
6
  autoload :Batch,
5
7
  'lhs/concerns/record/batch'
6
8
  autoload :Chainable,
@@ -45,9 +47,10 @@ class LHS::Record
45
47
  'lhs/concerns/record/scope'
46
48
  autoload :Tracing,
47
49
  'lhs/concerns/record/tracing'
48
- autoload :AttributeAssignment,
49
- 'lhs/concerns/record/attribute_assignment'
50
+ autoload :Update,
51
+ 'lhs/concerns/record/update'
50
52
 
53
+ include AttributeAssignment
51
54
  include Batch
52
55
  include Chainable
53
56
  include Configuration
@@ -72,7 +75,7 @@ class LHS::Record
72
75
  include Relations
73
76
  include Scope
74
77
  include Tracing
75
- include AttributeAssignment
78
+ include Update
76
79
 
77
80
  delegate :_proxy, :_endpoint, :merge_raw!, :select, :becomes, :respond_to?, to: :_data
78
81
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHS
4
- VERSION = '22.0.0'
4
+ VERSION = '22.1.0'
5
5
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHS::Record do
6
+ context 'update' do
7
+
8
+ before do
9
+ class Record < LHS::Record
10
+ endpoint 'http://datastore/records/{id}'
11
+ end
12
+ end
13
+
14
+ it 'allows to directly update a record without fetching it first' do
15
+ stub_request(:post, "http://datastore/records/123")
16
+ .with(body: { name: 'Steve' }.to_json)
17
+ .to_return(status: 200, body: {}.to_json)
18
+
19
+ Record.update(
20
+ id: '123',
21
+ name: 'Steve'
22
+ )
23
+ end
24
+
25
+ it 'does not fail during an error with update' do
26
+ stub_request(:post, "http://datastore/records/123")
27
+ .with(body: { name: 'Steve' }.to_json)
28
+ .to_return(status: 404, body: {}.to_json)
29
+
30
+ record = Record.update(
31
+ id: '123',
32
+ name: 'Steve'
33
+ )
34
+
35
+ expect(record.errors.status_code).to eq 404
36
+ end
37
+
38
+ it 'allows to directly update! a record without fetching it first' do
39
+ stub_request(:post, "http://datastore/records/123")
40
+ .with(body: { name: 'Steve' }.to_json)
41
+ .to_return(status: 200)
42
+
43
+ Record.update!(
44
+ id: '123',
45
+ name: 'Steve'
46
+ )
47
+ end
48
+
49
+ it 'raises an error when trying to update! but retrieving an error status' do
50
+ stub_request(:post, "http://datastore/records/123")
51
+ .with(body: { name: 'Steve' }.to_json)
52
+ .to_return(status: 404)
53
+
54
+ expect(-> {
55
+ Record.update!(
56
+ id: '123',
57
+ name: 'Steve'
58
+ )
59
+ }).to raise_error(LHC::NotFound)
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 22.0.0
4
+ version: 22.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-29 00:00:00.000000000 Z
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -312,6 +312,7 @@ files:
312
312
  - lib/lhs/concerns/record/request.rb
313
313
  - lib/lhs/concerns/record/scope.rb
314
314
  - lib/lhs/concerns/record/tracing.rb
315
+ - lib/lhs/concerns/record/update.rb
315
316
  - lib/lhs/config.rb
316
317
  - lib/lhs/data.rb
317
318
  - lib/lhs/endpoint.rb
@@ -530,6 +531,7 @@ files:
530
531
  - spec/record/to_hash_spec.rb
531
532
  - spec/record/to_json_spec.rb
532
533
  - spec/record/tracing_spec.rb
534
+ - spec/record/update_spec.rb
533
535
  - spec/record/where_chains_spec.rb
534
536
  - spec/record/where_spec.rb
535
537
  - spec/record/where_values_hash_spec.rb
@@ -757,6 +759,7 @@ test_files:
757
759
  - spec/record/to_hash_spec.rb
758
760
  - spec/record/to_json_spec.rb
759
761
  - spec/record/tracing_spec.rb
762
+ - spec/record/update_spec.rb
760
763
  - spec/record/where_chains_spec.rb
761
764
  - spec/record/where_spec.rb
762
765
  - spec/record/where_values_hash_spec.rb