Skip to content

Commit

Permalink
Update rubocop rules, small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Mar 24, 2020
1 parent cc82ea7 commit febfced
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 58 deletions.
56 changes: 42 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
GIT
remote: https://github.com/rspec/rspec-core.git
revision: 002ebcb65324bca7b3ee044e22f4c02133fce14d
specs:
rspec-core (3.10.0.pre)
rspec-support (= 3.10.0.pre)

GIT
remote: https://github.com/rspec/rspec-expectations.git
revision: 9f224eaeb5c6d7eaaab0f7f6e355efd9329328f8
specs:
rspec-expectations (3.10.0.pre)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (= 3.10.0.pre)

GIT
remote: https://github.com/rspec/rspec-mocks.git
revision: 81c17e89b2722cb225d602e08b600e4a4f6148a4
specs:
rspec-mocks (3.10.0.pre)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (= 3.10.0.pre)

GIT
remote: https://github.com/rspec/rspec-support.git
revision: 63c03e5e6f0ac858398933f820d37087f57c315a
specs:
rspec-support (3.10.0.pre)

PATH
remote: doorkeeper
specs:
Expand Down Expand Up @@ -63,19 +92,14 @@ GEM
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rake (13.0.1)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.2)
rspec-rails (4.0.0.beta3)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-core (~> 3.8)
rspec-expectations (~> 3.8)
rspec-mocks (~> 3.8)
rspec-support (~> 3.8)
thor (1.0.1)
thread_safe (0.3.6)
tzinfo (1.2.6)
Expand All @@ -88,7 +112,11 @@ DEPENDENCIES
doorkeeper!
mongoid
rake
rspec
rspec-core!
rspec-expectations!
rspec-mocks!
rspec-rails (= 4.0.0.beta3)
rspec-support!

BUNDLED WITH
1.17.3
13 changes: 6 additions & 7 deletions doorkeeper-mongodb.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

$:.push File.expand_path("../lib", __FILE__)
$LOAD_PATH.push File.expand_path("lib", __dir__)

# Maintain your gem's version:
require "doorkeeper-mongodb/version"
Expand All @@ -21,12 +21,11 @@ Gem::Specification.new do |gem|

gem.add_dependency "doorkeeper", ">= 5.2", "< 6.0"

gem.add_development_dependency "grape"
gem.add_development_dependency "coveralls"
gem.add_development_dependency "sqlite3", "~> 1.3.5"
gem.add_development_dependency "rspec-rails"
gem.add_development_dependency "capybara", "~> 2.17"
gem.add_development_dependency "generator_spec", "~> 0.9.4"
gem.add_development_dependency "factory_bot", "~> 4.8"
gem.add_development_dependency "coveralls"
gem.add_development_dependency "database_cleaner", "~> 1.6.0"
gem.add_development_dependency "factory_bot", "~> 4.8"
gem.add_development_dependency "generator_spec", "~> 0.9.4"
gem.add_development_dependency "grape"
gem.add_development_dependency "rspec-rails"
end
8 changes: 3 additions & 5 deletions gemfiles/Gemfile.common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

gemspec path: "../"

gem "rails", "~> #{ENV['RAILS']}"
gem "doorkeeper", "~> #{ENV['DOORKEEPER']}"
gem "rails", "~> #{ENV["RAILS"]}"
gem "doorkeeper", "~> #{ENV["DOORKEEPER"]}"
gem "bcrypt"

gem "rspec-core", git: "https://github.com/rspec/rspec-core.git"
Expand All @@ -18,6 +18,4 @@
gem "rspec-support", git: "https://github.com/rspec/rspec-support.git"

# Older Grape requires Ruby >= 2.2.2
if ENV["RAILS"][0] == "4"
gem "grape", "~> 0.16", "< 0.19.2"
end
gem "grape", "~> 0.16", "< 0.19.2" if ENV["RAILS"][0] == "4"
2 changes: 1 addition & 1 deletion gemfiles/Gemfile.mongoid4.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

gemfile = File.expand_path("../Gemfile.common.rb", __FILE__)
gemfile = File.expand_path("Gemfile.common.rb", __dir__)
instance_eval IO.read(gemfile), gemfile

gem "mongoid", "~> 4"
2 changes: 1 addition & 1 deletion gemfiles/Gemfile.mongoid5.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

