Skip to content

Commit

Permalink
Merge pull request #1126 from dks17/add_rubocop
Browse files Browse the repository at this point in the history
Rubocop Fixes
  • Loading branch information
Evan-M authored Mar 27, 2018
2 parents 062d2d8 + 60e8e1e commit 608dcc3
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 152 deletions.
184 changes: 63 additions & 121 deletions .rubocop_todo.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def set_user_by_token(mapping=nil)
return @resource if @resource && @resource.is_a?(rc)

# ensure we clear the client_id
if !@token
unless @token
@client_id = nil
return
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def show

yield @resource if block_given?

redirect_header_options = {account_confirmation_success: true}
redirect_header_options = { account_confirmation_success: true }
redirect_headers = build_redirect_headers(token,
client_id,
redirect_header_options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def omniauth_success

def omniauth_failure
@error = params[:message]
render_data_or_redirect('authFailure', {error: @error})
render_data_or_redirect('authFailure', { error: @error })
end

protected
Expand All @@ -60,7 +60,7 @@ def omniauth_failure
# after use. In the failure case, finally, the omniauth params
# are added as query params in our monkey patch to OmniAuth in engine.rb
def omniauth_params
if !defined?(@_omniauth_params)
unless defined?(@_omniauth_params)
if request.env['omniauth.params'] && request.env['omniauth.params'].any?
@_omniauth_params = request.env['omniauth.params']
elsif session['dta.omniauth.params'] && session['dta.omniauth.params'].any?
Expand Down Expand Up @@ -149,10 +149,10 @@ def devise_mapping

def set_random_password
# set crazy password for new oauth users. this is only used to prevent
# access via email sign-in.
p = SecureRandom.urlsafe_base64(nil, false)
@resource.password = p
@resource.password_confirmation = p
# access via email sign-in.
p = SecureRandom.urlsafe_base64(nil, false)
@resource.password = p
@resource.password_confirmation = p
end

def create_auth_params
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/devise_token_auth/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def edit

yield @resource if block_given?

redirect_header_options = {reset_password: true}
redirect_header_options = { reset_password: true }
redirect_headers = build_redirect_headers(token,
client_id,
redirect_header_options)
Expand Down Expand Up @@ -143,7 +143,7 @@ def render_create_success
def render_create_error(errors)
render json: {
success: false,
errors: errors,
errors: errors
}, status: 400
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/devise_token_auth/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def render_destroy_error
def resource_update_method
if DeviseTokenAuth.check_current_password_before_update == :attributes
'update_with_password'
elsif DeviseTokenAuth.check_current_password_before_update == :password && account_update_params.has_key?(:password)
elsif DeviseTokenAuth.check_current_password_before_update == :password && account_update_params.key?(:password)
'update_with_password'
elsif account_update_params.has_key?(:current_password)
elsif account_update_params.key?(:current_password)
'update_with_password'
else
'update_attributes'
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/devise_token_auth/unlocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def show
@resource.save!
yield @resource if block_given?

redirect_header_options = {unlock: true}
redirect_header_options = { unlock: true }
redirect_headers = build_redirect_headers(token,
client_id,
redirect_header_options)
Expand Down Expand Up @@ -70,7 +70,7 @@ def render_create_success
def render_create_error(errors)
render json: {
success: false,
errors: errors,
errors: errors
}, status: 400
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/devise_token_auth/concerns/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def remove_tokens_after_password_reset

if tokens.present? && tokens.many?
client_id, token_data = tokens.max_by { |cid, v| v[:expiry] || v['expiry'] }
self.tokens = {client_id => token_data}
self.tokens = { client_id => token_data }
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/devise_token_auth/controllers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module ClassMethods
# current_blogger :user # Preferably returns a User if one is signed in
#
def devise_token_auth_group(group_name, opts={})
mappings = "[#{ opts[:contains].map { |m| ":#{m}" }.join(',') }]"
mappings = "[#{opts[:contains].map { |m| ":#{m}" }.join(',')}]"

class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{group_name}!(favourite=nil, opts={})
Expand Down
8 changes: 4 additions & 4 deletions lib/devise_token_auth/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def mount_devise_token_auth_for(resource, opts)
unlocks_ctrl = opts[:controllers][:unlocks] || 'devise_token_auth/unlocks'

# define devise controller mappings
controllers = {sessions: sessions_ctrl,
registrations: registrations_ctrl,
passwords: passwords_ctrl,
confirmations: confirmations_ctrl}
controllers = { sessions: sessions_ctrl,
registrations: registrations_ctrl,
passwords: passwords_ctrl,
confirmations: confirmations_ctrl }

controllers[:unlocks] = unlocks_ctrl if unlocks_ctrl

Expand Down
10 changes: 5 additions & 5 deletions lib/generators/devise_token_auth/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ def create_initializer_file
end

def copy_migrations
if self.class.migration_exists?('db/migrate', "devise_token_auth_create_#{ user_class.underscore }")
say_status('skipped', "Migration 'devise_token_auth_create_#{ user_class.underscore }' already exists")
if self.class.migration_exists?('db/migrate', "devise_token_auth_create_#{user_class.underscore}")
say_status('skipped', "Migration 'devise_token_auth_create_#{user_class.underscore}' already exists")
else
migration_template(
'devise_token_auth_create_users.rb.erb',
"db/migrate/devise_token_auth_create_#{ user_class.pluralize.underscore }.rb"
"db/migrate/devise_token_auth_create_#{user_class.pluralize.underscore}.rb"
)
end
end

def create_user_model
fname = "app/models/#{ user_class.underscore }.rb"
fname = "app/models/#{user_class.underscore}.rb"
unless File.exist?(File.join(destination_root, fname))
template('user.rb.erb', fname)
else
inclusion = 'include DeviseTokenAuth::Concerns::User'
unless parse_file_for_line(fname, inclusion)

active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base'
inject_into_file fname, after: "class #{user_class} < #{active_record_needle}\n" do <<-'RUBY'
# Include default devise modules.
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/controllers/custom/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def update_block_called?
protected

def render_update_success
render json: {custom: 'foo'}
render json: { custom: 'foo' }
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def destroy_block_called?
protected

def render_create_success
render json: {custom: 'foo'}
render json: { custom: 'foo' }
end

end
2 changes: 1 addition & 1 deletion test/dummy/app/controllers/custom/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def destroy_block_called?
protected

def render_create_success
render json: {custom: 'foo'}
render json: { custom: 'foo' }
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def validate_token_block_called?
protected

def render_validate_token_success
render json: {custom: 'foo'}
render json: { custom: 'foo' }
end

end
4 changes: 2 additions & 2 deletions test/lib/devise_token_auth/url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class DeviseTokenAuth::UrlTest < ActiveSupport::TestCase
describe 'DeviseTokenAuth::Url#generate' do
test 'URI fragment should appear at the end of URL' do
params = {client_id: 123}
params = { client_id: 123 }
url = 'http://example.com#fragment'
assert_equal DeviseTokenAuth::Url.send(:generate, url, params), 'http://example.com?client_id=123#fragment'
end
Expand All @@ -15,7 +15,7 @@ class DeviseTokenAuth::UrlTest < ActiveSupport::TestCase
end

test 'should marge existing query params with new ones' do
params = {client_id: 123}
params = { client_id: 123 }
url = 'http://example.com?a=1'
assert_equal DeviseTokenAuth::Url.send(:generate, url, params), 'http://example.com?a=1&client_id=123'
end
Expand Down

0 comments on commit 608dcc3

Please sign in to comment.