Commit fc940cc1 authored by Ryan Cobb's avatar Ryan Cobb

Strong memoize and add spec

parent 837bbb40
......@@ -2,6 +2,8 @@
module Subscriptions
class CreateService
include Gitlab::Utils::StrongMemoize
attr_reader :current_user, :customer_params, :subscription_params
CUSTOMERS_OAUTH_APP_ID_CACHE_KEY = 'customers_oauth_app_id'
......@@ -103,13 +105,13 @@ module Subscriptions
end
def oauth_token
@oauth_token ||= begin
return unless customers_oauth_app_id
strong_memoize(:oauth_token) do
next unless customers_oauth_app_id
application = Doorkeeper::Application.find_by_uid(customers_oauth_app_id)
existing_token = Doorkeeper::AccessToken.matching_token_for(application, current_user.id, application.scopes)
return existing_token if existing_token
next existing_token if existing_token
Doorkeeper::AccessToken.new(
application_id: customers_oauth_app_id,
......
......@@ -124,4 +124,17 @@ RSpec.describe Gitlab::SubscriptionPortal::Clients::Rest do
it_behaves_like 'when response code is 500'
it_behaves_like 'when http call raises an exception'
end
describe '#customers_oauth_app_id' do
subject do
client.customers_oauth_app_id
end
let(:http_method) { :get }
it_behaves_like 'when response is successful'
it_behaves_like 'when response code is 422'
it_behaves_like 'when response code is 500'
it_behaves_like 'when http call raises an exception'
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment