lhs 21.2.2 → 21.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +208 -107
- data/lhs.gemspec +1 -1
- data/lib/lhs.rb +8 -0
- data/lib/lhs/concerns/autoload_records.rb +20 -3
- data/lib/lhs/concerns/o_auth.rb +25 -0
- data/lib/lhs/concerns/record/configuration.rb +28 -11
- data/lib/lhs/concerns/record/request.rb +29 -8
- data/lib/lhs/config.rb +1 -1
- data/lib/lhs/interceptors/auto_oauth/interceptor.rb +33 -0
- data/lib/lhs/interceptors/auto_oauth/thread_registry.rb +18 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/auto_oauth_spec.rb +129 -0
- data/spec/autoloading_spec.rb +35 -8
- data/spec/dummy/app/controllers/application_controller.rb +15 -0
- data/spec/dummy/app/controllers/automatic_authentication_controller.rb +22 -0
- 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/dummy_record_with_multiple_oauth_providers1.rb +7 -0
- data/spec/dummy/app/models/dummy_record_with_multiple_oauth_providers2.rb +7 -0
- data/spec/dummy/app/models/dummy_record_with_multiple_providers_per_endpoint.rb +6 -0
- data/spec/dummy/app/models/dummy_record_with_oauth.rb +7 -0
- 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/dummy/config/routes.rb +4 -0
- data/spec/option_blocks/ensure_reset_between_requests_spec.rb +2 -1
- data/spec/record/error_handling_integration_spec.rb +1 -1
- data/spec/record/includes_spec.rb +41 -0
- data/spec/request_cycle_cache_spec.rb +3 -3
- data/spec/support/reset.rb +31 -9
- metadata +29 -10
data/spec/dummy/config/routes.rb
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
Rails.application.routes.draw do
|
4
4
|
root 'application#root'
|
5
5
|
|
6
|
+
# Automatic Authentication
|
7
|
+
get 'automatic_authentication/oauth' => 'automatic_authentication#o_auth'
|
8
|
+
get 'automatic_authentication/oauth_with_multiple_providers' => 'automatic_authentication#o_auth_with_multiple_providers'
|
9
|
+
|
6
10
|
# Request Cycle Cache
|
7
11
|
get 'request_cycle_cache/simple' => 'request_cycle_cache#simple'
|
8
12
|
get 'request_cycle_cache/no_caching_interceptor' => 'request_cycle_cache#no_caching_interceptor'
|
@@ -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
|
@@ -683,4 +705,23 @@ describe LHS::Record do
|
|
683
705
|
}).not_to raise_exception
|
684
706
|
end
|
685
707
|
end
|
708
|
+
|
709
|
+
context 'include partially empty structures' do
|
710
|
+
before do
|
711
|
+
class Place < LHS::Record
|
712
|
+
endpoint 'https://places/{id}'
|
713
|
+
end
|
714
|
+
stub_request(:get, "https://places/1")
|
715
|
+
.to_return(body: {
|
716
|
+
id: '123',
|
717
|
+
customer: {}
|
718
|
+
}.to_json)
|
719
|
+
end
|
720
|
+
|
721
|
+
it 'skips includes when there is nothing and also does not raise an exception' do
|
722
|
+
expect(-> {
|
723
|
+
Place.includes(customer: :salesforce).find(1)
|
724
|
+
}).not_to raise_exception
|
725
|
+
end
|
726
|
+
end
|
686
727
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rails_helper'
|
4
|
-
require 'lhc/
|
4
|
+
require 'lhc/rspec'
|
5
5
|
|
6
6
|
describe 'Request Cycle Cache', type: :request do
|
7
7
|
let!(:request) do
|
@@ -37,7 +37,7 @@ describe 'Request Cycle Cache', type: :request do
|
|
37
37
|
expect(lambda do
|
38
38
|
get '/request_cycle_cache/no_caching_interceptor'
|
39
39
|
end).to output(
|
40
|
-
%r{\[WARNING\] Can't enable request cycle cache as LHC::Caching interceptor is not enabled/configured \(see https://github.com/local-ch/lhc/blob/master/
|
40
|
+
%r{\[WARNING\] Can't enable request cycle cache as LHC::Caching interceptor is not enabled/configured \(see https://github.com/local-ch/lhc/blob/master/README.md#caching-interceptor\)!}
|
41
41
|
).to_stderr
|
42
42
|
expect(request).to have_been_made.times(2)
|
43
43
|
end
|
@@ -70,7 +70,7 @@ describe 'Request Cycle Cache', type: :request do
|
|
70
70
|
expect(lambda do
|
71
71
|
get '/request_cycle_cache/no_caching_interceptor'
|
72
72
|
end).not_to output(
|
73
|
-
%r{\[WARNING\] Can't enable request cycle cache as LHC::Caching interceptor is not enabled/configured \(see https://github.com/local-ch/lhc/blob/master/
|
73
|
+
%r{\[WARNING\] Can't enable request cycle cache as LHC::Caching interceptor is not enabled/configured \(see https://github.com/local-ch/lhc/blob/master/README.md#caching-interceptor\)!}
|
74
74
|
).to_stderr
|
75
75
|
expect(request).to have_been_made.times(2)
|
76
76
|
end
|
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.
|
4
|
+
version: 21.3.0
|
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-
|
11
|
+
date: 2020-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -146,16 +146,16 @@ dependencies:
|
|
146
146
|
name: rollbar
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
148
148
|
requirements:
|
149
|
-
- - "
|
149
|
+
- - "<="
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
151
|
+
version: 2.24.0
|
152
152
|
type: :development
|
153
153
|
prerelease: false
|
154
154
|
version_requirements: !ruby/object:Gem::Requirement
|
155
155
|
requirements:
|
156
|
-
- - "
|
156
|
+
- - "<="
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
158
|
+
version: 2.24.0
|
159
159
|
- !ruby/object:Gem::Dependency
|
160
160
|
name: rspec-rails
|
161
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -283,6 +283,7 @@ files:
|
|
283
283
|
- lib/lhs/concerns/item/save.rb
|
284
284
|
- lib/lhs/concerns/item/update.rb
|
285
285
|
- lib/lhs/concerns/item/validation.rb
|
286
|
+
- lib/lhs/concerns/o_auth.rb
|
286
287
|
- lib/lhs/concerns/option_blocks.rb
|
287
288
|
- lib/lhs/concerns/proxy/accessors.rb
|
288
289
|
- lib/lhs/concerns/proxy/create.rb
|
@@ -314,6 +315,8 @@ files:
|
|
314
315
|
- lib/lhs/config.rb
|
315
316
|
- lib/lhs/data.rb
|
316
317
|
- lib/lhs/endpoint.rb
|
318
|
+
- lib/lhs/interceptors/auto_oauth/interceptor.rb
|
319
|
+
- lib/lhs/interceptors/auto_oauth/thread_registry.rb
|
317
320
|
- lib/lhs/interceptors/extended_rollbar/handler.rb
|
318
321
|
- lib/lhs/interceptors/extended_rollbar/interceptor.rb
|
319
322
|
- lib/lhs/interceptors/extended_rollbar/thread_registry.rb
|
@@ -340,6 +343,7 @@ files:
|
|
340
343
|
- lib/lhs/version.rb
|
341
344
|
- script/ci/build.sh
|
342
345
|
- spec/.DS_Store
|
346
|
+
- spec/auto_oauth_spec.rb
|
343
347
|
- spec/autoloading_spec.rb
|
344
348
|
- spec/collection/accessors_spec.rb
|
345
349
|
- spec/collection/collection_items_spec.rb
|
@@ -372,6 +376,7 @@ files:
|
|
372
376
|
- spec/dummy/app/assets/javascripts/application.js
|
373
377
|
- spec/dummy/app/assets/stylesheets/application.css
|
374
378
|
- spec/dummy/app/controllers/application_controller.rb
|
379
|
+
- spec/dummy/app/controllers/automatic_authentication_controller.rb
|
375
380
|
- spec/dummy/app/controllers/concerns/.keep
|
376
381
|
- spec/dummy/app/controllers/error_handling_with_chains_controller.rb
|
377
382
|
- spec/dummy/app/controllers/extended_rollbar_controller.rb
|
@@ -381,8 +386,14 @@ files:
|
|
381
386
|
- spec/dummy/app/mailers/.keep
|
382
387
|
- spec/dummy/app/models/.keep
|
383
388
|
- spec/dummy/app/models/concerns/.keep
|
384
|
-
- spec/dummy/app/models/
|
385
|
-
- spec/dummy/app/models/
|
389
|
+
- spec/dummy/app/models/dummy_customer.rb
|
390
|
+
- spec/dummy/app/models/dummy_record.rb
|
391
|
+
- spec/dummy/app/models/dummy_record_with_multiple_oauth_providers1.rb
|
392
|
+
- spec/dummy/app/models/dummy_record_with_multiple_oauth_providers2.rb
|
393
|
+
- spec/dummy/app/models/dummy_record_with_multiple_providers_per_endpoint.rb
|
394
|
+
- spec/dummy/app/models/dummy_record_with_oauth.rb
|
395
|
+
- spec/dummy/app/models/dummy_user.rb
|
396
|
+
- spec/dummy/app/models/providers/customer_system.rb
|
386
397
|
- spec/dummy/app/views/error_handling_with_chains/error.html.erb
|
387
398
|
- spec/dummy/app/views/error_handling_with_chains/show.html.erb
|
388
399
|
- spec/dummy/app/views/form_for.html.erb
|
@@ -557,6 +568,7 @@ specification_version: 4
|
|
557
568
|
summary: 'REST services accelerator: Rails gem providing an easy, active-record-like
|
558
569
|
interface for http (hypermedia) json services'
|
559
570
|
test_files:
|
571
|
+
- spec/auto_oauth_spec.rb
|
560
572
|
- spec/autoloading_spec.rb
|
561
573
|
- spec/collection/accessors_spec.rb
|
562
574
|
- spec/collection/collection_items_spec.rb
|
@@ -589,6 +601,7 @@ test_files:
|
|
589
601
|
- spec/dummy/app/assets/javascripts/application.js
|
590
602
|
- spec/dummy/app/assets/stylesheets/application.css
|
591
603
|
- spec/dummy/app/controllers/application_controller.rb
|
604
|
+
- spec/dummy/app/controllers/automatic_authentication_controller.rb
|
592
605
|
- spec/dummy/app/controllers/concerns/.keep
|
593
606
|
- spec/dummy/app/controllers/error_handling_with_chains_controller.rb
|
594
607
|
- spec/dummy/app/controllers/extended_rollbar_controller.rb
|
@@ -598,8 +611,14 @@ test_files:
|
|
598
611
|
- spec/dummy/app/mailers/.keep
|
599
612
|
- spec/dummy/app/models/.keep
|
600
613
|
- spec/dummy/app/models/concerns/.keep
|
601
|
-
- spec/dummy/app/models/
|
602
|
-
- spec/dummy/app/models/
|
614
|
+
- spec/dummy/app/models/dummy_customer.rb
|
615
|
+
- spec/dummy/app/models/dummy_record.rb
|
616
|
+
- spec/dummy/app/models/dummy_record_with_multiple_oauth_providers1.rb
|
617
|
+
- spec/dummy/app/models/dummy_record_with_multiple_oauth_providers2.rb
|
618
|
+
- spec/dummy/app/models/dummy_record_with_multiple_providers_per_endpoint.rb
|
619
|
+
- spec/dummy/app/models/dummy_record_with_oauth.rb
|
620
|
+
- spec/dummy/app/models/dummy_user.rb
|
621
|
+
- spec/dummy/app/models/providers/customer_system.rb
|
603
622
|
- spec/dummy/app/views/error_handling_with_chains/error.html.erb
|
604
623
|
- spec/dummy/app/views/error_handling_with_chains/show.html.erb
|
605
624
|
- spec/dummy/app/views/form_for.html.erb
|