lhs 1.6.1 → 2.0.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 +4 -4
- data/docs/items.md +1 -0
- data/lib/lhs/concerns/item/update.rb +8 -3
- data/lib/lhs/data.rb +0 -28
- data/lib/lhs/item.rb +1 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/data/item_spec.rb +0 -12
- data/spec/item/update_spec.rb +9 -1
- metadata +2 -4
- data/spec/data/pagination_spec.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 911fecf1a1b1e1d5a011b185b4d6ba8fb63f7445
|
4
|
+
data.tar.gz: 24b82515d4cfe87227d949afe0cd23048962bce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43a4a6f1605313a18ce9f26e00aafa80e11530d99c2f52e3fab6bf26fd40a4e249af9ab87f854e76a4b335df26940deb27e1a5ad8bbdc39481bb9a0aa80ca46e
|
7
|
+
data.tar.gz: 66e736a905f730e2216fe676051f16436437c45e7ca1f393c0169e13204d511b3f44f3d8c2b66ef66f5fbd9024cf7046fd13f0dbd7920213538667ee13948bd4
|
data/docs/items.md
CHANGED
@@ -39,6 +39,7 @@ You can persist changes like you would usually do with `save`.
|
|
39
39
|
## Update
|
40
40
|
|
41
41
|
`update` will return false if persisting fails. `update!` instead will an raise exception.
|
42
|
+
Update always updates the data of the local object first, before it tries to sync with an endpoint.
|
42
43
|
|
43
44
|
```ruby
|
44
45
|
feedback = Feedback.find('1z-5r1fkaj')
|
@@ -15,9 +15,14 @@ class LHS::Item < LHS::Proxy
|
|
15
15
|
|
16
16
|
def update!(params)
|
17
17
|
service = _data._root._service
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
_data.merge_raw!(LHS::Data.new(params))
|
19
|
+
response_data = service.instance.request(
|
20
|
+
method: :post,
|
21
|
+
url: href,
|
22
|
+
body: _data.to_json,
|
23
|
+
headers: {'Content-Type' => 'application/json'}
|
24
|
+
)
|
25
|
+
_data.merge_raw!(response_data)
|
21
26
|
true
|
22
27
|
end
|
23
28
|
end
|
data/lib/lhs/data.rb
CHANGED
@@ -33,34 +33,6 @@ class LHS::Data
|
|
33
33
|
_root._service
|
34
34
|
end
|
35
35
|
|
36
|
-
def current_page
|
37
|
-
offset + 1
|
38
|
-
end
|
39
|
-
|
40
|
-
def first_page
|
41
|
-
1
|
42
|
-
end
|
43
|
-
|
44
|
-
def last_page
|
45
|
-
total_pages
|
46
|
-
end
|
47
|
-
|
48
|
-
def prev_page
|
49
|
-
current_page - 1
|
50
|
-
end
|
51
|
-
|
52
|
-
def next_page
|
53
|
-
current_page + 1
|
54
|
-
end
|
55
|
-
|
56
|
-
def limit_value
|
57
|
-
limit
|
58
|
-
end
|
59
|
-
|
60
|
-
def total_pages
|
61
|
-
total / limit
|
62
|
-
end
|
63
|
-
|
64
36
|
protected
|
65
37
|
|
66
38
|
# Use existing mapping to provide data
|
data/lib/lhs/item.rb
CHANGED
data/lib/lhs/version.rb
CHANGED
data/spec/data/item_spec.rb
CHANGED
@@ -41,16 +41,4 @@ describe LHS::Data do
|
|
41
41
|
expect(item.valid_from).to be_kind_of Date
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
45
|
-
context 'different date time formats' do
|
46
|
-
let(:item) do
|
47
|
-
item = data[0]
|
48
|
-
item._raw[:created_date] = '2016-07-09T13:45:00+00:00'
|
49
|
-
item
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'returns TimeWithZone if string can be parsed as date_time' do
|
53
|
-
expect(item.created_date).to be_kind_of ActiveSupport::TimeWithZone
|
54
|
-
end
|
55
|
-
end
|
56
44
|
end
|
data/spec/item/update_spec.rb
CHANGED
@@ -38,10 +38,18 @@ describe LHS::Item do
|
|
38
38
|
|
39
39
|
it 'merges reponse data with object' do
|
40
40
|
stub_request(:post, item.href)
|
41
|
-
|
41
|
+
.to_return(status: 200, body: item._raw.merge(likes: 'Banana').to_json)
|
42
42
|
item.update(name: 'Steve')
|
43
43
|
expect(item.likes).to eq 'Banana'
|
44
44
|
end
|
45
|
+
|
46
|
+
it 'updates local version of an object even if BE request fails' do
|
47
|
+
stub_request(:post, item.href)
|
48
|
+
.to_return(status: 400, body: item._raw.merge(likes: 'Banana').to_json)
|
49
|
+
item.update(name: 'Andrea')
|
50
|
+
expect(item.name).to eq 'Andrea'
|
51
|
+
expect(item.likes).to_not eq 'Banana'
|
52
|
+
end
|
45
53
|
end
|
46
54
|
|
47
55
|
context 'update!' do
|
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- local.ch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -167,7 +167,6 @@ files:
|
|
167
167
|
- spec/data/collection_spec.rb
|
168
168
|
- spec/data/item_spec.rb
|
169
169
|
- spec/data/merge_spec.rb
|
170
|
-
- spec/data/pagination_spec.rb
|
171
170
|
- spec/data/raw_spec.rb
|
172
171
|
- spec/data/respond_to_spec.rb
|
173
172
|
- spec/data/root_spec.rb
|
@@ -280,7 +279,6 @@ test_files:
|
|
280
279
|
- spec/data/collection_spec.rb
|
281
280
|
- spec/data/item_spec.rb
|
282
281
|
- spec/data/merge_spec.rb
|
283
|
-
- spec/data/pagination_spec.rb
|
284
282
|
- spec/data/raw_spec.rb
|
285
283
|
- spec/data/respond_to_spec.rb
|
286
284
|
- spec/data/root_spec.rb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe LHS::Data do
|
4
|
-
context 'pagination' do
|
5
|
-
let(:datastore) { 'http://local.ch/v2' }
|
6
|
-
let(:record) { Feedback.where(entry_id: 1) }
|
7
|
-
let(:total) { 200 }
|
8
|
-
let(:total_pages) { total / limit }
|
9
|
-
let(:current_page) { offset + 1 }
|
10
|
-
let(:prev_page) { current_page - 1 }
|
11
|
-
let(:next_page) { current_page + 1 }
|
12
|
-
let(:offset) { 0 }
|
13
|
-
let(:limit) { 10 }
|
14
|
-
let(:body_json) do
|
15
|
-
{
|
16
|
-
items: [],
|
17
|
-
total: total,
|
18
|
-
offset: offset,
|
19
|
-
limit: limit
|
20
|
-
}.to_json
|
21
|
-
end
|
22
|
-
|
23
|
-
before(:each) do
|
24
|
-
LHC.config.placeholder('datastore', datastore)
|
25
|
-
class Feedback < LHS::Service
|
26
|
-
endpoint ':datastore/feedbacks'
|
27
|
-
end
|
28
|
-
stub_request(:get, 'http://local.ch/v2/feedbacks?entry_id=1')
|
29
|
-
.to_return(body: body_json)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'responds to limit_value' do
|
33
|
-
expect(record.limit_value).to eq(limit)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'responds to total_pages' do
|
37
|
-
expect(record.total_pages).to eq(total_pages)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'responds to current_page' do
|
41
|
-
expect(record.current_page).to eq(current_page)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'responds to first_page' do
|
45
|
-
expect(record.first_page).to eq(1)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'responds to last_page' do
|
49
|
-
expect(record.last_page).to eq(total_pages)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'responds to prev_page' do
|
53
|
-
expect(record.prev_page).to eq(prev_page)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'responds to next_page' do
|
57
|
-
expect(record.next_page).to eq(next_page)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|