lhs 21.2.2 → 21.2.3.pre.preload.pre.providers.pre.too.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/concerns/autoload_records.rb +20 -3
- data/lib/lhs/version.rb +1 -1
- data/spec/autoloading_spec.rb +35 -8
- data/spec/dummy/app/controllers/error_handling_with_chains_controller.rb +2 -2
- data/spec/dummy/app/controllers/extended_rollbar_controller.rb +2 -2
- data/spec/dummy/app/controllers/option_blocks_controller.rb +2 -2
- data/spec/dummy/app/models/dummy_customer.rb +6 -0
- data/spec/dummy/app/models/{record.rb → dummy_record.rb} +1 -1
- data/spec/dummy/app/models/{user.rb → dummy_user.rb} +1 -1
- data/spec/dummy/app/models/providers/customer_system.rb +7 -0
- data/spec/option_blocks/ensure_reset_between_requests_spec.rb +2 -1
- data/spec/record/includes_spec.rb +22 -0
- data/spec/support/reset.rb +31 -9
- metadata +12 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86d0b18d2781746245a64d4b1594cae9933712760d984685d61e19b680a27f43
|
4
|
+
data.tar.gz: 9b89ffa0271afe18cea56f049c539d19f40c498fd0da8351a94abacbc3bf27da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4afb8fd86eaa9127581720a1abdc2057033be1fe3196b074a6798224e01e25ad586d92b9683ebf77b70be2137fe6c575d119773f227f2986a4be04b7fccd0e37
|
7
|
+
data.tar.gz: 5f929ebc2f5f8d88300019c372507750ca48b4ad53930d89a0a34cf87621224dcbfd95908d0ca84fbbafe9c3d712db2cbfe01e46bd1db95f80dcf9ee222baa15
|
@@ -27,11 +27,28 @@ module AutoloadRecords
|
|
27
27
|
@app.call(env)
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.
|
31
|
-
Dir.glob(Rails.root.join('app', 'models', '**', '*.rb'))
|
32
|
-
|
30
|
+
def self.model_files
|
31
|
+
Dir.glob(Rails.root.join('app', 'models', '**', '*.rb'))
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.require_direct_inheritance
|
35
|
+
model_files.map do |file|
|
36
|
+
next unless File.read(file).match('LHS::Record')
|
37
|
+
require_dependency file
|
38
|
+
file.split('models/').last.gsub('.rb', '').classify
|
39
|
+
end.compact
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.require_inheriting_records(parents)
|
43
|
+
model_files.each do |file|
|
44
|
+
next if parents.none? { |parent| File.read(file).match(parent) }
|
45
|
+
require_dependency file
|
33
46
|
end
|
34
47
|
end
|
48
|
+
|
49
|
+
def self.require_records
|
50
|
+
require_inheriting_records(require_direct_inheritance)
|
51
|
+
end
|
35
52
|
end
|
36
53
|
end
|
37
54
|
end
|
data/lib/lhs/version.rb
CHANGED
data/spec/autoloading_spec.rb
CHANGED
@@ -4,18 +4,45 @@ require "rails_helper"
|
|
4
4
|
|
5
5
|
describe LHS, type: :request do
|
6
6
|
context 'autoloading' do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
expect(
|
7
|
+
|
8
|
+
let(:endpoints) { LHS::Record::Endpoints.all }
|
9
|
+
|
10
|
+
it "pre/re-loads all LHS classes initialy, because it's necessary for endpoint-to-record-class-discovery", reset_before: false do
|
11
|
+
|
12
|
+
expect(endpoints['http://datastore/v2/users']).to be_present
|
13
|
+
expect(endpoints['http://datastore/v2/users/{id}']).to be_present
|
14
|
+
|
13
15
|
expect(
|
14
|
-
|
16
|
+
DummyUser.endpoints.detect { |endpoint| endpoint.url == 'http://datastore/v2/users' }
|
15
17
|
).to be_present
|
16
18
|
expect(
|
17
|
-
|
19
|
+
DummyUser.endpoints.detect { |endpoint| endpoint.url == 'http://datastore/v2/users/{id}' }
|
18
20
|
).to be_present
|
19
21
|
end
|
22
|
+
|
23
|
+
it "also pre/re-loads all LHS classes that inherited from an LHS provider, because it's necessary for endpoint-to-record-class-discovery", reset_before: false do
|
24
|
+
|
25
|
+
expect(endpoints['http://customers']).to be_present
|
26
|
+
expect(endpoints['http://customers/{id}']).to be_present
|
27
|
+
|
28
|
+
expect(
|
29
|
+
DummyCustomer.endpoints.detect { |endpoint| endpoint.url == 'http://customers' }
|
30
|
+
).to be_present
|
31
|
+
expect(
|
32
|
+
DummyCustomer.endpoints.detect { |endpoint| endpoint.url == 'http://customers/{id}' }
|
33
|
+
).to be_present
|
34
|
+
|
35
|
+
customer_request = stub_request(:get, "http://customers/1")
|
36
|
+
.with(
|
37
|
+
headers: {
|
38
|
+
'Authorization' => 'token123'
|
39
|
+
}
|
40
|
+
)
|
41
|
+
.to_return(body: { name: 'Steve' }.to_json)
|
42
|
+
|
43
|
+
DummyCustomer.find(1)
|
44
|
+
|
45
|
+
expect(customer_request).to have_been_requested
|
46
|
+
end
|
20
47
|
end
|
21
48
|
end
|
@@ -5,7 +5,7 @@ class ErrorHandlingWithChainsController < ApplicationController
|
|
5
5
|
# Example where the query chain is resolved
|
6
6
|
# in the view (during render 'show')
|
7
7
|
def fetch_in_view
|
8
|
-
@records =
|
8
|
+
@records = DummyRecord
|
9
9
|
.handle(LHC::Error, ->(error) { handle_error(error) })
|
10
10
|
.where(color: 'blue')
|
11
11
|
render 'show'
|
@@ -15,7 +15,7 @@ class ErrorHandlingWithChainsController < ApplicationController
|
|
15
15
|
# Example where the query chain is resolved
|
16
16
|
# before the view is rendered
|
17
17
|
def fetch_in_controller
|
18
|
-
@records =
|
18
|
+
@records = DummyRecord
|
19
19
|
.handle(LHC::Error, ->(error) { handle_error(error) })
|
20
20
|
.where(color: 'blue').fetch
|
21
21
|
render 'show'
|
@@ -3,8 +3,8 @@
|
|
3
3
|
class ExtendedRollbarController < ApplicationController
|
4
4
|
|
5
5
|
def extended_rollbar
|
6
|
-
|
7
|
-
|
6
|
+
DummyRecord.where(color: 'blue').fetch
|
7
|
+
DummyRecord.where(color: 'red').fetch
|
8
8
|
raise "Let's see if rollbar logs information about what kind of requests where made around here!"
|
9
9
|
end
|
10
10
|
end
|
@@ -4,12 +4,12 @@ class OptionBlocksController < ApplicationController
|
|
4
4
|
|
5
5
|
def first
|
6
6
|
LHS::OptionBlocks::CurrentOptionBlock.options = { params: { request: 'first' } }
|
7
|
-
|
7
|
+
DummyRecord.where(request: 'second').fetch
|
8
8
|
render text: 'ok'
|
9
9
|
end
|
10
10
|
|
11
11
|
def second
|
12
|
-
|
12
|
+
DummyRecord.where(request: 'second').fetch
|
13
13
|
render text: 'ok'
|
14
14
|
end
|
15
15
|
end
|
@@ -13,7 +13,8 @@ describe 'Option Blocks', type: :request do
|
|
13
13
|
.to_return(status: 200)
|
14
14
|
end
|
15
15
|
|
16
|
-
it 'always ensures option blocks are always reset for new requests',
|
16
|
+
it 'always ensures option blocks are always reset for new requests',
|
17
|
+
dummy_models: true, reset_before: true do
|
17
18
|
get '/option_blocks/first'
|
18
19
|
expect(first_request).to have_been_made.once
|
19
20
|
get '/option_blocks/second'
|
@@ -664,6 +664,28 @@ describe LHS::Record do
|
|
664
664
|
expect(nested_request).to have_been_requested
|
665
665
|
expect(place.customer.salesforce.name).to eq 'Steve'
|
666
666
|
end
|
667
|
+
|
668
|
+
context 'included data has a configured record endpoint option' do
|
669
|
+
before do
|
670
|
+
class SalesforceCustomer < LHS::Record
|
671
|
+
endpoint 'https://salesforce/customers/{id}', headers: { 'Authorization': 'Bearer 123' }
|
672
|
+
end
|
673
|
+
end
|
674
|
+
|
675
|
+
let!(:nested_request) do
|
676
|
+
stub_request(:get, "https://salesforce/customers/1")
|
677
|
+
.with(headers: { 'Authorization' => 'Bearer 123' })
|
678
|
+
.to_return(body: {
|
679
|
+
name: 'Steve'
|
680
|
+
}.to_json)
|
681
|
+
end
|
682
|
+
|
683
|
+
it 'includes data that has been nested in an additional structure' do
|
684
|
+
place = Place.includes(customer: :salesforce).find(1)
|
685
|
+
expect(nested_request).to have_been_requested
|
686
|
+
expect(place.customer.salesforce.name).to eq 'Steve'
|
687
|
+
end
|
688
|
+
end
|
667
689
|
end
|
668
690
|
|
669
691
|
context 'include empty structures' do
|
data/spec/support/reset.rb
CHANGED
@@ -12,10 +12,15 @@ end
|
|
12
12
|
|
13
13
|
class LHS::Record
|
14
14
|
|
15
|
-
|
15
|
+
DESCENDANTS = []
|
16
16
|
|
17
17
|
def self.inherited(child)
|
18
|
-
|
18
|
+
DESCENDANTS.push(child)
|
19
|
+
child.singleton_class.class_eval do
|
20
|
+
define_method(:inherited) do |grand_child|
|
21
|
+
DESCENDANTS.push(grand_child)
|
22
|
+
end
|
23
|
+
end
|
19
24
|
super
|
20
25
|
end
|
21
26
|
|
@@ -27,9 +32,28 @@ end
|
|
27
32
|
|
28
33
|
def reset_lhs
|
29
34
|
LHS::Record::Endpoints.all = {}
|
30
|
-
LHS::Record::
|
31
|
-
|
32
|
-
|
35
|
+
LHS::Record::DESCENDANTS.each do |decendant|
|
36
|
+
decendant.endpoints = [] if !decendant.name['LHS'] && defined?(decendant.endpoints)
|
37
|
+
decendant.configuration({}) if !decendant.name['LHS']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def model_files_to_reload
|
42
|
+
Dir.glob(Rails.root.join('app', 'models', '**', '*.rb'))
|
43
|
+
end
|
44
|
+
|
45
|
+
def reload_direct_inheritance
|
46
|
+
model_files_to_reload.map do |file|
|
47
|
+
next unless File.read(file).match('LHS::Record')
|
48
|
+
load file
|
49
|
+
file.split('models/').last.gsub('.rb', '').classify
|
50
|
+
end.compact
|
51
|
+
end
|
52
|
+
|
53
|
+
def reload_inheriting_records(parents)
|
54
|
+
model_files_to_reload.each do |file|
|
55
|
+
next if parents.none? { |parent| File.read(file).match(parent) }
|
56
|
+
load file
|
33
57
|
end
|
34
58
|
end
|
35
59
|
|
@@ -37,9 +61,7 @@ RSpec.configure do |config|
|
|
37
61
|
config.before do |spec|
|
38
62
|
reset_lhc unless spec.metadata.key?(:reset_before) && spec.metadata[:reset_before] == false
|
39
63
|
reset_lhs unless spec.metadata.key?(:reset_before) && spec.metadata[:reset_before] == false
|
40
|
-
next
|
41
|
-
|
42
|
-
load file if File.read(file).match('LHS::Record')
|
43
|
-
end
|
64
|
+
next if !spec.metadata.key?(:dummy_models) || spec.metadata[:dummy_models] != true
|
65
|
+
reload_inheriting_records(reload_direct_inheritance)
|
44
66
|
end
|
45
67
|
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: 21.2.
|
4
|
+
version: 21.2.3.pre.preload.pre.providers.pre.too.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: 2020-03-
|
11
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -381,8 +381,10 @@ files:
|
|
381
381
|
- spec/dummy/app/mailers/.keep
|
382
382
|
- spec/dummy/app/models/.keep
|
383
383
|
- spec/dummy/app/models/concerns/.keep
|
384
|
-
- spec/dummy/app/models/
|
385
|
-
- spec/dummy/app/models/
|
384
|
+
- spec/dummy/app/models/dummy_customer.rb
|
385
|
+
- spec/dummy/app/models/dummy_record.rb
|
386
|
+
- spec/dummy/app/models/dummy_user.rb
|
387
|
+
- spec/dummy/app/models/providers/customer_system.rb
|
386
388
|
- spec/dummy/app/views/error_handling_with_chains/error.html.erb
|
387
389
|
- spec/dummy/app/views/error_handling_with_chains/show.html.erb
|
388
390
|
- spec/dummy/app/views/form_for.html.erb
|
@@ -546,9 +548,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
546
548
|
version: 2.3.0
|
547
549
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
548
550
|
requirements:
|
549
|
-
- - "
|
551
|
+
- - ">"
|
550
552
|
- !ruby/object:Gem::Version
|
551
|
-
version:
|
553
|
+
version: 1.3.1
|
552
554
|
requirements:
|
553
555
|
- Ruby >= 2.3.0
|
554
556
|
rubygems_version: 3.0.6
|
@@ -598,8 +600,10 @@ test_files:
|
|
598
600
|
- spec/dummy/app/mailers/.keep
|
599
601
|
- spec/dummy/app/models/.keep
|
600
602
|
- spec/dummy/app/models/concerns/.keep
|
601
|
-
- spec/dummy/app/models/
|
602
|
-
- spec/dummy/app/models/
|
603
|
+
- spec/dummy/app/models/dummy_customer.rb
|
604
|
+
- spec/dummy/app/models/dummy_record.rb
|
605
|
+
- spec/dummy/app/models/dummy_user.rb
|
606
|
+
- spec/dummy/app/models/providers/customer_system.rb
|
603
607
|
- spec/dummy/app/views/error_handling_with_chains/error.html.erb
|
604
608
|
- spec/dummy/app/views/error_handling_with_chains/show.html.erb
|
605
609
|
- spec/dummy/app/views/form_for.html.erb
|