From 1d21df1362591e4a13e6c308a4c9fca9d9f11027 Mon Sep 17 00:00:00 2001 From: Johan Halse Date: Thu, 28 Oct 2021 13:53:16 +0200 Subject: [PATCH] Update dependencies and Rubocop configuration --- .rubocop.yml | 692 +------------------- .ruby-version | 1 + .travis.yml | 6 +- Gemfile.lock | 273 ++++---- lib/tolken/simple_form.rb | 2 +- lib/tolken/translates.rb | 12 +- spec/tolken/hash_serializer_spec.rb | 14 +- spec/tolken/simple_form/jsonb_input_spec.rb | 2 +- spec/tolken/translates_spec.rb | 4 +- tolken.gemspec | 22 +- 10 files changed, 196 insertions(+), 832 deletions(-) create mode 100644 .ruby-version diff --git a/.rubocop.yml b/.rubocop.yml index a5ae34c..a6ca258 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,708 +3,40 @@ require: rubocop-rspec AllCops: - TargetRubyVersion: 2.6 + TargetRubyVersion: 3.0 + NewCops: enable Exclude: - Rakefile - .rubocop.yml -Rails: - Enabled: true - Documentation: Enabled: false -# -- Security - -Security/Eval: - Enabled: true - -# -- Performance - -Performance/StringReplacement: - Reference: "https://github.com/JuanitoFatas/fast-ruby#stringgsub-vs-stringtr-code'" - Enabled: true - -Performance/ReverseEach: - Description: "Use `reverse_each` instead of `reverse.each`." - Reference: "https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code" - Enabled: true - -Performance/Sample: - Description: "Use `sample` instead of `shuffle.first`, `shuffle.last`, and `shuffle[Fixnum]`." - Reference: "https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code" - Enabled: true - -Performance/Size: - Description: "Use `size` instead of `count` for counting the number of elements in `Array` and `Hash`." - Reference: "https://github.com/JuanitoFatas/fast-ruby#arraycount-vs-arraysize-code" - Enabled: true - -Performance/FlatMap: - Description: "Use `Enumerable#flat_map` instead of `Enumerable#map…Array#flatten` or `Enumberable#collect…Array#flatten`." - Reference: "https://github.com/JuanitoFatas/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code" - Enabled: true - EnabledForFlattenWithoutParams: false - -Performance/Detect: - Description: "Use `detect` instead of `select.first`, `find_all.first`, `select.last`, and `find_all.last`." - Reference: "https://github.com/JuanitoFatas/fast-ruby#enumerabledetect-vs-enumerableselectfirst-code" - Enabled: true - -Performance/Count: - Description: "Use `count` instead of `select|reject...size|count|length`" - Enabled: true - -# -- Lint - -Lint/Debugger: - Enabled: true - -Lint/AssignmentInCondition: - Description: "bad: `if foo = bar` ok: `if (foo = bar)`" - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition" - AllowSafeAssignment: true - -Lint/UnusedBlockArgument: - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars" - AllowUnusedKeywordArguments: false - -Lint/UnusedMethodArgument: - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars" - AllowUnusedKeywordArguments: false - -Lint/CircularArgumentReference: - Description: "Don't refer to the keyword argument in the default value." - Enabled: true - -Lint/DeprecatedClassMethods: - Enabled: true - -Lint/DuplicateMethods: - Enabled: true - -Lint/EachWithObjectArgument: - Description: "Check for immutable argument given to each_with_object." - Enabled: true - -Lint/ElseLayout: - Description: "Check for odd code arrangement in an else block." - Enabled: true - -Lint/EmptyEnsure: - Enabled: true - -Lint/EmptyInterpolation: - Enabled: true - -Lint/EnsureReturn: - Description: "Do not use return in an ensure block." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#no-return-ensure" - Enabled: true - -Lint/FormatParameterMismatch: - Enabled: true - -Lint/HandleExceptions: - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions" - Enabled: true - -Lint/LiteralInInterpolation: - Enabled: true - -Lint/Loop: - Description: "Use Kernel#loop with break rather than begin/end/until or begin/end/while for post-loop tests." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#loop-with-break" - Enabled: true - -Lint/NestedMethodDefinition: - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#no-nested-methods" - Enabled: true - -Lint/NonLocalExitFromIterator: - Enabled: true - -Lint/ParenthesesAsGroupedExpression: - Description: "bad: `f (3 + 2) + 1`. ok: `f(3 + 2) + 1`" - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#parens-no-spaces" - Enabled: true - -Lint/RequireParentheses: - Description: "Use parentheses in the method call to avoid confusion about precedence." - Enabled: true - -Lint/RescueException: - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#no-blind-rescues" - Enabled: true - -Lint/ShadowingOuterLocalVariable: - Description: "Do not use the same name as outer local variable for block arguments or block local variables." - Enabled: true - -Lint/StringConversionInInterpolation: - Description: "Checks for Object#to_s usage in string interpolation." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#no-to-s" - Enabled: true - -Lint/UnderscorePrefixedVariableName: - Description: "Do not use prefix `_` for a variable that is used." - Enabled: true - -Lint/UnreachableCode: - Enabled: true - -Lint/UselessAccessModifier: - Enabled: true - -Lint/UselessAssignment: - Description: "Checks for useless assignment to a local variable." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars" - Enabled: true - -Lint/UselessComparison: - Description: "Checks for comparison of something with itself." - Enabled: true - -Lint/UselessElseWithoutRescue: - Description: "Checks for useless `else` in `begin..end` without `rescue`." - Enabled: true - -Lint/UselessSetterCall: - Description: "Checks for useless setter call to a local variable." - Enabled: true - -Lint/Void: - Description: "Possible use of operator/literal/variable in void context." - Enabled: true - -Lint/AmbiguousOperator: - Enabled: true - -# -- Metrics - -Metrics/ClassLength: - Max: 300 - -Metrics/ModuleLength: - Max: 300 - -Metrics/MethodLength: - Max: 25 - -Metrics/LineLength: - Max: 125 - AllowHeredoc: true - AllowURI: true - URISchemes: - - http - - https - IgnoredPatterns: ['\A#', '#\s.+\Z', 'https?:\/\/'] - -Metrics/BlockLength: - Enabled: true - Exclude: - - tolken.gemspec - - spec/**/* - -Metrics/PerceivedComplexity: - Enabled: true - -Metrics/BlockNesting: - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count" - Enabled: true - Max: 4 - -Metrics/CyclomaticComplexity: - Description: "A complexity metric that is strongly correlated to the number of test cases needed to validate a method." - Max: 9 - -Metrics/AbcSize: - Description: "A calculated magnitude based on number of assignments, branches, and conditions." - Reference: "http://c2.com/cgi/wiki?AbcMetric" - Max: 20 - -Metrics/ParameterLists: - Description: "Avoid parameter lists longer than three or four parameters." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#too-many-params" - Enabled: true - CountKeywordArgs: false - -# -- Naming - -Naming/AsciiIdentifiers: - Enabled: true - -Naming/FileName: - Description: "Use snake_case for source file names." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#snake-case-files" - Enabled: true - -Naming/MethodName: - EnforcedStyle: snake_case - -Naming/VariableName: - EnforcedStyle: snake_case - -Naming/BinaryOperatorParameterName: - Enabled: false # don't require variable to <=> to be named just "other" - -# -- Layout - -Layout/EndAlignment: - EnforcedStyleAlignWith: variable - -Layout/BlockAlignment: - Enabled: true - -Layout/ConditionPosition: - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#same-line-condition" - Enabled: true - -Layout/DefEndAlignment: - Enabled: true - -Layout/IndentArray: - Enabled: false - # Or the following isn't allowed - # foo([ - # %w[n V n], - # %w[V S V] - # ]) - -Layout/CaseIndentation: - EnforcedStyle: end - -Layout/AccessModifierIndentation: - Description: "Check indentation of private/protected visibility modifiers." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#indent-public-private-protected" - EnforcedStyle: indent - -Layout/AlignHash: - Description: "Align the elements of a hash literal if they span more than one line." - EnforcedHashRocketStyle: key - EnforcedColonStyle: key - EnforcedLastArgumentHashStyle: always_inspect - -Layout/AlignParameters: - Description: "Align the parameters of a method call if they span more than one line." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#no-double-indent" - EnforcedStyle: with_first_parameter - -Layout/FirstHashElementLineBreak: - Enabled: true - -Layout/FirstArrayElementLineBreak: - Enabled: true - -Layout/FirstMethodArgumentLineBreak: - Enabled: true - -Layout/FirstMethodParameterLineBreak: - Enabled: true - -Layout/FirstParameterIndentation: - Enabled: true - -Layout/DotPosition: - EnforcedStyle: leading - -Layout/EmptyLinesAroundBlockBody: - EnforcedStyle: no_empty_lines - -Layout/EmptyLinesAroundClassBody: - EnforcedStyle: no_empty_lines - -Layout/EmptyLinesAroundModuleBody: - EnforcedStyle: no_empty_lines - -Layout/ExtraSpacing: - AllowForAlignment: true - -Layout/IndentationConsistency: - EnforcedStyle: normal - -Layout/IndentationWidth: - Width: 2 - -Layout/SpaceInLambdaLiteral: - EnforcedStyle: require_no_space - -Layout/MultilineArrayBraceLayout: - EnforcedStyle: new_line - -Layout/MultilineHashBraceLayout: - EnforcedStyle: new_line - -Layout/MultilineMethodCallBraceLayout: - EnforcedStyle: symmetrical - -Layout/MultilineMethodDefinitionBraceLayout: - EnforcedStyle: new_line - -Layout/ClosingParenthesisIndentation: - Enabled: true - -Layout/SpaceAroundBlockParameters: - EnforcedStyleInsidePipes: no_space - -Layout/SpaceAroundEqualsInParameterDefault: - EnforcedStyle: space - -Layout/SpaceBeforeBlockBraces: - EnforcedStyle: space - -Layout/SpaceInsideBlockBraces: - EnforcedStyle: space - -Layout/SpaceInsideHashLiteralBraces: - EnforcedStyle: space - EnforcedStyleForEmptyBraces: no_space - -Layout/SpaceInsideStringInterpolation: - EnforcedStyle: no_space - -Layout/TrailingBlankLines: - EnforcedStyle: final_newline - -Layout/MultilineMethodCallIndentation: - EnforcedStyle: indented - -Layout/SpaceBeforeComma: - Enabled: true - -Layout/LeadingCommentSpace: - Enabled: true - -# -- Style - -Style/UnneededPercentQ: - Description: "Checks for %q/%Q when single quotes or double quotes would do." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#percent-q" - Enabled: false - -Style/MultilineBlockChain: - Description: "Disallows multiline do…end.method_call" - Enabled: false - -Style/DoubleNegation: - Description: "Disallows !! to cast falsy values to false" - Enabled: false # Allow !! - -Style/AsciiComments: - Enabled: false - # Or we can't add comments about Swedish characters for example - -Style/InverseMethods: - Description: "bad: `!foo.blank?` ok: `foo.present?`" - Enabled: true # Allow !! - -Style/Alias: - EnforcedStyle: prefer_alias_method - -Style/AndOr: - Description: "Use &&/|| instead of and/or." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#no-and-or-or" - EnforcedStyle: conditionals - -Style/BlockDelimiters: - Description: "Use {…} for one line blocks and do…end for multiline blocks." - EnforcedStyle: line_count_based - -Style/BracesAroundHashParameters: - EnforcedStyle: no_braces - -Style/ClassAndModuleChildren: - EnforcedStyle: compact - Enabled: false # What style to enforce has not been decided - -Style/ClassCheck: - EnforcedStyle: is_a? - -Style/CollectionMethods: - PreferredMethods: - collect: "map" - collect!: "map!" - inject: "reduce" - detect: "find" - find_all: "select" - -Style/CommandLiteral: - EnforcedStyle: percent_x - AllowInnerBackticks: false - -Style/CommentAnnotation: - Keywords: - - TODO - - FIXME - - OPTIMIZE - - HACK - - REVIEW - -Style/EmptyElse: - EnforcedStyle: both - -Style/EmptyMethod: - EnforcedStyle: expanded - -Style/Encoding: - Enabled: true - -Style/For: - EnforcedStyle: each - -Style/FormatString: - Description: "bad: `'%d %d' % [20, 10].` ok: `format('%d %d', first: 20, second: 10)`" - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#sprintf" - EnforcedStyle: format - -Style/GlobalVars: - AllowedVariables: - - autogen_filepath - - autogen_buffer - -Style/HashSyntax: - Description: "{ a: 1, b: 2 } { :a => 1, :b => 2 }." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#hash-literals" - EnforcedStyle: ruby19_no_mixed_keys - -Style/Lambda: - EnforcedStyle: literal - -Style/LambdaCall: - EnforcedStyle: call - -Style/MethodDefParentheses: - EnforcedStyle: require_parentheses - -Style/ModuleFunction: - Description: "Checks for usage of `extend self` in modules." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#module-function" - EnforcedStyle: module_function - -Style/NonNilCheck: - Description: "Checks for redundant nil checks." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#no-non-nil-checks" - IncludeSemanticChanges: true - -Style/ParenthesesAroundCondition: - AllowSafeAssignment: true - -Style/PercentLiteralDelimiters: - PreferredDelimiters: - default: () - "%i": "[]" - "%I": "[]" - "%r": "{}" - "%w": "[]" - "%W": "[]" - "%Q": "{}" - "%q": "{}" - -Style/PercentQLiterals: - EnforcedStyle: upper_case_q - -Style/RaiseArgs: - Description: "raise SomeException, 'message' over raise SomeException.new('message')." - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#exception-class-messages" - EnforcedStyle: exploded - -Style/RedundantReturn: - AllowMultipleReturnValues: false - -Style/RegexpLiteral: +Style/Documentation: Enabled: false -Style/Semicolon: - AllowAsExpressionSeparator: false - -Style/SingleLineBlockParams: - Methods: - - reduce: - - acc - - elem - - inject: - - acc - - elem - -Style/SingleLineMethods: - AllowIfMethodIsEmpty: false - -Style/SpecialGlobalVars: - EnforcedStyle: use_english_names - -Style/StabbyLambdaParentheses: - EnforcedStyle: require_parentheses - Style/StringLiterals: + Enabled: true EnforcedStyle: double_quotes Style/StringLiteralsInInterpolation: - EnforcedStyle: double_quotes - -Style/StringMethods: - PreferredMethods: - intern: to_sym - -Style/BarePercentLiterals: - EnforcedStyle: percent_q - -Style/SymbolArray: - EnforcedStyle: percent - -Style/TernaryParentheses: - EnforcedStyle: require_no_parentheses - -Style/TrailingCommaInArguments: - EnforcedStyleForMultiline: no_comma - -Style/TrailingCommaInArrayLiteral: - EnforcedStyleForMultiline: no_comma - -Style/TrailingCommaInHashLiteral: - EnforcedStyleForMultiline: no_comma - -Style/WordArray: - EnforcedStyle: percent - -Style/GuardClause: - Description: "Enforces early return guard clauses" - StyleGuide: "https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals" - Enabled: false - -Style/MethodMissingSuper: - Enabled: true - -Style/MissingRespondToMissing: - Enabled: true - -Style/SymbolProc: - Enabled: true - -Style/MultilineIfModifier: - StyleGuide: "http://www.rubydoc.info/gems/rubocop/0.45.0/RuboCop/Cop/Style/MultilineIfModifier" - Enabled: false # I think there are cases where this is OK… - -Style/TrailingUnderscoreVariable: - Enabled: false - -Style/MixinUsage: - Enabled: true - -Style/StderrPuts: - Enabled: true - -Style/BlockComments: - Enabled: false # Just for big blocks, ok? - -Style/FrozenStringLiteralComment: - EnforcedStyle: always - -Style/MutableConstant: - Enabled: true - -Style/Next: - Enabled: false - -# -- Rails - -Rails/Date: - EnforcedStyle: flexible - # Flexible allows us to use the shorthand `Date.current` instead of `Time.zone.today`, - # just as we would use `Time.current` over `Time.zone.now`. - -Rails/TimeZone: - Description: "bad: `Time.now, Time.parse` ok: `Time.zone, Time.current, Time.in_time_zone`" - EnforcedStyle: flexible - -Rails/NotNullColumn: - Enabled: false # see https://github.com/bbatsov/rubocop/issues/3963 - -Rails/FindBy: - Description: "Prefer find_by(name: name) over find_by_name(name)" - -Rails/FindEach: - Description: "Prefer all.find_each over all.find for batch queries." - -Rails/HasAndBelongsToMany: - Description: "Prefer has_many :through to has_and_belongs_to_many." - -Rails/RequestReferer: - Description: "bad: `request.referrer` ok: `request.referer`." - EnforcedStyle: referer - -Rails/OutputSafety: - Description: "bad: `html_safe, raw` ok: `safe_join`." - Enabled: false - -Rails/Output: - Description: "Checks for calls to puts, print, etc." - Exclude: - - lib/tasks/* - -Rails/SkipsModelValidations: - Description: "bad: `update_attribute` ok: `update_attributes`." Enabled: true - Exclude: - - spec/**/*_spec.rb # Sometimes needed to setup invalid stats for tests. - -Rails/DynamicFindBy: - Enabled: true - -Rails/Exit: - Exclude: - - lib/tasks/* - -Bundler/OrderedGems: - Enabled: false # or we can make groups that makes sense - -# -- RSpec - -RSpec/EmptyLineAfterFinalLet: - Enabled: true - -RSpec/DescribedClass: - Description: "Forces usage of described_class" - Enabled: false + EnforcedStyle: double_quotes -RSpec/DescribeClass: - Description: "Requires top-level describe to contained tested contant" - Enabled: true +Metrics/BlockLength: + Max: 100 -RSpec/AnyInstance: - Enabled: true +Metrics/MethodLength: + Max: 30 RSpec/ExampleLength: - Enabled: true - Max: 30 + Max: 20 RSpec/MultipleExpectations: Enabled: false - # We trust ourselves to know when it's OK to - # have more than one expectation per spec. - -RSpec/ExpectActual: - Enabled: true -RSpec/RepeatedExample: - Enabled: true +RSpec/MultipleMemoizedHelpers: + Enabled: false RSpec/VerifiedDoubles: Enabled: false - # `instance_double` is randomly not finding deliver_now: - # e.g: "the VgDonationMailer class does not implement the instance method: deliver_now" - -RSpec/MessageSpies: - Enabled: true - -RSpec/NestedGroups: - Enabled: true - Max: 5 - -RSpec/HookArgument: - Enabled: true - -RSpec/NotToNot: - Enabled: true - -RSpec/EmptyLineAfterSubject: - Enabled: true diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..b502146 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.0.2 diff --git a/.travis.yml b/.travis.yml index 2f04a8e..c419a8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,11 @@ sudo: false language: ruby -rvm: - - 2.6.0 env: global: - CC_TEST_REPORTER_ID=38cf6fe42113efd6306798c2189499f6ff9da87a92dd548e8339a1bd98d2a7e6 addons: - postgresql: "9.6" -before_install: gem install bundler -v 1.16.1 + postgresql: "13.4" +before_install: gem install bundler before_script: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter diff --git a/Gemfile.lock b/Gemfile.lock index eac0fe2..7dccce6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,166 +2,194 @@ PATH remote: . specs: tolken (0.3.3) - rails (~> 5.2) + rails (>= 5.2) GEM remote: https://rubygems.org/ specs: - actioncable (5.2.3) - actionpack (= 5.2.3) + actioncable (6.1.4.1) + actionpack (= 6.1.4.1) + activesupport (= 6.1.4.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) - activejob (= 5.2.3) + actionmailbox (6.1.4.1) + actionpack (= 6.1.4.1) + activejob (= 6.1.4.1) + activerecord (= 6.1.4.1) + activestorage (= 6.1.4.1) + activesupport (= 6.1.4.1) + mail (>= 2.7.1) + actionmailer (6.1.4.1) + actionpack (= 6.1.4.1) + actionview (= 6.1.4.1) + activejob (= 6.1.4.1) + activesupport (= 6.1.4.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.3) - actionview (= 5.2.3) - activesupport (= 5.2.3) - rack (~> 2.0) + actionpack (6.1.4.1) + actionview (= 6.1.4.1) + activesupport (= 6.1.4.1) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.3) - activesupport (= 5.2.3) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.4.1) + actionpack (= 6.1.4.1) + activerecord (= 6.1.4.1) + activestorage (= 6.1.4.1) + activesupport (= 6.1.4.1) + nokogiri (>= 1.8.5) + actionview (6.1.4.1) + activesupport (= 6.1.4.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.3) - activesupport (= 5.2.3) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.4.1) + activesupport (= 6.1.4.1) globalid (>= 0.3.6) - activemodel (5.2.3) - activesupport (= 5.2.3) - activerecord (5.2.3) - activemodel (= 5.2.3) - activesupport (= 5.2.3) - arel (>= 9.0) - activestorage (5.2.3) - actionpack (= 5.2.3) - activerecord (= 5.2.3) - marcel (~> 0.3.1) - activesupport (5.2.3) + activemodel (6.1.4.1) + activesupport (= 6.1.4.1) + activerecord (6.1.4.1) + activemodel (= 6.1.4.1) + activesupport (= 6.1.4.1) + activestorage (6.1.4.1) + actionpack (= 6.1.4.1) + activejob (= 6.1.4.1) + activerecord (= 6.1.4.1) + activesupport (= 6.1.4.1) + marcel (~> 1.0.0) + mini_mime (>= 1.1.0) + activesupport (6.1.4.1) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - arel (9.0.0) - ast (2.4.0) - builder (3.2.3) - coderay (1.1.2) - concurrent-ruby (1.1.5) - crass (1.0.4) - diff-lcs (1.3) - docile (1.3.2) - erubi (1.8.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - i18n (1.6.0) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + ast (2.4.2) + builder (3.2.4) + coderay (1.1.3) + concurrent-ruby (1.1.9) + crass (1.0.6) + diff-lcs (1.4.4) + docile (1.4.0) + erubi (1.10.0) + globalid (0.5.2) + activesupport (>= 5.0) + i18n (1.8.10) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.2) - json (2.2.0) - loofah (2.2.3) + loofah (2.12.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) - method_source (0.9.2) - mimemagic (0.3.3) - mini_mime (1.0.2) - mini_portile2 (2.4.0) - minitest (5.11.3) - nio4r (2.5.1) - nokogiri (1.10.4) - mini_portile2 (~> 2.4.0) - parallel (1.17.0) - parser (2.6.3.0) - ast (~> 2.4.0) - pg (1.1.4) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - rack (2.0.6) + marcel (1.0.2) + method_source (1.0.0) + mini_mime (1.1.2) + mini_portile2 (2.6.1) + minitest (5.14.4) + nio4r (2.5.8) + nokogiri (1.12.5) + mini_portile2 (~> 2.6.1) + racc (~> 1.4) + parallel (1.21.0) + parser (3.0.2.0) + ast (~> 2.4.1) + pg (1.2.3) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) + racc (1.6.0) + rack (2.2.3) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.3) - actioncable (= 5.2.3) - actionmailer (= 5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) - activejob (= 5.2.3) - activemodel (= 5.2.3) - activerecord (= 5.2.3) - activestorage (= 5.2.3) - activesupport (= 5.2.3) - bundler (>= 1.3.0) - railties (= 5.2.3) + rails (6.1.4.1) + actioncable (= 6.1.4.1) + actionmailbox (= 6.1.4.1) + actionmailer (= 6.1.4.1) + actionpack (= 6.1.4.1) + actiontext (= 6.1.4.1) + actionview (= 6.1.4.1) + activejob (= 6.1.4.1) + activemodel (= 6.1.4.1) + activerecord (= 6.1.4.1) + activestorage (= 6.1.4.1) + activesupport (= 6.1.4.1) + bundler (>= 1.15.0) + railties (= 6.1.4.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.4) - loofah (~> 2.2, >= 2.2.2) - railties (5.2.3) - actionpack (= 5.2.3) - activesupport (= 5.2.3) + rails-html-sanitizer (1.4.2) + loofah (~> 2.3) + railties (6.1.4.1) + actionpack (= 6.1.4.1) + activesupport (= 6.1.4.1) method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + rake (>= 0.13) + thor (~> 1.0) rainbow (3.0.0) - rake (12.3.3) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) + rake (13.0.6) + regexp_parser (2.1.1) + rexml (3.2.5) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - rubocop (0.68.1) - jaro_winkler (~> 1.5.1) + rspec-support (~> 3.10.0) + rspec-support (3.10.2) + rubocop (1.22.3) parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) + parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.12.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.6) - rubocop-rspec (1.32.0) - rubocop (>= 0.60.0) - ruby-progressbar (1.10.0) - simple_form (4.1.0) - actionpack (>= 5.0) - activemodel (>= 5.0) - simplecov (0.17.0) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.12.0) + parser (>= 3.0.1.1) + rubocop-rails (2.12.4) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.7.0, < 2.0) + rubocop-rspec (2.5.0) + rubocop (~> 1.19) + ruby-progressbar (1.11.0) + simple_form (5.1.0) + actionpack (>= 5.2) + activemodel (>= 5.2) + simplecov (0.21.2) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - sprockets (3.7.2) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.3) + sprockets (4.0.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.1) + sprockets-rails (3.2.2) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - thor (0.20.3) - thread_safe (0.3.6) - tzinfo (1.2.5) - thread_safe (~> 0.1) - unicode-display_width (1.5.0) - websocket-driver (0.7.1) + thor (1.1.0) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + unicode-display_width (2.1.0) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) - with_model (2.1.2) - activerecord (>= 4.2, < 6.0) + websocket-extensions (0.1.5) + with_model (2.1.5) + activerecord (>= 5.2) + zeitwerk (2.5.1) PLATFORMS ruby @@ -172,7 +200,8 @@ DEPENDENCIES pry rake rspec - rubocop (= 0.68.1) + rubocop + rubocop-rails rubocop-rspec simple_form simplecov @@ -180,4 +209,4 @@ DEPENDENCIES with_model BUNDLED WITH - 1.17.2 + 2.2.28 diff --git a/lib/tolken/simple_form.rb b/lib/tolken/simple_form.rb index 8ab9814..8e4f474 100644 --- a/lib/tolken/simple_form.rb +++ b/lib/tolken/simple_form.rb @@ -9,7 +9,7 @@ module SimpleForm class JsonbInput < ::SimpleForm::Inputs::StringInput include ActionView::Helpers::OutputSafetyHelper - def input(_wrapper_options = {}) + def input(_wrapper_options = {}) # rubocop:disable Metrics/AbcSize safe_join( I18n.available_locales.map do |locale| options = { diff --git a/lib/tolken/translates.rb b/lib/tolken/translates.rb index 7338f76..fdc727d 100644 --- a/lib/tolken/translates.rb +++ b/lib/tolken/translates.rb @@ -6,13 +6,13 @@ def translates(field_name, options = {}) define_getter(field_name) serialize(field_name, HashSerializer) - if options[:presence] - validation_names = I18n.available_locales.map { |locale| "#{field_name}_#{locale}" } - readers = store_accessor(field_name, *validation_names) - private(*(readers + readers.map { |name| "#{name}=" })) + return unless options[:presence] - define_validator(field_name) if options[:presence] - end + validation_names = I18n.available_locales.map { |locale| "#{field_name}_#{locale}" } + readers = store_accessor(field_name, *validation_names) + private(*(readers + readers.map { |name| "#{name}=" })) + + define_validator(field_name) if options[:presence] end private diff --git a/spec/tolken/hash_serializer_spec.rb b/spec/tolken/hash_serializer_spec.rb index ab9e674..c14de0c 100644 --- a/spec/tolken/hash_serializer_spec.rb +++ b/spec/tolken/hash_serializer_spec.rb @@ -5,33 +5,33 @@ RSpec.describe Tolken::HashSerializer do describe ".dump" do it "returns the hash given as is" do - expect(Tolken::HashSerializer.dump(foo: "bar")).to eq(foo: "bar") + expect(described_class.dump(foo: "bar")).to eq(foo: "bar") end end describe ".load" do it "returns a hash if given a string" do - expect(Tolken::HashSerializer.load({ foo: "bar" }.to_json)).to eq("foo" => "bar") + expect(described_class.load({ foo: "bar" }.to_json)).to eq("foo" => "bar") end it "returns a hash if given a hash" do - expect(Tolken::HashSerializer.load(foo: "bar")).to eq("foo" => "bar") + expect(described_class.load(foo: "bar")).to eq("foo" => "bar") end it "returned hash has indifferent access" do - expect(Tolken::HashSerializer.load(foo: "bar")[:foo]).to eq("bar") + expect(described_class.load(foo: "bar")[:foo]).to eq("bar") end it "returns an empty hash if given nil" do - expect(Tolken::HashSerializer.load(nil)).to eq({}) + expect(described_class.load(nil)).to eq({}) end it "returns an empty hash if given false" do - expect(Tolken::HashSerializer.load(false)).to eq({}) + expect(described_class.load(false)).to eq({}) end it "returns raises argument error if not given any argument" do - expect { Tolken::HashSerializer.load }.to raise_error(ArgumentError) + expect { described_class.load }.to raise_error(ArgumentError) end end end diff --git a/spec/tolken/simple_form/jsonb_input_spec.rb b/spec/tolken/simple_form/jsonb_input_spec.rb index 1f56885..e51b316 100644 --- a/spec/tolken/simple_form/jsonb_input_spec.rb +++ b/spec/tolken/simple_form/jsonb_input_spec.rb @@ -21,7 +21,7 @@ let(:column) { "title" } let(:input_type) { spy("input_type") } let(:input_options) { {} } - let(:input_builder) { Tolken::SimpleForm::JsonbInput.new(builder, attribute_name, column, input_type, input_options) } + let(:input_builder) { described_class.new(builder, attribute_name, column, input_type, input_options) } describe "#input" do context "with no input options given" do diff --git a/spec/tolken/translates_spec.rb b/spec/tolken/translates_spec.rb index d40a355..593b751 100644 --- a/spec/tolken/translates_spec.rb +++ b/spec/tolken/translates_spec.rb @@ -111,8 +111,8 @@ describe "serialization" do it "serialize correctly to json string" do - expect(post.to_json).to eq("{\"id\":1,\"title\":{\"en\":\"Hi\",\"sv\":\"Hej\"}}") - expect(post.title.to_json).to eq("{\"en\":\"Hi\",\"sv\":\"Hej\"}") + expect(post.to_json).to eq('{"id":1,"title":{"en":"Hi","sv":"Hej"}}') + expect(post.title.to_json).to eq('{"en":"Hi","sv":"Hej"}') end end end diff --git a/tolken.gemspec b/tolken.gemspec index 1c1ed65..2999472 100644 --- a/tolken.gemspec +++ b/tolken.gemspec @@ -11,29 +11,33 @@ Gem::Specification.new do |spec| spec.email = ["nicklas.ramhoj@varvet.com", "julia.friberg@varvet.com"] spec.summary = "Straightforward Rails database translations using psql jsonb" - spec.description = %q{ - Tolken's API is more verbose than most similar gems. The idea is that you should be aware of when you're dealing with - translatable fields and what language you're interested in in any given moment. In tolken a translatable field is just a - Ruby hash which makes it easy to reason about. - } + spec.description = + "Tolken's API is more verbose than most similar gems. The idea is that you + should be aware of when you're dealing with translatable fields and what + language you're interested in in any given moment. In tolken a + translatable field is just a Ruby hash which makes it easy to reason + about." + spec.homepage = "https://github.com/varvet/tolken" spec.license = "MIT" - spec.files = %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] + spec.required_ruby_version = ">= 3.0.0" - spec.add_dependency "rails", "~> 5.2" + spec.add_dependency "rails", ">= 5.2" spec.add_development_dependency "bundler" spec.add_development_dependency "pg" spec.add_development_dependency "pry" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" - spec.add_development_dependency "rubocop", "= 0.68.1" + spec.add_development_dependency "rubocop" + spec.add_development_dependency "rubocop-rails" spec.add_development_dependency "rubocop-rspec" - spec.add_development_dependency "simple_form" spec.add_development_dependency "simplecov" + spec.add_development_dependency "simple_form" spec.add_development_dependency "with_model" end