Skip to content

Commit

Permalink
Add rubocop linter to code climate
Browse files Browse the repository at this point in the history
  • Loading branch information
MaicolBen committed Sep 23, 2018
1 parent 470c84b commit d75d713
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 17 deletions.
11 changes: 10 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ inherit_from: .rubocop_todo.yml
AllCops:
Exclude:
- 'coverage/**/*'
- 'test/dummy/db/**/*'
- 'test/dummy/tmp/**/*'
- 'test/dummy/log/**/*'
- 'gemfiles/*'
TargetRubyVersion: 2.2

# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentationWidth.
Expand All @@ -15,10 +18,15 @@ AllCops:
# that span more than one line.
#
# https://rubocop.readthedocs.io/en/latest/cops_layout/#layoutmultilinemethodcallindentation
Layout/ClosingHeredocIndentation:
Exclude:
- 'lib/generators/devise_token_auth/install_generator.rb'

Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented_relative_to_receiver


# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
Expand Down Expand Up @@ -91,6 +99,7 @@ Metrics/BlockLength:
- 'lib/devise_token_auth/engine.rb'
- 'test/dummy/config/**/*'
- 'test/dummy/db/**/*'
- 'test/factories/*'
ExcludedMethods:
- describe
- draw
Expand All @@ -111,4 +120,4 @@ Metrics/LineLength:
- 'devise_token_auth.gemspec'
IgnoredPatterns:
- '(\A|\s)#'
Max: 80
Max: 80
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ addons:

after_success:
- bundle exec codeclimate-test-reporter
- bundle exec rubocop .
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def resource_class(m = nil)

def json_api?
return false unless defined?(ActiveModel::Serializer)

return ActiveModel::Serializer.setup do |config|
config.adapter == :json_api
end if ActiveModel::Serializer.respond_to?(:setup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ module DeviseTokenAuth::Concerns::SetUserByToken

# keep track of request duration
def set_request_start
@request_started_at = Time.zone.now
@used_auth_by_token = true

# initialize instance variables
@client_id ||= nil
@resource ||= nil
@token ||= nil
@is_batch_request ||= nil
@request_started_at = Time.zone.now
end

def ensure_pristine_resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def show
# fall back to default value if provided
@redirect_url ||= DeviseTokenAuth.default_confirm_success_url


redirect_to(@resource.build_auth_url(@redirect_url, redirect_headers))
else
raise ActionController::RoutingError, 'Not Found'
Expand Down
11 changes: 7 additions & 4 deletions app/controllers/devise_token_auth/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ def create
end

if @resource && valid_params?(field, q_value) && (!@resource.respond_to?(:active_for_authentication?) || @resource.active_for_authentication?)
valid_password = @resource.valid_password?(resource_params[:password])
if (@resource.respond_to?(:valid_for_authentication?) && !@resource.valid_for_authentication? { valid_password }) || !valid_password
return render_create_error_bad_credentials
end
return render_create_error_bad_credentials unless valid_credentials?

@client_id, @token = @resource.create_token
@resource.save

Expand Down Expand Up @@ -127,5 +125,10 @@ def render_destroy_error
def resource_params
params.permit(*params_for_resource(:sign_in))
end

def valid_credentials?
valid_password = @resource.valid_password?(resource_params[:password])
(@resource.respond_to?(:valid_for_authentication?) && @resource.valid_for_authentication? { valid_password }) || valid_password
end
end
end
1 change: 1 addition & 0 deletions app/models/devise_token_auth/concerns/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def will_save_change_to_email?; false; end

def password_required?
return false unless provider == 'email'

super
end

Expand Down
2 changes: 1 addition & 1 deletion devise_token_auth.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.test_files = Dir['test/**/*']
s.test_files.reject! { |file| file.match(/[.log|.sqlite3]$/) }

s.required_ruby_version = ">= 2.2.0"
s.required_ruby_version = '>= 2.2.0'

s.add_dependency 'rails', '>= 4.2.0', '< 6'
s.add_dependency 'devise', '> 3.5.2', '< 4.6'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Custom::ConfirmationsControllerTest < ActionController::TestCase
describe Custom::ConfirmationsController do
include CustomControllersRoutes

before do
@redirect_url = Faker::Internet.url
@new_user = create(:user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Custom::RegistrationsControllerTest < ActionDispatch::IntegrationTest

before do
@create_params = attributes_for(:user,
confirm_success_url: Faker::Internet.url,
unpermitted_param: '(x_x)')
confirm_success_url: Faker::Internet.url,
unpermitted_param: '(x_x)')

@existing_user = create(:user, :confirmed)
@auth_headers = @existing_user.create_new_auth_token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DeviseTokenAuth::TokenValidationsControllerTest < ActionDispatch::Integrat
error = assert_raises DeviseTokenAuth::Errors::InvalidModel do
get '/auth/validate_token', params: {}, headers: @auth_headers
end
assert_equal(error.message, "Cannot set auth token in invalid model. Errors: [\"Email is not an email\"]")
assert_equal(error.message, 'Cannot set auth token in invalid model. Errors: ["Email is not an email\"]')
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
end

trait :confirmed do
after(:create) { |user| user.confirm }
after(:create, &:confirm)
end

# confirmation period is expired
trait :unconfirmed do
after(:create) do |user, evaluator|
user.update_attribute(:confirmation_sent_at, evaluator.allow_unconfirmed_period - 1.day )
user.update_attribute(:confirmation_sent_at, evaluator.allow_unconfirmed_period - 1.day)
end
end

Expand All @@ -29,7 +29,7 @@
end

trait :locked do
after(:create) { |user| user.lock_access! }
after(:create, &:lock_access!)
end

factory :lockable_user, class: 'LockableUser'
Expand Down

0 comments on commit d75d713

Please sign in to comment.