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
data/lib/lhs/data.rb
CHANGED
@@ -18,7 +18,8 @@ class LHS::Data
|
|
18
18
|
delegate :instance_methods, :items_key, :limit_key, :total_key, :pagination_key, to: :class
|
19
19
|
|
20
20
|
# prevent clashing with attributes of underlying data
|
21
|
-
attr_accessor :_proxy, :
|
21
|
+
attr_accessor :_proxy, :_parent, :_record, :_request, :_endpoint
|
22
|
+
attr_reader :_raw
|
22
23
|
|
23
24
|
def initialize(input, parent = nil, record = nil, request = nil, endpoint = nil)
|
24
25
|
self._raw = raw_from_input(input)
|
@@ -47,12 +48,12 @@ class LHS::Data
|
|
47
48
|
|
48
49
|
def _root
|
49
50
|
root = self
|
50
|
-
root = root._parent while root
|
51
|
+
root = root._parent while root&._parent
|
51
52
|
root
|
52
53
|
end
|
53
54
|
|
54
55
|
def parent
|
55
|
-
if _parent
|
56
|
+
if _parent&._record
|
56
57
|
_parent._record.new(_parent, false)
|
57
58
|
else
|
58
59
|
_parent
|
@@ -65,7 +66,7 @@ class LHS::Data
|
|
65
66
|
|
66
67
|
# enforce internal data structure to have deep symbolized keys
|
67
68
|
def _raw=(raw)
|
68
|
-
raw.to_hash.deep_symbolize_keys! if raw
|
69
|
+
raw.to_hash.deep_symbolize_keys! if raw&.respond_to?(:to_hash)
|
69
70
|
@_raw = raw
|
70
71
|
end
|
71
72
|
|
data/lib/lhs/endpoint.rb
CHANGED
@@ -5,6 +5,6 @@ class LHS::Endpoint
|
|
5
5
|
template, record = LHS::Record::Endpoints.all.detect do |template, _record|
|
6
6
|
LHC::Endpoint.match?(url, template)
|
7
7
|
end
|
8
|
-
record
|
8
|
+
record&.endpoints&.detect { |endpoint| endpoint.url == template }
|
9
9
|
end
|
10
10
|
end
|
data/lib/lhs/item.rb
CHANGED
data/lib/lhs/pagination/base.rb
CHANGED
data/lib/lhs/problems/base.rb
CHANGED
data/lib/lhs/record.rb
CHANGED
@@ -61,7 +61,7 @@ class LHS::Record
|
|
61
61
|
delegate :_proxy, :_endpoint, :merge_raw!, :select, :becomes, to: :_data
|
62
62
|
|
63
63
|
def initialize(data = nil, apply_customer_setters = true)
|
64
|
-
data
|
64
|
+
data ||= LHS::Data.new({}, nil, self.class)
|
65
65
|
data = LHS::Data.new(data, nil, self.class) unless data.is_a?(LHS::Data)
|
66
66
|
define_singleton_method(:_data) { data }
|
67
67
|
apply_custom_setters! if apply_customer_setters
|
data/lib/lhs/version.rb
CHANGED
data/spec/autoloading_spec.rb
CHANGED
@@ -6,14 +6,14 @@ describe LHS, type: :request do
|
|
6
6
|
because it's necessary for endpoint-to-record-class-discovery",
|
7
7
|
cleanup_before: false do
|
8
8
|
all_endpoints = LHS::Record::Endpoints.all
|
9
|
-
expect(all_endpoints['http://datastore/v2/users']).to
|
10
|
-
expect(all_endpoints['http://datastore/v2/users/{id}']).to
|
9
|
+
expect(all_endpoints['http://datastore/v2/users']).to be_present
|
10
|
+
expect(all_endpoints['http://datastore/v2/users/{id}']).to be_present
|
11
11
|
expect(
|
12
12
|
User.endpoints.detect { |endpoint| endpoint.url == 'http://datastore/v2/users' }
|
13
|
-
).to
|
13
|
+
).to be_present
|
14
14
|
expect(
|
15
15
|
User.endpoints.detect { |endpoint| endpoint.url == 'http://datastore/v2/users/{id}' }
|
16
|
-
).to
|
16
|
+
).to be_present
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -5,7 +5,7 @@ describe LHS::Collection do
|
|
5
5
|
let(:limit) { 10 }
|
6
6
|
let(:total) { 20 }
|
7
7
|
|
8
|
-
before
|
8
|
+
before do
|
9
9
|
LHC.config.placeholder('search', search)
|
10
10
|
class Search < LHS::Record
|
11
11
|
configuration items_key: :docs, limit_key: :size, pagination_key: :start, pagination_strategy: :start, total_key: :totalResults
|
@@ -6,7 +6,7 @@ describe LHS::Collection do
|
|
6
6
|
let(:collection) { Record.where }
|
7
7
|
|
8
8
|
context 'to_ary' do
|
9
|
-
before
|
9
|
+
before do
|
10
10
|
class Record < LHS::Record
|
11
11
|
endpoint 'http://datastore/records`'
|
12
12
|
end
|
@@ -25,10 +25,14 @@ describe LHS::Collection do
|
|
25
25
|
let(:subject) { collection.to_ary }
|
26
26
|
|
27
27
|
it 'returns an array' do
|
28
|
-
expect(subject).to
|
28
|
+
expect(subject).to be_present
|
29
29
|
expect(subject).to be_kind_of Array
|
30
30
|
expect(subject[0]).to be_kind_of Record
|
31
31
|
expect(subject[0].name).to eq 'Steve'
|
32
32
|
end
|
33
|
+
|
34
|
+
it 'responds to to_ary' do
|
35
|
+
expect(subject.respond_to?(:to_ary)).to eq true
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
data/spec/complex/reduce_spec.rb
CHANGED
@@ -171,7 +171,7 @@ describe LHS::Complex do
|
|
171
171
|
)
|
172
172
|
end
|
173
173
|
|
174
|
-
it 'reduces another complex multi-level example' do
|
174
|
+
it 'reduces another complex multi-level example (single plus array)' do
|
175
175
|
expect(LHS::Complex.reduce([
|
176
176
|
{ entries: :products },
|
177
177
|
{ entries: [:customer, :contracts] }
|
@@ -180,7 +180,7 @@ describe LHS::Complex do
|
|
180
180
|
)
|
181
181
|
end
|
182
182
|
|
183
|
-
it 'reduces another complex multi-level example' do
|
183
|
+
it 'reduces another complex multi-level example (single hash plus array)' do
|
184
184
|
expect(LHS::Complex.reduce([
|
185
185
|
{ entries: { customer: :contracts } },
|
186
186
|
{ entries: [:customer, :content_ads] }
|
@@ -21,7 +21,7 @@ describe LHS::Record::Request do
|
|
21
21
|
expect(subject.send(:prepare_options_for_include_all_request!, abc: 'def')).to eq(abc: 'def')
|
22
22
|
end
|
23
23
|
|
24
|
-
it 'calls correct prepare method for a Hash' do
|
24
|
+
it 'calls correct prepare method for a Hash (collection)' do
|
25
25
|
expect(subject).to receive(:prepare_option_for_include_all_request!)
|
26
26
|
.with(abc: 'def').and_return('ignore')
|
27
27
|
expect(subject).to receive(:prepare_option_for_include_all_request!)
|
data/spec/data/equality_spec.rb
CHANGED
data/spec/data/inspect_spec.rb
CHANGED
data/spec/data/item_spec.rb
CHANGED
data/spec/data/merge_spec.rb
CHANGED
data/spec/data/parent_spec.rb
CHANGED
data/spec/data/raw_spec.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
describe LHS::Data do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
class Record < LHS::Record
|
6
6
|
map :test_mapping?, ->(_item) { true }
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
context '#respond_to?' do
|
11
|
-
it '
|
11
|
+
it 'is true for mappings that are defined' do
|
12
12
|
data = LHS::Data.new({ 'campaign' => { 'id' => 123 } }, nil, Record)
|
13
13
|
|
14
14
|
expect(data.respond_to?(:test_mapping?)).to be(true)
|
15
15
|
end
|
16
16
|
|
17
17
|
# proxy for this example is LHC::Collection which implements total
|
18
|
-
it '
|
18
|
+
it 'is true for calls forwarded to proxy' do
|
19
19
|
data = LHS::Data.new({ 'items' => [{ 'campaign' => { 'id' => 123 } }] }, nil, Record)
|
20
20
|
|
21
21
|
expect(data.respond_to?(:total)).to be(true)
|
data/spec/data/root_spec.rb
CHANGED
data/spec/data/select_spec.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Data do
|
4
|
+
before(:each) do
|
5
|
+
class Record < LHS::Record
|
6
|
+
endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
|
7
|
+
endpoint '{+datastore}/v2/feedbacks'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:json) do
|
12
|
+
load_json(:feedbacks)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:data) do
|
16
|
+
LHS::Data.new(json, nil, Record)
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:item) do
|
20
|
+
data[0]
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'does not respond to to_ary' do
|
24
|
+
expect(item.respond_to?(:to_ary)).to eq false
|
25
|
+
end
|
26
|
+
end
|
data/spec/data/to_json_spec.rb
CHANGED
data/spec/item/accessors_spec.rb
CHANGED
data/spec/item/add_error_spec.rb
CHANGED