gemfile = File.expand_path("../Gemfile.common.rb", __FILE__)
gemfile = File.expand_path("Gemfile.common.rb", __dir__)
instance_eval IO.read(gemfile), gemfile

gem "mongoid", "~> 5"
2 changes: 1 addition & 1 deletion gemfiles/Gemfile.mongoid6.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

gemfile = File.expand_path("../Gemfile.common.rb", __FILE__)
gemfile = File.expand_path("Gemfile.common.rb", __dir__)
instance_eval IO.read(gemfile), gemfile

gem "mongoid", "~> 6"
2 changes: 1 addition & 1 deletion gemfiles/Gemfile.mongoid7.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

gemfile = File.expand_path("../Gemfile.common.rb", __FILE__)
gemfile = File.expand_path("Gemfile.common.rb", __dir__)
instance_eval IO.read(gemfile), gemfile

gem "mongoid", "~> 7.0"
2 changes: 1 addition & 1 deletion lib/doorkeeper-mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

module DoorkeeperMongodb
def load_locales
locales_dir = File.expand_path("../../config/locales", __FILE__)
locales_dir = File.expand_path("../config/locales", __dir__)
locales = Dir[File.join(locales_dir, "*.yml")]

I18n.load_path |= locales
Expand Down
7 changes: 6 additions & 1 deletion lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ module AccessGrantMixin
included do
belongs_to_opts = {
class_name: "Doorkeeper::Application",
inverse_of: :access_grants
inverse_of: :access_grants,
}

if DoorkeeperMongodb.doorkeeper_version?(5, 3)
belongs_to_opts[:class_name] = Doorkeeper.config.application_class
end

# optional associations added in Mongoid 6
if ::Mongoid::VERSION[0].to_i >= 6
belongs_to_opts[:optional] = true
Expand Down Expand Up @@ -152,6 +156,7 @@ def fallback_secret_strategy
#
def generate_token
return if self[:token].present?

@raw_token = UniqueToken.generate
secret_strategy.store_secret(self, :token, @raw_token)
end
Expand Down
34 changes: 18 additions & 16 deletions lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ module AccessTokenMixin
included do
belongs_to_opts = {
class_name: "Doorkeeper::Application",
inverse_of: :access_tokens
inverse_of: :access_tokens,
}

if DoorkeeperMongodb.doorkeeper_version?(5, 3)
belongs_to_opts[:class_name] = Doorkeeper.config.application_class
end

# optional associations added in Mongoid 6
if ::Mongoid::VERSION[0].to_i >= 6
belongs_to_opts[:optional] = true
Expand Down Expand Up @@ -66,7 +70,6 @@ def by_token(token)
find_by_plaintext_token(:token, token)
end


# Returns an instance of the Doorkeeper::AccessToken
# with specific token value.
#
Expand Down Expand Up @@ -116,7 +119,7 @@ def matching_token_for(application, resource_owner, scopes)
find_matching_token(tokens, application, scopes)
end

def find_access_token_in_batches(relation, *args, &block)
def find_access_token_in_batches(relation, *_args, &block)
relation.all.each(&block)
end

