lhs 14.1.0 → 14.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhs.rb +3 -0
- data/lib/lhs/concerns/record/find.rb +5 -2
- data/lib/lhs/concerns/record/find_by.rb +1 -0
- data/lib/lhs/unprocessable.rb +4 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/record/find_by_spec.rb +4 -0
- data/spec/record/find_spec.rb +59 -39
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 410e4fb105669f81e2f5d2597bfce8e70067ce22
|
4
|
+
data.tar.gz: 242bab7a1495a4b232b1ef25f99eef6f307c657d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b36a19677807863f4dafee0c9bc939b89ba922f76b1493610746b0c54a06dc8aa29e3fbed82c4992e1c72591e605c36fc9640680e316294cb733a2b578940ab6
|
7
|
+
data.tar.gz: 410dbbf82a0172b9604dc2c5ca91a5352a8b095f715a8c9347aff46e51a5699d761d316c0e4c89887924d1d27ef6ad820593b16ca095b780ed4ad8eae66a5efc
|
data/lib/lhs.rb
CHANGED
@@ -9,8 +9,9 @@ class LHS::Record
|
|
9
9
|
# Find a single uniqe record
|
10
10
|
def find(*args)
|
11
11
|
args, options = process_args(args)
|
12
|
+
raise(LHS::Unprocessable.new, 'Cannot find Record without an ID') if args.blank? && !args.is_a?(Array)
|
12
13
|
data =
|
13
|
-
if args.is_a?
|
14
|
+
if args.present? && args.is_a?(Array)
|
14
15
|
find_in_parallel(args, options)
|
15
16
|
elsif args.is_a? Hash
|
16
17
|
find_with_parameters(args, options)
|
@@ -65,8 +66,10 @@ class LHS::Record
|
|
65
66
|
options.merge(params: args)
|
66
67
|
elsif href?(args)
|
67
68
|
options.merge(url: args)
|
68
|
-
|
69
|
+
elsif args.present?
|
69
70
|
options.merge(params: { id: args })
|
71
|
+
else
|
72
|
+
options
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
@@ -21,6 +21,7 @@ class LHS::Record
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def _find_by(params, options = {})
|
24
|
+
raise(LHS::Unprocessable.new, 'Cannot find Record without an ID') if params.any? && params.all? { |_, value| value.blank? }
|
24
25
|
options ||= {}
|
25
26
|
params = params.dup.merge(limit: 1).merge(options.fetch(:params, {}))
|
26
27
|
data = request(options.merge(params: params))
|
data/lib/lhs/version.rb
CHANGED
data/spec/record/find_by_spec.rb
CHANGED
@@ -38,6 +38,10 @@ describe LHS::Record do
|
|
38
38
|
Record.find_by(has_reviews: true).id
|
39
39
|
).to eq json['items'].first['id']
|
40
40
|
end
|
41
|
+
|
42
|
+
it 'returns nil if empty id' do
|
43
|
+
expect { Record.find_by(id: '') }.to raise_error LHS::Unprocessable
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
context 'find_by!' do
|
data/spec/record/find_spec.rb
CHANGED
@@ -33,50 +33,70 @@ describe LHS::Record do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
context 'endpoint without identifier' do
|
37
|
+
before :each do
|
38
|
+
class LatestAGB < LHS::Record
|
39
|
+
endpoint 'agbs/latest'
|
40
|
+
end
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
data = Record.find(campaign_id: '123', id: '123')
|
46
|
-
expect(data._proxy).to be_kind_of LHS::Item
|
47
|
-
end
|
43
|
+
it 'finds a single unique record' do
|
44
|
+
stub_request(:get, 'http://agbs/latest')
|
45
|
+
.to_return(body: { pdf: 'http://local.ch/1.pdf' }.to_json)
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
data['items'] = [data['items'].first]
|
52
|
-
stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
|
53
|
-
.to_return(body: data.to_json)
|
54
|
-
data = Record.find(campaign_id: '123', id: '123')
|
55
|
-
expect(data._proxy).to be_kind_of LHS::Item
|
47
|
+
expect(LatestAGB.find.pdf).to eq 'http://local.ch/1.pdf'
|
48
|
+
end
|
56
49
|
end
|
57
50
|
|
58
|
-
|
59
|
-
stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
|
60
|
-
.to_return(body: load_json(:feedbacks))
|
61
|
-
expect(lambda {
|
62
|
-
Record.find(campaign_id: '123', id: '123')
|
63
|
-
}).to raise_error LHC::NotFound
|
64
|
-
end
|
51
|
+
end
|
65
52
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
|
70
|
-
.to_return(body: data.to_json)
|
71
|
-
expect(lambda {
|
72
|
-
Record.find(campaign_id: '123', id: '123')
|
73
|
-
}).to raise_error LHC::NotFound
|
74
|
-
end
|
53
|
+
it 'raises if empty id' do
|
54
|
+
expect { Record.find('') }.to raise_error LHS::Unprocessable
|
55
|
+
end
|
75
56
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
57
|
+
it 'raises if nothing was found' do
|
58
|
+
stub_request(:get, "#{datastore}/feedbacks/not-existing")
|
59
|
+
.to_return(status: 404)
|
60
|
+
expect { Record.find('not-existing') }.to raise_error LHC::NotFound
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'finds unique item by providing parameters' do
|
64
|
+
stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
|
65
|
+
.to_return(body: "{}")
|
66
|
+
data = Record.find(campaign_id: '123', id: '123')
|
67
|
+
expect(data._proxy).to be_kind_of LHS::Item
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns item in case of backend returning collection' do
|
71
|
+
data = JSON.parse(load_json(:feedbacks))
|
72
|
+
data['items'] = [data['items'].first]
|
73
|
+
stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
|
74
|
+
.to_return(body: data.to_json)
|
75
|
+
data = Record.find(campaign_id: '123', id: '123')
|
76
|
+
expect(data._proxy).to be_kind_of LHS::Item
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'fails when multiple items where found by parameters' do
|
80
|
+
stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
|
81
|
+
.to_return(body: load_json(:feedbacks))
|
82
|
+
expect(lambda {
|
83
|
+
Record.find(campaign_id: '123', id: '123')
|
84
|
+
}).to raise_error LHC::NotFound
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'fails when no item as found by parameters' do
|
88
|
+
data = JSON.parse(load_json(:feedbacks))
|
89
|
+
data['items'] = []
|
90
|
+
stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
|
91
|
+
.to_return(body: data.to_json)
|
92
|
+
expect(lambda {
|
93
|
+
Record.find(campaign_id: '123', id: '123')
|
94
|
+
}).to raise_error LHC::NotFound
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'raises if nothing was found with parameters' do
|
98
|
+
stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
|
99
|
+
.to_return(status: 404)
|
100
|
+
expect { Record.find(campaign_id: '123', id: '123') }.to raise_error LHC::NotFound
|
81
101
|
end
|
82
102
|
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: 14.1.
|
4
|
+
version: 14.1.1
|
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: 2017-09-
|
11
|
+
date: 2017-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- lib/lhs/railtie.rb
|
246
246
|
- lib/lhs/record.rb
|
247
247
|
- lib/lhs/test/request_cycle_cache_helper.rb
|
248
|
+
- lib/lhs/unprocessable.rb
|
248
249
|
- lib/lhs/version.rb
|
249
250
|
- script/ci/build.sh
|
250
251
|
- spec/.DS_Store
|
@@ -419,7 +420,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
419
420
|
requirements:
|
420
421
|
- Ruby >= 2.3.0
|
421
422
|
rubyforge_project:
|
422
|
-
rubygems_version: 2.6.
|
423
|
+
rubygems_version: 2.6.13
|
423
424
|
signing_key:
|
424
425
|
specification_version: 4
|
425
426
|
summary: Rails gem providing an easy, active-record-like interface for http json services
|