diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..4b881bf27 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,114 @@ +inherit_from: .rubocop_todo.yml + +AllCops: + Exclude: + - 'coverage/**/*' + - 'test/dummy/tmp/**/*' + - 'test/dummy/log/**/*' + +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented, indented_relative_to_receiver +# +# Description from Rubocop Manual: +# This cop checks the indentation of the method name part in method calls +# that span more than one line. +# +# https://rubocop.readthedocs.io/en/latest/cops_layout/#layoutmultilinemethodcallindentation +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 +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + IgnoredMethods: + - assert_output + - assert_raises + - assert_silent + - assert_throws + - refute_output + - refute_raises + - refute_silent + - refute_throws + +# Offense count: 34 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle. +# SupportedStyles: nested, compact +# +# Description from Rubocop Manual: +# https://rubocop.readthedocs.io/en/latest/cops_style/#styleclassandmodulechildren +Style/ClassAndModuleChildren: + Enabled: false + +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, +# PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +# +# Description from Rubocop Manual: +# This cop checks hash literal syntax +# +# https://rubocop.readthedocs.io/en/latest/cops_style/#stylehashsyntax +Style/HashSyntax: + Enabled: true + EnforcedStyle: ruby19 + +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinSize. +# SupportedStyles: percent, brackets +# +# Description from Rubocop Manual: +# Check for array literals made up of symbols that are not using +# the `%i()` syntax. +# +# https://rubocop.readthedocs.io/en/latest/cops_style/#stylesymbolarray +Style/SymbolArray: + Enabled: true + EnforcedStyle: percent + MinSize: 3 + +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinSize, WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + Enabled: true + EnforcedStyle: percent + MinSize: 3 + +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + inherit_mode: + merge: + - Exclude + - ExcludedMethod + Exclude: + - 'lib/devise_token_auth/engine.rb' + - 'test/dummy/config/**/*' + - 'test/dummy/db/**/*' + ExcludedMethods: + - describe + - draw + - namespace + - devise_scope + - unnest_namespace + Max: 25 + +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + inherit_mode: + merge: + - Exclude + Exclude: + - 'test/**/*' + - 'Guardfile' + - 'devise_token_auth.gemspec' + IgnoredPatterns: + - '(\A|\s)#' + Max: 80 \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 000000000..417c11e21 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,574 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --exclude-limit 100` +# on 2018-04-09 16:05:53 -0700 using RuboCop version 0.54.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: Include, TreatCommentsAsGroupSeparators. +# Include: **/*.gemfile, **/Gemfile, **/gems.rb +Bundler/OrderedGems: + Exclude: + - 'gemfiles/rails_4_2.gemfile' + - 'gemfiles/rails_5_0.gemfile' + - 'gemfiles/rails_5_1.gemfile' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: Include, TreatCommentsAsGroupSeparators. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'devise_token_auth.gemspec' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. +Layout/EmptyLineBetweenDefs: + Exclude: + - 'app/models/devise_token_auth/concerns/user.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundAccessModifier: + Exclude: + - 'app/controllers/devise_token_auth/unlocks_controller.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Exclude: + - 'app/controllers/devise_token_auth/concerns/set_user_by_token.rb' + - 'test/controllers/demo_user_controller_test.rb' + - 'test/controllers/devise_token_auth/passwords_controller_test.rb' + - 'test/dummy/db/schema.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundMethodBody: + Exclude: + - 'app/controllers/devise_token_auth/concerns/set_user_by_token.rb' + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + - 'test/dummy/app/models/user.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines +Layout/EmptyLinesAroundModuleBody: + Exclude: + - 'lib/devise_token_auth/url.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'Guardfile' + - 'test/dummy/bin/rails' + - 'test/dummy/config.ru' + - 'test/dummy/config/environments/test.rb' + - 'test/dummy/config/initializers/omniauth.rb' + - 'test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + - 'app/controllers/devise_token_auth/sessions_controller.rb' + +# Offense count: 19 +# Cop supports --auto-correct. +Layout/LeadingCommentSpace: + Exclude: + - 'app/controllers/devise_token_auth/unlocks_controller.rb' + - 'test/dummy/config/initializers/devise_token_auth.rb' + - 'test/dummy/config/initializers/figaro.rb' + - 'test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Layout/MultilineBlockLayout: + Exclude: + - 'lib/generators/devise_token_auth/install_generator.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented, indented_relative_to_receiver +Layout/MultilineMethodCallIndentation: + Exclude: + - 'test/controllers/devise_token_auth/sessions_controller_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/SpaceAfterColon: + Exclude: + - 'app/controllers/devise_token_auth/sessions_controller.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Exclude: + - 'app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb' + - 'lib/devise_token_auth/url.rb' + - 'lib/generators/devise_token_auth/install_generator.rb' + - 'test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Layout/SpaceAroundOperators: + Exclude: + - 'app/controllers/devise_token_auth/concerns/set_user_by_token.rb' + - 'test/dummy/app/models/user.rb' + - 'test/dummy/config/environments/test.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: + Exclude: + - 'lib/devise_token_auth/rails/routes.rb' + - 'test/dummy/app/models/user.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideArrayLiteralBrackets: + Exclude: + - 'config/initializers/devise.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingBlankLines: + Exclude: + - 'app/validators/email_validator.rb' + - 'test/dummy/config/initializers/cookies_serializer.rb' + - 'test/dummy/lib/migration_database_helper.rb' + - 'test/integration/navigation_test.rb' + +# Offense count: 1 +Lint/AmbiguousBlockAssociation: + Exclude: + - 'test/models/user_test.rb' + +# Offense count: 1 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Exclude: + - 'test/dummy/bin/spring' + +# Offense count: 1 +Lint/DuplicateMethods: + Exclude: + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + +# Offense count: 2 +Lint/HandleExceptions: + Exclude: + - 'test/dummy/bin/rails' + - 'test/dummy/bin/rake' + +# Offense count: 1 +Lint/IneffectiveAccessModifier: + Exclude: + - 'lib/generators/devise_token_auth/install_generator.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Lint/StringConversionInInterpolation: + Exclude: + - 'app/controllers/devise_token_auth/concerns/resource_finder.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'app/models/devise_token_auth/concerns/user.rb' + - 'test/controllers/demo_user_controller_test.rb' + - 'test/controllers/devise_token_auth/sessions_controller_test.rb' + - 'test/dummy/app/controllers/custom/registrations_controller.rb' + - 'test/dummy/config/initializers/omniauth.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. +Lint/UnusedMethodArgument: + Exclude: + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + - 'app/controllers/devise_token_auth/unlocks_controller.rb' + - 'lib/devise_token_auth/engine.rb' + - 'lib/generators/devise_token_auth/install_generator.rb' + +# Offense count: 3 +Lint/UriEscapeUnescape: + Exclude: + - 'test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb' + - 'test/controllers/devise_token_auth/registrations_controller_test.rb' + - 'test/controllers/overrides/confirmations_controller_test.rb' + +# Offense count: 35 +Metrics/AbcSize: + Max: 76 + +# Offense count: 1 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + Exclude: + - 'app/models/devise_token_auth/concerns/user.rb' + +# Offense count: 15 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 698 + +# Offense count: 14 +Metrics/CyclomaticComplexity: + Max: 17 + +# Offense count: 92 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Exclude: + - 'app/controllers/devise_token_auth/application_controller.rb' + - 'app/controllers/devise_token_auth/concerns/set_user_by_token.rb' + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + - 'app/controllers/devise_token_auth/passwords_controller.rb' + - 'app/controllers/devise_token_auth/registrations_controller.rb' + - 'app/controllers/devise_token_auth/sessions_controller.rb' + - 'app/controllers/devise_token_auth/unlocks_controller.rb' + - 'app/models/devise_token_auth/concerns/user.rb' + - 'app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb' + - 'app/validators/email_validator.rb' + - 'lib/devise_token_auth/engine.rb' + - 'lib/devise_token_auth/rails/routes.rb' + - 'lib/generators/devise_token_auth/install_generator.rb' + +# Offense count: 35 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 63 + +# Offense count: 2 +# Configuration parameters: CountComments. +Metrics/ModuleLength: + Max: 1037 + +# Offense count: 13 +Metrics/PerceivedComplexity: + Max: 19 + +# Offense count: 5 +Naming/AccessorMethodName: + Exclude: + - 'app/controllers/devise_token_auth/concerns/set_user_by_token.rb' + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + - 'app/controllers/devise_token_auth/sessions_controller.rb' + - 'lib/devise_token_auth/rails/routes.rb' + - 'test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb' + +# Offense count: 2 +# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros. +# NamePrefix: is_, has_, have_ +# NamePrefixBlacklist: is_, has_, have_ +# NameWhitelist: is_a? +# MethodDefinitionMacros: define_method, define_singleton_method +Naming/PredicateName: + Exclude: + - 'spec/**/*' + - 'app/controllers/devise_token_auth/concerns/set_user_by_token.rb' + - 'lib/generators/devise_token_auth/install_generator.rb' + +# Offense count: 2 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: io, id, to +Naming/UncommunicativeMethodParamName: + Exclude: + - 'app/controllers/devise_token_auth/application_controller.rb' + - 'app/controllers/devise_token_auth/concerns/resource_finder.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: MaxKeyValuePairs. +Performance/RedundantMerge: + Exclude: + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Performance/RegexpMatch: + Exclude: + - 'app/validators/email_validator.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Performance/StringReplacement: + Exclude: + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + - 'lib/devise_token_auth/rails/routes.rb' + - 'test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: percent_q, bare_percent +Style/BarePercentLiterals: + Exclude: + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/ColonMethodCall: + Exclude: + - 'lib/devise_token_auth/engine.rb' + - 'lib/devise_token_auth/rails/routes.rb' + +# Offense count: 3 +Style/CommentedKeyword: + Exclude: + - 'app/controllers/devise_token_auth/concerns/set_user_by_token.rb' + - 'test/controllers/demo_user_controller_test.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'app/controllers/devise_token_auth/application_controller.rb' + - 'app/controllers/devise_token_auth/concerns/resource_finder.rb' + - 'app/controllers/devise_token_auth/registrations_controller.rb' + +# Offense count: 2 +Style/DateTime: + Exclude: + - 'app/models/devise_token_auth/concerns/user.rb' + +# Offense count: 24 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'app/controllers/devise_token_auth/application_controller.rb' + - 'app/controllers/devise_token_auth/concerns/resource_finder.rb' + - 'app/controllers/devise_token_auth/concerns/set_user_by_token.rb' + - 'app/controllers/devise_token_auth/confirmations_controller.rb' + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + - 'app/controllers/devise_token_auth/passwords_controller.rb' + - 'app/controllers/devise_token_auth/registrations_controller.rb' + - 'app/controllers/devise_token_auth/sessions_controller.rb' + - 'app/controllers/devise_token_auth/token_validations_controller.rb' + - 'app/controllers/devise_token_auth/unlocks_controller.rb' + - 'app/models/devise_token_auth/concerns/user.rb' + - 'app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb' + - 'app/validators/email_validator.rb' + - 'lib/devise_token_auth.rb' + - 'lib/devise_token_auth/controllers/helpers.rb' + - 'lib/devise_token_auth/controllers/url_helpers.rb' + - 'lib/devise_token_auth/engine.rb' + - 'lib/devise_token_auth/rails/routes.rb' + - 'lib/devise_token_auth/url.rb' + - 'lib/generators/devise_token_auth/install_generator.rb' + - 'lib/generators/devise_token_auth/install_views_generator.rb' + +# Offense count: 3 +Style/DoubleNegation: + Exclude: + - 'lib/devise_token_auth/url.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/EachWithObject: + Exclude: + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: compact, expanded +Style/EmptyMethod: + Exclude: + - 'lib/devise_token_auth/controllers/url_helpers.rb' + +# Offense count: 13 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'app/controllers/devise_token_auth/confirmations_controller.rb' + - 'app/controllers/devise_token_auth/passwords_controller.rb' + - 'app/controllers/devise_token_auth/unlocks_controller.rb' + - 'app/models/devise_token_auth/concerns/user.rb' + - 'app/validators/email_validator.rb' + - 'test/dummy/app/controllers/overrides/confirmations_controller.rb' + - 'test/dummy/app/controllers/overrides/passwords_controller.rb' + - 'test/dummy/app/models/user.rb' + - 'test/test_helper.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/MethodCallWithoutArgsParentheses: + Exclude: + - 'test/models/user_test.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline +Style/MethodDefParentheses: + Exclude: + - 'app/controllers/devise_token_auth/passwords_controller.rb' + - 'app/controllers/devise_token_auth/registrations_controller.rb' + +# Offense count: 9 +Style/MixinUsage: + Exclude: + - 'test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb' + - 'test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb' + - 'test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb' + - 'test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb' + - 'test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb' + - 'test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb' + - 'test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb' + - 'test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb' + - 'test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/MultilineIfModifier: + Exclude: + - 'app/controllers/devise_token_auth/application_controller.rb' + +# Offense count: 2 +Style/MultilineTernaryOperator: + Exclude: + - 'test/dummy/config/environments/test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinBodyLength. +# SupportedStyles: skip_modifier_ifs, always +Style/Next: + Exclude: + - 'app/controllers/devise_token_auth/sessions_controller.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/Not: + Exclude: + - 'test/dummy/app/controllers/overrides/sessions_controller.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: Strict. +Style/NumericLiterals: + MinDigits: 15 + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'app/controllers/devise_token_auth/confirmations_controller.rb' + - 'test/dummy/app/models/user.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowSafeAssignment. +Style/ParenthesesAroundCondition: + Exclude: + - 'app/models/devise_token_auth/concerns/user.rb' + - 'lib/devise_token_auth/url.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RescueModifier: + Exclude: + - 'app/models/devise_token_auth/concerns/user.rb' + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, Whitelist. +# Whitelist: present?, blank?, presence, try +Style/SafeNavigation: + Exclude: + - 'app/controllers/devise_token_auth/concerns/set_user_by_token.rb' + - 'app/controllers/devise_token_auth/confirmations_controller.rb' + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' + - 'app/controllers/devise_token_auth/passwords_controller.rb' + - 'app/controllers/devise_token_auth/unlocks_controller.rb' + - 'app/models/devise_token_auth/concerns/user.rb' + - 'lib/devise_token_auth/engine.rb' + - 'test/dummy/app/controllers/overrides/confirmations_controller.rb' + - 'test/dummy/app/controllers/overrides/passwords_controller.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AllowIfMethodIsEmpty. +Style/SingleLineMethods: + Exclude: + - 'app/models/devise_token_auth/concerns/user.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: use_perl_names, use_english_names +Style/SpecialGlobalVars: + Exclude: + - 'devise_token_auth.gemspec' + +# Offense count: 7 +# Cop supports --auto-correct. +Style/SymbolLiteral: + Exclude: + - 'app/controllers/devise_token_auth/application_controller.rb' + - 'app/controllers/devise_token_auth/concerns/set_user_by_token.rb' + - 'app/models/devise_token_auth/concerns/user.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'app/models/devise_token_auth/concerns/user.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowSafeAssignment. +# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex +Style/TernaryParentheses: + Exclude: + - 'lib/generators/devise_token_auth/install_generator.rb' + - 'test/lib/generators/devise_token_auth/install_generator_test.rb' + - 'test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowNamedUnderscoreVariables. +Style/TrailingUnderscoreVariable: + Exclude: + - 'test/controllers/devise_token_auth/sessions_controller_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/UnneededPercentQ: + Exclude: + - 'app/controllers/devise_token_auth/omniauth_callbacks_controller.rb' diff --git a/Appraisals b/Appraisals index 4558c869b..2fde90088 100644 --- a/Appraisals +++ b/Appraisals @@ -1,18 +1,20 @@ +# frozen_string_literal: true + [ { name: '4-2', version: '4.2.10' } ].each do |rails| appraise "rails-#{rails[:name]}" do - gem "mysql2", "~> 0.4.10" - gem "pg", "~> 0.21" - gem "rails", "~> #{rails[:version]}" + gem 'mysql2', '~> 0.4.10' + gem 'pg', '~> 0.21' + gem 'rails', "~> #{rails[:version]}" end end [ { name: '5-0', version: '5.0.7' }, - { name: '5-1', version: '5.1.6' }, + { name: '5-1', version: '5.1.6' } ].each do |rails| appraise "rails-#{rails[:name]}" do - gem "rails", "~> #{rails[:version]}" + gem 'rails', "~> #{rails[:version]}" end end diff --git a/Gemfile b/Gemfile index 3d3090c58..5bbb86393 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Declare your gem's dependencies in devise_token_auth.gemspec. @@ -35,6 +37,8 @@ group :development, :test do gem 'mocha', '>= 1.5' gem 'pry' gem 'pry-remote' + + gem 'rubocop', require: false end # code coverage, metrics diff --git a/Gemfile.lock b/Gemfile.lock index 3d4c6c4b0..023b1162a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,6 +85,7 @@ GEM rake thor (>= 0.14.0) arel (8.0.0) + ast (2.4.0) attr_encrypted (3.0.3) encryptor (~> 3.0.0) bcrypt (3.1.11) @@ -193,7 +194,11 @@ GEM oauth2 (~> 1.0) omniauth (~> 1.2) orm_adapter (0.5.0) + parallel (1.12.1) + parser (2.5.1.0) + ast (~> 2.4.0) pg (0.20.0) + powerpack (0.1.1) pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) @@ -233,9 +238,8 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rainbow (2.2.2) - rake - rake (12.3.0) + rainbow (3.0.0) + rake (12.3.1) rb-fsevent (0.9.8) rb-inotify (0.9.8) ffi (>= 0.5.0) @@ -243,6 +247,13 @@ GEM actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) retriable (2.1.0) + rubocop (0.55.0) + parallel (~> 1.10) + parser (>= 2.5) + powerpack (~> 0.1) + rainbow (>= 2.2.2, < 4.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.9.0) ruby_dep (1.5.0) sawyer (0.8.1) @@ -267,6 +278,7 @@ GEM thread_safe (0.3.6) tzinfo (1.2.4) thread_safe (~> 0.1) + unicode-display_width (1.3.2) warden (1.2.7) rack (>= 1.0) websocket-driver (0.6.5) @@ -301,6 +313,7 @@ DEPENDENCIES pry-remote rack-cors rails-controller-testing + rubocop sqlite3 (~> 1.3) thor diff --git a/Guardfile b/Guardfile index 1c909c3aa..24f70edd5 100644 --- a/Guardfile +++ b/Guardfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # A sample Guardfile # More info at https://github.com/guard/guard#readme diff --git a/Rakefile b/Rakefile index e96e6932b..b118b6583 100644 --- a/Rakefile +++ b/Rakefile @@ -16,11 +16,9 @@ RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_files.include('lib/**/*.rb') end -APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) +APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__) load 'rails/tasks/engine.rake' - - Bundler::GemHelper.install_tasks require 'rake/testtask' @@ -33,5 +31,12 @@ Rake::TestTask.new(:test) do |t| t.warning = false end - task default: :test + +require 'rubocop/rake_task' + +desc 'Run RuboCop' +RuboCop::RakeTask.new(:rubocop) do |task| + task.formatters = %w[fuubar offenses worst] + task.fail_on_error = false # don't abort rake on failure +end diff --git a/app/controllers/devise_token_auth/application_controller.rb b/app/controllers/devise_token_auth/application_controller.rb index 99efaa169..87f9e12e9 100644 --- a/app/controllers/devise_token_auth/application_controller.rb +++ b/app/controllers/devise_token_auth/application_controller.rb @@ -5,16 +5,14 @@ class ApplicationController < DeviseController include DeviseTokenAuth::Concerns::SetUserByToken include DeviseTokenAuth::Concerns::ResourceFinder - def resource_data(opts={}) + def resource_data(opts = {}) response_data = opts[:resource_json] || @resource.as_json - if json_api? - response_data['type'] = @resource.class.name.parameterize - end + response_data['type'] = @resource.class.name.parameterize if json_api? response_data end def resource_errors - return @resource.errors.to_hash.merge(full_messages: @resource.errors.full_messages) + @resource.errors.to_hash.merge(full_messages: @resource.errors.full_messages) end protected @@ -44,7 +42,7 @@ def params_for_resource(resource) devise_parameter_sanitizer.instance_values['permitted'][resource] end - def resource_class(m=nil) + def resource_class(m = nil) if m mapping = Devise.mappings[m] else @@ -59,7 +57,7 @@ def json_api? return ActiveModel::Serializer.setup do |config| config.adapter == :json_api end if ActiveModel::Serializer.respond_to?(:setup) - return ActiveModelSerializers.config.adapter == :json_api + ActiveModelSerializers.config.adapter == :json_api end def recoverable_enabled? diff --git a/app/controllers/devise_token_auth/concerns/resource_finder.rb b/app/controllers/devise_token_auth/concerns/resource_finder.rb index 9ee1a4386..fb66118cb 100644 --- a/app/controllers/devise_token_auth/concerns/resource_finder.rb +++ b/app/controllers/devise_token_auth/concerns/resource_finder.rb @@ -23,13 +23,13 @@ def find_resource(field, value) # fix for mysql default case insensitivity q = "#{field.to_s} = ? AND provider='#{provider.to_s}'" if ActiveRecord::Base.connection.adapter_name.downcase.starts_with? 'mysql' - q = "BINARY " + q + q = 'BINARY ' + q end @resource = resource_class.where(q, value).first end - def resource_class(m=nil) + def resource_class(m = nil) if m mapping = Devise.mappings[m] else diff --git a/app/controllers/devise_token_auth/concerns/set_user_by_token.rb b/app/controllers/devise_token_auth/concerns/set_user_by_token.rb index 1715461c4..e22d19aa2 100644 --- a/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +++ b/app/controllers/devise_token_auth/concerns/set_user_by_token.rb @@ -36,7 +36,7 @@ def ensure_pristine_resource end # user auth - def set_user_by_token(mapping=nil) + def set_user_by_token(mapping = nil) # determine target authentication class rc = resource_class(mapping) @@ -72,7 +72,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 @@ -84,7 +84,7 @@ def set_user_by_token(mapping=nil) if user && user.valid_token?(@token, @client_id) # sign_in with bypass: true will be deprecated in the next version of Devise - if self.respond_to?(:bypass_sign_in) && DeviseTokenAuth.bypass_sign_in + if respond_to?(:bypass_sign_in) && DeviseTokenAuth.bypass_sign_in bypass_sign_in(user, scope: :user) else sign_in(:user, user, store: false, event: :fetch, bypass: DeviseTokenAuth.bypass_sign_in) @@ -159,11 +159,10 @@ def update_auth_header private - def is_batch_request?(user, client_id) !params[:unbatch] && - user.tokens[client_id] && - user.tokens[client_id]['updated_at'] && - Time.parse(user.tokens[client_id]['updated_at']) > @request_started_at - DeviseTokenAuth.batch_request_buffer_throttle + user.tokens[client_id] && + user.tokens[client_id]['updated_at'] && + Time.parse(user.tokens[client_id]['updated_at']) > @request_started_at - DeviseTokenAuth.batch_request_buffer_throttle end end diff --git a/app/controllers/devise_token_auth/confirmations_controller.rb b/app/controllers/devise_token_auth/confirmations_controller.rb index ed14894a0..2f6b07acd 100644 --- a/app/controllers/devise_token_auth/confirmations_controller.rb +++ b/app/controllers/devise_token_auth/confirmations_controller.rb @@ -18,14 +18,14 @@ 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) redirect_to(@resource.build_auth_url(params[:redirect_url], redirect_headers)) else - raise ActionController::RoutingError.new('Not Found') + raise ActionController::RoutingError, 'Not Found' end end end diff --git a/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb b/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb index c0917716b..e3eb5ba64 100644 --- a/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +++ b/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb @@ -2,7 +2,6 @@ module DeviseTokenAuth class OmniauthCallbacksController < DeviseTokenAuth::ApplicationController - attr_reader :auth_params skip_before_action :set_user_by_token, raise: false skip_after_action :update_auth_header @@ -48,7 +47,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 @@ -62,7 +61,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? @@ -88,13 +87,11 @@ def assign_provider_attrs(user, auth_hash) def whitelisted_params whitelist = params_for_resource(:sign_up) - whitelist.inject({}){|coll, key| + whitelist.inject({}) do |coll, key| param = omniauth_params[key.to_s] - if param - coll[key] = param - end + coll[key] = param if param coll - } + end end def resource_class(mapping = nil) @@ -103,7 +100,7 @@ def resource_class(mapping = nil) elsif params['resource_class'] params['resource_class'].constantize else - raise "No resource_class found" + raise 'No resource_class found' end end @@ -151,10 +148,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 @@ -175,10 +172,8 @@ def set_token_on_resource end def render_data(message, data) - @data = data.merge({ - message: message - }) - render :layout => nil, :template => "devise_token_auth/omniauth_external_window" + @data = data.merge(message: message) + render layout: nil, template: 'devise_token_auth/omniauth_external_window' end def render_data_or_redirect(message, data, user_data = {}) @@ -209,22 +204,22 @@ def render_data_or_redirect(message, data, user_data = {}) end def fallback_render(text) - render inline: %Q| + render inline: %Q( #{text} - | + ) end def get_resource_from_auth_hash # find or create user by provider and provider uid - @resource = resource_class.where({ - uid: auth_hash['uid'], + @resource = resource_class.where( + uid: auth_hash['uid'], provider: auth_hash['provider'] - }).first_or_initialize + ).first_or_initialize if @resource.new_record? @oauth_registration = true @@ -240,6 +235,5 @@ def get_resource_from_auth_hash @resource end - end end diff --git a/app/controllers/devise_token_auth/passwords_controller.rb b/app/controllers/devise_token_auth/passwords_controller.rb index 92fdd0230..e6ceb2397 100644 --- a/app/controllers/devise_token_auth/passwords_controller.rb +++ b/app/controllers/devise_token_auth/passwords_controller.rb @@ -2,21 +2,19 @@ module DeviseTokenAuth class PasswordsController < DeviseTokenAuth::ApplicationController - before_action :set_user_by_token, :only => [:update] - skip_after_action :update_auth_header, :only => [:create, :edit] + before_action :set_user_by_token, only: [:update] + skip_after_action :update_auth_header, only: [:create, :edit] # this action is responsible for generating password reset tokens and # sending emails def create - unless resource_params[:email] - return render_create_error_missing_email - end + return render_create_error_missing_email unless resource_params[:email] # give redirect value from params priority @redirect_url = params.fetch( - :redirect_url, - DeviseTokenAuth.default_password_reset_url - ) + :redirect_url, + DeviseTokenAuth.default_password_reset_url + ) return render_create_error_missing_redirect_url unless @redirect_url return render_create_error_not_allowed_redirect_url if blacklisted_redirect_url? @@ -26,12 +24,12 @@ def create if @resource yield @resource if block_given? - @resource.send_reset_password_instructions({ + @resource.send_reset_password_instructions( email: @email, provider: 'email', redirect_url: @redirect_url, client_config: params[:config_name] - }) + ) if @resource.errors.empty? return render_create_success @@ -61,7 +59,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) @@ -74,9 +72,7 @@ def edit def update # make sure user is authorized - unless @resource - return render_update_error_unauthorized - end + return render_update_error_unauthorized unless @resource # make sure account doesn't use oauth2 provider unless @resource.provider == 'email' @@ -104,18 +100,18 @@ def update def resource_update_method allow_password_change = recoverable_enabled? && @resource.allow_password_change == true if DeviseTokenAuth.check_current_password_before_update == false || allow_password_change - "update_attributes" + 'update_attributes' else - "update_with_password" + 'update_with_password' end end def render_create_error_missing_email - render_error(401, I18n.t("devise_token_auth.passwords.missing_email")) + render_error(401, I18n.t('devise_token_auth.passwords.missing_email')) end def render_create_error_missing_redirect_url - render_error(401, I18n.t("devise_token_auth.passwords.missing_redirect_url")) + render_error(401, I18n.t('devise_token_auth.passwords.missing_redirect_url')) end def render_create_error_not_allowed_redirect_url @@ -123,26 +119,26 @@ def render_create_error_not_allowed_redirect_url status: 'error', data: resource_data } - message = I18n.t("devise_token_auth.passwords.not_allowed_redirect_url", redirect_url: @redirect_url) + message = I18n.t('devise_token_auth.passwords.not_allowed_redirect_url', redirect_url: @redirect_url) render_error(422, message, response) end def render_create_success render json: { success: true, - message: I18n.t("devise_token_auth.passwords.sended", email: @email) + message: I18n.t('devise_token_auth.passwords.sended', email: @email) } end def render_create_error(errors) render json: { success: false, - errors: errors, + errors: errors }, status: 400 end def render_edit_error - raise ActionController::RoutingError.new('Not Found') + raise ActionController::RoutingError, 'Not Found' end def render_update_error_unauthorized @@ -150,23 +146,23 @@ def render_update_error_unauthorized end def render_update_error_password_not_required - render_error(422, I18n.t("devise_token_auth.passwords.password_not_required", provider: @resource.provider.humanize)) + render_error(422, I18n.t('devise_token_auth.passwords.password_not_required', provider: @resource.provider.humanize)) end def render_update_error_missing_password - render_error(422, I18n.t("devise_token_auth.passwords.missing_passwords")) + render_error(422, I18n.t('devise_token_auth.passwords.missing_passwords')) end def render_update_success render json: { success: true, data: resource_data, - message: I18n.t("devise_token_auth.passwords.successfully_updated") + message: I18n.t('devise_token_auth.passwords.successfully_updated') } end def render_update_error - return render json: { + render json: { success: false, errors: resource_errors }, status: 422 @@ -190,7 +186,7 @@ def with_reset_password_token token end def render_not_found_error - render_error(404, I18n.t("devise_token_auth.passwords.user_not_found", email: @email)) + render_error(404, I18n.t('devise_token_auth.passwords.user_not_found', email: @email)) end end end diff --git a/app/controllers/devise_token_auth/registrations_controller.rb b/app/controllers/devise_token_auth/registrations_controller.rb index 2dc38066e..5b9271707 100644 --- a/app/controllers/devise_token_auth/registrations_controller.rb +++ b/app/controllers/devise_token_auth/registrations_controller.rb @@ -12,7 +12,8 @@ def create unless @resource.present? raise DeviseTokenAuth::Errors::NoResourceDefinedError, - "#{self.class.name} #build_resource does not define @resource, execution stopped" + "#{self.class.name} #build_resource does not define @resource,"\ + ' execution stopped.' end # give redirect value from params priority @@ -31,8 +32,8 @@ def create begin # override email confirmation, must be sent manually from ctrl - resource_class.set_callback("create", :after, :send_on_create_confirmation_instructions) - resource_class.skip_callback("create", :after, :send_on_create_confirmation_instructions) + resource_class.set_callback('create', :after, :send_on_create_confirmation_instructions) + resource_class.skip_callback('create', :after, :send_on_create_confirmation_instructions) if @resource.respond_to? :skip_confirmation_notification! # Fix duplicate e-mails by disabling Devise confirmation e-mail @@ -42,18 +43,19 @@ def create if @resource.save yield @resource if block_given? - unless @resource.confirmed? - # user will require email authentication - @resource.send_confirmation_instructions({ - client_config: params[:config_name], - redirect_url: @redirect_url - }) - else + if @resource.confirmed? # email auth has been bypassed, authenticate user @client_id, @token = @resource.create_token @resource.save! update_auth_header + else + # user will require email authentication + @resource.send_confirmation_instructions( + client_config: params[:config_name], + redirect_url: @redirect_url + ) end + render_create_success else clean_up_passwords @resource @@ -167,7 +169,7 @@ def render_update_error end def render_update_error_user_not_found - render_error(404, I18n.t('devise_token_auth.registrations.user_not_found'), { status: 'error' }) + render_error(404, I18n.t('devise_token_auth.registrations.user_not_found'), status: 'error') end def render_destroy_success @@ -178,7 +180,7 @@ def render_destroy_success end def render_destroy_error - render_error(404, I18n.t('devise_token_auth.registrations.account_to_destroy_not_found'), { status: 'error' }) + render_error(404, I18n.t('devise_token_auth.registrations.account_to_destroy_not_found'), status: 'error') end private @@ -186,9 +188,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' @@ -204,7 +206,7 @@ def validate_account_update_params end def validate_post_data which, message - render_error(:unprocessable_entity, message, { status: 'error' }) if which.empty? + render_error(:unprocessable_entity, message, status: 'error') if which.empty? end end end diff --git a/app/controllers/devise_token_auth/sessions_controller.rb b/app/controllers/devise_token_auth/sessions_controller.rb index 7ffa97aa8..fc54c35a3 100644 --- a/app/controllers/devise_token_auth/sessions_controller.rb +++ b/app/controllers/devise_token_auth/sessions_controller.rb @@ -3,8 +3,8 @@ # see http://www.emilsoman.com/blog/2013/05/18/building-a-tested/ module DeviseTokenAuth class SessionsController < DeviseTokenAuth::ApplicationController - before_action :set_user_by_token, :only => [:destroy] - after_action :reset_session, :only => [:destroy] + before_action :set_user_by_token, only: [:destroy] + after_action :reset_session, only: [:destroy] def new render_new_error @@ -87,14 +87,11 @@ def get_auth_params auth_val.downcase! end - return { - key: auth_key, - val: auth_val - } + { key: auth_key, val: auth_val } end def render_new_error - render_error(405, I18n.t("devise_token_auth.sessions.not_supported")) + render_error(405, I18n.t('devise_token_auth.sessions.not_supported')) end def render_create_success @@ -104,15 +101,15 @@ def render_create_success end def render_create_error_not_confirmed - render_error(401, I18n.t("devise_token_auth.sessions.not_confirmed", email: @resource.email)) + render_error(401, I18n.t('devise_token_auth.sessions.not_confirmed', email: @resource.email)) end def render_create_error_account_locked - render_error(401, I18n.t("devise.mailer.unlock_instructions.account_lock_msg")) + render_error(401, I18n.t('devise.mailer.unlock_instructions.account_lock_msg')) end def render_create_error_bad_credentials - render_error(401, I18n.t("devise_token_auth.sessions.bad_credentials")) + render_error(401, I18n.t('devise_token_auth.sessions.bad_credentials')) end def render_destroy_success @@ -122,7 +119,7 @@ def render_destroy_success end def render_destroy_error - render_error(404, I18n.t("devise_token_auth.sessions.user_not_found")) + render_error(404, I18n.t('devise_token_auth.sessions.user_not_found')) end private @@ -130,6 +127,5 @@ def render_destroy_error def resource_params params.permit(*params_for_resource(:sign_in)) end - end end diff --git a/app/controllers/devise_token_auth/token_validations_controller.rb b/app/controllers/devise_token_auth/token_validations_controller.rb index 4d82fdec4..9989e1f04 100644 --- a/app/controllers/devise_token_auth/token_validations_controller.rb +++ b/app/controllers/devise_token_auth/token_validations_controller.rb @@ -2,8 +2,8 @@ module DeviseTokenAuth class TokenValidationsController < DeviseTokenAuth::ApplicationController - skip_before_action :assert_is_devise_resource!, :only => [:validate_token] - before_action :set_user_by_token, :only => [:validate_token] + skip_before_action :assert_is_devise_resource!, only: [:validate_token] + before_action :set_user_by_token, only: [:validate_token] def validate_token # @resource will have been set by set_user_by_token concern @@ -25,7 +25,7 @@ def render_validate_token_success end def render_validate_token_error - render_error(401, I18n.t("devise_token_auth.token_validations.invalid")) + render_error(401, I18n.t('devise_token_auth.token_validations.invalid')) end end end diff --git a/app/controllers/devise_token_auth/unlocks_controller.rb b/app/controllers/devise_token_auth/unlocks_controller.rb index 13faa023d..eda8d84d7 100644 --- a/app/controllers/devise_token_auth/unlocks_controller.rb +++ b/app/controllers/devise_token_auth/unlocks_controller.rb @@ -2,14 +2,12 @@ module DeviseTokenAuth class UnlocksController < DeviseTokenAuth::ApplicationController - skip_after_action :update_auth_header, :only => [:create, :show] + skip_after_action :update_auth_header, only: [:create, :show] # this action is responsible for generating unlock tokens and # sending emails def create - unless resource_params[:email] - return render_create_error_missing_email - end + return render_create_error_missing_email unless resource_params[:email] @email = get_case_insensitive_field_from_resource_params(:email) @resource = find_resource(:email, @email) @@ -17,11 +15,11 @@ def create if @resource yield @resource if block_given? - @resource.send_unlock_instructions({ + @resource.send_unlock_instructions( email: @email, provider: 'email', client_config: params[:config_name] - }) + ) if @resource.errors.empty? return render_create_success @@ -41,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) @@ -59,29 +57,29 @@ def after_unlock_path_for(resource) end def render_create_error_missing_email - render_error(401, I18n.t("devise_token_auth.unlocks.missing_email")) + render_error(401, I18n.t('devise_token_auth.unlocks.missing_email')) end def render_create_success render json: { success: true, - message: I18n.t("devise_token_auth.unlocks.sended", email: @email) + message: I18n.t('devise_token_auth.unlocks.sended', email: @email) } end def render_create_error(errors) render json: { success: false, - errors: errors, + errors: errors }, status: 400 end def render_show_error - raise ActionController::RoutingError.new('Not Found') + raise ActionController::RoutingError, 'Not Found' end def render_not_found_error - render_error(404, I18n.t("devise_token_auth.unlocks.user_not_found", email: @email)) + render_error(404, I18n.t('devise_token_auth.unlocks.user_not_found', email: @email)) end def resource_params diff --git a/app/models/devise_token_auth/concerns/user.rb b/app/models/devise_token_auth/concerns/user.rb index 32ccdcbf6..b6a898e45 100644 --- a/app/models/devise_token_auth/concerns/user.rb +++ b/app/models/devise_token_auth/concerns/user.rb @@ -10,24 +10,20 @@ def self.tokens_match?(token_hash, token) key = "#{token_hash}/#{token}" result = @token_equality_cache[key] ||= (::BCrypt::Password.new(token_hash) == token) - if @token_equality_cache.size > 10000 - @token_equality_cache = {} - end + @token_equality_cache = {} if @token_equality_cache.size > 10000 result end included do # Hack to check if devise is already enabled - unless self.method_defined?(:devise_modules) - devise :database_authenticatable, :registerable, - :recoverable, :trackable, :validatable, :confirmable + if method_defined?(:devise_modules) + devise_modules.delete(:omniauthable) else - self.devise_modules.delete(:omniauthable) + devise :database_authenticatable, :registerable, + :recoverable, :trackable, :validatable, :confirmable end - unless tokens_has_json_column_type? - serialize :tokens, JSON - end + serialize :tokens, JSON unless tokens_has_json_column_type? if DeviseTokenAuth.default_callbacks include DeviseTokenAuth::Concerns::UserOmniauthCallbacks @@ -54,11 +50,11 @@ def password_required? end # override devise method to include additional info as opts hash - def send_confirmation_instructions(opts={}) + def send_confirmation_instructions(opts = {}) generate_confirmation_token! unless @raw_confirmation_token # fall back to "default" config name - opts[:client_config] ||= "default" + opts[:client_config] ||= 'default' opts[:to] = unconfirmed_email if pending_reconfirmation? opts[:redirect_url] ||= DeviseTokenAuth.default_confirm_success_url @@ -66,24 +62,24 @@ def send_confirmation_instructions(opts={}) end # override devise method to include additional info as opts hash - def send_reset_password_instructions(opts={}) + def send_reset_password_instructions(opts = {}) token = set_reset_password_token # fall back to "default" config name - opts[:client_config] ||= "default" + opts[:client_config] ||= 'default' send_devise_notification(:reset_password_instructions, token, opts) token end # override devise method to include additional info as opts hash - def send_unlock_instructions(opts={}) + def send_unlock_instructions(opts = {}) raw, enc = Devise.token_generator.generate(self.class, :unlock_token) self.unlock_token = enc save(validate: false) # fall back to "default" config name - opts[:client_config] ||= "default" + opts[:client_config] ||= 'default' send_devise_notification(:unlock_instructions, raw, opts) raw @@ -95,7 +91,7 @@ def create_token(client_id: nil, token: nil, expiry: nil, **token_extras) token ||= SecureRandom.urlsafe_base64(nil, false) expiry ||= (Time.zone.now + token_lifespan).to_i - self.tokens[client_id] = { + tokens[client_id] = { token: BCrypt::Password.create(token), expiry: expiry }.merge!(token_extras) @@ -109,7 +105,7 @@ module ClassMethods protected def tokens_has_json_column_type? - database_exists? && table_exists? && self.columns_hash['tokens'] && self.columns_hash['tokens'].type.in?([:json, :jsonb]) + database_exists? && table_exists? && columns_hash['tokens'] && columns_hash['tokens'].type.in?([:json, :jsonb]) end def database_exists? @@ -117,22 +113,19 @@ def database_exists? end end - - def valid_token?(token, client_id='default') + def valid_token?(token, client_id = 'default') return false unless tokens[client_id] return true if token_is_current?(token, client_id) return true if token_can_be_reused?(token, client_id) # return false if none of the above conditions are met - return false + false end - # this must be done from the controller so that additional params # can be passed on from the client def send_confirmation_notification?; false; end - def token_is_current?(token, client_id) # ghetto HashWithIndifferentAccess expiry = tokens[client_id]['expiry'] || tokens[client_id][:expiry] @@ -150,7 +143,6 @@ def token_is_current?(token, client_id) ) end - # allow batch requests to use the previous token def token_can_be_reused?(token, client_id) # ghetto HashWithIndifferentAccess @@ -169,9 +161,8 @@ def token_can_be_reused?(token, client_id) ) end - # update user's auth token (should happen on each request) - def create_new_auth_token(client_id=nil) + def create_new_auth_token(client_id = nil) now = Time.zone.now client_id, token = create_token( @@ -184,21 +175,21 @@ def create_new_auth_token(client_id=nil) update_auth_header(token, client_id) end - def build_auth_header(token, client_id='default') + def build_auth_header(token, client_id = 'default') # client may use expiry to prevent validation request if expired # must be cast as string or headers will break expiry = tokens[client_id]['expiry'] || tokens[client_id][:expiry] { DeviseTokenAuth.headers_names[:"access-token"] => token, - DeviseTokenAuth.headers_names[:"token-type"] => "Bearer", + DeviseTokenAuth.headers_names[:"token-type"] => 'Bearer', DeviseTokenAuth.headers_names[:"client"] => client_id, DeviseTokenAuth.headers_names[:"expiry"] => expiry.to_s, DeviseTokenAuth.headers_names[:"uid"] => uid } end - def update_auth_header(token, client_id='default') + def update_auth_header(token, client_id = 'default') headers = build_auth_header(token, client_id) clean_old_tokens save! @@ -214,7 +205,7 @@ def build_auth_url(base_url, args) end def extend_batch_buffer(token, client_id) - self.tokens[client_id]['updated_at'] = Time.zone.now + tokens[client_id]['updated_at'] = Time.zone.now update_auth_header(token, client_id) end @@ -223,7 +214,7 @@ def confirmed? end def token_validation_response - as_json(except: [:tokens, :created_at, :updated_at]) + as_json(except: %i[tokens created_at updated_at]) end def token_lifespan @@ -239,7 +230,7 @@ def set_empty_token_hash def destroy_expired_tokens if tokens tokens.delete_if do |cid, v| - expiry = v[:expiry] || v["expiry"] + expiry = v[:expiry] || v['expiry'] DateTime.strptime(expiry.to_s, '%s') < Time.zone.now end end @@ -248,10 +239,10 @@ def destroy_expired_tokens def should_remove_tokens_after_password_reset? if Rails::VERSION::MAJOR <= 5 encrypted_password_changed? && - DeviseTokenAuth.remove_tokens_after_password_reset + DeviseTokenAuth.remove_tokens_after_password_reset else saved_change_to_encrypted_password? && - DeviseTokenAuth.remove_tokens_after_password_reset + DeviseTokenAuth.remove_tokens_after_password_reset end end @@ -259,8 +250,8 @@ def remove_tokens_after_password_reset return unless should_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} + client_id, token_data = tokens.max_by { |cid, v| v[:expiry] || v['expiry'] } + self.tokens = { client_id => token_data } end end diff --git a/bin/rails b/bin/rails index 39596cbd0..3ea4de6fc 100755 --- a/bin/rails +++ b/bin/rails @@ -1,11 +1,13 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. -ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/devise_token_auth/engine', __FILE__) +ENGINE_ROOT = File.expand_path('..', __dir__) +ENGINE_PATH = File.expand_path('../lib/devise_token_auth/engine', __dir__) # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) require 'rails/all' diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index d6f92d0f1..c8724c2b4 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -12,7 +12,7 @@ # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' + config.mailer_sender = 'no-reply@example.com' # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' diff --git a/devise_token_auth.gemspec b/devise_token_auth.gemspec index 5620cacf0..d87dc6714 100644 --- a/devise_token_auth.gemspec +++ b/devise_token_auth.gemspec @@ -1,28 +1,30 @@ -$:.push File.expand_path("../lib", __FILE__) +# frozen_string_literal: true + +$:.push File.expand_path('lib', __dir__) # Maintain your gem's version: -require "devise_token_auth/version" +require 'devise_token_auth/version' # Describe your gem and declare its dependencies: Gem::Specification.new do |s| - s.name = "devise_token_auth" + s.name = 'devise_token_auth' s.version = DeviseTokenAuth::VERSION - s.authors = ["Lynn Hurley"] - s.email = ["lynn.dylan.hurley@gmail.com"] - s.homepage = "http://github.com/lynndylanhurley/devise_token_auth" - s.summary = "Token based authentication for rails. Uses Devise + OmniAuth." - s.description = "For use with client side single page apps such as the venerable https://github.com/lynndylanhurley/ng-token-auth." - s.license = "WTFPL" + s.authors = ['Lynn Hurley'] + s.email = ['lynn.dylan.hurley@gmail.com'] + s.homepage = 'http://github.com/lynndylanhurley/devise_token_auth' + s.summary = 'Token based authentication for rails. Uses Devise + OmniAuth.' + s.description = 'For use with client side single page apps such as the venerable https://github.com/lynndylanhurley/ng-token-auth.' + s.license = 'WTFPL' - s.files = Dir["{app,config,db,lib}/**/*", "LICENSE", "Rakefile", "README.md"] - s.test_files = Dir["test/**/*"] + s.files = Dir['{app,config,db,lib}/**/*', 'LICENSE', 'Rakefile', 'README.md'] + s.test_files = Dir['test/**/*'] s.test_files.reject! { |file| file.match(/[.log|.sqlite3]$/) } - s.add_dependency "rails", "< 6" - s.add_dependency "devise", "> 3.5.2", "< 4.5" + s.add_dependency 'rails', '< 6' + s.add_dependency 'devise', '> 3.5.2', '< 4.5' s.add_development_dependency 'appraisal' - s.add_development_dependency "sqlite3", "~> 1.3" + s.add_development_dependency 'sqlite3', '~> 1.3' s.add_development_dependency 'pg' s.add_development_dependency 'mysql2' end diff --git a/gemfiles/rails_4_2.gemfile b/gemfiles/rails_4_2.gemfile index ea26a991b..b3595939c 100644 --- a/gemfiles/rails_4_2.gemfile +++ b/gemfiles/rails_4_2.gemfile @@ -1,39 +1,43 @@ +# frozen_string_literal: true + # This file was generated by Appraisal -source "https://rubygems.org" +source 'https://rubygems.org' -gem "mysql2", "~> 0.4.10" -gem "pg", "~> 0.21" -gem "rails", "~> 4.2.10" +gem 'mysql2', '~> 0.4.10' +gem 'pg', '~> 0.21' +gem 'rails', '~> 4.2.10' group :development, :test do - gem "attr_encrypted" - gem "figaro", git: "https://github.com/laserlemon/figaro" - gem "omniauth-facebook", git: "https://github.com/mkdynamic/omniauth-facebook" - gem "omniauth-github", git: "https://github.com/intridea/omniauth-github" - gem "omniauth-google-oauth2", git: "https://github.com/zquestz/omniauth-google-oauth2" - gem "rack-cors", require: "rack/cors" - gem "thor" - gem "faker" - gem "fuzz_ball" - gem "guard" - gem "guard-minitest" - gem "minitest" - gem "minitest-focus" - gem "minitest-rails" - gem "minitest-reporters" - gem "mocha", ">= 1.5" - gem "pry" - gem "pry-remote" + gem 'attr_encrypted' + gem 'figaro', git: 'https://github.com/laserlemon/figaro' + gem 'omniauth-facebook', git: 'https://github.com/mkdynamic/omniauth-facebook' + gem 'omniauth-github', git: 'https://github.com/intridea/omniauth-github' + gem 'omniauth-google-oauth2', git: 'https://github.com/zquestz/omniauth-google-oauth2' + gem 'rack-cors', require: 'rack/cors' + gem 'thor' + gem 'faker' + gem 'fuzz_ball' + gem 'guard' + gem 'guard-minitest' + gem 'minitest' + gem 'minitest-focus' + gem 'minitest-rails' + gem 'minitest-reporters' + gem 'mocha', '>= 1.5' + gem 'pry' + gem 'pry-remote' + + gem 'rubocop', require: false end group :test do - gem "codeclimate-test-reporter", require: nil - gem "rails-controller-testing" + gem 'codeclimate-test-reporter', require: nil + gem 'rails-controller-testing' end group :development do - gem "github_changelog_generator" + gem 'github_changelog_generator' end -gemspec path: "../" +gemspec path: '../' diff --git a/gemfiles/rails_5_0.gemfile b/gemfiles/rails_5_0.gemfile index 09183de9b..52920e43e 100644 --- a/gemfiles/rails_5_0.gemfile +++ b/gemfiles/rails_5_0.gemfile @@ -1,37 +1,41 @@ +# frozen_string_literal: true + # This file was generated by Appraisal -source "https://rubygems.org" +source 'https://rubygems.org' -gem "rails", "~> 5.0.7" +gem 'rails', '~> 5.0.7' group :development, :test do - gem "attr_encrypted" - gem "figaro", git: "https://github.com/laserlemon/figaro" - gem "omniauth-facebook", git: "https://github.com/mkdynamic/omniauth-facebook" - gem "omniauth-github", git: "https://github.com/intridea/omniauth-github" - gem "omniauth-google-oauth2", git: "https://github.com/zquestz/omniauth-google-oauth2" - gem "rack-cors", require: "rack/cors" - gem "thor" - gem "faker" - gem "fuzz_ball" - gem "guard" - gem "guard-minitest" - gem "minitest" - gem "minitest-focus" - gem "minitest-rails" - gem "minitest-reporters" - gem "mocha", ">= 1.5" - gem "pry" - gem "pry-remote" + gem 'attr_encrypted' + gem 'figaro', git: 'https://github.com/laserlemon/figaro' + gem 'omniauth-facebook', git: 'https://github.com/mkdynamic/omniauth-facebook' + gem 'omniauth-github', git: 'https://github.com/intridea/omniauth-github' + gem 'omniauth-google-oauth2', git: 'https://github.com/zquestz/omniauth-google-oauth2' + gem 'rack-cors', require: 'rack/cors' + gem 'thor' + gem 'faker' + gem 'fuzz_ball' + gem 'guard' + gem 'guard-minitest' + gem 'minitest' + gem 'minitest-focus' + gem 'minitest-rails' + gem 'minitest-reporters' + gem 'mocha', '>= 1.5' + gem 'pry' + gem 'pry-remote' + + gem 'rubocop', require: false end group :test do - gem "codeclimate-test-reporter", require: nil - gem "rails-controller-testing" + gem 'codeclimate-test-reporter', require: nil + gem 'rails-controller-testing' end group :development do - gem "github_changelog_generator" + gem 'github_changelog_generator' end -gemspec path: "../" +gemspec path: '../' diff --git a/gemfiles/rails_5_1.gemfile b/gemfiles/rails_5_1.gemfile index 8ac7a6359..bfbb4c186 100644 --- a/gemfiles/rails_5_1.gemfile +++ b/gemfiles/rails_5_1.gemfile @@ -1,37 +1,41 @@ +# frozen_string_literal: true + # This file was generated by Appraisal -source "https://rubygems.org" +source 'https://rubygems.org' -gem "rails", "~> 5.1.6" +gem 'rails', '~> 5.1.6' group :development, :test do - gem "attr_encrypted" - gem "figaro", git: "https://github.com/laserlemon/figaro" - gem "omniauth-facebook", git: "https://github.com/mkdynamic/omniauth-facebook" - gem "omniauth-github", git: "https://github.com/intridea/omniauth-github" - gem "omniauth-google-oauth2", git: "https://github.com/zquestz/omniauth-google-oauth2" - gem "rack-cors", require: "rack/cors" - gem "thor" - gem "faker" - gem "fuzz_ball" - gem "guard" - gem "guard-minitest" - gem "minitest" - gem "minitest-focus" - gem "minitest-rails" - gem "minitest-reporters" - gem "mocha", ">= 1.5" - gem "pry" - gem "pry-remote" + gem 'attr_encrypted' + gem 'figaro', git: 'https://github.com/laserlemon/figaro' + gem 'omniauth-facebook', git: 'https://github.com/mkdynamic/omniauth-facebook' + gem 'omniauth-github', git: 'https://github.com/intridea/omniauth-github' + gem 'omniauth-google-oauth2', git: 'https://github.com/zquestz/omniauth-google-oauth2' + gem 'rack-cors', require: 'rack/cors' + gem 'thor' + gem 'faker' + gem 'fuzz_ball' + gem 'guard' + gem 'guard-minitest' + gem 'minitest' + gem 'minitest-focus' + gem 'minitest-rails' + gem 'minitest-reporters' + gem 'mocha', '>= 1.5' + gem 'pry' + gem 'pry-remote' + + gem 'rubocop', require: false end group :test do - gem "codeclimate-test-reporter", require: nil - gem "rails-controller-testing" + gem 'codeclimate-test-reporter', require: nil + gem 'rails-controller-testing' end group :development do - gem "github_changelog_generator" + gem 'github_changelog_generator' end -gemspec path: "../" +gemspec path: '../' diff --git a/lib/devise_token_auth.rb b/lib/devise_token_auth.rb index 28af93b3a..461ce84b6 100644 --- a/lib/devise_token_auth.rb +++ b/lib/devise_token_auth.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require "devise" -require "devise_token_auth/engine" -require "devise_token_auth/controllers/helpers" -require "devise_token_auth/controllers/url_helpers" -require "devise_token_auth/url" -require "devise_token_auth/errors" +require 'devise' +require 'devise_token_auth/engine' +require 'devise_token_auth/controllers/helpers' +require 'devise_token_auth/controllers/url_helpers' +require 'devise_token_auth/url' +require 'devise_token_auth/errors' module DeviseTokenAuth end diff --git a/lib/devise_token_auth/controllers/helpers.rb b/lib/devise_token_auth/controllers/helpers.rb index fb070cf52..2f2352a92 100644 --- a/lib/devise_token_auth/controllers/helpers.rb +++ b/lib/devise_token_auth/controllers/helpers.rb @@ -28,8 +28,8 @@ module ClassMethods # before_action ->{ authenticate_blogger! :admin } # Redirects to the admin login page # 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(',') }]" + def devise_token_auth_group(group_name, opts = {}) + mappings = "[#{opts[:contains].map { |m| ":#{m}" }.join(',')}]" class_eval <<-METHODS, __FILE__, __LINE__ + 1 def authenticate_#{group_name}!(favourite=nil, opts={}) @@ -75,7 +75,12 @@ def render_authenticate_error end if respond_to?(:helper_method) - helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?", "render_authenticate_error" + helper_method( + "current_#{group_name}", + "current_#{group_name.to_s.pluralize}", + "#{group_name}_signed_in?", + "render_authenticate_error" + ) end METHODS end @@ -142,7 +147,12 @@ def render_authenticate_error ActiveSupport.on_load(:action_controller) do if respond_to?(:helper_method) - helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session", "render_authenticate_error" + helper_method( + "current_#{mapping}", + "#{mapping}_signed_in?", + "#{mapping}_session", + 'render_authenticate_error' + ) end end end diff --git a/lib/devise_token_auth/engine.rb b/lib/devise_token_auth/engine.rb index d2d44fd79..a799f1e1a 100644 --- a/lib/devise_token_auth/engine.rb +++ b/lib/devise_token_auth/engine.rb @@ -6,7 +6,7 @@ module DeviseTokenAuth class Engine < ::Rails::Engine isolate_namespace DeviseTokenAuth - initializer "devise_token_auth.url_helpers" do + initializer 'devise_token_auth.url_helpers' do Devise.helpers << DeviseTokenAuth::Controllers::Helpers end end @@ -38,11 +38,11 @@ class Engine < ::Rails::Engine self.enable_standard_devise_support = false self.remove_tokens_after_password_reset = false self.default_callbacks = true - self.headers_names = {:'access-token' => 'access-token', - :'client' => 'client', - :'expiry' => 'expiry', - :'uid' => 'uid', - :'token-type' => 'token-type' } + self.headers_names = { 'access-token': 'access-token', + 'client': 'client', + 'expiry': 'expiry', + 'uid': 'uid', + 'token-type': 'token-type' } self.bypass_sign_in = true def self.setup(&block) @@ -50,23 +50,21 @@ def self.setup(&block) Rails.application.config.after_initialize do if defined?(::OmniAuth) - ::OmniAuth::config.path_prefix = Devise.omniauth_path_prefix = self.omniauth_prefix - + ::OmniAuth::config.path_prefix = Devise.omniauth_path_prefix = omniauth_prefix # Omniauth currently does not pass along omniauth.params upon failure redirect # see also: https://github.com/intridea/omniauth/issues/626 OmniAuth::FailureEndpoint.class_eval do def redirect_to_failure message_key = env['omniauth.error.type'] - origin_query_param = env['omniauth.origin'] ? "&origin=#{CGI.escape(env['omniauth.origin'])}" : "" - strategy_name_query_param = env['omniauth.error.strategy'] ? "&strategy=#{env['omniauth.error.strategy'].name}" : "" - extra_params = env['omniauth.params'] ? "&#{env['omniauth.params'].to_query}" : "" + origin_query_param = env['omniauth.origin'] ? "&origin=#{CGI.escape(env['omniauth.origin'])}" : '' + strategy_name_query_param = env['omniauth.error.strategy'] ? "&strategy=#{env['omniauth.error.strategy'].name}" : '' + extra_params = env['omniauth.params'] ? "&#{env['omniauth.params'].to_query}" : '' new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}#{origin_query_param}#{strategy_name_query_param}#{extra_params}" - Rack::Response.new(["302 Moved"], 302, 'Location' => new_path).finish + Rack::Response.new(['302 Moved'], 302, 'Location' => new_path).finish end end - # Omniauth currently removes omniauth.params during mocked requests # see also: https://github.com/intridea/omniauth/pull/812 OmniAuth::Strategy.class_eval do diff --git a/lib/devise_token_auth/errors.rb b/lib/devise_token_auth/errors.rb index ca9fd5a0c..3b3a392e3 100644 --- a/lib/devise_token_auth/errors.rb +++ b/lib/devise_token_auth/errors.rb @@ -2,6 +2,6 @@ module DeviseTokenAuth module Errors - class NoResourceDefinedError < StandardError ; end + class NoResourceDefinedError < StandardError; end end end diff --git a/lib/devise_token_auth/rails/routes.rb b/lib/devise_token_auth/rails/routes.rb index 4167d7e7c..158487658 100644 --- a/lib/devise_token_auth/rails/routes.rb +++ b/lib/devise_token_auth/rails/routes.rb @@ -8,31 +8,31 @@ def mount_devise_token_auth_for(resource, opts) opts[:skip] ||= [] # check for ctrl overrides, fall back to defaults - sessions_ctrl = opts[:controllers][:sessions] || "devise_token_auth/sessions" - registrations_ctrl = opts[:controllers][:registrations] || "devise_token_auth/registrations" - passwords_ctrl = opts[:controllers][:passwords] || "devise_token_auth/passwords" - confirmations_ctrl = opts[:controllers][:confirmations] || "devise_token_auth/confirmations" - token_validations_ctrl = opts[:controllers][:token_validations] || "devise_token_auth/token_validations" - omniauth_ctrl = opts[:controllers][:omniauth_callbacks] || "devise_token_auth/omniauth_callbacks" - unlocks_ctrl = opts[:controllers][:unlocks] || "devise_token_auth/unlocks" + sessions_ctrl = opts[:controllers][:sessions] || 'devise_token_auth/sessions' + registrations_ctrl = opts[:controllers][:registrations] || 'devise_token_auth/registrations' + passwords_ctrl = opts[:controllers][:passwords] || 'devise_token_auth/passwords' + confirmations_ctrl = opts[:controllers][:confirmations] || 'devise_token_auth/confirmations' + token_validations_ctrl = opts[:controllers][:token_validations] || 'devise_token_auth/token_validations' + omniauth_ctrl = opts[:controllers][:omniauth_callbacks] || 'devise_token_auth/omniauth_callbacks' + 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 # remove any unwanted devise modules - opts[:skip].each{|item| controllers.delete(item)} + opts[:skip].each{ |item| controllers.delete(item) } devise_for resource.pluralize.underscore.gsub('/', '_').to_sym, - :class_name => resource, - :module => :devise, - :path => "#{opts[:at]}", - :controllers => controllers, - :skip => opts[:skip] + [:omniauth_callbacks] + class_name: resource, + module: :devise, + path: opts[:at].to_s, + controllers: controllers, + skip: opts[:skip] + [:omniauth_callbacks] unnest_namespace do # get full url path as if it were namespaced @@ -43,8 +43,8 @@ def mount_devise_token_auth_for(resource, opts) # clear scope so controller routes aren't namespaced @scope = ActionDispatch::Routing::Mapper::Scope.new( - path: "", - shallow_path: "", + path: '', + shallow_path: '', constraints: {}, defaults: {}, options: {}, @@ -56,29 +56,29 @@ def mount_devise_token_auth_for(resource, opts) devise_scope mapping_name.to_sym do # path to verify token validity - get "#{full_path}/validate_token", controller: "#{token_validations_ctrl}", action: "validate_token" + get "#{full_path}/validate_token", controller: token_validations_ctrl.to_s, action: 'validate_token' # omniauth routes. only define if omniauth is installed and not skipped. if defined?(::OmniAuth) && !opts[:skip].include?(:omniauth_callbacks) - match "#{full_path}/failure", controller: omniauth_ctrl, action: "omniauth_failure", via: [:get] - match "#{full_path}/:provider/callback", controller: omniauth_ctrl, action: "omniauth_success", via: [:get] + match "#{full_path}/failure", controller: omniauth_ctrl, action: 'omniauth_failure', via: [:get] + match "#{full_path}/:provider/callback", controller: omniauth_ctrl, action: 'omniauth_success', via: [:get] - match "#{DeviseTokenAuth.omniauth_prefix}/:provider/callback", controller: omniauth_ctrl, action: "redirect_callbacks", via: [:get, :post] - match "#{DeviseTokenAuth.omniauth_prefix}/failure", controller: omniauth_ctrl, action: "omniauth_failure", via: [:get, :post] + match "#{DeviseTokenAuth.omniauth_prefix}/:provider/callback", controller: omniauth_ctrl, action: 'redirect_callbacks', via: [:get, :post] + match "#{DeviseTokenAuth.omniauth_prefix}/failure", controller: omniauth_ctrl, action: 'omniauth_failure', via: [:get, :post] # preserve the resource class thru oauth authentication by setting name of # resource as "resource_class" param - match "#{full_path}/:provider", to: redirect{|params, request| + match "#{full_path}/:provider", to: redirect{ |params, request| # get the current querystring - qs = CGI::parse(request.env["QUERY_STRING"]) + qs = CGI::parse(request.env['QUERY_STRING']) # append name of current resource - qs["resource_class"] = [resource] - qs["namespace_name"] = [namespace_name] if namespace_name + qs['resource_class'] = [resource] + qs['namespace_name'] = [namespace_name] if namespace_name set_omniauth_path_prefix!(DeviseTokenAuth.omniauth_prefix) - redirect_params = {}.tap {|hash| qs.each{|k, v| hash[k] = v.first}} + redirect_params = {}.tap { |hash| qs.each{ |k, v| hash[k] = v.first } } if DeviseTokenAuth.redirect_whitelist redirect_url = request.params['auth_origin_url'] diff --git a/lib/devise_token_auth/url.rb b/lib/devise_token_auth/url.rb index a0532eba3..8ffb61468 100644 --- a/lib/devise_token_auth/url.rb +++ b/lib/devise_token_auth/url.rb @@ -7,19 +7,21 @@ def self.generate(url, params = {}) res = "#{uri.scheme}://#{uri.host}" res += ":#{uri.port}" if (uri.port && uri.port != 80 && uri.port != 443) - res += "#{uri.path}" if uri.path + res += uri.path.to_s if uri.path query = [uri.query, params.to_query].reject(&:blank?).join('&') res += "?#{query}" res += "##{uri.fragment}" if uri.fragment - return res + res end def self.whitelisted?(url) - url.nil? || !!DeviseTokenAuth.redirect_whitelist.find { |pattern| !!Wildcat.new(pattern).match(url) } + url.nil? || \ + !!DeviseTokenAuth.redirect_whitelist.find do |pattern| + !!Wildcat.new(pattern).match(url) + end end - # wildcard convenience class class Wildcat def self.parse_to_regex(str) diff --git a/lib/devise_token_auth/version.rb b/lib/devise_token_auth/version.rb index d769b2e1b..356717664 100644 --- a/lib/devise_token_auth/version.rb +++ b/lib/devise_token_auth/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module DeviseTokenAuth - VERSION = '0.1.43' + VERSION = '0.1.43'.freeze end diff --git a/lib/generators/devise_token_auth/install_generator.rb b/lib/generators/devise_token_auth/install_generator.rb index f7785f651..09dfe9934 100644 --- a/lib/generators/devise_token_auth/install_generator.rb +++ b/lib/generators/devise_token_auth/install_generator.rb @@ -4,54 +4,54 @@ module DeviseTokenAuth class InstallGenerator < Rails::Generators::Base include Rails::Generators::Migration - source_root File.expand_path('../templates', __FILE__) + source_root File.expand_path('templates', __dir__) - argument :user_class, type: :string, default: "User" + argument :user_class, type: :string, default: 'User' argument :mount_path, type: :string, default: 'auth' def create_initializer_file - copy_file("devise_token_auth.rb", "config/initializers/devise_token_auth.rb") + copy_file('devise_token_auth.rb', 'config/initializers/devise_token_auth.rb') end def copy_migrations - if self.class.migration_exists?("db/migrate", "devise_token_auth_create_#{ user_class.pluralize.gsub("::","").underscore }") - say_status("skipped", "Migration 'devise_token_auth_create_#{ user_class.pluralize.gsub("::","").underscore }' already exists") + if self.class.migration_exists?('db/migrate', "devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}") + say_status('skipped', "Migration 'devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}' already exists") else migration_template( - "devise_token_auth_create_users.rb.erb", - "db/migrate/devise_token_auth_create_#{ user_class.pluralize.gsub("::","").underscore }.rb" + 'devise_token_auth_create_users.rb.erb', + "db/migrate/devise_token_auth_create_#{user_class.pluralize.gsub('::','').underscore}.rb" ) end end def create_user_model - fname = "app/models/#{ user_class.underscore }.rb" - unless File.exist?(File.join(destination_root, fname)) - template("user.rb", fname) - else - inclusion = "include DeviseTokenAuth::Concerns::User" + fname = "app/models/#{user_class.underscore}.rb" + if File.exist?(File.join(destination_root, fname)) + 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. - devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable, - :confirmable, :omniauthable - include DeviseTokenAuth::Concerns::User - RUBY + # Include default devise modules. + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable, + :confirmable, :omniauthable + include DeviseTokenAuth::Concerns::User + RUBY end end + else + template('user.rb.erb', fname) end end def include_controller_concerns - fname = "app/controllers/application_controller.rb" - line = "include DeviseTokenAuth::Concerns::SetUserByToken" + fname = 'app/controllers/application_controller.rb' + line = 'include DeviseTokenAuth::Concerns::SetUserByToken' if File.exist?(File.join(destination_root, fname)) if parse_file_for_line(fname, line) - say_status("skipped", "Concern is already included in the application controller.") + say_status('skipped', 'Concern is already included in the application controller.') elsif is_rails_api? inject_into_file fname, after: "class ApplicationController < ActionController::API\n" do <<-'RUBY' include DeviseTokenAuth::Concerns::SetUserByToken @@ -64,46 +64,46 @@ def include_controller_concerns end end else - say_status("skipped", "app/controllers/application_controller.rb not found. Add 'include DeviseTokenAuth::Concerns::SetUserByToken' to any controllers that require authentication.") + say_status('skipped', "app/controllers/application_controller.rb not found. Add 'include DeviseTokenAuth::Concerns::SetUserByToken' to any controllers that require authentication.") end end def add_route_mount - f = "config/routes.rb" + f = 'config/routes.rb' str = "mount_devise_token_auth_for '#{user_class}', at: '#{mount_path}'" if File.exist?(File.join(destination_root, f)) - line = parse_file_for_line(f, "mount_devise_token_auth_for") + line = parse_file_for_line(f, 'mount_devise_token_auth_for') - unless line - line = "Rails.application.routes.draw do" - existing_user_class = false - else + if line existing_user_class = true + else + line = 'Rails.application.routes.draw do' + existing_user_class = false end if parse_file_for_line(f, str) - say_status("skipped", "Routes already exist for #{user_class} at #{mount_path}") + say_status('skipped', "Routes already exist for #{user_class} at #{mount_path}") else insert_after_line(f, line, str) if existing_user_class - scoped_routes = ""+ - "as :#{user_class.underscore} do\n"+ - " # Define routes for #{user_class} within this block.\n"+ + scoped_routes = ''\ + "as :#{user_class.underscore} do\n"\ + " # Define routes for #{user_class} within this block.\n"\ " end\n" insert_after_line(f, str, scoped_routes) end end else - say_status("skipped", "config/routes.rb not found. Add \"mount_devise_token_auth_for '#{user_class}', at: '#{mount_path}'\" to your routes file.") + say_status('skipped', "config/routes.rb not found. Add \"mount_devise_token_auth_for '#{user_class}', at: '#{mount_path}'\" to your routes file.") end end private def self.next_migration_number(path) - Time.zone.now.utc.strftime("%Y%m%d%H%M%S") + Time.zone.now.utc.strftime('%Y%m%d%H%M%S') end def insert_after_line(filename, line, str) @@ -117,17 +117,15 @@ def parse_file_for_line(filename, str) File.open(File.join(destination_root, filename)) do |f| f.each_line do |line| - if line =~ /(#{Regexp.escape(str)})/mi - match = line - end + match = line if line =~ /(#{Regexp.escape(str)})/mi end end match end def is_rails_api? - fname = "app/controllers/application_controller.rb" - line = "class ApplicationController < ActionController::API" + fname = 'app/controllers/application_controller.rb' + line = 'class ApplicationController < ActionController::API' parse_file_for_line(fname, line) end diff --git a/lib/generators/devise_token_auth/install_views_generator.rb b/lib/generators/devise_token_auth/install_views_generator.rb index 38b7a7580..88ba3070c 100644 --- a/lib/generators/devise_token_auth/install_views_generator.rb +++ b/lib/generators/devise_token_auth/install_views_generator.rb @@ -2,16 +2,16 @@ module DeviseTokenAuth class InstallViewsGenerator < Rails::Generators::Base - source_root File.expand_path('../../../../app/views/devise/mailer', __FILE__) + source_root File.expand_path('../../../app/views/devise/mailer', __dir__) def copy_mailer_templates copy_file( - "confirmation_instructions.html.erb", - "app/views/devise/mailer/confirmation_instructions.html.erb" + 'confirmation_instructions.html.erb', + 'app/views/devise/mailer/confirmation_instructions.html.erb' ) copy_file( - "reset_password_instructions.html.erb", - "app/views/devise/mailer/reset_password_instructions.html.erb" + 'reset_password_instructions.html.erb', + 'app/views/devise/mailer/reset_password_instructions.html.erb' ) end end diff --git a/lib/generators/devise_token_auth/templates/user.rb b/lib/generators/devise_token_auth/templates/user.rb.erb similarity index 100% rename from lib/generators/devise_token_auth/templates/user.rb rename to lib/generators/devise_token_auth/templates/user.rb.erb diff --git a/test/controllers/demo_user_controller_test.rb b/test/controllers/demo_user_controller_test.rb index 676ca9dbf..252fb5ccf 100644 --- a/test/controllers/demo_user_controller_test.rb +++ b/test/controllers/demo_user_controller_test.rb @@ -440,8 +440,8 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest # get the oldest token client_id oldest_client_id, = @resource.reload.tokens.min_by do |cid, v| - v[:expiry] || v["expiry"] - end # => [ 'CLIENT_ID', {token: ...} ] + v[:expiry] || v['expiry'] + end # => [ 'CLIENT_ID', {token: ...} ] # create another token, thereby dropping the oldest token @resource.create_new_auth_token @@ -549,8 +549,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest refute_equal @resource, @controller.current_mang end - - end it 'should return success status' do diff --git a/test/controllers/devise_token_auth/passwords_controller_test.rb b/test/controllers/devise_token_auth/passwords_controller_test.rb index ee9565a24..98797b774 100644 --- a/test/controllers/devise_token_auth/passwords_controller_test.rb +++ b/test/controllers/devise_token_auth/passwords_controller_test.rb @@ -53,8 +53,10 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase test 'error message should be returned' do assert @data['errors'] - assert_equal @data['errors'], - [I18n.t('devise_token_auth.passwords.missing_redirect_url')] + assert_equal( + @data['errors'], + [I18n.t('devise_token_auth.passwords.missing_redirect_url')] + ) end end @@ -113,7 +115,9 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase end test 'response should contains message' do - assert_equal @data['message'], I18n.t('devise_token_auth.passwords.sended', email: @resource.email) + assert_equal \ + @data['message'], + I18n.t('devise_token_auth.passwords.sended', email: @resource.email) end test 'action should send an email' do diff --git a/test/controllers/devise_token_auth/sessions_controller_test.rb b/test/controllers/devise_token_auth/sessions_controller_test.rb index 8fe6bfa20..932530120 100644 --- a/test/controllers/devise_token_auth/sessions_controller_test.rb +++ b/test/controllers/devise_token_auth/sessions_controller_test.rb @@ -112,7 +112,7 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase end oldest_token, _ = @existing_user.reload.tokens \ - .min_by { |cid, v| v[:expiry] || v["expiry"] } + .min_by { |cid, v| v[:expiry] || v['expiry'] } post :create, params: @user_session_params diff --git a/test/controllers/overrides/passwords_controller_test.rb b/test/controllers/overrides/passwords_controller_test.rb index a373dddfd..e04a80530 100644 --- a/test/controllers/overrides/passwords_controller_test.rb +++ b/test/controllers/overrides/passwords_controller_test.rb @@ -12,38 +12,29 @@ class Overrides::PasswordsControllerTest < ActionDispatch::IntegrationTest describe Overrides::PasswordsController do before do @resource = evil_users(:confirmed_email_user) - @redirect_url = Faker::Internet.url post '/evil_user_auth/password', params: { email: @resource.email, - redirect_url: @redirect_url + redirect_url: Faker::Internet.url } - @mail = ActionMailer::Base.deliveries.last + mail = ActionMailer::Base.deliveries.last @resource.reload - @mail_config_name = CGI.unescape(@mail.body.match(/config=([^&]*)&/)[1]) - @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1]) - @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1] + mail_reset_token = mail.body.match(/reset_password_token=(.*)\"/)[1] + mail_redirect_url = CGI.unescape(mail.body.match(/redirect_url=([^&]*)&/)[1]) get '/evil_user_auth/password/edit', - params: { reset_password_token: @mail_reset_token, - redirect_url: @mail_redirect_url } + params: { + reset_password_token: mail_reset_token, + redirect_url: mail_redirect_url + } @resource.reload - raw_qs = response.location.split('?')[1] - @qs = Rack::Utils.parse_nested_query(raw_qs) - - @access_token = @qs['access-token'] - @client = @qs['client'] - @client_id = @qs['client_id'] - @expiry = @qs['expiry'] - @override_proof = @qs['override_proof'] - @reset_password = @qs['reset_password'] - @token = @qs['token'] - @uid = @qs['uid'] + _, raw_query_string = response.location.split('?') + @query_string = Rack::Utils.parse_nested_query(raw_query_string) end test 'response should have success redirect status' do @@ -51,18 +42,21 @@ class Overrides::PasswordsControllerTest < ActionDispatch::IntegrationTest end test 'response should contain auth params + override proof' do - assert @access_token - assert @client - assert @client_id - assert @expiry - assert @override_proof - assert @reset_password - assert @token - assert @uid + assert @query_string['access-token'] + assert @query_string['client'] + assert @query_string['client_id'] + assert @query_string['expiry'] + assert @query_string['override_proof'] + assert @query_string['reset_password'] + assert @query_string['token'] + assert @query_string['uid'] end test 'override proof is correct' do - assert_equal @override_proof, Overrides::PasswordsController::OVERRIDE_PROOF + assert_equal( + @query_string['override_proof'], + Overrides::PasswordsController::OVERRIDE_PROOF + ) end end end diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile index da4efd575..e51cf0e17 100644 --- a/test/dummy/Rakefile +++ b/test/dummy/Rakefile @@ -3,6 +3,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path('../config/application', __FILE__) +require File.expand_path('config/application', __dir__) Rails.application.load_tasks diff --git a/test/dummy/app/controllers/custom/confirmations_controller.rb b/test/dummy/app/controllers/custom/confirmations_controller.rb index 31ee06c2c..2a7ccfb8d 100644 --- a/test/dummy/app/controllers/custom/confirmations_controller.rb +++ b/test/dummy/app/controllers/custom/confirmations_controller.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class Custom::ConfirmationsController < DeviseTokenAuth::ConfirmationsController - def show super do |resource| @show_block_called = true unless resource.nil? @@ -11,5 +10,4 @@ def show def show_block_called? @show_block_called == true end - end diff --git a/test/dummy/app/controllers/custom/passwords_controller.rb b/test/dummy/app/controllers/custom/passwords_controller.rb index d3a6b03d3..d9cf7d881 100644 --- a/test/dummy/app/controllers/custom/passwords_controller.rb +++ b/test/dummy/app/controllers/custom/passwords_controller.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class Custom::PasswordsController < DeviseTokenAuth::PasswordsController - def create super do |resource| @create_block_called = true unless resource.nil? @@ -35,8 +34,6 @@ def update_block_called? protected def render_update_success - render json: {custom: "foo"} + render json: { custom: 'foo' } end - - end diff --git a/test/dummy/app/controllers/custom/registrations_controller.rb b/test/dummy/app/controllers/custom/registrations_controller.rb index 9994c0f85..d4363b333 100644 --- a/test/dummy/app/controllers/custom/registrations_controller.rb +++ b/test/dummy/app/controllers/custom/registrations_controller.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class Custom::RegistrationsController < DeviseTokenAuth::RegistrationsController - def create super do |resource| @create_block_called = true @@ -35,6 +34,6 @@ def destroy_block_called? protected def render_create_success - render json: {custom: "foo"} + render json: { custom: 'foo' } end end diff --git a/test/dummy/app/controllers/custom/sessions_controller.rb b/test/dummy/app/controllers/custom/sessions_controller.rb index 91fb0e195..3219ab620 100644 --- a/test/dummy/app/controllers/custom/sessions_controller.rb +++ b/test/dummy/app/controllers/custom/sessions_controller.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class Custom::SessionsController < DeviseTokenAuth::SessionsController - def create super do |resource| @create_block_called = true unless resource.nil? @@ -25,7 +24,6 @@ def destroy_block_called? protected def render_create_success - render json: {custom: "foo"} + render json: { custom: 'foo' } end - end diff --git a/test/dummy/app/controllers/custom/token_validations_controller.rb b/test/dummy/app/controllers/custom/token_validations_controller.rb index d4ee4fda8..2e1e0cf05 100644 --- a/test/dummy/app/controllers/custom/token_validations_controller.rb +++ b/test/dummy/app/controllers/custom/token_validations_controller.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class Custom::TokenValidationsController < DeviseTokenAuth::TokenValidationsController - def validate_token super do |resource| @validate_token_block_called = true unless resource.nil? @@ -15,7 +14,6 @@ def validate_token_block_called? protected def render_validate_token_success - render json: {custom: "foo"} + render json: { custom: 'foo' } end - end diff --git a/test/dummy/app/controllers/overrides/confirmations_controller.rb b/test/dummy/app/controllers/overrides/confirmations_controller.rb index 9d51f5e8c..09bdee321 100644 --- a/test/dummy/app/controllers/overrides/confirmations_controller.rb +++ b/test/dummy/app/controllers/overrides/confirmations_controller.rb @@ -5,14 +5,14 @@ class ConfirmationsController < DeviseTokenAuth::ConfirmationsController def show @resource = resource_class.confirm_by_token(params[:confirmation_token]) - if @resource and @resource.id + if @resource && @resource.id client_id, token = @resource.create_token @resource.save! redirect_header_options = { account_confirmation_success: true, config: params[:config], - override_proof: "(^^,)" + override_proof: '(^^,)' } redirect_headers = build_redirect_headers(token, client_id, @@ -21,7 +21,7 @@ def show redirect_to(@resource.build_auth_url(params[:redirect_url], redirect_headers)) else - raise ActionController::RoutingError.new('Not Found') + raise ActionController::RoutingError, 'Not Found' end end end diff --git a/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb b/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb index 3c27d3186..1ff7277fb 100644 --- a/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +++ b/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb @@ -2,15 +2,15 @@ module Overrides class OmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController - DEFAULT_NICKNAME = "stimpy" + DEFAULT_NICKNAME = 'stimpy'.freeze def assign_provider_attrs(user, auth_hash) - user.assign_attributes({ + user.assign_attributes( nickname: DEFAULT_NICKNAME, name: auth_hash['info']['name'], image: auth_hash['info']['image'], email: auth_hash['info']['email'] - }) + ) end end end diff --git a/test/dummy/app/controllers/overrides/passwords_controller.rb b/test/dummy/app/controllers/overrides/passwords_controller.rb index d568e6459..5a781801d 100644 --- a/test/dummy/app/controllers/overrides/passwords_controller.rb +++ b/test/dummy/app/controllers/overrides/passwords_controller.rb @@ -2,15 +2,15 @@ module Overrides class PasswordsController < DeviseTokenAuth::PasswordsController - OVERRIDE_PROOF = "(^^,)" + OVERRIDE_PROOF = '(^^,)'.freeze # this is where users arrive after visiting the email confirmation link def edit - @resource = resource_class.reset_password_by_token({ + @resource = resource_class.reset_password_by_token( reset_password_token: resource_params[:reset_password_token] - }) + ) - if @resource and @resource.id + if @resource && @resource.id client_id, token = @resource.create_token # ensure that user is confirmed @@ -28,7 +28,7 @@ def edit redirect_to(@resource.build_auth_url(params[:redirect_url], redirect_headers)) else - raise ActionController::RoutingError.new('Not Found') + raise ActionController::RoutingError, 'Not Found' end end end diff --git a/test/dummy/app/controllers/overrides/registrations_controller.rb b/test/dummy/app/controllers/overrides/registrations_controller.rb index 429f12c11..1dd67bbb4 100644 --- a/test/dummy/app/controllers/overrides/registrations_controller.rb +++ b/test/dummy/app/controllers/overrides/registrations_controller.rb @@ -2,7 +2,7 @@ module Overrides class RegistrationsController < DeviseTokenAuth::RegistrationsController - OVERRIDE_PROOF = "(^^,)" + OVERRIDE_PROOF = '(^^,)'.freeze def update if @resource @@ -21,7 +21,7 @@ def update else render json: { status: 'error', - errors: ["User not found."] + errors: ['User not found.'] }, status: 404 end end diff --git a/test/dummy/app/controllers/overrides/sessions_controller.rb b/test/dummy/app/controllers/overrides/sessions_controller.rb index 20b6fabda..aa7fa34f2 100644 --- a/test/dummy/app/controllers/overrides/sessions_controller.rb +++ b/test/dummy/app/controllers/overrides/sessions_controller.rb @@ -2,35 +2,33 @@ module Overrides class SessionsController < DeviseTokenAuth::SessionsController - OVERRIDE_PROOF = "(^^,)" + OVERRIDE_PROOF = '(^^,)'.freeze def create @resource = resource_class.find_by(email: resource_params[:email]) - if @resource and valid_params?(:email, resource_params[:email]) and @resource.valid_password?(resource_params[:password]) and @resource.confirmed? + if @resource && valid_params?(:email, resource_params[:email]) && @resource.valid_password?(resource_params[:password]) && @resource.confirmed? @client_id, @token = @resource.create_token @resource.save render json: { - data: @resource.as_json(except: [ - :tokens, :created_at, :updated_at - ]), + data: @resource.as_json(except: %i[tokens created_at updated_at]), override_proof: OVERRIDE_PROOF } - elsif @resource and not @resource.confirmed? + elsif @resource && (not @resource.confirmed?) render json: { success: false, errors: [ - "A confirmation email was sent to your account at #{@resource.email}. "+ - "You must follow the instructions in the email before your account "+ - "can be activated" + "A confirmation email was sent to your account at #{@resource.email}. "\ + 'You must follow the instructions in the email before your account '\ + 'can be activated' ] }, status: 401 else render json: { - errors: ["Invalid login credentials. Please try again."] + errors: ['Invalid login credentials. Please try again.'] }, status: 401 end end diff --git a/test/dummy/app/controllers/overrides/token_validations_controller.rb b/test/dummy/app/controllers/overrides/token_validations_controller.rb index bab35f595..3967de8c5 100644 --- a/test/dummy/app/controllers/overrides/token_validations_controller.rb +++ b/test/dummy/app/controllers/overrides/token_validations_controller.rb @@ -2,22 +2,20 @@ module Overrides class TokenValidationsController < DeviseTokenAuth::TokenValidationsController - OVERRIDE_PROOF = '(^^,)' + OVERRIDE_PROOF = '(^^,)'.freeze def validate_token # @resource will have been set by set_user_by_token concern if @resource render json: { success: true, - data: @resource.as_json(except: [ - :tokens, :created_at, :updated_at - ]), + data: @resource.as_json(except: %i[tokens created_at updated_at]), override_proof: OVERRIDE_PROOF } else render json: { success: false, - errors: ["Invalid login credentials"] + errors: ['Invalid login credentials'] }, status: 401 end end diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb index a0764ef32..1739dd954 100644 --- a/test/dummy/app/helpers/application_helper.rb +++ b/test/dummy/app/helpers/application_helper.rb @@ -2,1066 +2,1057 @@ module ApplicationHelper COLOR_NAMES = [ - "Acid green", - "Aero", - "Aero blue", - "African violet", - "Air Force blue", - "Air superiority blue", - "Alabama Crimson", - "Alice blue", - "Alizarin crimson", - "Alloy orange", - "Almond", - "Amaranth", - "Amaranth pink", - "Amaranth purple", - "Amazon", - "Amber", - "Amethyst", - "Android green", - "Anti-flash white", - "Antique brass", - "Antique bronze", - "Antique fuchsia", - "Antique ruby", - "Antique white", - "Ao", - "Apple green", - "Apricot", - "Aqua", - "Aquamarine", - "Army green", - "Arsenic", - "Artichoke", - "Arylide yellow", - "Ash grey", - "Asparagus", - "Atomic tangerine", - "Auburn", - "Aureolin", - "AuroMetalSaurus", - "Avocado", - "Azure", - "Azure mist/web", + 'Acid green', + 'Aero', + 'Aero blue', + 'African violet', + 'Air Force blue', + 'Air superiority blue', + 'Alabama Crimson', + 'Alice blue', + 'Alizarin crimson', + 'Alloy orange', + 'Almond', + 'Amaranth', + 'Amaranth pink', + 'Amaranth purple', + 'Amazon', + 'Amber', + 'Amethyst', + 'Android green', + 'Anti-flash white', + 'Antique brass', + 'Antique bronze', + 'Antique fuchsia', + 'Antique ruby', + 'Antique white', + 'Ao', + 'Apple green', + 'Apricot', + 'Aqua', + 'Aquamarine', + 'Army green', + 'Arsenic', + 'Artichoke', + 'Arylide yellow', + 'Ash grey', + 'Asparagus', + 'Atomic tangerine', + 'Auburn', + 'Aureolin', + 'AuroMetalSaurus', + 'Avocado', + 'Azure', + 'Azure mist/web', - "Baby blue", - "Baby blue eyes", - "Baby pink", - "Baby powder", - "Baker-Miller pink", - "Ball blue", - "Banana Mania", - "Banana yellow", - "Bangladesh green", - "Barbie pink", - "Barn red", - "Battleship grey", - "Bazaar", - "Beau blue", - "Beaver", - "Beige", + 'Baby blue', + 'Baby blue eyes', + 'Baby pink', + 'Baby powder', + 'Baker-Miller pink', + 'Ball blue', + 'Banana Mania', + 'Banana yellow', + 'Bangladesh green', + 'Barbie pink', + 'Barn red', + 'Battleship grey', + 'Bazaar', + 'Beau blue', + 'Beaver', + 'Beige', "B'dazzled blue", "Big dip o'ruby", - "Bisque", - "Bistre", - "Bistre brown", - "Bitter lemon", - "Bitter lime", - "Bittersweet", - "Bittersweet shimmer", - "Black", - "Black bean", - "Black leather jacket", - "Black olive", - "Blanched almond", - "Blast-off bronze", - "Bleu de France", - "Blizzard Blue", - "Blond", - "Blue", - "Blue Bell", - "Blue-gray", - "Blue-green", - "Blue sapphire", - "Blue-violet", - "Blue yonder", - "Blueberry", - "Bluebonnet", - "Blush", - "Bole", - "Bondi blue", - "Bone", - "Boston University Red", - "Bottle green", - "Boysenberry", - "Brandeis blue", - "Brass", - "Brick red", - "Bright cerulean", - "Bright green", - "Bright lavender", - "Bright lilac", - "Bright maroon", - "Bright navy blue", - "Bright pink", - "Bright turquoise", - "Bright ube", - "Brilliant lavender", - "Brilliant rose", - "Brink pink", - "British racing green", - "Bronze", - "Bronze Yellow", - "Brown", - "Brown-nose", - "Brunswick green", - "Bubble gum", - "Bubbles", - "Buff", - "Bud green", - "Bulgarian rose", - "Burgundy", - "Burlywood", - "Burnt orange", - "Burnt sienna", - "Burnt umber", - "Byzantine", - "Byzantium", + 'Bisque', + 'Bistre', + 'Bistre brown', + 'Bitter lemon', + 'Bitter lime', + 'Bittersweet', + 'Bittersweet shimmer', + 'Black', + 'Black bean', + 'Black leather jacket', + 'Black olive', + 'Blanched almond', + 'Blast-off bronze', + 'Bleu de France', + 'Blizzard Blue', + 'Blond', + 'Blue', + 'Blue Bell', + 'Blue-gray', + 'Blue-green', + 'Blue sapphire', + 'Blue-violet', + 'Blue yonder', + 'Blueberry', + 'Bluebonnet', + 'Blush', + 'Bole', + 'Bondi blue', + 'Bone', + 'Boston University Red', + 'Bottle green', + 'Boysenberry', + 'Brandeis blue', + 'Brass', + 'Brick red', + 'Bright cerulean', + 'Bright green', + 'Bright lavender', + 'Bright lilac', + 'Bright maroon', + 'Bright navy blue', + 'Bright pink', + 'Bright turquoise', + 'Bright ube', + 'Brilliant lavender', + 'Brilliant rose', + 'Brink pink', + 'British racing green', + 'Bronze', + 'Bronze Yellow', + 'Brown', + 'Brown-nose', + 'Brunswick green', + 'Bubble gum', + 'Bubbles', + 'Buff', + 'Bud green', + 'Bulgarian rose', + 'Burgundy', + 'Burlywood', + 'Burnt orange', + 'Burnt sienna', + 'Burnt umber', + 'Byzantine', + 'Byzantium', - "Cadet", - "Cadet blue", - "Cadet grey", - "Cadmium green", - "Cadmium orange", - "Cadmium red", - "Cadmium yellow", - "Cafe au lait", - "Cafe noir", - "Cal Poly Pomona green", - "Cambridge Blue", - "Camel", - "Cameo pink", - "Camouflage green", - "Canary yellow", - "Candy apple red", - "Candy pink", - "Capri", - "Caput mortuum", - "Cardinal", - "Caribbean green", - "Carmine", - "Carmine", - "Carmine pink", - "Carmine red", - "Carnation pink", - "Carnelian", - "Carolina blue", - "Carrot orange", - "Castleton green", - "Catalina blue", - "Catawba", - "Cedar Chest", - "Ceil", - "Celadon", - "Celadon blue", - "Celadon green", - "Celeste", - "Celestial blue", - "Cerise", - "Cerise pink", - "Cerulean", - "Cerulean blue", - "Cerulean frost", - "CG Blue", - "CG Red", - "Chamoisee", - "Champagne", - "Charcoal", - "Charleston green", - "Charm pink", - "Chartreuse", - "Cherry", - "Cherry blossom pink", - "Chestnut", - "China pink", - "China rose", - "Chinese red", - "Chinese violet", - "Chocolate", - "Chrome yellow", - "Cinereous", - "Cinnabar", - "Cinnamon", - "Citrine", - "Citron", - "Claret", - "Classic rose", - "Cobalt", - "Cocoa brown", - "Coconut", - "Coffee", - "Columbia blue", - "Congo pink", - "Cool grey", - "Copper", - "Copper penny", - "Copper red", - "Copper rose", - "Coquelicot", - "Coral", - "Coral pink", - "Coral red", - "Cordovan", - "Corn", - "Cornell Red", - "Cornflower blue", - "Cornsilk", - "Cosmic latte", - "Cotton candy", - "Cream", - "Crimson", - "Crimson glory", - "Cyan", - "Cyber grape", - "Cyber yellow", + 'Cadet', + 'Cadet blue', + 'Cadet grey', + 'Cadmium green', + 'Cadmium orange', + 'Cadmium red', + 'Cadmium yellow', + 'Cafe au lait', + 'Cafe noir', + 'Cal Poly Pomona green', + 'Cambridge Blue', + 'Camel', + 'Cameo pink', + 'Camouflage green', + 'Canary yellow', + 'Candy apple red', + 'Candy pink', + 'Capri', + 'Caput mortuum', + 'Cardinal', + 'Caribbean green', + 'Carmine', + 'Carmine', + 'Carmine pink', + 'Carmine red', + 'Carnation pink', + 'Carnelian', + 'Carolina blue', + 'Carrot orange', + 'Castleton green', + 'Catalina blue', + 'Catawba', + 'Cedar Chest', + 'Ceil', + 'Celadon', + 'Celadon blue', + 'Celadon green', + 'Celeste', + 'Celestial blue', + 'Cerise', + 'Cerise pink', + 'Cerulean', + 'Cerulean blue', + 'Cerulean frost', + 'CG Blue', + 'CG Red', + 'Chamoisee', + 'Champagne', + 'Charcoal', + 'Charleston green', + 'Charm pink', + 'Chartreuse', + 'Cherry', + 'Cherry blossom pink', + 'Chestnut', + 'China pink', + 'China rose', + 'Chinese red', + 'Chinese violet', + 'Chocolate', + 'Chrome yellow', + 'Cinereous', + 'Cinnabar', + 'Cinnamon', + 'Citrine', + 'Citron', + 'Claret', + 'Classic rose', + 'Cobalt', + 'Cocoa brown', + 'Coconut', + 'Coffee', + 'Columbia blue', + 'Congo pink', + 'Cool grey', + 'Copper', + 'Copper penny', + 'Copper red', + 'Copper rose', + 'Coquelicot', + 'Coral', + 'Coral pink', + 'Coral red', + 'Cordovan', + 'Corn', + 'Cornell Red', + 'Cornflower blue', + 'Cornsilk', + 'Cosmic latte', + 'Cotton candy', + 'Cream', + 'Crimson', + 'Crimson glory', + 'Cyan', + 'Cyber grape', + 'Cyber yellow', - "Daffodil", - "Dandelion", - "Dark blue", - "Dark blue-gray", - "Dark brown", - "Dark byzantium", - "Dark candy apple red", - "Dark cerulean", - "Dark chestnut", - "Dark coral", - "Dark cyan", - "Dark electric blue", - "Dark goldenrod", - "Dark gray", - "Dark green", - "Dark imperial blue", - "Dark jungle green", - "Dark khaki", - "Dark lava", - "Dark lavender", - "Dark liver", - "Dark magenta", - "Dark medium gray", - "Dark midnight blue", - "Dark moss green", - "Dark olive green", - "Dark orange", - "Dark orchid", - "Dark pastel blue", - "Dark pastel green", - "Dark pastel purple", - "Dark pastel red", - "Dark pink", - "Dark powder blue", - "Dark puce", - "Dark raspberry", - "Dark red", - "Dark salmon", - "Dark scarlet", - "Dark sea green", - "Dark sienna", - "Dark sky blue", - "Dark slate blue", - "Dark slate gray", - "Dark spring green", - "Dark tan", - "Dark tangerine", - "Dark taupe", - "Dark terra cotta", - "Dark turquoise", - "Dark vanilla", - "Dark violet", - "Dark yellow", - "Dartmouth green", + 'Daffodil', + 'Dandelion', + 'Dark blue', + 'Dark blue-gray', + 'Dark brown', + 'Dark byzantium', + 'Dark candy apple red', + 'Dark cerulean', + 'Dark chestnut', + 'Dark coral', + 'Dark cyan', + 'Dark electric blue', + 'Dark goldenrod', + 'Dark gray', + 'Dark green', + 'Dark imperial blue', + 'Dark jungle green', + 'Dark khaki', + 'Dark lava', + 'Dark lavender', + 'Dark liver', + 'Dark magenta', + 'Dark medium gray', + 'Dark midnight blue', + 'Dark moss green', + 'Dark olive green', + 'Dark orange', + 'Dark orchid', + 'Dark pastel blue', + 'Dark pastel green', + 'Dark pastel purple', + 'Dark pastel red', + 'Dark pink', + 'Dark powder blue', + 'Dark puce', + 'Dark raspberry', + 'Dark red', + 'Dark salmon', + 'Dark scarlet', + 'Dark sea green', + 'Dark sienna', + 'Dark sky blue', + 'Dark slate blue', + 'Dark slate gray', + 'Dark spring green', + 'Dark tan', + 'Dark tangerine', + 'Dark taupe', + 'Dark terra cotta', + 'Dark turquoise', + 'Dark vanilla', + 'Dark violet', + 'Dark yellow', + 'Dartmouth green', "Davy's grey", - "Debian red", - "Deep carmine", - "Deep carmine pink", - "Deep carrot orange", - "Deep cerise", - "Deep champagne", - "Deep chestnut", - "Deep coffee", - "Deep fuchsia", - "Deep jungle green", - "Deep lemon", - "Deep lilac", - "Deep magenta", - "Deep mauve", - "Deep moss green", - "Deep peach", - "Deep pink", - "Deep puce", - "Deep ruby", - "Deep saffron", - "Deep sky blue", - "Deep Space Sparkle", - "Deep Taupe", - "Deep Tuscan red", - "Deer", - "Denim", - "Desert", - "Desert sand", - "Desire", - "Diamond", - "Dim gray", - "Dirt", - "Dodger blue", - "Dogwood rose", - "Dollar bill", - "Donkey brown", - "Drab", - "Duke blue", - "Dust storm", - "Dutch white", + 'Debian red', + 'Deep carmine', + 'Deep carmine pink', + 'Deep carrot orange', + 'Deep cerise', + 'Deep champagne', + 'Deep chestnut', + 'Deep coffee', + 'Deep fuchsia', + 'Deep jungle green', + 'Deep lemon', + 'Deep lilac', + 'Deep magenta', + 'Deep mauve', + 'Deep moss green', + 'Deep peach', + 'Deep pink', + 'Deep puce', + 'Deep ruby', + 'Deep saffron', + 'Deep sky blue', + 'Deep Space Sparkle', + 'Deep Taupe', + 'Deep Tuscan red', + 'Deer', + 'Denim', + 'Desert', + 'Desert sand', + 'Desire', + 'Diamond', + 'Dim gray', + 'Dirt', + 'Dodger blue', + 'Dogwood rose', + 'Dollar bill', + 'Donkey brown', + 'Drab', + 'Duke blue', + 'Dust storm', + 'Dutch white', - "Earth yellow", - "Ebony", - "Ecru", - "Eerie black", - "Eggplant", - "Eggshell", - "Egyptian blue", - "Electric blue", - "Electric crimson", - "Electric cyan", - "Electric green", - "Electric indigo", - "Electric lavender", - "Electric lime", - "Electric purple", - "Electric ultramarine", - "Electric violet", - "Electric yellow", - "Emerald", - "Eminence", - "English green", - "English lavender", - "English red", - "English violet", - "Eton blue", - "Eucalyptus", + 'Earth yellow', + 'Ebony', + 'Ecru', + 'Eerie black', + 'Eggplant', + 'Eggshell', + 'Egyptian blue', + 'Electric blue', + 'Electric crimson', + 'Electric cyan', + 'Electric green', + 'Electric indigo', + 'Electric lavender', + 'Electric lime', + 'Electric purple', + 'Electric ultramarine', + 'Electric violet', + 'Electric yellow', + 'Emerald', + 'Eminence', + 'English green', + 'English lavender', + 'English red', + 'English violet', + 'Eton blue', + 'Eucalyptus', + 'Fallow', + 'Falu red', + 'Fandango', + 'Fandango pink', + 'Fashion fuchsia', + 'Fawn', + 'Feldgrau', + 'Feldspar', + 'Fern green', + 'Ferrari Red', + 'Field drab', + 'Firebrick', + 'Fire engine red', + 'Flame', + 'Flamingo pink', + 'Flattery', + 'Flavescent', + 'Flax', + 'Flirt', + 'Floral white', + 'Fluorescent orange', + 'Fluorescent pink', + 'Fluorescent yellow', + 'Folly', + 'Forest green', + 'French beige', + 'French bistre', + 'French blue', + 'French fuchsia', + 'French lilac', + 'French lime', + 'French mauve', + 'French pink', + 'French plum', + 'French puce', + 'French raspberry', + 'French rose', + 'French sky blue', + 'French violet', + 'French wine', + 'Fresh Air', + 'Fuchsia', + 'Fuchsia', + 'Fuchsia pink', + 'Fuchsia purple', + 'Fuchsia rose', + 'Fulvous', + 'Fuzzy Wuzzy', - "Fallow", - "Falu red", - "Fandango", - "Fandango pink", - "Fashion fuchsia", - "Fawn", - "Feldgrau", - "Feldspar", - "Fern green", - "Ferrari Red", - "Field drab", - "Firebrick", - "Fire engine red", - "Flame", - "Flamingo pink", - "Flattery", - "Flavescent", - "Flax", - "Flirt", - "Floral white", - "Fluorescent orange", - "Fluorescent pink", - "Fluorescent yellow", - "Folly", - "Forest green", - "French beige", - "French bistre", - "French blue", - "French fuchsia", - "French lilac", - "French lime", - "French mauve", - "French pink", - "French plum", - "French puce", - "French raspberry", - "French rose", - "French sky blue", - "French violet", - "French wine", - "Fresh Air", - "Fuchsia", - "Fuchsia", - "Fuchsia pink", - "Fuchsia purple", - "Fuchsia rose", - "Fulvous", - "Fuzzy Wuzzy", - - "Gainsboro", - "Gamboge", - "Generic viridian", - "Ghost white", - "Giants orange", - "Ginger", - "Glaucous", - "Glitter", - "GO green", - "Gold", - "Gold Fusion", - "Golden brown", - "Golden poppy", - "Golden yellow", - "Goldenrod", - "Granny Smith Apple", - "Grape", - "Gray", - "Gray-asparagus", - "Gray-blue", - "Green", - "Green-yellow", - "Grizzly", - "Grullo", - "Guppie green", - "Halaya ube", - "Han blue", - "Han purple", - "Hansa yellow", - "Harlequin", - "Harvard crimson", - "Harvest gold", - "Heart Gold", - "Heliotrope", - "Heliotrope gray", - "Hollywood cerise", - "Honeydew", - "Honolulu blue", + 'Gainsboro', + 'Gamboge', + 'Generic viridian', + 'Ghost white', + 'Giants orange', + 'Ginger', + 'Glaucous', + 'Glitter', + 'GO green', + 'Gold', + 'Gold Fusion', + 'Golden brown', + 'Golden poppy', + 'Golden yellow', + 'Goldenrod', + 'Granny Smith Apple', + 'Grape', + 'Gray', + 'Gray-asparagus', + 'Gray-blue', + 'Green', + 'Green-yellow', + 'Grizzly', + 'Grullo', + 'Guppie green', + 'Halaya ube', + 'Han blue', + 'Han purple', + 'Hansa yellow', + 'Harlequin', + 'Harvard crimson', + 'Harvest gold', + 'Heart Gold', + 'Heliotrope', + 'Heliotrope gray', + 'Hollywood cerise', + 'Honeydew', + 'Honolulu blue', "Hooker's green", - "Hot magenta", - "Hot pink", - "Hunter green", - - - "Iceberg", - "Icterine", - "Illuminating Emerald", - "Imperial", - "Imperial blue", - "Imperial purple", - "Imperial red", - "Inchworm", - "Independence", - "India green", - "Indian red", - "Indian yellow", - "Indigo", - "Indigo dye", - "International Klein Blue", - "International orange", - "Iris", - "Irresistible", - "Isabelline", - "Islamic green", - "Italian sky blue", - "Ivory", - "Jade", - "Japanese carmine", - "Japanese indigo", - "Japanese violet", - "Jasmine", - "Jasper", - "Jazzberry jam", - "Jelly Bean", - "Jet", - "Jonquil", - "Jordy blue", - "June bud", - "Jungle green", - "Kelly green", - "Kenyan copper", - "Keppel", - "Khaki", - "Kobe", - "Kobi", - "Kombu green", - "KU Crimson", - - - "La Salle Green", - "Languid lavender", - "Lapis lazuli", - "Laser Lemon", - "Laurel green", - "Lava", - "Lavender", - "Lavender blue", - "Lavender blush", - "Lavender gray", - "Lavender indigo", - "Lavender magenta", - "Lavender mist", - "Lavender pink", - "Lavender purple", - "Lavender rose", - "Lawn green", - "Lemon", - "Lemon chiffon", - "Lemon curry", - "Lemon glacier", - "Lemon lime", - "Lemon meringue", - "Lemon yellow", - "Licorice", - "Liberty", - "Light apricot", - "Light blue", - "Light brown", - "Light carmine pink", - "Light coral", - "Light cornflower blue", - "Light crimson", - "Light cyan", - "Light deep pink", - "Light French beige", - "Light fuchsia pink", - "Light goldenrod yellow", - "Light gray", - "Light green", - "Light hot pink", - "Light khaki", - "Light medium orchid", - "Light moss green", - "Light orchid", - "Light pastel purple", - "Light pink", - "Light red ochre", - "Light salmon", - "Light salmon pink", - "Light sea green", - "Light sky blue", - "Light slate gray", - "Light steel blue", - "Light taupe", - "Light Thulian pink", - "Light yellow", - "Lilac", - "Lime", - "Lime green", - "Limerick", - "Lincoln green", - "Linen", - "Lion", - "Liseran Purple", - "Little boy blue", - "Liver", - "Liver", - "Liver chestnut", - "Livid", - "Lumber", - "Lust", + 'Hot magenta', + 'Hot pink', + 'Hunter green', + 'Iceberg', + 'Icterine', + 'Illuminating Emerald', + 'Imperial', + 'Imperial blue', + 'Imperial purple', + 'Imperial red', + 'Inchworm', + 'Independence', + 'India green', + 'Indian red', + 'Indian yellow', + 'Indigo', + 'Indigo dye', + 'International Klein Blue', + 'International orange', + 'Iris', + 'Irresistible', + 'Isabelline', + 'Islamic green', + 'Italian sky blue', + 'Ivory', + 'Jade', + 'Japanese carmine', + 'Japanese indigo', + 'Japanese violet', + 'Jasmine', + 'Jasper', + 'Jazzberry jam', + 'Jelly Bean', + 'Jet', + 'Jonquil', + 'Jordy blue', + 'June bud', + 'Jungle green', + 'Kelly green', + 'Kenyan copper', + 'Keppel', + 'Khaki', + 'Kobe', + 'Kobi', + 'Kombu green', + 'KU Crimson', - "Magenta", - "Magenta", - "Magenta haze", - "Magic mint", - "Magnolia", - "Mahogany", - "Maize", - "Majorelle Blue", - "Malachite", - "Manatee", - "Mango Tango", - "Mantis", - "Mardi Gras", - "Maroon", - "Mauve", - "Mauve taupe", - "Mauvelous", - "May green", - "Maya blue", - "Meat brown", - "Medium aquamarine", - "Medium blue", - "Medium candy apple red", - "Medium carmine", - "Medium champagne", - "Medium electric blue", - "Medium jungle green", - "Medium lavender magenta", - "Medium orchid", - "Medium Persian blue", - "Medium purple", - "Medium red-violet", - "Medium ruby", - "Medium sea green", - "Medium sky blue", - "Medium slate blue", - "Medium spring bud", - "Medium spring green", - "Medium taupe", - "Medium turquoise", - "Medium Tuscan red", - "Medium vermilion", - "Medium violet-red", - "Mellow apricot", - "Mellow yellow", - "Melon", - "Metallic Seaweed", - "Metallic Sunburst", - "Mexican pink", - "Midnight blue", - "Milky blue", - "Midnight green", - "Mikado yellow", - "Mindaro", - "Mint", - "Mint cream", - "Mint green", - "Misty rose", - "Moccasin", - "Mode beige", - "Moonstone blue", - "Mordant red 19", - "Moss green", - "Mountain Meadow", - "Mountbatten pink", - "MSU Green", - "Mughal green", - "Mulberry", - "Mustard", - "Myrtle green", + 'La Salle Green', + 'Languid lavender', + 'Lapis lazuli', + 'Laser Lemon', + 'Laurel green', + 'Lava', + 'Lavender', + 'Lavender blue', + 'Lavender blush', + 'Lavender gray', + 'Lavender indigo', + 'Lavender magenta', + 'Lavender mist', + 'Lavender pink', + 'Lavender purple', + 'Lavender rose', + 'Lawn green', + 'Lemon', + 'Lemon chiffon', + 'Lemon curry', + 'Lemon glacier', + 'Lemon lime', + 'Lemon meringue', + 'Lemon yellow', + 'Licorice', + 'Liberty', + 'Light apricot', + 'Light blue', + 'Light brown', + 'Light carmine pink', + 'Light coral', + 'Light cornflower blue', + 'Light crimson', + 'Light cyan', + 'Light deep pink', + 'Light French beige', + 'Light fuchsia pink', + 'Light goldenrod yellow', + 'Light gray', + 'Light green', + 'Light hot pink', + 'Light khaki', + 'Light medium orchid', + 'Light moss green', + 'Light orchid', + 'Light pastel purple', + 'Light pink', + 'Light red ochre', + 'Light salmon', + 'Light salmon pink', + 'Light sea green', + 'Light sky blue', + 'Light slate gray', + 'Light steel blue', + 'Light taupe', + 'Light Thulian pink', + 'Light yellow', + 'Lilac', + 'Lime', + 'Lime green', + 'Limerick', + 'Lincoln green', + 'Linen', + 'Lion', + 'Liseran Purple', + 'Little boy blue', + 'Liver', + 'Liver', + 'Liver chestnut', + 'Livid', + 'Lumber', + 'Lust', - "Nadeshiko pink", - "Napier green", - "Naples yellow", - "Navajo white", - "Navy", - "Navy purple", - "Neon Carrot", - "Neon fuchsia", - "Neon green", - "New Car", - "New York pink", - "Non-photo blue", - "North Texas Green", - "Nyanza", - "Ocean Boat Blue", - "Ochre", - "Office green", - "Old burgundy", - "Old gold", - "Old heliotrope", - "Old lace", - "Old lavender", - "Old mauve", - "Old moss green", - "Old rose", - "Old silver", - "Olive", - "Olive Drab", - "Olivine", - "Onyx", - "Opera mauve", - "Orange", - "Orange peel", - "Orange-red", - "Orchid", - "Orchid pink", - "Orioles orange", - "Otter brown", - "Outer Space", - "Outrageous Orange", - "Oxford Blue", - "OU Crimson Red", + 'Magenta', + 'Magenta', + 'Magenta haze', + 'Magic mint', + 'Magnolia', + 'Mahogany', + 'Maize', + 'Majorelle Blue', + 'Malachite', + 'Manatee', + 'Mango Tango', + 'Mantis', + 'Mardi Gras', + 'Maroon', + 'Mauve', + 'Mauve taupe', + 'Mauvelous', + 'May green', + 'Maya blue', + 'Meat brown', + 'Medium aquamarine', + 'Medium blue', + 'Medium candy apple red', + 'Medium carmine', + 'Medium champagne', + 'Medium electric blue', + 'Medium jungle green', + 'Medium lavender magenta', + 'Medium orchid', + 'Medium Persian blue', + 'Medium purple', + 'Medium red-violet', + 'Medium ruby', + 'Medium sea green', + 'Medium sky blue', + 'Medium slate blue', + 'Medium spring bud', + 'Medium spring green', + 'Medium taupe', + 'Medium turquoise', + 'Medium Tuscan red', + 'Medium vermilion', + 'Medium violet-red', + 'Mellow apricot', + 'Mellow yellow', + 'Melon', + 'Metallic Seaweed', + 'Metallic Sunburst', + 'Mexican pink', + 'Midnight blue', + 'Milky blue', + 'Midnight green', + 'Mikado yellow', + 'Mindaro', + 'Mint', + 'Mint cream', + 'Mint green', + 'Misty rose', + 'Moccasin', + 'Mode beige', + 'Moonstone blue', + 'Mordant red 19', + 'Moss green', + 'Mountain Meadow', + 'Mountbatten pink', + 'MSU Green', + 'Mughal green', + 'Mulberry', + 'Mustard', + 'Myrtle green', + 'Nadeshiko pink', + 'Napier green', + 'Naples yellow', + 'Navajo white', + 'Navy', + 'Navy purple', + 'Neon Carrot', + 'Neon fuchsia', + 'Neon green', + 'New Car', + 'New York pink', + 'Non-photo blue', + 'North Texas Green', + 'Nyanza', + 'Ocean Boat Blue', + 'Ochre', + 'Office green', + 'Old burgundy', + 'Old gold', + 'Old heliotrope', + 'Old lace', + 'Old lavender', + 'Old mauve', + 'Old moss green', + 'Old rose', + 'Old silver', + 'Olive', + 'Olive Drab', + 'Olivine', + 'Onyx', + 'Opera mauve', + 'Orange', + 'Orange peel', + 'Orange-red', + 'Orchid', + 'Orchid pink', + 'Orioles orange', + 'Otter brown', + 'Outer Space', + 'Outrageous Orange', + 'Oxford Blue', + 'OU Crimson Red', - "Pakistan green", - "Palatinate blue", - "Palatinate purple", - "Pale aqua", - "Pale blue", - "Pale brown", - "Pale carmine", - "Pale cerulean", - "Pale chestnut", - "Pale copper", - "Pale cornflower blue", - "Pale gold", - "Pale goldenrod", - "Pale green", - "Pale lavender", - "Pale magenta", - "Pale pink", - "Pale plum", - "Pale red-violet", - "Pale robin egg blue", - "Pale silver", - "Pale spring bud", - "Pale taupe", - "Pale turquoise", - "Pale violet-red", - "Pansy purple", - "Paolo Veronese green", - "Papaya whip", - "Paradise pink", - "Paris Green", - "Pastel blue", - "Pastel brown", - "Pastel gray", - "Pastel green", - "Pastel magenta", - "Pastel orange", - "Pastel pink", - "Pastel purple", - "Pastel red", - "Pastel violet", - "Pastel yellow", - "Patriarch", + 'Pakistan green', + 'Palatinate blue', + 'Palatinate purple', + 'Pale aqua', + 'Pale blue', + 'Pale brown', + 'Pale carmine', + 'Pale cerulean', + 'Pale chestnut', + 'Pale copper', + 'Pale cornflower blue', + 'Pale gold', + 'Pale goldenrod', + 'Pale green', + 'Pale lavender', + 'Pale magenta', + 'Pale pink', + 'Pale plum', + 'Pale red-violet', + 'Pale robin egg blue', + 'Pale silver', + 'Pale spring bud', + 'Pale taupe', + 'Pale turquoise', + 'Pale violet-red', + 'Pansy purple', + 'Paolo Veronese green', + 'Papaya whip', + 'Paradise pink', + 'Paris Green', + 'Pastel blue', + 'Pastel brown', + 'Pastel gray', + 'Pastel green', + 'Pastel magenta', + 'Pastel orange', + 'Pastel pink', + 'Pastel purple', + 'Pastel red', + 'Pastel violet', + 'Pastel yellow', + 'Patriarch', "Payne's grey", - "Peach", - "Peach", - "Peach-orange", - "Peach puff", - "Peach-yellow", - "Pear", - "Pearl", - "Pearl Aqua", - "Pearly purple", - "Peridot", - "Periwinkle", - "Persian blue", - "Persian green", - "Persian indigo", - "Persian orange", - "Persian pink", - "Persian plum", - "Persian red", - "Persian rose", - "Persimmon", - "Peru", - "Phlox", - "Phthalo blue", - "Phthalo green", - "Picton blue", - "Pictorial carmine", - "Piggy pink", - "Pine green", - "Pineapple", - "Pink", - "Pink lace", - "Pink lavender", - "Pink-orange", - "Pink pearl", - "Pink Sherbet", - "Pistachio", - "Platinum", - "Plum", - "Pomp and Power", - "Popstar", - "Portland Orange", - "Powder blue", - "Princeton orange", - "Prune", - "Prussian blue", - "Psychedelic purple", - "Puce", - "Puce red", - "Pullman Brown", - "Pumpkin", - "Purple", - "Purple Heart", - "Purple mountain majesty", - "Purple navy", - "Purple pizzazz", - "Purple taupe", - "Purpureus", + 'Peach', + 'Peach', + 'Peach-orange', + 'Peach puff', + 'Peach-yellow', + 'Pear', + 'Pearl', + 'Pearl Aqua', + 'Pearly purple', + 'Peridot', + 'Periwinkle', + 'Persian blue', + 'Persian green', + 'Persian indigo', + 'Persian orange', + 'Persian pink', + 'Persian plum', + 'Persian red', + 'Persian rose', + 'Persimmon', + 'Peru', + 'Phlox', + 'Phthalo blue', + 'Phthalo green', + 'Picton blue', + 'Pictorial carmine', + 'Piggy pink', + 'Pine green', + 'Pineapple', + 'Pink', + 'Pink lace', + 'Pink lavender', + 'Pink-orange', + 'Pink pearl', + 'Pink Sherbet', + 'Pistachio', + 'Platinum', + 'Plum', + 'Pomp and Power', + 'Popstar', + 'Portland Orange', + 'Powder blue', + 'Princeton orange', + 'Prune', + 'Prussian blue', + 'Psychedelic purple', + 'Puce', + 'Puce red', + 'Pullman Brown', + 'Pumpkin', + 'Purple', + 'Purple Heart', + 'Purple mountain majesty', + 'Purple navy', + 'Purple pizzazz', + 'Purple taupe', + 'Purpureus', + 'Quartz', + 'Queen blue', + 'Queen pink', + 'Quinacridone magenta', + 'Rackley', + 'Radical Red', + 'Rajah', + 'Raspberry', + 'Raspberry glace', + 'Raspberry pink', + 'Raspberry rose', + 'Raw umber', + 'Razzle dazzle rose', + 'Razzmatazz', + 'Razzmic Berry', + 'Rebecca Purple', + 'Red', + 'Red', + 'Red-brown', + 'Red devil', + 'Red-orange', + 'Red-purple', + 'Red-violet', + 'Redwood', + 'Regalia', + 'Resolution blue', + 'Rhythm', + 'Rich black', + 'Rich brilliant lavender', + 'Rich carmine', + 'Rich electric blue', + 'Rich lavender', + 'Rich lilac', + 'Rich maroon', + 'Rifle green', + 'Roast coffee', + 'Robin egg blue', + 'Rocket metallic', + 'Roman silver', + 'Rose', + 'Rose bonbon', + 'Rose ebony', + 'Rose gold', + 'Rose madder', + 'Rose pink', + 'Rose quartz', + 'Rose red', + 'Rose taupe', + 'Rose vale', + 'Rosewood', + 'Rosso corsa', + 'Rosy brown', + 'Royal azure', + 'Royal blue', + 'Royal blue', + 'Royal fuchsia', + 'Royal purple', + 'Royal yellow', + 'Ruber', + 'Rubine red', + 'Ruby', + 'Ruby red', + 'Ruddy', + 'Ruddy brown', + 'Ruddy pink', + 'Rufous', + 'Russet', + 'Russian green', + 'Russian violet', + 'Rust', + 'Rusty red', - "Quartz", - "Queen blue", - "Queen pink", - "Quinacridone magenta", - "Rackley", - "Radical Red", - "Rajah", - "Raspberry", - "Raspberry glace", - "Raspberry pink", - "Raspberry rose", - "Raw umber", - "Razzle dazzle rose", - "Razzmatazz", - "Razzmic Berry", - "Rebecca Purple", - "Red", - "Red", - "Red-brown", - "Red devil", - "Red-orange", - "Red-purple", - "Red-violet", - "Redwood", - "Regalia", - "Resolution blue", - "Rhythm", - "Rich black", - "Rich brilliant lavender", - "Rich carmine", - "Rich electric blue", - "Rich lavender", - "Rich lilac", - "Rich maroon", - "Rifle green", - "Roast coffee", - "Robin egg blue", - "Rocket metallic", - "Roman silver", - "Rose", - "Rose bonbon", - "Rose ebony", - "Rose gold", - "Rose madder", - "Rose pink", - "Rose quartz", - "Rose red", - "Rose taupe", - "Rose vale", - "Rosewood", - "Rosso corsa", - "Rosy brown", - "Royal azure", - "Royal blue", - "Royal blue", - "Royal fuchsia", - "Royal purple", - "Royal yellow", - "Ruber", - "Rubine red", - "Ruby", - "Ruby red", - "Ruddy", - "Ruddy brown", - "Ruddy pink", - "Rufous", - "Russet", - "Russian green", - "Russian violet", - "Rust", - "Rusty red", - - - "Sacramento State green", - "Saddle brown", - "Safety orange", - "Safety yellow", - "Saffron", - "Sage", + 'Sacramento State green', + 'Saddle brown', + 'Safety orange', + 'Safety yellow', + 'Saffron', + 'Sage', "St. Patrick's blue", - "Salmon", - "Salmon pink", - "Sand", - "Sand dune", - "Sandstorm", - "Sandy brown", - "Sandy taupe", - "Sangria", - "Sap green", - "Sapphire", - "Sapphire blue", - "Satin sheen gold", - "Scarlet", - "Scarlet", - "Schauss pink", - "School bus yellow", + 'Salmon', + 'Salmon pink', + 'Sand', + 'Sand dune', + 'Sandstorm', + 'Sandy brown', + 'Sandy taupe', + 'Sangria', + 'Sap green', + 'Sapphire', + 'Sapphire blue', + 'Satin sheen gold', + 'Scarlet', + 'Scarlet', + 'Schauss pink', + 'School bus yellow', "Screamin' Green", - "Sea blue", - "Sea green", - "Seal brown", - "Seashell", - "Selective yellow", - "Sepia", - "Shadow", - "Shadow blue", - "Shampoo", - "Shamrock green", - "Sheen Green", - "Shimmering Blush", - "Shocking pink", - "Sienna", - "Silver", - "Silver chalice", - "Silver Lake blue", - "Silver pink", - "Silver sand", - "Sinopia", - "Skobeloff", - "Sky blue", - "Sky magenta", - "Slate blue", - "Slate gray", - "Smalt", - "Smitten", - "Smoke", - "Smoky black", - "Smoky Topaz", - "Snow", - "Soap", - "Solid pink", - "Sonic silver", - "Spartan Crimson", - "Space cadet", - "Spanish bistre", - "Spanish blue", - "Spanish carmine", - "Spanish crimson", - "Spanish gray", - "Spanish green", - "Spanish orange", - "Spanish pink", - "Spanish red", - "Spanish sky blue", - "Spanish violet", - "Spanish viridian", - "Spiro Disco Ball", - "Spring bud", - "Spring green", - "Star command blue", - "Steel blue", - "Steel pink", - "Stil de grain yellow", - "Stizza", - "Stormcloud", - "Straw", - "Strawberry", - "Sunglow", - "Sunray", - "Sunset", - "Sunset orange", - "Super pink", + 'Sea blue', + 'Sea green', + 'Seal brown', + 'Seashell', + 'Selective yellow', + 'Sepia', + 'Shadow', + 'Shadow blue', + 'Shampoo', + 'Shamrock green', + 'Sheen Green', + 'Shimmering Blush', + 'Shocking pink', + 'Sienna', + 'Silver', + 'Silver chalice', + 'Silver Lake blue', + 'Silver pink', + 'Silver sand', + 'Sinopia', + 'Skobeloff', + 'Sky blue', + 'Sky magenta', + 'Slate blue', + 'Slate gray', + 'Smalt', + 'Smitten', + 'Smoke', + 'Smoky black', + 'Smoky Topaz', + 'Snow', + 'Soap', + 'Solid pink', + 'Sonic silver', + 'Spartan Crimson', + 'Space cadet', + 'Spanish bistre', + 'Spanish blue', + 'Spanish carmine', + 'Spanish crimson', + 'Spanish gray', + 'Spanish green', + 'Spanish orange', + 'Spanish pink', + 'Spanish red', + 'Spanish sky blue', + 'Spanish violet', + 'Spanish viridian', + 'Spiro Disco Ball', + 'Spring bud', + 'Spring green', + 'Star command blue', + 'Steel blue', + 'Steel pink', + 'Stil de grain yellow', + 'Stizza', + 'Stormcloud', + 'Straw', + 'Strawberry', + 'Sunglow', + 'Sunray', + 'Sunset', + 'Sunset orange', + 'Super pink', - - "Tan", - "Tangelo", - "Tangerine", - "Tangerine yellow", - "Tango pink", - "Taupe", - "Taupe gray", - "Tea green", - "Tea rose", - "Tea rose", - "Teal", - "Teal blue", - "Teal deer", - "Teal green", - "Telemagenta", - "Tenne", - "Terra cotta", - "Thistle", - "Thulian pink", - "Tickle Me Pink", - "Tiffany Blue", + 'Tan', + 'Tangelo', + 'Tangerine', + 'Tangerine yellow', + 'Tango pink', + 'Taupe', + 'Taupe gray', + 'Tea green', + 'Tea rose', + 'Tea rose', + 'Teal', + 'Teal blue', + 'Teal deer', + 'Teal green', + 'Telemagenta', + 'Tenne', + 'Terra cotta', + 'Thistle', + 'Thulian pink', + 'Tickle Me Pink', + 'Tiffany Blue', "Tiger's eye", - "Timberwolf", - "Titanium yellow", - "Tomato", - "Toolbox", - "Topaz", - "Tractor red", - "Trolley Grey", - "Tropical rain forest", - "True Blue", - "Tufts Blue", - "Tulip", - "Tumbleweed", - "Turkish rose", - "Turquoise", - "Turquoise blue", - "Turquoise green", - "Tuscan", - "Tuscan brown", - "Tuscan red", - "Tuscan tan", - "Tuscany", - "Twilight lavender", - "Tyrian purple", - + 'Timberwolf', + 'Titanium yellow', + 'Tomato', + 'Toolbox', + 'Topaz', + 'Tractor red', + 'Trolley Grey', + 'Tropical rain forest', + 'True Blue', + 'Tufts Blue', + 'Tulip', + 'Tumbleweed', + 'Turkish rose', + 'Turquoise', + 'Turquoise blue', + 'Turquoise green', + 'Tuscan', + 'Tuscan brown', + 'Tuscan red', + 'Tuscan tan', + 'Tuscany', + 'Twilight lavender', + 'Tyrian purple', - "UA blue", - "UA red", - "Ube", - "UCLA Blue", - "UCLA Gold", - "UFO Green", - "Ultramarine", - "Ultramarine blue", - "Ultra pink", - "Ultra red", - "Umber", - "Unbleached silk", - "United Nations blue", - "University of California Gold", - "Unmellow yellow", - "UP Forest green", - "UP Maroon", - "Upsdell red", - "Urobilin", - "USAFA blue", - "USC Cardinal", - "USC Gold", - "University of Tennessee Orange", - "Utah Crimson", - "Vanilla", - "Vanilla ice", - "Vegas gold", - "Venetian red", - "Verdigris", - "Vermilion", - "Vermilion", - "Veronica", - "Violet", - "Violet-blue", - "Violet-red", - "Viridian", - "Viridian green", - "Vista blue", - "Vivid auburn", - "Vivid burgundy", - "Vivid cerise", - "Vivid orchid", - "Vivid sky blue", - "Vivid tangerine", - "Vivid violet", + 'UA blue', + 'UA red', + 'Ube', + 'UCLA Blue', + 'UCLA Gold', + 'UFO Green', + 'Ultramarine', + 'Ultramarine blue', + 'Ultra pink', + 'Ultra red', + 'Umber', + 'Unbleached silk', + 'United Nations blue', + 'University of California Gold', + 'Unmellow yellow', + 'UP Forest green', + 'UP Maroon', + 'Upsdell red', + 'Urobilin', + 'USAFA blue', + 'USC Cardinal', + 'USC Gold', + 'University of Tennessee Orange', + 'Utah Crimson', + 'Vanilla', + 'Vanilla ice', + 'Vegas gold', + 'Venetian red', + 'Verdigris', + 'Vermilion', + 'Vermilion', + 'Veronica', + 'Violet', + 'Violet-blue', + 'Violet-red', + 'Viridian', + 'Viridian green', + 'Vista blue', + 'Vivid auburn', + 'Vivid burgundy', + 'Vivid cerise', + 'Vivid orchid', + 'Vivid sky blue', + 'Vivid tangerine', + 'Vivid violet', - "Warm black", - "Waterspout", - "Wenge", - "Wheat", - "White", - "White smoke", - "Wild blue yonder", - "Wild orchid", - "Wild Strawberry", - "Wild watermelon", - "Willpower orange", - "Windsor tan", - "Wine", - "Wine dregs", - "Wisteria", - "Wood brown", - "Xanadu", - "Yale Blue", - "Yankees blue", - "Yellow", - "Yellow-green", - "Yellow Orange", - "Yellow rose", - "Zaffre", - "Zinnwaldite brown", - "Zomp" - ] + 'Warm black', + 'Waterspout', + 'Wenge', + 'Wheat', + 'White', + 'White smoke', + 'Wild blue yonder', + 'Wild orchid', + 'Wild Strawberry', + 'Wild watermelon', + 'Willpower orange', + 'Windsor tan', + 'Wine', + 'Wine dregs', + 'Wisteria', + 'Wood brown', + 'Xanadu', + 'Yale Blue', + 'Yankees blue', + 'Yellow', + 'Yellow-green', + 'Yellow Orange', + 'Yellow rose', + 'Zaffre', + 'Zinnwaldite brown', + 'Zomp' + ].freeze COLOR_SEARCH = FuzzBall::Searcher.new(COLOR_NAMES) end diff --git a/test/dummy/app/models/nice_user.rb b/test/dummy/app/models/nice_user.rb index 300056732..0e81f5ef8 100644 --- a/test/dummy/app/models/nice_user.rb +++ b/test/dummy/app/models/nice_user.rb @@ -3,7 +3,7 @@ class NiceUser < ActiveRecord::Base # Include default devise modules. devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable, - :confirmable, :omniauthable + :recoverable, :rememberable, :trackable, :validatable, + :confirmable, :omniauthable include DeviseTokenAuth::Concerns::User end diff --git a/test/dummy/app/models/scoped_user.rb b/test/dummy/app/models/scoped_user.rb index 44b22649d..1153887df 100644 --- a/test/dummy/app/models/scoped_user.rb +++ b/test/dummy/app/models/scoped_user.rb @@ -3,7 +3,7 @@ class ScopedUser < ActiveRecord::Base # Include default devise modules. devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable, - :confirmable, :omniauthable + :recoverable, :rememberable, :trackable, :validatable, + :confirmable, :omniauthable include DeviseTokenAuth::Concerns::User end diff --git a/test/dummy/app/models/unregisterable_user.rb b/test/dummy/app/models/unregisterable_user.rb index 659beea0f..113e86844 100644 --- a/test/dummy/app/models/unregisterable_user.rb +++ b/test/dummy/app/models/unregisterable_user.rb @@ -3,7 +3,7 @@ class UnregisterableUser < ActiveRecord::Base # Include default devise modules. devise :database_authenticatable, - :recoverable, :trackable, :validatable, - :confirmable, :omniauthable + :recoverable, :trackable, :validatable, + :confirmable, :omniauthable include DeviseTokenAuth::Concerns::User end diff --git a/test/dummy/app/models/user.rb b/test/dummy/app/models/user.rb index 679ba10e9..3943ca30d 100644 --- a/test/dummy/app/models/user.rb +++ b/test/dummy/app/models/user.rb @@ -8,7 +8,7 @@ class User < ActiveRecord::Base def ensure_correct_favorite_color - if favorite_color and favorite_color != "" + if favorite_color && (favorite_color != '') unless ApplicationHelper::COLOR_NAMES.any?{ |s| s.casecmp(favorite_color)==0 } matches = ApplicationHelper::COLOR_SEARCH.search(favorite_color) closest_match = matches.last[:string] diff --git a/test/dummy/bin/bundle b/test/dummy/bin/bundle index 66e9889e8..2dbb71769 100755 --- a/test/dummy/bin/bundle +++ b/test/dummy/bin/bundle @@ -1,3 +1,5 @@ #!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +# frozen_string_literal: true + +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails index 7feb6a30e..666ce44df 100755 --- a/test/dummy/bin/rails +++ b/test/dummy/bin/rails @@ -1,8 +1,10 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin - load File.expand_path("../spring", __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError end -APP_PATH = File.expand_path('../../config/application', __FILE__) +APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/test/dummy/bin/rake b/test/dummy/bin/rake index 8017a0271..fbda80b1d 100755 --- a/test/dummy/bin/rake +++ b/test/dummy/bin/rake @@ -1,6 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin - load File.expand_path("../spring", __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError end require_relative '../config/boot' diff --git a/test/dummy/bin/spring b/test/dummy/bin/spring index 253ec37c3..a019c01c0 100755 --- a/test/dummy/bin/spring +++ b/test/dummy/bin/spring @@ -1,18 +1,19 @@ #!/usr/bin/env ruby +# frozen_string_literal: true # This file loads spring without using Bundler, in order to be fast # It gets overwritten when you run the `spring binstub` command unless defined?(Spring) - require "rubygems" - require "bundler" + require 'rubygems' + require 'bundler' if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m) - ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) - ENV["GEM_HOME"] = "" + ENV['GEM_PATH'] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) + ENV['GEM_HOME'] = '' Gem.paths = ENV - gem "spring", match[1] - require "spring/binstub" + gem 'spring', match[1] + require 'spring/binstub' end end diff --git a/test/dummy/config.ru b/test/dummy/config.ru index 0a867388d..6270bcdfd 100644 --- a/test/dummy/config.ru +++ b/test/dummy/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) @@ -9,8 +11,8 @@ use Rack::Cors do allow do origins '*' resource '*', - :headers => :any, - :expose => ['access-token', 'expiry', 'token-type', 'uid', 'client'], - :methods => [:get, :post, :options, :delete, :put] + headers: :any, + expose: ['access-token', 'expiry', 'token-type', 'uid', 'client'], + methods: %i[get post options delete put] end end diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index c212f34d4..096381d67 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require File.expand_path('../boot', __FILE__) +require File.expand_path('boot', __dir__) require 'rack/cors' require 'rails/all' Bundler.require(*Rails.groups) -require "devise_token_auth" +require 'devise_token_auth' module Dummy class Application < Rails::Application diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index 18536532a..6d2cba07a 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) -$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__) diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb index 3fa662183..32d57aa44 100644 --- a/test/dummy/config/environment.rb +++ b/test/dummy/config/environment.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # Load the Rails application. -require File.expand_path('../application', __FILE__) +require File.expand_path('application', __dir__) # Initialize the Rails application. Rails.application.initialize! diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 9a14a1bd5..04184e7fb 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -19,9 +19,9 @@ config.action_mailer.raise_delivery_errors = true # use mailcatcher for development - config.action_mailer.default_url_options = { :host => 'devise-token-auth.dev' } + config.action_mailer.default_url_options = { host: 'devise-token-auth.dev' } config.action_mailer.delivery_method = :smtp - config.action_mailer.smtp_settings = { :address => 'localhost', :port => 1025 } + config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 } # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -42,5 +42,5 @@ # Raises error for missing translations # config.action_view.raise_on_missing_translations = true - OmniAuth.config.full_host = "http://devise-token-auth.dev" + OmniAuth.config.full_host = 'http://devise-token-auth.dev' end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 0d52cbc1d..7346cae85 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -37,7 +37,7 @@ # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - config.action_mailer.default_url_options = { :host => 'localhost' } + config.action_mailer.default_url_options = { host: 'localhost' } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/test/dummy/config/initializers/omniauth.rb b/test/dummy/config/initializers/omniauth.rb index 0a3d1dd5c..e495f2364 100644 --- a/test/dummy/config/initializers/omniauth.rb +++ b/test/dummy/config/initializers/omniauth.rb @@ -5,6 +5,6 @@ provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'] provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'] provider :developer, - :fields => [:first_name, :last_name], - :uid_field => :last_name + fields: [:first_name, :last_name], + uid_field: :last_name end diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index 5f4f48d45..47f57ea31 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -10,7 +10,7 @@ # define :mangs as the second devise mapping. routes using this class will # need to be defined within a devise_scope as shown below - mount_devise_token_auth_for "Mang", at: 'mangs' + mount_devise_token_auth_for 'Mang', at: 'mangs' mount_devise_token_auth_for 'EvilUser', at: 'evil_user_auth', controllers: { confirmations: 'overrides/confirmations', @@ -47,22 +47,21 @@ # test namespacing with not created devise mapping namespace :api_v2, defaults: { format: :json } do - mount_devise_token_auth_for "ScopedUser", - at: "auth", - controllers: { - omniauth_callbacks: "api_v2/omniauth_callbacks", - sessions: "api_v2/sessions", - registrations: "api_v2/registrations", - confirmations: "api_v2/confirmations", - passwords: "api_v2/passwords" - } + mount_devise_token_auth_for 'ScopedUser', + at: 'auth', + controllers: { + omniauth_callbacks: 'api_v2/omniauth_callbacks', + sessions: 'api_v2/sessions', + registrations: 'api_v2/registrations', + confirmations: 'api_v2/confirmations', + passwords: 'api_v2/passwords' + } end # this route will authorize visitors using the User class get 'demo/members_only', to: 'demo_user#members_only' get 'demo/members_only_remove_token', to: 'demo_user#members_only_remove_token' - # routes within this block will authorize visitors using the Mang class get 'demo/members_only_mang', to: 'demo_mang#members_only' diff --git a/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb b/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb index 7e3486e7b..f869f3dd9 100644 --- a/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +++ b/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb @@ -7,19 +7,19 @@ def change create_table(:users) do |t| ## Database authenticatable t.string :email - t.string :encrypted_password, :null => false, :default => "" + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at t.string :reset_password_redirect_url - t.boolean :allow_password_change, :default => false + t.boolean :allow_password_change, default: false ## Rememberable t.datetime :remember_created_at ## Trackable - t.integer :sign_in_count, :default => 0, :null => false + t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip @@ -43,7 +43,7 @@ def change ## unique oauth id t.string :provider - t.string :uid, :null => false, :default => "" + t.string :uid, null: false, default: '' ## Tokens if json_supported_database? @@ -56,10 +56,10 @@ def change end add_index :users, :email - add_index :users, [:uid, :provider], :unique => true - add_index :users, :reset_password_token, :unique => true - add_index :users, :confirmation_token, :unique => true - add_index :users, :nickname, :unique => true + add_index :users, [:uid, :provider], unique: true + add_index :users, :reset_password_token, unique: true + add_index :users, :confirmation_token, unique: true + add_index :users, :nickname, unique: true # add_index :users, :unlock_token, :unique => true end end diff --git a/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb b/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb index 1952a61e2..9d853601b 100644 --- a/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +++ b/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb @@ -7,19 +7,19 @@ def change create_table(:mangs) do |t| ## Database authenticatable t.string :email - t.string :encrypted_password, :null => false, :default => "" + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at t.string :reset_password_redirect_url - t.boolean :allow_password_change, :default => false + t.boolean :allow_password_change, default: false ## Rememberable t.datetime :remember_created_at ## Trackable - t.integer :sign_in_count, :default => 0, :null => false + t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip @@ -43,7 +43,7 @@ def change ## unique oauth id t.string :provider - t.string :uid, :null => false, :default => "" + t.string :uid, null: false, default: '' ## Tokens if json_supported_database? @@ -56,9 +56,9 @@ def change end add_index :mangs, :email - add_index :mangs, [:uid, :provider], :unique => true - add_index :mangs, :reset_password_token, :unique => true - add_index :mangs, :confirmation_token, :unique => true + add_index :mangs, [:uid, :provider], unique: true + add_index :mangs, :reset_password_token, unique: true + add_index :mangs, :confirmation_token, unique: true # add_index :mangs, :unlock_token, :unique => true end end diff --git a/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb b/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb index e90f47249..0d53d32d6 100644 --- a/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb +++ b/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb @@ -7,18 +7,18 @@ def change create_table(:evil_users) do |t| ## Database authenticatable t.string :email - t.string :encrypted_password, :null => false, :default => "" + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at - t.boolean :allow_password_change, :default => false + t.boolean :allow_password_change, default: false ## Rememberable t.datetime :remember_created_at ## Trackable - t.integer :sign_in_count, :default => 0, :null => false + t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip @@ -42,7 +42,7 @@ def change ## unique oauth id t.string :provider - t.string :uid, :null => false, :default => "" + t.string :uid, null: false, default: '' ## Tokens if json_supported_database? @@ -58,9 +58,9 @@ def change end add_index :evil_users, :email - add_index :evil_users, [:uid, :provider], :unique => true - add_index :evil_users, :reset_password_token, :unique => true - add_index :evil_users, :confirmation_token, :unique => true + add_index :evil_users, [:uid, :provider], unique: true + add_index :evil_users, :reset_password_token, unique: true + add_index :evil_users, :confirmation_token, unique: true # add_index :evil_users, :unlock_token, :unique => true end end diff --git a/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb b/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb index 0d6d88649..86e82085b 100644 --- a/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +++ b/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb @@ -6,11 +6,11 @@ class DeviseTokenAuthCreateOnlyEmailUsers < ActiveRecord::Migration[4.2] def change create_table(:only_email_users) do |t| ## Required - t.string :provider, :null => false - t.string :uid, :null => false, :default => "" + t.string :provider, null: false + t.string :uid, null: false, default: '' ## Database authenticatable - t.string :encrypted_password, :null => false, :default => "" + t.string :encrypted_password, null: false, default: '' ## Recoverable #t.string :reset_password_token @@ -54,7 +54,7 @@ def change end add_index :only_email_users, :email - add_index :only_email_users, [:uid, :provider], :unique => true + add_index :only_email_users, [:uid, :provider], unique: true #add_index :only_email_users, :reset_password_token, :unique => true # add_index :only_email_users, :confirmation_token, :unique => true # add_index :only_email_users, :unlock_token, :unique => true diff --git a/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb b/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb index c9e0ec4de..db9546a1f 100644 --- a/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +++ b/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb @@ -6,22 +6,22 @@ class DeviseTokenAuthCreateUnregisterableUsers < ActiveRecord::Migration[4.2] def change create_table(:unregisterable_users) do |t| ## Required - t.string :provider, :null => false - t.string :uid, :null => false, :default => "" + t.string :provider, null: false + t.string :uid, null: false, default: '' ## Database authenticatable - t.string :encrypted_password, :null => false, :default => "" + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at - t.boolean :allow_password_change, :default => false + t.boolean :allow_password_change, default: false ## Rememberable t.datetime :remember_created_at ## Trackable - t.integer :sign_in_count, :default => 0, :null => false + t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip @@ -55,8 +55,8 @@ def change end add_index :unregisterable_users, :email - add_index :unregisterable_users, [:uid, :provider], :unique => true - add_index :unregisterable_users, :reset_password_token, :unique => true + add_index :unregisterable_users, [:uid, :provider], unique: true + add_index :unregisterable_users, :reset_password_token, unique: true # add_index :unregisterable_users, :confirmation_token, :unique => true # add_index :unregisterable_users, :unlock_token, :unique => true end diff --git a/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb b/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb index d4e816245..b4e85cf79 100644 --- a/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb +++ b/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb @@ -6,22 +6,22 @@ class DeviseTokenAuthCreateNiceUsers < ActiveRecord::Migration[4.2] def change create_table(:nice_users) do |t| ## Required - t.string :provider, :null => false - t.string :uid, :null => false, :default => "" + t.string :provider, null: false + t.string :uid, null: false, default: '' ## Database authenticatable - t.string :encrypted_password, :null => false, :default => "" + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at - t.boolean :allow_password_change, :default => false + t.boolean :allow_password_change, default: false ## Rememberable t.datetime :remember_created_at ## Trackable - t.integer :sign_in_count, :default => 0, :null => false + t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip @@ -55,8 +55,8 @@ def change end add_index :nice_users, :email - add_index :nice_users, [:uid, :provider], :unique => true - add_index :nice_users, :reset_password_token, :unique => true + add_index :nice_users, [:uid, :provider], unique: true + add_index :nice_users, :reset_password_token, unique: true # add_index :nice_users, :confirmation_token, :unique => true # add_index :nice_users, :unlock_token, :unique => true end diff --git a/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb b/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb index bdc06b995..9547e4047 100644 --- a/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +++ b/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb @@ -6,22 +6,22 @@ class DeviseTokenAuthCreateUnconfirmableUsers < ActiveRecord::Migration[4.2] def change create_table(:unconfirmable_users) do |t| ## Required - t.string :provider, :null => false - t.string :uid, :null => false, :default => "" + t.string :provider, null: false + t.string :uid, null: false, default: '' ## Database authenticatable - t.string :encrypted_password, :null => false, :default => "" + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at - t.boolean :allow_password_change, :default => false + t.boolean :allow_password_change, default: false ## Rememberable t.datetime :remember_created_at ## Trackable - t.integer :sign_in_count, :default => 0, :null => false + t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip @@ -55,8 +55,8 @@ def change end add_index :unconfirmable_users, :email - add_index :unconfirmable_users, [:uid, :provider], :unique => true - add_index :unconfirmable_users, :reset_password_token, :unique => true + add_index :unconfirmable_users, [:uid, :provider], unique: true + add_index :unconfirmable_users, :reset_password_token, unique: true # add_index :nice_users, :confirmation_token, :unique => true # add_index :nice_users, :unlock_token, :unique => true end diff --git a/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb b/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb index 8aadb08f9..8a29f17d2 100644 --- a/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +++ b/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb @@ -6,22 +6,22 @@ class DeviseTokenAuthCreateScopedUsers < ActiveRecord::Migration[4.2] def change create_table(:scoped_users) do |t| ## Required - t.string :provider, :null => false - t.string :uid, :null => false, :default => "" + t.string :provider, null: false + t.string :uid, null: false, default: '' ## Database authenticatable - t.string :encrypted_password, :null => false, :default => "" + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at - t.boolean :allow_password_change, :default => false + t.boolean :allow_password_change, default: false ## Rememberable t.datetime :remember_created_at ## Trackable - t.integer :sign_in_count, :default => 0, :null => false + t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip @@ -55,8 +55,8 @@ def change end add_index :scoped_users, :email - add_index :scoped_users, [:uid, :provider], :unique => true - add_index :scoped_users, :reset_password_token, :unique => true + add_index :scoped_users, [:uid, :provider], unique: true + add_index :scoped_users, :reset_password_token, unique: true # add_index :scoped_users, :confirmation_token, :unique => true # add_index :scoped_users, :unlock_token, :unique => true end diff --git a/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb b/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb index 5309aae72..b5159b6e2 100644 --- a/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +++ b/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb @@ -6,11 +6,11 @@ class DeviseTokenAuthCreateLockableUsers < ActiveRecord::Migration[4.2] def change create_table(:lockable_users) do |t| ## Required - t.string :provider, :null => false - t.string :uid, :null => false, :default => "" + t.string :provider, null: false + t.string :uid, null: false, default: '' ## Database authenticatable - t.string :encrypted_password, :null => false, :default => "" + t.string :encrypted_password, null: false, default: '' ## Recoverable # t.string :reset_password_token @@ -34,7 +34,7 @@ def change # t.string :unconfirmed_email # Only if using reconfirmable ## Lockable - t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts + t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts t.string :unlock_token # Only if unlock strategy is :email or :both t.datetime :locked_at @@ -55,9 +55,9 @@ def change end add_index :lockable_users, :email - add_index :lockable_users, [:uid, :provider], :unique => true + add_index :lockable_users, [:uid, :provider], unique: true # add_index :lockable_users, :reset_password_token, :unique => true # add_index :lockable_users, :confirmation_token, :unique => true - add_index :lockable_users, :unlock_token, :unique => true + add_index :lockable_users, :unlock_token, unique: true end end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 292cf3ee8..7cb4e1a81 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -12,247 +14,247 @@ ActiveRecord::Schema.define(version: 20160629184441) do - create_table "evil_users", force: :cascade do |t| - t.string "email" - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.boolean "allow_password_change", default: false - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "provider" - t.string "uid", default: "", null: false - t.text "tokens" - t.string "favorite_color" - t.datetime "created_at" - t.datetime "updated_at" - t.index ["confirmation_token"], name: "index_evil_users_on_confirmation_token", unique: true - t.index ["email"], name: "index_evil_users_on_email" - t.index ["reset_password_token"], name: "index_evil_users_on_reset_password_token", unique: true - t.index ["uid", "provider"], name: "index_evil_users_on_uid_and_provider", unique: true + create_table 'evil_users', force: :cascade do |t| + t.string 'email' + t.string 'encrypted_password', default: '', null: false + t.string 'reset_password_token' + t.datetime 'reset_password_sent_at' + t.boolean 'allow_password_change', default: false + t.datetime 'remember_created_at' + t.integer 'sign_in_count', default: 0, null: false + t.datetime 'current_sign_in_at' + t.datetime 'last_sign_in_at' + t.string 'current_sign_in_ip' + t.string 'last_sign_in_ip' + t.string 'confirmation_token' + t.datetime 'confirmed_at' + t.datetime 'confirmation_sent_at' + t.string 'unconfirmed_email' + t.string 'name' + t.string 'nickname' + t.string 'image' + t.string 'provider' + t.string 'uid', default: '', null: false + t.text 'tokens' + t.string 'favorite_color' + t.datetime 'created_at' + t.datetime 'updated_at' + t.index ['confirmation_token'], name: 'index_evil_users_on_confirmation_token', unique: true + t.index ['email'], name: 'index_evil_users_on_email' + t.index ['reset_password_token'], name: 'index_evil_users_on_reset_password_token', unique: true + t.index ['uid', 'provider'], name: 'index_evil_users_on_uid_and_provider', unique: true end - create_table "lockable_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.integer "failed_attempts", default: 0, null: false - t.string "unlock_token" - t.datetime "locked_at" - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" - t.datetime "created_at" - t.datetime "updated_at" - t.index ["email"], name: "index_lockable_users_on_email" - t.index ["uid", "provider"], name: "index_lockable_users_on_uid_and_provider", unique: true - t.index ["unlock_token"], name: "index_lockable_users_on_unlock_token", unique: true + create_table 'lockable_users', force: :cascade do |t| + t.string 'provider', null: false + t.string 'uid', default: '', null: false + t.string 'encrypted_password', default: '', null: false + t.integer 'failed_attempts', default: 0, null: false + t.string 'unlock_token' + t.datetime 'locked_at' + t.string 'name' + t.string 'nickname' + t.string 'image' + t.string 'email' + t.text 'tokens' + t.datetime 'created_at' + t.datetime 'updated_at' + t.index ['email'], name: 'index_lockable_users_on_email' + t.index ['uid', 'provider'], name: 'index_lockable_users_on_uid_and_provider', unique: true + t.index ['unlock_token'], name: 'index_lockable_users_on_unlock_token', unique: true end - create_table "mangs", force: :cascade do |t| - t.string "email" - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.string "reset_password_redirect_url" - t.boolean "allow_password_change", default: false - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "provider" - t.string "uid", default: "", null: false - t.text "tokens" - t.datetime "created_at" - t.datetime "updated_at" - t.string "favorite_color" - t.index ["confirmation_token"], name: "index_mangs_on_confirmation_token", unique: true - t.index ["email"], name: "index_mangs_on_email" - t.index ["reset_password_token"], name: "index_mangs_on_reset_password_token", unique: true - t.index ["uid", "provider"], name: "index_mangs_on_uid_and_provider", unique: true + create_table 'mangs', force: :cascade do |t| + t.string 'email' + t.string 'encrypted_password', default: '', null: false + t.string 'reset_password_token' + t.datetime 'reset_password_sent_at' + t.string 'reset_password_redirect_url' + t.boolean 'allow_password_change', default: false + t.datetime 'remember_created_at' + t.integer 'sign_in_count', default: 0, null: false + t.datetime 'current_sign_in_at' + t.datetime 'last_sign_in_at' + t.string 'current_sign_in_ip' + t.string 'last_sign_in_ip' + t.string 'confirmation_token' + t.datetime 'confirmed_at' + t.datetime 'confirmation_sent_at' + t.string 'unconfirmed_email' + t.string 'name' + t.string 'nickname' + t.string 'image' + t.string 'provider' + t.string 'uid', default: '', null: false + t.text 'tokens' + t.datetime 'created_at' + t.datetime 'updated_at' + t.string 'favorite_color' + t.index ['confirmation_token'], name: 'index_mangs_on_confirmation_token', unique: true + t.index ['email'], name: 'index_mangs_on_email' + t.index ['reset_password_token'], name: 'index_mangs_on_reset_password_token', unique: true + t.index ['uid', 'provider'], name: 'index_mangs_on_uid_and_provider', unique: true end - create_table "nice_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.boolean "allow_password_change", default: false - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" - t.datetime "created_at" - t.datetime "updated_at" - t.index ["email"], name: "index_nice_users_on_email" - t.index ["reset_password_token"], name: "index_nice_users_on_reset_password_token", unique: true - t.index ["uid", "provider"], name: "index_nice_users_on_uid_and_provider", unique: true + create_table 'nice_users', force: :cascade do |t| + t.string 'provider', null: false + t.string 'uid', default: '', null: false + t.string 'encrypted_password', default: '', null: false + t.string 'reset_password_token' + t.datetime 'reset_password_sent_at' + t.boolean 'allow_password_change', default: false + t.datetime 'remember_created_at' + t.integer 'sign_in_count', default: 0, null: false + t.datetime 'current_sign_in_at' + t.datetime 'last_sign_in_at' + t.string 'current_sign_in_ip' + t.string 'last_sign_in_ip' + t.string 'confirmation_token' + t.datetime 'confirmed_at' + t.datetime 'confirmation_sent_at' + t.string 'unconfirmed_email' + t.string 'name' + t.string 'nickname' + t.string 'image' + t.string 'email' + t.text 'tokens' + t.datetime 'created_at' + t.datetime 'updated_at' + t.index ['email'], name: 'index_nice_users_on_email' + t.index ['reset_password_token'], name: 'index_nice_users_on_reset_password_token', unique: true + t.index ['uid', 'provider'], name: 'index_nice_users_on_uid_and_provider', unique: true end - create_table "only_email_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" - t.datetime "created_at" - t.datetime "updated_at" - t.index ["email"], name: "index_only_email_users_on_email" - t.index ["uid", "provider"], name: "index_only_email_users_on_uid_and_provider", unique: true + create_table 'only_email_users', force: :cascade do |t| + t.string 'provider', null: false + t.string 'uid', default: '', null: false + t.string 'encrypted_password', default: '', null: false + t.string 'name' + t.string 'nickname' + t.string 'image' + t.string 'email' + t.text 'tokens' + t.datetime 'created_at' + t.datetime 'updated_at' + t.index ['email'], name: 'index_only_email_users_on_email' + t.index ['uid', 'provider'], name: 'index_only_email_users_on_uid_and_provider', unique: true end - create_table "scoped_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.boolean "allow_password_change", default: false - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" - t.datetime "created_at" - t.datetime "updated_at" - t.index ["email"], name: "index_scoped_users_on_email" - t.index ["reset_password_token"], name: "index_scoped_users_on_reset_password_token", unique: true - t.index ["uid", "provider"], name: "index_scoped_users_on_uid_and_provider", unique: true + create_table 'scoped_users', force: :cascade do |t| + t.string 'provider', null: false + t.string 'uid', default: '', null: false + t.string 'encrypted_password', default: '', null: false + t.string 'reset_password_token' + t.datetime 'reset_password_sent_at' + t.boolean 'allow_password_change', default: false + t.datetime 'remember_created_at' + t.integer 'sign_in_count', default: 0, null: false + t.datetime 'current_sign_in_at' + t.datetime 'last_sign_in_at' + t.string 'current_sign_in_ip' + t.string 'last_sign_in_ip' + t.string 'confirmation_token' + t.datetime 'confirmed_at' + t.datetime 'confirmation_sent_at' + t.string 'unconfirmed_email' + t.string 'name' + t.string 'nickname' + t.string 'image' + t.string 'email' + t.text 'tokens' + t.datetime 'created_at' + t.datetime 'updated_at' + t.index ['email'], name: 'index_scoped_users_on_email' + t.index ['reset_password_token'], name: 'index_scoped_users_on_reset_password_token', unique: true + t.index ['uid', 'provider'], name: 'index_scoped_users_on_uid_and_provider', unique: true end - create_table "unconfirmable_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.boolean "allow_password_change", default: false - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" - t.datetime "created_at" - t.datetime "updated_at" - t.index ["email"], name: "index_unconfirmable_users_on_email" - t.index ["reset_password_token"], name: "index_unconfirmable_users_on_reset_password_token", unique: true - t.index ["uid", "provider"], name: "index_unconfirmable_users_on_uid_and_provider", unique: true + create_table 'unconfirmable_users', force: :cascade do |t| + t.string 'provider', null: false + t.string 'uid', default: '', null: false + t.string 'encrypted_password', default: '', null: false + t.string 'reset_password_token' + t.datetime 'reset_password_sent_at' + t.boolean 'allow_password_change', default: false + t.datetime 'remember_created_at' + t.integer 'sign_in_count', default: 0, null: false + t.datetime 'current_sign_in_at' + t.datetime 'last_sign_in_at' + t.string 'current_sign_in_ip' + t.string 'last_sign_in_ip' + t.string 'name' + t.string 'nickname' + t.string 'image' + t.string 'email' + t.text 'tokens' + t.datetime 'created_at' + t.datetime 'updated_at' + t.index ['email'], name: 'index_unconfirmable_users_on_email' + t.index ['reset_password_token'], name: 'index_unconfirmable_users_on_reset_password_token', unique: true + t.index ['uid', 'provider'], name: 'index_unconfirmable_users_on_uid_and_provider', unique: true end - create_table "unregisterable_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.boolean "allow_password_change", default: false - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" - t.datetime "created_at" - t.datetime "updated_at" - t.index ["email"], name: "index_unregisterable_users_on_email" - t.index ["reset_password_token"], name: "index_unregisterable_users_on_reset_password_token", unique: true - t.index ["uid", "provider"], name: "index_unregisterable_users_on_uid_and_provider", unique: true + create_table 'unregisterable_users', force: :cascade do |t| + t.string 'provider', null: false + t.string 'uid', default: '', null: false + t.string 'encrypted_password', default: '', null: false + t.string 'reset_password_token' + t.datetime 'reset_password_sent_at' + t.boolean 'allow_password_change', default: false + t.datetime 'remember_created_at' + t.integer 'sign_in_count', default: 0, null: false + t.datetime 'current_sign_in_at' + t.datetime 'last_sign_in_at' + t.string 'current_sign_in_ip' + t.string 'last_sign_in_ip' + t.string 'confirmation_token' + t.datetime 'confirmed_at' + t.datetime 'confirmation_sent_at' + t.string 'unconfirmed_email' + t.string 'name' + t.string 'nickname' + t.string 'image' + t.string 'email' + t.text 'tokens' + t.datetime 'created_at' + t.datetime 'updated_at' + t.index ['email'], name: 'index_unregisterable_users_on_email' + t.index ['reset_password_token'], name: 'index_unregisterable_users_on_reset_password_token', unique: true + t.index ['uid', 'provider'], name: 'index_unregisterable_users_on_uid_and_provider', unique: true end - create_table "users", force: :cascade do |t| - t.string "email" - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.string "reset_password_redirect_url" - t.boolean "allow_password_change", default: false - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "provider" - t.string "uid", default: "", null: false - t.text "tokens" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "operating_thetan" - t.string "favorite_color" - t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true - t.index ["email"], name: "index_users_on_email" - t.index ["nickname"], name: "index_users_on_nickname", unique: true - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - t.index ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true + create_table 'users', force: :cascade do |t| + t.string 'email' + t.string 'encrypted_password', default: '', null: false + t.string 'reset_password_token' + t.datetime 'reset_password_sent_at' + t.string 'reset_password_redirect_url' + t.boolean 'allow_password_change', default: false + t.datetime 'remember_created_at' + t.integer 'sign_in_count', default: 0, null: false + t.datetime 'current_sign_in_at' + t.datetime 'last_sign_in_at' + t.string 'current_sign_in_ip' + t.string 'last_sign_in_ip' + t.string 'confirmation_token' + t.datetime 'confirmed_at' + t.datetime 'confirmation_sent_at' + t.string 'unconfirmed_email' + t.string 'name' + t.string 'nickname' + t.string 'image' + t.string 'provider' + t.string 'uid', default: '', null: false + t.text 'tokens' + t.datetime 'created_at' + t.datetime 'updated_at' + t.integer 'operating_thetan' + t.string 'favorite_color' + t.index ['confirmation_token'], name: 'index_users_on_confirmation_token', unique: true + t.index ['email'], name: 'index_users_on_email' + t.index ['nickname'], name: 'index_users_on_nickname', unique: true + t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true + t.index ['uid', 'provider'], name: 'index_users_on_uid_and_provider', unique: true end end diff --git a/test/lib/devise_token_auth/url_test.rb b/test/lib/devise_token_auth/url_test.rb index 262dd9b3d..6e89ce30c 100644 --- a/test/lib/devise_token_auth/url_test.rb +++ b/test/lib/devise_token_auth/url_test.rb @@ -3,23 +3,23 @@ require 'test_helper' class DeviseTokenAuth::UrlTest < ActiveSupport::TestCase - describe "DeviseTokenAuth::Url#generate" do + 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" + assert_equal DeviseTokenAuth::Url.send(:generate, url, params), 'http://example.com?client_id=123#fragment' end describe 'with existing query params' do test 'should preserve existing query params' do url = 'http://example.com?a=1' - assert_equal DeviseTokenAuth::Url.send(:generate, url), "http://example.com?a=1" + assert_equal DeviseTokenAuth::Url.send(:generate, url), 'http://example.com?a=1' 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" + assert_equal DeviseTokenAuth::Url.send(:generate, url, params), 'http://example.com?a=1&client_id=123' end end end diff --git a/test/lib/generators/devise_token_auth/install_generator_test.rb b/test/lib/generators/devise_token_auth/install_generator_test.rb index d540767fd..b546f52f2 100644 --- a/test/lib/generators/devise_token_auth/install_generator_test.rb +++ b/test/lib/generators/devise_token_auth/install_generator_test.rb @@ -47,9 +47,9 @@ class InstallGeneratorTest < Rails::Generators::TestCase setup :prepare_destination before do - @dir = File.join(destination_root, "app", "models") + @dir = File.join(destination_root, 'app', 'models') - @fname = File.join(@dir, "user.rb") + @fname = File.join(@dir, 'user.rb') # make dir if not exists FileUtils.mkdir_p(@dir) @@ -57,7 +57,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase # account for rails version 5 active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base' - @f = File.open(@fname, 'w') {|f| + @f = File.open(@fname, 'w') do |f| f.write <<-RUBY class User < #{active_record_needle} @@ -66,7 +66,7 @@ def whatever end end RUBY - } + end run_generator end @@ -86,25 +86,24 @@ def whatever end end - describe 'routes' do setup :prepare_destination before do - @dir = File.join(destination_root, "config") + @dir = File.join(destination_root, 'config') - @fname = File.join(@dir, "routes.rb") + @fname = File.join(@dir, 'routes.rb') # make dir if not exists FileUtils.mkdir_p(@dir) - @f = File.open(@fname, 'w') {|f| + @f = File.open(@fname, 'w') do |f| f.write <<-RUBY Rails.application.routes.draw do patch '/chong', to: 'bong#index' end RUBY - } + end run_generator end @@ -125,7 +124,7 @@ def whatever describe 'subsequent models' do before do - run_generator %w(Mang mangs) + run_generator %w[Mang mangs] end test 'migration is created' do @@ -151,14 +150,14 @@ def whatever setup :prepare_destination before do - @dir = File.join(destination_root, "app", "controllers") + @dir = File.join(destination_root, 'app', 'controllers') - @fname = File.join(@dir, "application_controller.rb") + @fname = File.join(@dir, 'application_controller.rb') # make dir if not exists FileUtils.mkdir_p(@dir) - @f = File.open(@fname, 'w') {|f| + @f = File.open(@fname, 'w') do |f| f.write <<-RUBY class ApplicationController < ActionController::Base def whatever @@ -166,7 +165,7 @@ def whatever end end RUBY - } + end run_generator end diff --git a/test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb b/test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb index ac1cd8e3b..ec06056af 100644 --- a/test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb +++ b/test/lib/generators/devise_token_auth/install_generator_with_namespace_test.rb @@ -10,15 +10,15 @@ class InstallGeneratorTest < Rails::Generators::TestCase destination Rails.root.join('tmp/generators') # The namespaced user model for testing - let(:user_class) { "Azpire::V1::HumanResource::User" } + let(:user_class) { 'Azpire::V1::HumanResource::User' } let(:namespace_path) { user_class.underscore } - let(:table_name) { user_class.pluralize.underscore.gsub("/","_") } + let(:table_name) { user_class.pluralize.underscore.gsub('/','_') } describe 'user model with namespace, clean install' do setup :prepare_destination before do - run_generator %W(#{user_class} auth) + run_generator %W[#{user_class} auth] end test 'user model (with namespace) is created, concern is included' do @@ -44,7 +44,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase end test 'subsequent runs raise no errors' do - run_generator %W(#{user_class} auth) + run_generator %W[#{user_class} auth] end end @@ -52,9 +52,9 @@ class InstallGeneratorTest < Rails::Generators::TestCase setup :prepare_destination before do - @dir = File.join(destination_root, "app", "models") + @dir = File.join(destination_root, 'app', 'models') - @fname = File.join(@dir, "user.rb") + @fname = File.join(@dir, 'user.rb') # make dir if not exists FileUtils.mkdir_p(@dir) @@ -62,7 +62,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase # account for rails version 5 active_record_needle = (Rails::VERSION::MAJOR == 5) ? 'ApplicationRecord' : 'ActiveRecord::Base' - @f = File.open(@fname, 'w') {|f| + @f = File.open(@fname, 'w') do |f| f.write <<-RUBY class User < #{active_record_needle} @@ -71,7 +71,7 @@ def whatever end end RUBY - } + end run_generator end @@ -91,27 +91,26 @@ def whatever end end - describe 'routes' do setup :prepare_destination before do - @dir = File.join(destination_root, "config") + @dir = File.join(destination_root, 'config') - @fname = File.join(@dir, "routes.rb") + @fname = File.join(@dir, 'routes.rb') # make dir if not exists FileUtils.mkdir_p(@dir) - @f = File.open(@fname, 'w') {|f| + @f = File.open(@fname, 'w') do |f| f.write <<-RUBY Rails.application.routes.draw do patch '/chong', to: 'bong#index' end RUBY - } + end - run_generator %W(#{user_class} auth) + run_generator %W[#{user_class} auth] end test 'route method for user model with namespace is appended to routes file' do @@ -121,7 +120,7 @@ def whatever end test 'subsequent runs do not modify file' do - run_generator %W(#{user_class} auth) + run_generator %W[#{user_class} auth] assert_file 'config/routes.rb' do |routes| matches = routes.scan(/mount_devise_token_auth_for '#{user_class}', at: 'auth'/m).size assert_equal 1, matches @@ -130,7 +129,7 @@ def whatever describe 'subsequent models' do before do - run_generator %w(Mang mangs) + run_generator %w[Mang mangs] end test 'migration is created' do @@ -156,14 +155,14 @@ def whatever setup :prepare_destination before do - @dir = File.join(destination_root, "app", "controllers") + @dir = File.join(destination_root, 'app', 'controllers') - @fname = File.join(@dir, "application_controller.rb") + @fname = File.join(@dir, 'application_controller.rb') # make dir if not exists FileUtils.mkdir_p(@dir) - @f = File.open(@fname, 'w') {|f| + @f = File.open(@fname, 'w') do |f| f.write <<-RUBY class ApplicationController < ActionController::Base def whatever @@ -171,9 +170,9 @@ def whatever end end RUBY - } + end - run_generator %W(#{user_class} auth) + run_generator %W[#{user_class} auth] end test 'controller concern is appended to application controller' do @@ -183,7 +182,7 @@ def whatever end test 'subsequent runs do not modify file' do - run_generator %W(#{user_class} auth) + run_generator %W[#{user_class} auth] assert_file 'app/controllers/application_controller.rb' do |controller| matches = controller.scan(/include DeviseTokenAuth::Concerns::SetUserByToken/m).size assert_equal 1, matches diff --git a/test/lib/generators/devise_token_auth/install_views_generator_test.rb b/test/lib/generators/devise_token_auth/install_views_generator_test.rb index 564b2ca0b..161f74648 100644 --- a/test/lib/generators/devise_token_auth/install_views_generator_test.rb +++ b/test/lib/generators/devise_token_auth/install_views_generator_test.rb @@ -16,7 +16,7 @@ class InstallViewsGeneratorTest < Rails::Generators::TestCase run_generator end - test "files are copied" do + test 'files are copied' do assert_file 'app/views/devise/mailer/reset_password_instructions.html.erb' assert_file 'app/views/devise/mailer/confirmation_instructions.html.erb' end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 6309ae6e3..e12c2988e 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -33,7 +33,7 @@ class UserTest < ActiveSupport::TestCase @resource.password_confirmation = @password refute @resource.save - assert @resource.errors.messages[:email] == [I18n.t("errors.messages.blank")] + assert @resource.errors.messages[:email] == [I18n.t('errors.messages.blank')] end test 'model should not save if email is not an email' do @@ -43,7 +43,7 @@ class UserTest < ActiveSupport::TestCase @resource.password_confirmation = @password refute @resource.save - assert @resource.errors.messages[:email] == [I18n.t("errors.messages.not_email")] + assert @resource.errors.messages[:email] == [I18n.t('errors.messages.not_email')] end end @@ -151,7 +151,7 @@ def @resource.token_lifespan end test 'current token was not removed' do - assert @resource.tokens[@new_auth_headers["client"]] + assert @resource.tokens[@new_auth_headers['client']] end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 46dbb5131..519d80c08 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,13 +8,13 @@ ENV['RAILS_ENV'] = 'test' -require File.expand_path('../dummy/config/environment', __FILE__) +require File.expand_path('dummy/config/environment', __dir__) require 'rails/test_help' require 'minitest/rails' require 'mocha/minitest' -ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__) -ActionDispatch::IntegrationTest.fixture_path = File.expand_path('../fixtures', __FILE__) +ActiveSupport::TestCase.fixture_path = File.expand_path('fixtures', __dir__) +ActionDispatch::IntegrationTest.fixture_path = File.expand_path('fixtures', __dir__) # I hate the default reporter. Use ProgressReporter instead. Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new @@ -53,7 +53,7 @@ def expire_token(user, client_id) # Suppress OmniAuth logger output def silence_omniauth previous_logger = OmniAuth.config.logger - OmniAuth.config.logger = Logger.new("/dev/null") + OmniAuth.config.logger = Logger.new('/dev/null') yield ensure OmniAuth.config.logger = previous_logger