lhs 15.3.1 → 15.3.2
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/.rubocop.localch.yml +158 -21
- data/.rubocop.yml +9 -3
- data/lhs.gemspec +10 -9
- data/lib/lhs/complex.rb +1 -1
- data/lib/lhs/concerns/autoload_records.rb +1 -1
- data/lib/lhs/concerns/collection/handle_nested.rb +1 -1
- data/lib/lhs/concerns/inspect.rb +1 -1
- data/lib/lhs/concerns/item/validation.rb +2 -2
- data/lib/lhs/concerns/proxy/accessors.rb +1 -1
- data/lib/lhs/concerns/proxy/problems.rb +1 -1
- data/lib/lhs/concerns/record/chainable.rb +1 -1
- data/lib/lhs/concerns/record/endpoints.rb +2 -2
- data/lib/lhs/concerns/record/model.rb +1 -1
- data/lib/lhs/concerns/record/request.rb +5 -5
- data/lib/lhs/data.rb +5 -4
- data/lib/lhs/endpoint.rb +1 -1
- data/lib/lhs/item.rb +8 -0
- data/lib/lhs/pagination/base.rb +0 -1
- data/lib/lhs/problems/base.rb +1 -1
- data/lib/lhs/record.rb +1 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/autoloading_spec.rb +4 -4
- data/spec/collection/accessors_spec.rb +1 -1
- data/spec/collection/collection_items_spec.rb +1 -1
- data/spec/collection/configurable_spec.rb +1 -1
- data/spec/collection/meta_data_spec.rb +1 -1
- data/spec/collection/to_a_spec.rb +1 -1
- data/spec/collection/to_ary_spec.rb +6 -2
- data/spec/collection/without_object_items_spec.rb +1 -1
- data/spec/complex/reduce_spec.rb +2 -2
- data/spec/concerns/record/request_spec.rb +1 -1
- data/spec/data/collection_spec.rb +1 -1
- data/spec/data/equality_spec.rb +1 -1
- data/spec/data/inspect_spec.rb +1 -1
- data/spec/data/is_item_or_collection_spec.rb +1 -1
- data/spec/data/item_spec.rb +1 -1
- data/spec/data/merge_spec.rb +1 -1
- data/spec/data/parent_spec.rb +1 -1
- data/spec/data/raw_spec.rb +1 -1
- data/spec/data/respond_to_spec.rb +3 -3
- data/spec/data/root_spec.rb +1 -1
- data/spec/data/select_spec.rb +1 -1
- data/spec/data/to_ary_spec.rb +26 -0
- data/spec/data/to_json_spec.rb +1 -1
- data/spec/endpoint/for_url_spec.rb +1 -1
- data/spec/item/access_errors_spec.rb +1 -1
- data/spec/item/accessors_spec.rb +1 -1
- data/spec/item/add_error_spec.rb +1 -1
- data/spec/item/becomes_spec.rb +1 -1
- data/spec/item/blacklisted_keywords_spec.rb +1 -1
- data/spec/item/delegate_spec.rb +1 -1
- data/spec/item/destroy_spec.rb +2 -2
- data/spec/item/dig_spec.rb +1 -1
- data/spec/item/error_codes_spec.rb +1 -1
- data/spec/item/errors_spec.rb +22 -22
- data/spec/item/fetch_spec.rb +1 -1
- data/spec/item/getter_spec.rb +1 -1
- data/spec/item/internal_data_structure_spec.rb +1 -1
- data/spec/item/map_spec.rb +1 -1
- data/spec/item/partial_update_spec.rb +3 -3
- data/spec/item/save_spec.rb +2 -2
- data/spec/item/setter_spec.rb +1 -1
- data/spec/item/translate_errors_spec.rb +1 -1
- data/spec/item/update_spec.rb +1 -1
- data/spec/item/validation_spec.rb +4 -4
- data/spec/item/warning_codes_spec.rb +1 -1
- data/spec/item/warnings_spec.rb +1 -3
- data/spec/pagination/pages_left_spec.rb +1 -1
- data/spec/pagination/parameters_spec.rb +1 -1
- data/spec/proxy/create_sub_resource_spec.rb +5 -5
- data/spec/proxy/load_spec.rb +8 -10
- data/spec/proxy/record_identification_spec.rb +1 -1
- data/spec/record/all_spec.rb +3 -3
- data/spec/record/build_spec.rb +1 -1
- data/spec/record/cast_nested_data_spec.rb +1 -1
- data/spec/record/chain_error_handling_spec.rb +1 -1
- data/spec/record/create_spec.rb +4 -4
- data/spec/record/creation_failed_spec.rb +2 -2
- data/spec/record/definitions_spec.rb +1 -1
- data/spec/record/destroy_spec.rb +1 -1
- data/spec/record/dig_configuration_spec.rb +1 -1
- data/spec/record/endpoint_inheritance_spec.rb +3 -3
- data/spec/record/endpoint_options_spec.rb +2 -2
- data/spec/record/endpoints_spec.rb +7 -7
- data/spec/record/equality_spec.rb +1 -1
- data/spec/record/expanded_spec.rb +1 -1
- data/spec/record/fetch_spec.rb +1 -1
- data/spec/record/find_by_chains_spec.rb +1 -1
- data/spec/record/find_by_spec.rb +2 -2
- data/spec/record/find_each_spec.rb +1 -1
- data/spec/record/find_in_batches_spec.rb +2 -2
- data/spec/record/find_in_parallel_spec.rb +2 -2
- data/spec/record/find_spec.rb +3 -3
- data/spec/record/first_spec.rb +2 -2
- data/spec/record/handle_includes_errors_spec.rb +1 -1
- data/spec/record/has_many_spec.rb +3 -3
- data/spec/record/ignore_errors_spec.rb +5 -14
- data/spec/record/immutable_chains_spec.rb +1 -1
- data/spec/record/includes_all_spec.rb +6 -6
- data/spec/record/includes_spec.rb +13 -13
- data/spec/record/includes_warning_spec.rb +1 -1
- data/spec/record/item_key_spec.rb +1 -1
- data/spec/record/items_created_key_configuration_spec.rb +1 -1
- data/spec/record/mapping_spec.rb +1 -1
- data/spec/record/model_name_spec.rb +1 -1
- data/spec/record/new_spec.rb +5 -5
- data/spec/record/options_spec.rb +5 -5
- data/spec/record/paginatable_collection_spec.rb +5 -6
- data/spec/record/pagination_chain_spec.rb +3 -3
- data/spec/record/pagination_links_spec.rb +1 -1
- data/spec/record/pagination_spec.rb +1 -1
- data/spec/record/persisted_spec.rb +2 -1
- data/spec/record/references_spec.rb +1 -1
- data/spec/record/reload_by_id_spec.rb +1 -1
- data/spec/record/reload_spec.rb +2 -2
- data/spec/record/request_spec.rb +3 -3
- data/spec/record/scope_chains_spec.rb +1 -1
- data/spec/record/to_hash_spec.rb +1 -1
- data/spec/record/to_json_spec.rb +1 -1
- data/spec/record/where_chains_spec.rb +3 -3
- data/spec/record/where_spec.rb +1 -1
- data/spec/record/where_values_hash_spec.rb +1 -1
- data/spec/request_cycle_cache/main_spec.rb +2 -1
- data/spec/require_lhs_spec.rb +1 -1
- data/spec/support/cleanup.rb +1 -1
- data/spec/support/request_cycle_cache.rb +1 -1
- data/spec/views/form_for_spec.rb +1 -1
- metadata +47 -31
@@ -2,7 +2,7 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
describe LHS::Record do
|
4
4
|
context 'includes all' do
|
5
|
-
before
|
5
|
+
before do
|
6
6
|
class Customer < LHS::Record
|
7
7
|
endpoint 'http://datastore/customers/{id}'
|
8
8
|
end
|
@@ -170,7 +170,7 @@ describe LHS::Record do
|
|
170
170
|
end
|
171
171
|
|
172
172
|
context 'includes for an empty array' do
|
173
|
-
before
|
173
|
+
before do
|
174
174
|
class Contract < LHS::Record
|
175
175
|
endpoint 'http://datastore/contracts/{id}'
|
176
176
|
end
|
@@ -194,7 +194,7 @@ describe LHS::Record do
|
|
194
194
|
end
|
195
195
|
|
196
196
|
context 'weird array without hrefs' do
|
197
|
-
before
|
197
|
+
before do
|
198
198
|
stub_request(:get, "http://datastore/options/1?limit=100")
|
199
199
|
.to_return(body: { type: 'REACH_EXT' }.to_json)
|
200
200
|
end
|
@@ -213,7 +213,7 @@ describe LHS::Record do
|
|
213
213
|
end
|
214
214
|
|
215
215
|
context 'include a known/identifiable record' do
|
216
|
-
before
|
216
|
+
before do
|
217
217
|
class Contract < LHS::Record
|
218
218
|
endpoint 'http://datastore/contracts/{id}'
|
219
219
|
end
|
@@ -262,7 +262,7 @@ describe LHS::Record do
|
|
262
262
|
end
|
263
263
|
|
264
264
|
context 'includes all for parallel loaded ids' do
|
265
|
-
before
|
265
|
+
before do
|
266
266
|
class Place < LHS::Record
|
267
267
|
endpoint 'http://datastore/places/{id}'
|
268
268
|
end
|
@@ -341,7 +341,7 @@ describe LHS::Record do
|
|
341
341
|
end
|
342
342
|
|
343
343
|
context 'Linked resources' do
|
344
|
-
before
|
344
|
+
before do
|
345
345
|
stub_request(:get, 'http://datastore/places/1/contracts?offset=0&limit=10')
|
346
346
|
.to_return(
|
347
347
|
body: {
|
@@ -2,7 +2,7 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
describe LHS::Record do
|
4
4
|
let(:datastore) { 'http://local.ch/v2' }
|
5
|
-
before
|
5
|
+
before { LHC.config.placeholder('datastore', datastore) }
|
6
6
|
|
7
7
|
let(:stub_campaign_request) do
|
8
8
|
stub_request(:get, "#{datastore}/content-ads/51dfc5690cf271c375c5a12d")
|
@@ -24,7 +24,7 @@ describe LHS::Record do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'singlelevel includes' do
|
27
|
-
before
|
27
|
+
before do
|
28
28
|
class LocalEntry < LHS::Record
|
29
29
|
endpoint '{+datastore}/local-entries'
|
30
30
|
endpoint '{+datastore}/local-entries/{id}'
|
@@ -72,7 +72,7 @@ describe LHS::Record do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
context 'multilevel includes' do
|
75
|
-
before
|
75
|
+
before do
|
76
76
|
class Feedback < LHS::Record
|
77
77
|
endpoint '{+datastore}/feedbacks'
|
78
78
|
endpoint '{+datastore}/feedbacks/{id}'
|
@@ -151,7 +151,7 @@ describe LHS::Record do
|
|
151
151
|
|
152
152
|
let(:interceptor) { spy('interceptor') }
|
153
153
|
|
154
|
-
before
|
154
|
+
before do
|
155
155
|
class Entry < LHS::Record
|
156
156
|
endpoint '{+datastore}/local-entries/{id}'
|
157
157
|
end
|
@@ -167,7 +167,7 @@ describe LHS::Record do
|
|
167
167
|
end
|
168
168
|
|
169
169
|
context 'includes not present in response' do
|
170
|
-
before
|
170
|
+
before do
|
171
171
|
class Parent < LHS::Record
|
172
172
|
endpoint '{+datastore}/local-parents'
|
173
173
|
endpoint '{+datastore}/local-parents/{id}'
|
@@ -239,12 +239,12 @@ describe LHS::Record do
|
|
239
239
|
|
240
240
|
feedback = Feedback.includes(campaign: :entry).find(123)
|
241
241
|
expect(feedback.campaign._raw.keys.count).to eq 1
|
242
|
-
expect(feedback.campaign.href).to
|
242
|
+
expect(feedback.campaign.href).to be_present
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
246
246
|
context 'modules' do
|
247
|
-
before
|
247
|
+
before do
|
248
248
|
module Services
|
249
249
|
class LocalEntry < LHS::Record
|
250
250
|
endpoint '{+datastore}/local-entries'
|
@@ -264,7 +264,7 @@ describe LHS::Record do
|
|
264
264
|
end
|
265
265
|
|
266
266
|
context 'arrays' do
|
267
|
-
before
|
267
|
+
before do
|
268
268
|
class Place < LHS::Record
|
269
269
|
endpoint '{+datastore}/place'
|
270
270
|
endpoint '{+datastore}/place/{id}'
|
@@ -307,7 +307,7 @@ describe LHS::Record do
|
|
307
307
|
|
308
308
|
it 'loads places in parallel and merges included data properly' do
|
309
309
|
place = Place.includes(:relations).find(2, 1)
|
310
|
-
expect(place[0].relations.empty?)
|
310
|
+
expect(place[0].relations.empty?).to be true
|
311
311
|
expect(place[1].relations[0].name).to eq 'Category'
|
312
312
|
expect(place[1].relations[1].name).to eq 'ZeFrank'
|
313
313
|
end
|
@@ -359,7 +359,7 @@ describe LHS::Record do
|
|
359
359
|
end
|
360
360
|
|
361
361
|
context 'unexpanded response when requesting the included collection' do
|
362
|
-
before
|
362
|
+
before do
|
363
363
|
class Customer < LHS::Record
|
364
364
|
endpoint '{+datastore}/customer/{id}'
|
365
365
|
end
|
@@ -428,7 +428,7 @@ describe LHS::Record do
|
|
428
428
|
end
|
429
429
|
|
430
430
|
context 'includes with options' do
|
431
|
-
before
|
431
|
+
before do
|
432
432
|
class Customer < LHS::Record
|
433
433
|
endpoint '{+datastore}/customers/{id}'
|
434
434
|
endpoint '{+datastore}/customers'
|
@@ -474,7 +474,7 @@ describe LHS::Record do
|
|
474
474
|
end
|
475
475
|
|
476
476
|
context 'more complex examples' do
|
477
|
-
before
|
477
|
+
before do
|
478
478
|
class Place < LHS::Record
|
479
479
|
endpoint 'http://datastore/places/{id}'
|
480
480
|
end
|
@@ -536,7 +536,7 @@ describe LHS::Record do
|
|
536
536
|
end
|
537
537
|
|
538
538
|
context 'include and merge arrays when calling find in parallel' do
|
539
|
-
before
|
539
|
+
before do
|
540
540
|
class Place < LHS::Record
|
541
541
|
endpoint 'http://datastore/places/{id}'
|
542
542
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHS::Record do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
class Business < LHS::Record
|
6
6
|
configuration item_created_key: [:response, :business], limit_key: [:response, :max], pagination_key: [:response, :offset], total_key: [:response, :count], pagination_strategy: :offset
|
7
7
|
endpoint 'http://uberall/businesses'
|
data/spec/record/mapping_spec.rb
CHANGED
data/spec/record/new_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe LHS::Record do
|
|
4
4
|
context 'new' do
|
5
5
|
let(:datastore) { 'http://local.ch/v2' }
|
6
6
|
|
7
|
-
before
|
7
|
+
before do
|
8
8
|
LHC.config.placeholder('datastore', datastore)
|
9
9
|
class Rating < LHS::Record
|
10
10
|
endpoint '{+datastore}/content-ads/{campaign_id}/feedbacks'
|
@@ -27,7 +27,7 @@ describe LHS::Record do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'initialise records with raw data' do
|
30
|
-
before
|
30
|
+
before do
|
31
31
|
class User < LHS::Record
|
32
32
|
endpoint '{+datastore}/users'
|
33
33
|
end
|
@@ -46,7 +46,7 @@ describe LHS::Record do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
context 'custom setters' do
|
49
|
-
before
|
49
|
+
before do
|
50
50
|
class Rating
|
51
51
|
def ratings=(ratings)
|
52
52
|
_raw[:ratings] = ratings.map { |k, v| { name: k, value: v } }
|
@@ -66,7 +66,7 @@ describe LHS::Record do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
context 'that do not affect raw data' do
|
69
|
-
before
|
69
|
+
before do
|
70
70
|
class Rating
|
71
71
|
attr_accessor :listing
|
72
72
|
end
|
@@ -86,7 +86,7 @@ describe LHS::Record do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
context 'and custom getters' do
|
89
|
-
before
|
89
|
+
before do
|
90
90
|
class Rating
|
91
91
|
def ratings
|
92
92
|
Hash[_raw[:ratings].map { |r| [r[:name], r[:value]] }]
|
data/spec/record/options_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe LHS::Record do
|
|
5
5
|
'http://datastore/v2'
|
6
6
|
end
|
7
7
|
|
8
|
-
before
|
8
|
+
before do
|
9
9
|
LHC.config.placeholder('datastore', datastore)
|
10
10
|
class Record < LHS::Record
|
11
11
|
endpoint '{+datastore}/records', validates: { persist: false }
|
@@ -73,7 +73,7 @@ describe LHS::Record do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
context 'save' do
|
76
|
-
before
|
76
|
+
before do
|
77
77
|
stub_request(:post, 'http://datastore/v2/records/123').to_return(body: {}.to_json)
|
78
78
|
expect(LHC).to receive(:request)
|
79
79
|
.with(options.merge(method: :post, url: "http://datastore/v2/records/123", body: { href: 'http://datastore/v2/records/123' }, headers: { "Content-Type" => "application/json" }))
|
@@ -98,7 +98,7 @@ describe LHS::Record do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
context 'destroy' do
|
101
|
-
before
|
101
|
+
before do
|
102
102
|
stub_request(:delete, 'http://datastore/v2/records/123').to_return(body: {}.to_json)
|
103
103
|
expect(LHC).to receive(:request)
|
104
104
|
.with(options.merge(method: :delete, url: "http://datastore/v2/records/123"))
|
@@ -115,7 +115,7 @@ describe LHS::Record do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
context 'update' do
|
118
|
-
before
|
118
|
+
before do
|
119
119
|
stub_request(:post, "http://datastore/v2/records/123").to_return(body: {}.to_json)
|
120
120
|
body = LHS::Data.new({ href: 'http://datastore/v2/records/123', name: 'steve' }, nil, Record)
|
121
121
|
expect(LHC).to receive(:request)
|
@@ -141,7 +141,7 @@ describe LHS::Record do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
context 'valid' do
|
144
|
-
before
|
144
|
+
before do
|
145
145
|
stub_request(:post, 'http://datastore/v2/records?persist=false').to_return(body: {}.to_json)
|
146
146
|
body = LHS::Data.new({ href: 'http://datastore/v2/records/123' }, nil, Record)
|
147
147
|
expect(LHC).to receive(:request)
|
@@ -1,12 +1,11 @@
|
|
1
|
-
|
2
1
|
require 'rails_helper'
|
3
2
|
|
4
3
|
describe LHS::Record do
|
5
|
-
before
|
4
|
+
before { LHC.config.placeholder('datastore', datastore) }
|
6
5
|
let(:datastore) { 'http://local.ch/v2' }
|
7
6
|
|
8
7
|
context 'default pagination behaviour' do
|
9
|
-
before
|
8
|
+
before do
|
10
9
|
class Record < LHS::Record
|
11
10
|
endpoint '{+datastore}/feedbacks'
|
12
11
|
end
|
@@ -49,7 +48,7 @@ describe LHS::Record do
|
|
49
48
|
end
|
50
49
|
|
51
50
|
context 'pagination using offset(0,100,200,...)' do
|
52
|
-
before
|
51
|
+
before do
|
53
52
|
class Record < LHS::Record
|
54
53
|
configuration pagination_strategy: 'offset', pagination_key: 'offset'
|
55
54
|
endpoint '{+datastore}/feedbacks'
|
@@ -129,7 +128,7 @@ describe LHS::Record do
|
|
129
128
|
end
|
130
129
|
|
131
130
|
context 'pagination using page(1,2,3,...)' do
|
132
|
-
before
|
131
|
+
before do
|
133
132
|
class Record < LHS::Record
|
134
133
|
configuration pagination_strategy: 'page', pagination_key: 'page'
|
135
134
|
endpoint '{+datastore}/feedbacks'
|
@@ -207,7 +206,7 @@ describe LHS::Record do
|
|
207
206
|
end
|
208
207
|
|
209
208
|
context 'pagination using start(1,101,201,...)' do
|
210
|
-
before
|
209
|
+
before do
|
211
210
|
class Record < LHS::Record
|
212
211
|
configuration pagination_strategy: 'start', pagination_key: 'start'
|
213
212
|
endpoint '{+datastore}/feedbacks'
|
@@ -3,7 +3,7 @@ require 'rails_helper'
|
|
3
3
|
describe LHS::Record do
|
4
4
|
context 'pagination chain' do
|
5
5
|
context 'default pagination (offset)' do
|
6
|
-
before
|
6
|
+
before do
|
7
7
|
class Record < LHS::Record
|
8
8
|
endpoint 'http://local.ch/records'
|
9
9
|
endpoint 'http://local.ch/records/{id}'
|
@@ -55,7 +55,7 @@ describe LHS::Record do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'start pagination' do
|
58
|
-
before
|
58
|
+
before do
|
59
59
|
class Record < LHS::Record
|
60
60
|
configuration pagination_strategy: 'start', pagination_key: 'start'
|
61
61
|
endpoint 'http://local.ch/records'
|
@@ -76,7 +76,7 @@ describe LHS::Record do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
context 'page pagination' do
|
79
|
-
before
|
79
|
+
before do
|
80
80
|
class Record < LHS::Record
|
81
81
|
configuration pagination_strategy: 'page', pagination_key: 'page'
|
82
82
|
endpoint 'http://local.ch/records'
|
@@ -4,7 +4,7 @@ describe LHS::Record do
|
|
4
4
|
context '#persisted?' do
|
5
5
|
let(:datastore) { 'http://local.ch/v2' }
|
6
6
|
|
7
|
-
before
|
7
|
+
before do
|
8
8
|
LHC.config.placeholder('datastore', datastore)
|
9
9
|
class Feedback < LHS::Record
|
10
10
|
endpoint '{+datastore}/content-ads/{campaign_id}/feedbacks'
|
@@ -32,6 +32,7 @@ describe LHS::Record do
|
|
32
32
|
context 'for saved record' do
|
33
33
|
let(:campaign_id) { 'aaa' }
|
34
34
|
let(:parameters) { { recommended: true } }
|
35
|
+
|
35
36
|
subject { Feedback.new(parameters.merge(campaign_id: campaign_id)) }
|
36
37
|
|
37
38
|
before do
|
data/spec/record/reload_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHS::Record do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
class Record < LHS::Record
|
6
6
|
endpoint 'http://datastore/records'
|
7
7
|
endpoint 'http://datastore/records/{id}'
|
@@ -24,7 +24,7 @@ describe LHS::Record do
|
|
24
24
|
|
25
25
|
context 'nested items' do
|
26
26
|
|
27
|
-
before
|
27
|
+
before do
|
28
28
|
class Location < LHS::Record
|
29
29
|
endpoint 'http://uberall/locations'
|
30
30
|
endpoint 'http://uberall/locations/{id}'
|