Skip to content

Commit

Permalink
Fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelien-reeves-scalingo committed Dec 21, 2022
1 parent fb18f2c commit 1a37f70
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/scalingo/api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def authenticated_connection
def database_connection(database_id)
raise Error::Unauthenticated unless token_holder.authenticated_for_database?(database_id)

@database_connections ||= Hash.new
@database_connections ||= {}
@database_connections[database_id] ||= Faraday.new(connection_options) { |conn|
conn.response :json, content_type: /\bjson$/, parser_options: {symbolize_names: true}
conn.request :json
Expand Down
4 changes: 2 additions & 2 deletions lib/scalingo/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def osc_fr1
scalingo: self,
)
end
alias apps_api_osc_fr1 osc_fr1
alias_method apps_api_osc_fr1 osc_fr1

def osc_secnum_fr1
@osc_secnum_fr1 ||= Regional.new(
"https://api.osc-secnum-fr1.scalingo.com/v1",
scalingo: self,
)
end
alias apps_api_osc_secnum_fr1 osc_secnum_fr1
alias_method apps_api_osc_secnum_fr1 osc_secnum_fr1

def db_api_osc_fr1
@db_api_osc_fr1 ||= RegionalDatabase.new(
Expand Down
2 changes: 1 addition & 1 deletion lib/scalingo/regional/addons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def authenticate(app_id, addon_id, headers = nil, &block)
addon_id,
token,
expires_at: Time.now + 1.hour,
raise_on_expired_token: client.config.raise_on_expired_token
raise_on_expired_token: client.config.raise_on_expired_token,
)

response
Expand Down
2 changes: 1 addition & 1 deletion lib/scalingo/token_holder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def token=(input)
end

def add_database_token(database_id, token)
@database_tokens ||= Hash.new
@database_tokens ||= {}
@database_tokens[database_id] = bearer_token(token)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/scalingo/api/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
database_id,
"1234",
expires_at: Time.now + 1.hour,
raise_on_expired_token: false
raise_on_expired_token: false,
)
expect(subject.database_connection(database_id).headers["Authorization"]).to eq "Bearer #{subject.token_holder.database_tokens[database_id].value}"
end
Expand All @@ -202,7 +202,7 @@
database_id_2,
"1234",
expires_at: Time.now + 1.hour,
raise_on_expired_token: false
raise_on_expired_token: false,
)
expect {
subject.database_connection(database_id)
Expand Down
13 changes: 8 additions & 5 deletions spec/scalingo/token_holder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

RSpec.describe Scalingo::TokenHolder do
subject(:token_holder_dummy_class) do
Class.new { include(Scalingo::TokenHolder); attr_accessor :config }
Class.new {
include(Scalingo::TokenHolder)
attr_accessor :config
}
end

describe "authenticate_with_bearer_token" do
Expand All @@ -21,7 +24,7 @@

it "set the auth token" do
expect(token_holder.authenticated?).to be false
subject()
subject
expect(token_holder.authenticated?).to be true
end
end
Expand All @@ -34,7 +37,7 @@
token_holder.authenticate_with_bearer_token(token, expires_at: 1.hour.ago, raise_on_expired_token: false)
expect(token_holder.authenticated?).to be false

subject()
subject
expect(token_holder.authenticated?).to be true
end
end
Expand All @@ -58,7 +61,7 @@

it "set the database auth token" do
expect(token_holder.authenticated_for_database?(database_id)).to be false
subject()
subject
expect(token_holder.authenticated_for_database?(database_id)).to be true
end
end
Expand All @@ -70,7 +73,7 @@
it "refresh the database token" do
token_holder.authenticate_database_with_bearer_token(database_id, token, expires_at: 1.hour.ago, raise_on_expired_token: false)
expect(token_holder.authenticated_for_database?(database_id)).to be false
subject()
subject
expect(token_holder.authenticated_for_database?(database_id)).to be true
end
end
Expand Down

0 comments on commit 1a37f70

Please sign in to comment.