File tree Expand file tree Collapse file tree 2 files changed +17
-14
lines changed
app/services/forest_liana
spec/services/forest_liana Expand file tree Collapse file tree 2 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -49,20 +49,15 @@ def self.invalidate_scope_cache(rendering_id)
4949 end
5050
5151 def self . fetch_scopes ( rendering_id )
52- response = ForestLiana ::ForestApiRequester . get ( "/liana/v4/permissions/renderings/#{ rendering_id } " )
53-
54- if response . is_a? ( Net ::HTTPOK )
55- Rails . cache . fetch ( 'forest.scopes.' + rendering_id . to_s , expires_in : @@scope_cache_expiration_delta ) do
56- data = { }
57- parse_response = JSON . parse ( response . body )
58-
59- data [ 'scopes' ] = decode_scope ( parse_response [ 'collections' ] )
60- data [ 'team' ] = parse_response [ 'team' ]
61-
62- data
63- end
64- else
65- raise 'Unable to fetch scopes'
52+ Rails . cache . fetch ( "forest.scopes.#{ rendering_id } " , expires_in : @@scope_cache_expiration_delta ) do
53+ response = ForestLiana ::ForestApiRequester . get ( "/liana/v4/permissions/renderings/#{ rendering_id } " )
54+ raise 'Unable to fetch scopes' unless response . is_a? ( Net ::HTTPOK )
55+ parsed_response = JSON . parse ( response . body )
56+
57+ {
58+ 'scopes' => decode_scope ( parsed_response [ 'collections' ] ) ,
59+ 'team' => parsed_response [ 'team' ]
60+ }
6661 end
6762 end
6863
Original file line number Diff line number Diff line change @@ -73,6 +73,14 @@ module ForestLiana
7373 'team' => { 'id' => '1' , 'name' => 'Operations' } ,
7474 } )
7575 end
76+
77+ it 'calls the API only once, even with multiple fetch_scopes calls' do
78+ described_class . fetch_scopes ( rendering_id )
79+ described_class . fetch_scopes ( rendering_id )
80+
81+ expect ( ForestLiana ::ForestApiRequester ) . to have_received ( :get ) . once
82+ end
83+
7684 end
7785
7886 describe 'when scope contains dynamic values' do
You can’t perform that action at this time.
0 commit comments