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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 504f8883ad45f75b004de4cbf3dbf5aa1e9e12bc
4
- data.tar.gz: 1076be76ce857bc401a2222e7c1459cf9f300901
3
+ metadata.gz: 410e4fb105669f81e2f5d2597bfce8e70067ce22
4
+ data.tar.gz: 242bab7a1495a4b232b1ef25f99eef6f307c657d
5
5
  SHA512:
6
- metadata.gz: 41286eb7d5bcf95c24c39d67ac6c5d35460d66514ead66bebcbcda7256c8322ab7706058c1920ffceb00e1fd9e887baa05285d8eb43fd40e03c438b4b8f2f648
7
- data.tar.gz: b1401bde9eb82be62b2d90750adfbaae6b23349054e088b9142db8b8ddfabdde92841c7a61701a24a53bb183d49e2b3b5f9301b4cdefd4c6bcdf1a8ef39b13ee
6
+ metadata.gz: b36a19677807863f4dafee0c9bc939b89ba922f76b1493610746b0c54a06dc8aa29e3fbed82c4992e1c72591e605c36fc9640680e316294cb733a2b578940ab6
7
+ data.tar.gz: 410dbbf82a0172b9604dc2c5ca91a5352a8b095f715a8c9347aff46e51a5699d761d316c0e4c89887924d1d27ef6ad820593b16ca095b780ed4ad8eae66a5efc
data/lib/lhs.rb CHANGED
@@ -40,6 +40,9 @@ module LHS
40
40
  autoload :Record,
41
41
  'lhs/record'
42
42
 
43
+ autoload :Unprocessable,
44
+ 'lhs/unprocessable'
45
+
43
46
  include Configuration
44
47
  include AutoloadRecords if defined?(Rails)
45
48
 
@@ -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? Array
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
- else
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))
@@ -0,0 +1,4 @@
1
+ module LHS
2
+ class Unprocessable < StandardError
3
+ end
4
+ end
data/lib/lhs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '14.1.0'
2
+ VERSION = '14.1.1'
3
3
  end
@@ -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
@@ -33,50 +33,70 @@ describe LHS::Record do
33
33
  end
34
34
  end
35
35
 
36
- it 'raises if nothing was found' do
37
- stub_request(:get, "#{datastore}/feedbacks/not-existing")
38
- .to_return(status: 404)
39
- expect { Record.find('not-existing') }.to raise_error LHC::NotFound
40
- end
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
- it 'finds unique item by providing parameters' do
43
- stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
44
- .to_return(body: "{}")
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
- it 'returns item in case of backend returning collection' do
50
- data = JSON.parse(load_json(:feedbacks))
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
- it 'fails when multiple items where found by parameters' do
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
- it 'fails when no item as found by parameters' do
67
- data = JSON.parse(load_json(:feedbacks))
68
- data['items'] = []
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
- it 'raises if nothing was found with parameters' do
77
- stub_request(:get, "#{datastore}/content-ads/123/feedbacks/123")
78
- .to_return(status: 404)
79
- expect { Record.find(campaign_id: '123', id: '123') }.to raise_error LHC::NotFound
80
- end
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.0
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-19 00:00:00.000000000 Z
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.8
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