Expand Down Expand Up @@ -177,10 +180,10 @@ def find_or_create_for(application, resource_owner, scopes, expires_in, use_refr
end

attributes = {
application_id: application.try(:id),
scopes: scopes.to_s,
expires_in: expires_in,
use_refresh_token: use_refresh_token
application_id: application.try(:id),
scopes: scopes.to_s,
expires_in: expires_in,
use_refresh_token: use_refresh_token,
}

if Doorkeeper::VERSION::MINOR > 3 && Doorkeeper.config.polymorphic_resource_owner?
Expand Down Expand Up @@ -232,7 +235,6 @@ def fallback_secret_strategy
end
end


# Access Token type: Bearer.
# @see https://tools.ietf.org/html/rfc6750
# The OAuth 2.0 Authorization Framework: Bearer Token Usage
Expand All @@ -252,10 +254,10 @@ def use_refresh_token?
def as_json(_options = {})
{
resource_owner_id: resource_owner_id,
scope: scopes,
expires_in: expires_in_seconds,
application: { uid: application.try(:uid) },
created_at: created_at.to_i
scope: scopes,
expires_in: expires_in_seconds,
application: { uid: application.try(:uid) },
created_at: created_at.to_i,
}
end

Expand Down Expand Up @@ -361,10 +363,10 @@ def generate_token

@raw_token = token_generator.generate(
resource_owner_id: resource_owner_id,
scopes: scopes,
application: application,
expires_in: expires_in,
created_at: created_at,
scopes: scopes,
application: application,
expires_in: expires_in,
created_at: created_at,
)
secret_strategy.store_secret(self, :token, @raw_token)
@raw_token
Expand Down
9 changes: 4 additions & 5 deletions lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module ApplicationMixin

included do
has_many_options = {
dependent: :delete
dependent: :delete,
}

# Mongoid7 dropped :delete option
Expand Down Expand Up @@ -52,6 +52,7 @@ def by_uid_and_secret(uid, secret)
return unless app
return app if secret.blank? && !app.confidential?
return unless app.secret_matches?(secret)

app
end

Expand Down Expand Up @@ -142,9 +143,7 @@ def authorized_for_resource_owner?(resource_owner)
private

def generate_uid
if uid.blank?
self.uid = UniqueToken.generate
end
self.uid = UniqueToken.generate if uid.blank?
end

def generate_secret
Expand All @@ -156,7 +155,7 @@ def generate_secret

def scopes_match_configured
if scopes.present? &&
!ScopeChecker.valid?(scope_str: scopes.to_s, server_scopes: Doorkeeper.configuration.scopes)
!ScopeChecker.valid?(scope_str: scopes.to_s, server_scopes: Doorkeeper.configuration.scopes)
errors.add(:scopes, :not_match_configured)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/orm/concerns/mongoid/resource_ownerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module ClassMethods
#
def by_resource_owner(resource_owner)
if DoorkeeperMongodb.doorkeeper_version?(5, 3) &&
Doorkeeper.configuration.polymorphic_resource_owner?
Doorkeeper.configuration.polymorphic_resource_owner?
where(resource_owner: resource_owner)
else
where(resource_owner_id: resource_owner_id_for(resource_owner))
Expand Down
10 changes: 9 additions & 1 deletion lib/doorkeeper/orm/mongoid4/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ class Application

index({ uid: 1 }, unique: true)

has_many :authorized_tokens, class_name: "Doorkeeper::AccessToken"
has_many_opts = {
class_name: "Doorkeeper::AccessToken",
}

if DoorkeeperMongodb.doorkeeper_version?(5, 3)
has_many_opts[:class_name] = Doorkeeper.config.access_token_class
end

has_many :authorized_tokens, has_many_opts

def self.authorized_for(resource_owner)
ids = AccessToken.where(
Expand Down
10 changes: 9 additions & 1 deletion lib/doorkeeper/orm/mongoid5/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ class Application

index({ uid: 1 }, unique: true)

has_many :authorized_tokens, class_name: "Doorkeeper::AccessToken"
has_many_opts = {
class_name: "Doorkeeper::AccessToken",
}

if DoorkeeperMongodb.doorkeeper_version?(5, 3)
has_many_opts[:class_name] = Doorkeeper.config.access_token_class
end

has_many :authorized_tokens, has_many_opts

def self.authorized_for(resource_owner)
ids = AccessToken.where(
Expand Down
10 changes: 9 additions & 1 deletion lib/doorkeeper/orm/mongoid6/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ class Application

index({ uid: 1 }, unique: true)

has_many :authorized_tokens, class_name: "Doorkeeper::AccessToken"
has_many_opts = {
class_name: "Doorkeeper::AccessToken",
}

if DoorkeeperMongodb.doorkeeper_version?(5, 3)
has_many_opts[:class_name] = Doorkeeper.config.access_token_class
end

has_many :authorized_tokens, has_many_opts

def self.authorized_for(resource_owner)
ids = AccessToken.where(
Expand Down
10 changes: 9 additions & 1 deletion lib/doorkeeper/orm/mongoid7/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ class Application

index({ uid: 1 }, unique: true)

has_many :authorized_tokens, class_name: "Doorkeeper::AccessToken"
has_many_opts = {
class_name: "Doorkeeper::AccessToken",
}

if DoorkeeperMongodb.doorkeeper_version?(5, 3)
has_many_opts[:class_name] = Doorkeeper.config.access_token_class
end

has_many :authorized_tokens, has_many_opts

def self.authorized_for(resource_owner)
ids = AccessToken.where(
Expand Down

0 comments on commit febfced

Please sign in to comment.