diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..ee10ecf --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,3 @@ +bc6c274ba2ba0a60fcb0b95d9e483faae928e608 +ddecab1191e897dfb1e3fceec774e2782495f261 +eee1a5f87757938eb85bdca0a77df4ab81dadd87 \ No newline at end of file diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 1d96522..a3df2a1 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -35,7 +35,7 @@ jobs: with: bundler-cache: true - name: linter - run: bundle exec rake rubocop + run: bundle exec rake standard # This wrapper is used in the main branch protection rules as a required check. # This way, we don’t need to update those rules when we add or remove a version in the test matrix. diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index e808fea..0000000 --- a/.rubocop.yml +++ /dev/null @@ -1,115 +0,0 @@ -AllCops: - SuggestExtensions: false - NewCops: enable - TargetRubyVersion: 2.7 # lowest supported version - Exclude: - - vendor/**/* - - gemfiles/vendor/**/* - -Gemspec/DevelopmentDependencies: - EnforcedStyle: gemspec - -Layout/LineLength: - Max: 120 - -Layout/CommentIndentation: - Enabled: false - -Style/StringLiterals: - Enabled: false - -Style/SignalException: - Enabled: false - -Layout/SpaceInsideHashLiteralBraces: - Enabled: false - -Style/PerlBackrefs: - Enabled: false - -Lint/AmbiguousOperator: - Enabled: false - -Style/Lambda: - Enabled: false - -Style/SpecialGlobalVars: - Enabled: false - -Style/WordArray: - Enabled: false - -Layout/EndAlignment: - EnforcedStyleAlignWith: variable - -Style/StringLiteralsInInterpolation: - Enabled: false - -Style/NumericLiterals: - Enabled: false - -Layout/FirstArgumentIndentation: - Enabled: false - -Layout/FirstHashElementIndentation: - Enabled: false - -Layout/ParameterAlignment: - Enabled: false - -Layout/MultilineOperationIndentation: - Enabled: false - -Metrics: - Enabled: false - -Style/DoubleNegation: - Enabled: false - -Style/Documentation: - Enabled: false - -Layout/MultilineMethodCallIndentation: - Enabled: false - -Lint/AssignmentInCondition: - Enabled: false - -Layout/DotPosition: - EnforcedStyle: trailing - -Layout/EmptyLineAfterMagicComment: - Enabled: false - -Style/SymbolArray: - Enabled: false - -Bundler/OrderedGems: - Enabled: false - -Style/GuardClause: - Enabled: false - -Style/ClassAndModuleChildren: - Enabled: false - -Style/NumericPredicate: - Enabled: false - -Naming/MethodParameterName: - Enabled: false - -Gemspec/OrderedDependencies: - Enabled: false - -Style/IfUnlessModifier: - Enabled: false - -Lint/MissingSuper: - Enabled: false - -Style/FetchEnvVar: - Enabled: false - -Lint/ParenthesesAsGroupedExpression: - Enabled: false diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..c19ce03 --- /dev/null +++ b/.standard.yml @@ -0,0 +1 @@ +ruby_version: 2.7 diff --git a/Gemfile b/Gemfile index 22f2382..f9c7825 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + eval_gemfile Dir["gemfiles/*.gemfile"].max -gem 'minitest-rails', '~> 7.1' -gem 'minitest', '~> 5.20' +gem "minitest-rails", "~> 7.1" +gem "minitest", "~> 5.20" diff --git a/Gemfile.lock b/Gemfile.lock index 841f3a8..43bd0e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,8 +102,9 @@ GEM irb (1.8.3) rdoc reline (>= 0.3.8) - json (2.6.3) + json (2.7.1) language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.21.4) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -138,7 +139,7 @@ GEM parallel (1.23.0) parallel_tests (4.3.0) parallel - parser (3.2.2.4) + parser (3.3.0.5) ast (~> 2.4.1) racc psych (5.1.1.1) @@ -185,11 +186,11 @@ GEM rake (13.1.0) rdoc (6.5.0) psych (>= 4.0.0) - regexp_parser (2.8.2) + regexp_parser (2.9.0) reline (0.3.9) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.57.2) + rubocop (1.59.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -197,14 +198,29 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) single_cov (1.11.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) stringio (3.0.8) thor (1.3.0) timeout (0.4.0) @@ -230,8 +246,8 @@ DEPENDENCIES minitest-rails (~> 7.1) rails (~> 7.1.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/Rakefile b/Rakefile index c2b6c01..6819a94 100644 --- a/Rakefile +++ b/Rakefile @@ -1,22 +1,19 @@ # frozen_string_literal: true -require 'bundler/setup' -require 'bump/tasks' + +require "bundler/setup" +require "standard/rake" +require "bump/tasks" # Pushing to rubygems is handled by a github workflow -require 'bundler/gem_tasks' -ENV['gem_push'] = 'false' +require "bundler/gem_tasks" +ENV["gem_push"] = "false" -task default: [:test, :rubocop] +task default: [:test, :standard] task :test do sh "forking-test-runner test --merge-coverage --quiet" end -desc "Run rubocop" -task :rubocop do - sh "rubocop -a --fail-level A" -end - desc "Bundle all gemfiles [CMD=]" task :bundle_all do cmd = ENV["CMD"] diff --git a/gemfiles/common.rb b/gemfiles/common.rb index 43ee679..b82e83e 100644 --- a/gemfiles/common.rb +++ b/gemfiles/common.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" -gemspec path: '..' +gemspec path: ".." diff --git a/gemfiles/rails5.0.gemfile b/gemfiles/rails5.0.gemfile index 6ed6ca4..337fc86 100644 --- a/gemfiles/rails5.0.gemfile +++ b/gemfiles/rails5.0.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 5.0.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails5.0.gemfile.lock b/gemfiles/rails5.0.gemfile.lock index 20c5ad7..6e1a595 100644 --- a/gemfiles/rails5.0.gemfile.lock +++ b/gemfiles/rails5.0.gemfile.lock @@ -58,7 +58,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -94,8 +96,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (0.6.3) @@ -125,21 +128,25 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) @@ -148,12 +155,24 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) thread_safe (0.3.6) timeout (0.3.1) tzinfo (1.2.11) thread_safe (~> 0.1) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -170,8 +189,8 @@ DEPENDENCIES minitest-rails rails (~> 5.0.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails5.1.gemfile b/gemfiles/rails5.1.gemfile index 87f6cb6..b1d86e5 100644 --- a/gemfiles/rails5.1.gemfile +++ b/gemfiles/rails5.1.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 5.1.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails5.1.gemfile.lock b/gemfiles/rails5.1.gemfile.lock index 572f3d7..8808d72 100644 --- a/gemfiles/rails5.1.gemfile.lock +++ b/gemfiles/rails5.1.gemfile.lock @@ -58,7 +58,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -94,8 +96,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (2.0.2) @@ -125,21 +128,25 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) @@ -148,12 +155,24 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) thread_safe (0.3.6) timeout (0.3.1) tzinfo (1.2.11) thread_safe (~> 0.1) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -170,8 +189,8 @@ DEPENDENCIES minitest-rails rails (~> 5.1.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails5.2.gemfile b/gemfiles/rails5.2.gemfile index e4d350f..dfe563b 100644 --- a/gemfiles/rails5.2.gemfile +++ b/gemfiles/rails5.2.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 5.2.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails5.2.gemfile.lock b/gemfiles/rails5.2.gemfile.lock index ed411e2..55c5003 100644 --- a/gemfiles/rails5.2.gemfile.lock +++ b/gemfiles/rails5.2.gemfile.lock @@ -62,7 +62,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -99,8 +101,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (2.0.2) @@ -131,21 +134,25 @@ GEM thor (>= 0.19.0, < 2.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) @@ -154,12 +161,24 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) thread_safe (0.3.6) timeout (0.3.1) tzinfo (1.2.11) thread_safe (~> 0.1) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -176,8 +195,8 @@ DEPENDENCIES minitest-rails rails (~> 5.2.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails6.0.gemfile b/gemfiles/rails6.0.gemfile index 11bf725..edaec37 100644 --- a/gemfiles/rails6.0.gemfile +++ b/gemfiles/rails6.0.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 6.0.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails6.0.gemfile.lock b/gemfiles/rails6.0.gemfile.lock index 41b9b3a..5f5268c 100644 --- a/gemfiles/rails6.0.gemfile.lock +++ b/gemfiles/rails6.0.gemfile.lock @@ -75,7 +75,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -112,8 +114,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (2.0.2) @@ -146,21 +149,25 @@ GEM thor (>= 0.20.3, < 2.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) @@ -169,12 +176,24 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) thread_safe (0.3.6) timeout (0.3.1) tzinfo (1.2.11) thread_safe (~> 0.1) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -192,8 +211,8 @@ DEPENDENCIES minitest-rails rails (~> 6.0.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails6.1.gemfile b/gemfiles/rails6.1.gemfile index 48d05bc..8fda593 100644 --- a/gemfiles/rails6.1.gemfile +++ b/gemfiles/rails6.1.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 6.1.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails6.1.gemfile.lock b/gemfiles/rails6.1.gemfile.lock index f9b072c..89f4970 100644 --- a/gemfiles/rails6.1.gemfile.lock +++ b/gemfiles/rails6.1.gemfile.lock @@ -79,7 +79,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -116,8 +118,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (2.0.2) @@ -150,21 +153,25 @@ GEM thor (~> 1.0) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) sprockets (4.2.0) concurrent-ruby (~> 1.0) @@ -173,11 +180,23 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) timeout (0.3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -195,8 +214,8 @@ DEPENDENCIES minitest-rails rails (~> 6.1.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails7.0.gemfile b/gemfiles/rails7.0.gemfile index b47ccc8..1695fb3 100644 --- a/gemfiles/rails7.0.gemfile +++ b/gemfiles/rails7.0.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 7.0.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails7.0.gemfile.lock b/gemfiles/rails7.0.gemfile.lock index 5c63cdb..d2f4ca0 100644 --- a/gemfiles/rails7.0.gemfile.lock +++ b/gemfiles/rails7.0.gemfile.lock @@ -85,7 +85,9 @@ GEM activesupport (>= 5.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - json (2.6.3) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -122,8 +124,9 @@ GEM parallel (1.22.1) parallel_tests (4.1.0) parallel - parser (3.2.0.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc racc (1.6.2) rack (2.2.6.2) rack-test (2.0.2) @@ -156,27 +159,43 @@ GEM zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.6.2) - rexml (3.2.5) - rubocop (1.44.1) + regexp_parser (2.9.0) + rexml (3.2.6) + rubocop (1.59.0) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.24.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.24.1) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) single_cov (1.8.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) thor (1.2.1) timeout (0.3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -194,8 +213,8 @@ DEPENDENCIES minitest-rails rails (~> 7.0.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/gemfiles/rails7.1.gemfile b/gemfiles/rails7.1.gemfile index 1c97b1c..c26a8a8 100644 --- a/gemfiles/rails7.1.gemfile +++ b/gemfiles/rails7.1.gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + gem "rails", "~> 7.1.0" -eval_gemfile 'common.rb' +eval_gemfile "common.rb" diff --git a/gemfiles/rails7.1.gemfile.lock b/gemfiles/rails7.1.gemfile.lock index 7182e52..0590f9e 100644 --- a/gemfiles/rails7.1.gemfile.lock +++ b/gemfiles/rails7.1.gemfile.lock @@ -102,8 +102,9 @@ GEM irb (1.8.3) rdoc reline (>= 0.3.8) - json (2.6.3) + json (2.7.1) language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.21.4) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -138,7 +139,7 @@ GEM parallel (1.23.0) parallel_tests (4.3.0) parallel - parser (3.2.2.4) + parser (3.3.0.5) ast (~> 2.4.1) racc psych (5.1.1.1) @@ -185,11 +186,11 @@ GEM rake (13.1.0) rdoc (6.5.0) psych (>= 4.0.0) - regexp_parser (2.8.2) + regexp_parser (2.9.0) reline (0.3.9) io-console (~> 0.5) rexml (3.2.6) - rubocop (1.57.2) + rubocop (1.59.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -197,14 +198,29 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) single_cov (1.11.0) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) stringio (3.0.8) thor (1.3.0) timeout (0.4.0) @@ -229,8 +245,8 @@ DEPENDENCIES minitest-rails rails (~> 7.1.0) rake - rubocop single_cov + standard stronger_parameters! BUNDLED WITH diff --git a/lib/stronger_parameters.rb b/lib/stronger_parameters.rb index d41dcf3..4b6b146 100644 --- a/lib/stronger_parameters.rb +++ b/lib/stronger_parameters.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -require 'stronger_parameters/version' -require 'action_pack' -require 'stronger_parameters/parameters' -require 'stronger_parameters/constraints' -require 'stronger_parameters/controller_support/permitted_parameters' + +require "stronger_parameters/version" +require "action_pack" +require "stronger_parameters/parameters" +require "stronger_parameters/constraints" +require "stronger_parameters/controller_support/permitted_parameters" diff --git a/lib/stronger_parameters/constraint.rb b/lib/stronger_parameters/constraint.rb index a59de39..589c179 100644 --- a/lib/stronger_parameters/constraint.rb +++ b/lib/stronger_parameters/constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/errors' + +require "stronger_parameters/errors" module StrongerParameters class Constraint diff --git a/lib/stronger_parameters/constraints.rb b/lib/stronger_parameters/constraints.rb index 17aa9bb..f30f647 100644 --- a/lib/stronger_parameters/constraints.rb +++ b/lib/stronger_parameters/constraints.rb @@ -1,23 +1,24 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' -require 'stronger_parameters/constraints/string_constraint' -require 'stronger_parameters/constraints/float_constraint' -require 'stronger_parameters/constraints/date_constraint' -require 'stronger_parameters/constraints/date_iso8601_constraint' -require 'stronger_parameters/constraints/time_constraint' -require 'stronger_parameters/constraints/time_iso8601_constraint' -require 'stronger_parameters/constraints/date_time_constraint' -require 'stronger_parameters/constraints/date_time_iso8601_constraint' -require 'stronger_parameters/constraints/regexp_constraint' -require 'stronger_parameters/constraints/integer_constraint' -require 'stronger_parameters/constraints/nil_constraint' -require 'stronger_parameters/constraints/boolean_constraint' -require 'stronger_parameters/constraints/array_constraint' -require 'stronger_parameters/constraints/hash_constraint' -require 'stronger_parameters/constraints/enumeration_constraint' -require 'stronger_parameters/constraints/comparison_constraints' -require 'stronger_parameters/constraints/nil_string_constraint' -require 'stronger_parameters/constraints/file_constraint' -require 'stronger_parameters/constraints/decimal_constraint' -require 'stronger_parameters/constraints/hex_constraint' -require 'stronger_parameters/constraints/ulid_constraint' + +require "stronger_parameters/constraint" +require "stronger_parameters/constraints/string_constraint" +require "stronger_parameters/constraints/float_constraint" +require "stronger_parameters/constraints/date_constraint" +require "stronger_parameters/constraints/date_iso8601_constraint" +require "stronger_parameters/constraints/time_constraint" +require "stronger_parameters/constraints/time_iso8601_constraint" +require "stronger_parameters/constraints/date_time_constraint" +require "stronger_parameters/constraints/date_time_iso8601_constraint" +require "stronger_parameters/constraints/regexp_constraint" +require "stronger_parameters/constraints/integer_constraint" +require "stronger_parameters/constraints/nil_constraint" +require "stronger_parameters/constraints/boolean_constraint" +require "stronger_parameters/constraints/array_constraint" +require "stronger_parameters/constraints/hash_constraint" +require "stronger_parameters/constraints/enumeration_constraint" +require "stronger_parameters/constraints/comparison_constraints" +require "stronger_parameters/constraints/nil_string_constraint" +require "stronger_parameters/constraints/file_constraint" +require "stronger_parameters/constraints/decimal_constraint" +require "stronger_parameters/constraints/hex_constraint" +require "stronger_parameters/constraints/ulid_constraint" diff --git a/lib/stronger_parameters/constraints/array_constraint.rb b/lib/stronger_parameters/constraints/array_constraint.rb index 3739845..a5fa0b5 100644 --- a/lib/stronger_parameters/constraints/array_constraint.rb +++ b/lib/stronger_parameters/constraints/array_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class ArrayConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/boolean_constraint.rb b/lib/stronger_parameters/constraints/boolean_constraint.rb index c6ce6d1..e3b21e3 100644 --- a/lib/stronger_parameters/constraints/boolean_constraint.rb +++ b/lib/stronger_parameters/constraints/boolean_constraint.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class BooleanConstraint < Constraint - TRUE_VALUES = [true, 'true', '1', 1, 'on'].freeze - FALSE_VALUES = [false, 'false', '0', 0].freeze + TRUE_VALUES = [true, "true", "1", 1, "on"].freeze + FALSE_VALUES = [false, "false", "0", 0].freeze def value(v) v = v.downcase if v.is_a? String diff --git a/lib/stronger_parameters/constraints/comparison_constraints.rb b/lib/stronger_parameters/constraints/comparison_constraints.rb index 6d1f845..3bb1c9a 100644 --- a/lib/stronger_parameters/constraints/comparison_constraints.rb +++ b/lib/stronger_parameters/constraints/comparison_constraints.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class ComparisonConstraints < Constraint diff --git a/lib/stronger_parameters/constraints/date_constraint.rb b/lib/stronger_parameters/constraints/date_constraint.rb index 8cad206..a890c8e 100644 --- a/lib/stronger_parameters/constraints/date_constraint.rb +++ b/lib/stronger_parameters/constraints/date_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class DateConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/date_iso8601_constraint.rb b/lib/stronger_parameters/constraints/date_iso8601_constraint.rb index 5dd8e89..4e704ec 100644 --- a/lib/stronger_parameters/constraints/date_iso8601_constraint.rb +++ b/lib/stronger_parameters/constraints/date_iso8601_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class DateIso8601Constraint < Constraint diff --git a/lib/stronger_parameters/constraints/date_time_constraint.rb b/lib/stronger_parameters/constraints/date_time_constraint.rb index c842129..c4d4b4d 100644 --- a/lib/stronger_parameters/constraints/date_time_constraint.rb +++ b/lib/stronger_parameters/constraints/date_time_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class DateTimeConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb b/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb index 805c085..e616ea7 100644 --- a/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb +++ b/lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class DateTimeIso8601Constraint < Constraint diff --git a/lib/stronger_parameters/constraints/decimal_constraint.rb b/lib/stronger_parameters/constraints/decimal_constraint.rb index 5d67145..1fe2d25 100644 --- a/lib/stronger_parameters/constraints/decimal_constraint.rb +++ b/lib/stronger_parameters/constraints/decimal_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class DecimalConstraint < Constraint @@ -11,7 +12,7 @@ def initialize(precision, scale) def value(v) match = v.to_s - if match =~ @regex + if match&.match?(@regex) BigDecimal(match) else StrongerParameters::InvalidValue.new(v, "must be a decimal with precision #{@precision} and scale #{@scale}") diff --git a/lib/stronger_parameters/constraints/enumeration_constraint.rb b/lib/stronger_parameters/constraints/enumeration_constraint.rb index 1eae0db..2861ed1 100644 --- a/lib/stronger_parameters/constraints/enumeration_constraint.rb +++ b/lib/stronger_parameters/constraints/enumeration_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class EnumerationConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/file_constraint.rb b/lib/stronger_parameters/constraints/file_constraint.rb index 0f5f0a7..711f540 100644 --- a/lib/stronger_parameters/constraints/file_constraint.rb +++ b/lib/stronger_parameters/constraints/file_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class FileConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/float_constraint.rb b/lib/stronger_parameters/constraints/float_constraint.rb index 7d76596..b979cb0 100644 --- a/lib/stronger_parameters/constraints/float_constraint.rb +++ b/lib/stronger_parameters/constraints/float_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class FloatConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/hash_constraint.rb b/lib/stronger_parameters/constraints/hash_constraint.rb index 047e2d4..749792b 100644 --- a/lib/stronger_parameters/constraints/hash_constraint.rb +++ b/lib/stronger_parameters/constraints/hash_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class HashConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/hex_constraint.rb b/lib/stronger_parameters/constraints/hex_constraint.rb index df317e5..203a0d1 100644 --- a/lib/stronger_parameters/constraints/hex_constraint.rb +++ b/lib/stronger_parameters/constraints/hex_constraint.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class HexConstraint < Constraint def value(v) return v if v.is_a?(String) && v.match?(/\A[a-f0-9]+\z/i) - InvalidValue.new(v, 'must be a hexadecimal string') + InvalidValue.new(v, "must be a hexadecimal string") end end end diff --git a/lib/stronger_parameters/constraints/integer_constraint.rb b/lib/stronger_parameters/constraints/integer_constraint.rb index cd4085a..c32e300 100644 --- a/lib/stronger_parameters/constraints/integer_constraint.rb +++ b/lib/stronger_parameters/constraints/integer_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class IntegerConstraint < Constraint @@ -10,7 +11,7 @@ def value(v) return v.to_i end - InvalidValue.new(v, 'must be an integer') + InvalidValue.new(v, "must be an integer") end end end diff --git a/lib/stronger_parameters/constraints/nil_constraint.rb b/lib/stronger_parameters/constraints/nil_constraint.rb index e7f6da7..88d6069 100644 --- a/lib/stronger_parameters/constraints/nil_constraint.rb +++ b/lib/stronger_parameters/constraints/nil_constraint.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class NilConstraint < Constraint def value(v) return v if v.nil? - InvalidValue.new(v, 'must be an nil') + InvalidValue.new(v, "must be an nil") end end end diff --git a/lib/stronger_parameters/constraints/nil_string_constraint.rb b/lib/stronger_parameters/constraints/nil_string_constraint.rb index f71eb59..42a54f4 100644 --- a/lib/stronger_parameters/constraints/nil_string_constraint.rb +++ b/lib/stronger_parameters/constraints/nil_string_constraint.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class NilStringConstraint < Constraint - NULL_VALUES = [nil, '', 'undefined'].freeze + NULL_VALUES = [nil, "", "undefined"].freeze def value(v) if NULL_VALUES.include?(v) diff --git a/lib/stronger_parameters/constraints/regexp_constraint.rb b/lib/stronger_parameters/constraints/regexp_constraint.rb index 0b2a853..520c1b2 100644 --- a/lib/stronger_parameters/constraints/regexp_constraint.rb +++ b/lib/stronger_parameters/constraints/regexp_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class RegexpConstraint < Constraint @@ -14,7 +15,7 @@ def value(v) v = @string.value(v) return v if v.is_a?(InvalidValue) - if v =~ regexp + if v&.match?(regexp) v else InvalidValue.new(v, "must match #{regexp.source}") diff --git a/lib/stronger_parameters/constraints/string_constraint.rb b/lib/stronger_parameters/constraints/string_constraint.rb index 09ce059..232d9cd 100644 --- a/lib/stronger_parameters/constraints/string_constraint.rb +++ b/lib/stronger_parameters/constraints/string_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class StringConstraint < Constraint @@ -17,13 +18,13 @@ def value(v) elsif minimum_length && v.bytesize < minimum_length return InvalidValue.new(v, "can not be shorter than #{minimum_length} bytes") elsif !v.valid_encoding? - return InvalidValue.new(v, 'must have valid encoding') + return InvalidValue.new(v, "must have valid encoding") end return v end - InvalidValue.new(v, 'must be a string') + InvalidValue.new(v, "must be a string") end def ==(other) diff --git a/lib/stronger_parameters/constraints/time_constraint.rb b/lib/stronger_parameters/constraints/time_constraint.rb index 9369409..dec70fa 100644 --- a/lib/stronger_parameters/constraints/time_constraint.rb +++ b/lib/stronger_parameters/constraints/time_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class TimeConstraint < Constraint diff --git a/lib/stronger_parameters/constraints/time_iso8601_constraint.rb b/lib/stronger_parameters/constraints/time_iso8601_constraint.rb index 9419b66..075a335 100644 --- a/lib/stronger_parameters/constraints/time_iso8601_constraint.rb +++ b/lib/stronger_parameters/constraints/time_iso8601_constraint.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class TimeIso8601Constraint < Constraint diff --git a/lib/stronger_parameters/constraints/ulid_constraint.rb b/lib/stronger_parameters/constraints/ulid_constraint.rb index f459080..87e806b 100644 --- a/lib/stronger_parameters/constraints/ulid_constraint.rb +++ b/lib/stronger_parameters/constraints/ulid_constraint.rb @@ -1,16 +1,17 @@ # frozen_string_literal: true -require 'stronger_parameters/constraint' + +require "stronger_parameters/constraint" module StrongerParameters class UlidConstraint < Constraint # https://www.crockford.com/base32.html - INVALID_CHAR_REGEX = /[ilou]|[^a-z0-9]/i.freeze + INVALID_CHAR_REGEX = /[ilou]|[^a-z0-9]/i ULID_LENGTH = 26 def value(v) return invalid_value(v) unless v.is_a?(String) return invalid_value(v) unless v.length == ULID_LENGTH - return invalid_value(v) if v =~ INVALID_CHAR_REGEX + return invalid_value(v) if INVALID_CHAR_REGEX.match?(v) v end diff --git a/lib/stronger_parameters/controller_support/permitted_parameters.rb b/lib/stronger_parameters/controller_support/permitted_parameters.rb index 48371ee..5687081 100644 --- a/lib/stronger_parameters/controller_support/permitted_parameters.rb +++ b/lib/stronger_parameters/controller_support/permitted_parameters.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require 'stronger_parameters/constraints' + +require "stronger_parameters/constraints" module StrongerParameters module ControllerSupport @@ -50,7 +51,7 @@ def permitted_parameters(action, permitted) end def permitted_parameters_for(action) - unless for_action = permit_parameters[action] + unless (for_action = permit_parameters[action]) # NOTE: there is no easy way to test this, so make sure to test with # a real rails controller if you make changes. message = "Action #{action} for #{self} does not have any permitted parameters" @@ -101,7 +102,7 @@ def permit_parameters def show_unpermitted_keys(unpermitted_keys, log_unpermitted) return if unpermitted_keys.empty? - log_prefix = (log_unpermitted ? 'Found' : 'Removed') + log_prefix = (log_unpermitted ? "Found" : "Removed") message = "#{log_prefix} restricted keys #{unpermitted_keys.inspect} from parameters according to permitted list" diff --git a/lib/stronger_parameters/errors.rb b/lib/stronger_parameters/errors.rb index c014c5b..96187b9 100644 --- a/lib/stronger_parameters/errors.rb +++ b/lib/stronger_parameters/errors.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module StrongerParameters class InvalidValue attr_reader :value, :message diff --git a/lib/stronger_parameters/parameters.rb b/lib/stronger_parameters/parameters.rb index 92ca851..528ac92 100644 --- a/lib/stronger_parameters/parameters.rb +++ b/lib/stronger_parameters/parameters.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true -require 'action_pack' -require 'action_controller/base' -require 'action_controller/api' -require 'action_controller/metal/strong_parameters' +require "action_pack" -require 'stronger_parameters/constraints' -require 'stronger_parameters/errors' +require "action_controller/base" +require "action_controller/api" +require "action_controller/metal/strong_parameters" + +require "stronger_parameters/constraints" +require "stronger_parameters/errors" module StrongerParameters module Parameters @@ -83,7 +84,7 @@ def ubigid def enumeration(*allowed) EnumerationConstraint.new(*allowed) end - alias enum enumeration + alias_method :enum, :enumeration def boolean BooleanConstraint.new @@ -148,7 +149,7 @@ def ulid def hash_filter_with_stronger_parameters(params, filter) stronger_filter = ActiveSupport::HashWithIndifferentAccess.new - other_filter = ActiveSupport::HashWithIndifferentAccess.new + other_filter = ActiveSupport::HashWithIndifferentAccess.new filter.each do |k, v| if v.is_a?(Constraint) @@ -173,7 +174,7 @@ def hash_filter_with_stronger_parameters(params, filter) if key?(key) result = constraint.value(value) elsif constraint.required? - result = InvalidValue.new(nil, 'must be present') + result = InvalidValue.new(nil, "must be present") else next # uncovered end @@ -211,8 +212,8 @@ module ControllerSupport # TODO: this is not consistent with the behavior of raising ActionController::UnpermittedParameters # should have the same render vs raise behavior in test/dev ... see permitted_parameters_test.rb rescue_from(StrongerParameters::InvalidParameter) do |e| - if request.format.to_s.include?('json') - render json: { error: e.message }, status: :bad_request + if request.format.to_s.include?("json") + render json: {error: e.message}, status: :bad_request else render plain: e.message, status: :bad_request end diff --git a/lib/stronger_parameters/version.rb b/lib/stronger_parameters/version.rb index 49b79a6..86bd00b 100644 --- a/lib/stronger_parameters/version.rb +++ b/lib/stronger_parameters/version.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module StrongerParameters - VERSION = '2.22.0' + VERSION = "2.22.0" end diff --git a/stronger_parameters.gemspec b/stronger_parameters.gemspec index b8b005b..bb3f793 100644 --- a/stronger_parameters.gemspec +++ b/stronger_parameters.gemspec @@ -1,27 +1,28 @@ # frozen_string_literal: true -require './lib/stronger_parameters/version' + +require "./lib/stronger_parameters/version" Gem::Specification.new do |spec| - spec.name = 'stronger_parameters' - spec.version = StrongerParameters::VERSION - spec.authors = ['Mick Staugaard'] - spec.email = ['mick@zendesk.com'] - spec.summary = 'Type checking and type casting of parameters for Action Pack' - spec.homepage = 'https://github.com/zendesk/stronger_parameters' - spec.license = 'Apache License Version 2.0' + spec.name = "stronger_parameters" + spec.version = StrongerParameters::VERSION + spec.authors = ["Mick Staugaard"] + spec.email = ["mick@zendesk.com"] + spec.summary = "Type checking and type casting of parameters for Action Pack" + spec.homepage = "https://github.com/zendesk/stronger_parameters" + spec.license = "Apache License Version 2.0" - spec.files = Dir.glob('lib/**/*') + %w[README.md] + spec.files = Dir.glob("lib/**/*") + %w[README.md] - spec.add_development_dependency 'bundler', '<= 3' - spec.add_development_dependency 'rake' - spec.add_development_dependency 'minitest-rails' - spec.add_development_dependency 'maxitest' - spec.add_development_dependency 'bump' - spec.add_development_dependency 'single_cov' - spec.add_development_dependency 'rubocop' - spec.add_development_dependency 'forking_test_runner' - spec.add_runtime_dependency 'actionpack', '>= 5.0', '< 7.2' + spec.add_development_dependency "bundler", "<= 3" + spec.add_development_dependency "rake" + spec.add_development_dependency "minitest-rails" + spec.add_development_dependency "maxitest" + spec.add_development_dependency "bump" + spec.add_development_dependency "single_cov" + spec.add_development_dependency "standard" + spec.add_development_dependency "forking_test_runner" + spec.add_runtime_dependency "actionpack", ">= 5.0", "< 7.2" - spec.required_ruby_version = '>= 2.7.0' - spec.metadata['rubygems_mfa_required'] = 'true' + spec.required_ruby_version = ">= 2.7.0" + spec.metadata["rubygems_mfa_required"] = "true" end diff --git a/test/benchmark.rb b/test/benchmark.rb index 9b4113d..53c49f4 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -require_relative 'test_helper' -require 'benchmark' + +require_relative "test_helper" +require "benchmark" def build_stack(count, &block) if count.zero? diff --git a/test/controller_test.rb b/test/controller_test.rb index 1a05962..b0777fb 100644 --- a/test/controller_test.rb +++ b/test/controller_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative 'test_helper' + +require_relative "test_helper" SingleCov.not_covered! @@ -9,8 +10,8 @@ class BooksController < ActionController::Base include ROUTES.url_helpers rescue_from(ActionController::ParameterMissing) do |e| - if request.format.to_s.include?('json') - render json: { error: "Required parameter missing: #{e.param}" }, status: :bad_request + if request.format.to_s.include?("json") + render json: {error: "Required parameter missing: #{e.param}"}, status: :bad_request else render plain: "Required parameter missing: #{e.param}", status: :bad_request end @@ -26,36 +27,36 @@ def create describe BooksController do before { @routes = BooksController::ROUTES } - context 'for text format' do - it 'rejects invalid params' do - post :create, params: {magazine: {name: 'Mjallo!'}} + context "for text format" do + it "rejects invalid params" do + post :create, params: {magazine: {name: "Mjallo!"}} assert_response :bad_request - response.body.must_equal 'Required parameter missing: book' + response.body.must_equal "Required parameter missing: book" - post :create, params: {book: {id: 'Mjallo!'}} + post :create, params: {book: {id: "Mjallo!"}} assert_response :bad_request - response.body.must_equal 'Invalid parameter: id must be an integer' + response.body.must_equal "Invalid parameter: id must be an integer" end - it 'permits valid params' do - post :create, params: {book: {id: '123'}} + it "permits valid params" do + post :create, params: {book: {id: "123"}} assert_response :ok end end - context 'for json format' do - it 'rejects invalid params' do - post :create, params: {magazine: {name: 'Mjallo!'}}, format: :json + context "for json format" do + it "rejects invalid params" do + post :create, params: {magazine: {name: "Mjallo!"}}, format: :json assert_response :bad_request - (JSON.parse(response.body)["error"]).must_equal 'Required parameter missing: book' + (JSON.parse(response.body)["error"]).must_equal "Required parameter missing: book" - post :create, params: {book: {id: 'Mjallo!'}}, format: :json + post :create, params: {book: {id: "Mjallo!"}}, format: :json assert_response :bad_request - (JSON.parse(response.body)["error"]).must_equal 'Invalid parameter: id must be an integer' + (JSON.parse(response.body)["error"]).must_equal "Invalid parameter: id must be an integer" end - it 'permits valid params' do - post :create, params: {book: {id: '123'}}, format: :json + it "permits valid params" do + post :create, params: {book: {id: "123"}}, format: :json assert_response :ok end end diff --git a/test/coverage_test.rb b/test/coverage_test.rb index 5fa966d..69cdd65 100644 --- a/test/coverage_test.rb +++ b/test/coverage_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative 'test_helper' + +require_relative "test_helper" SingleCov.not_covered! # not testing any code in lib/ diff --git a/test/stronger_parameters/constraint_test.rb b/test/stronger_parameters/constraint_test.rb index 894a592..4b1412d 100644 --- a/test/stronger_parameters/constraint_test.rb +++ b/test/stronger_parameters/constraint_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../test_helper' + +require_relative "../test_helper" SingleCov.covered! @@ -7,7 +8,7 @@ subject { StrongerParameters::Constraint.new } describe "#value" do - permits 'abc' + permits "abc" end describe "#==" do @@ -34,8 +35,8 @@ describe StrongerParameters::OrConstraint do subject { ActionController::Parameters.integer | ActionController::Parameters.string } - permits 'abc' - permits '123', as: 123 + permits "abc" + permits "123", as: 123 rejects Date.today rejects Time.now @@ -44,11 +45,11 @@ describe "multi-chain" do subject do ActionController::Parameters.integer | - ActionController::Parameters.string | - ActionController::Parameters.boolean + ActionController::Parameters.string | + ActionController::Parameters.boolean end - permits 'abc' + permits "abc" permits true rejects Date.today @@ -88,22 +89,22 @@ describe StrongerParameters::AndConstraint do subject { ActionController::Parameters.string & ActionController::Parameters.integer } - permits '123', as: 123 + permits "123", as: 123 rejects 123 - rejects 'abc' + rejects "abc" rejects nil describe "multi-chain" do subject do ActionController::Parameters.string & - ActionController::Parameters.integer & - ActionController::Parameters.lt(5) + ActionController::Parameters.integer & + ActionController::Parameters.lt(5) end - permits '4', as: 4 + permits "4", as: 4 - rejects '5' + rejects "5" end describe "#==" do @@ -141,5 +142,5 @@ subject { ActionController::Parameters.string.required } rejects nil - permits '123' + permits "123" end diff --git a/test/stronger_parameters/constraints/array_constraint_test.rb b/test/stronger_parameters/constraints/array_constraint_test.rb index 2344546..81b609c 100644 --- a/test/stronger_parameters/constraints/array_constraint_test.rb +++ b/test/stronger_parameters/constraints/array_constraint_test.rb @@ -1,21 +1,22 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! describe StrongerParameters::ArrayConstraint do subject { ActionController::Parameters.array(ActionController::Parameters.string) } - permits ['a', 'b'] + permits ["a", "b"] - rejects 'abc' + rejects "abc" rejects 123 rejects [123, 456] - rejects ['abc', 123] + rejects ["abc", 123] rejects nil rejects [nil] - describe '#==' do + describe "#==" do it "is the same with same constraints" do subject.must_equal ActionController::Parameters.array(ActionController::Parameters.string) end diff --git a/test/stronger_parameters/constraints/boolean_constraint_test.rb b/test/stronger_parameters/constraints/boolean_constraint_test.rb index 26d0820..22881c5 100644 --- a/test/stronger_parameters/constraints/boolean_constraint_test.rb +++ b/test/stronger_parameters/constraints/boolean_constraint_test.rb @@ -1,24 +1,25 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'boolean parameter constraints' do +describe "boolean parameter constraints" do subject { ActionController::Parameters.boolean } - permits true, as: true - permits 'true', as: true - permits 'True', as: true - permits 1, as: true - permits '1', as: true - permits 'on', as: true + permits true, as: true + permits "true", as: true + permits "True", as: true + permits 1, as: true + permits "1", as: true + permits "on", as: true - permits false, as: false - permits 'false', as: false - permits 'FALSE', as: false - permits 0, as: false - permits '0', as: false + permits false, as: false + permits "false", as: false + permits "FALSE", as: false + permits 0, as: false + permits "0", as: false - rejects 'foo' + rejects "foo" rejects nil end diff --git a/test/stronger_parameters/constraints/comparison_constraints_test.rb b/test/stronger_parameters/constraints/comparison_constraints_test.rb index 9002ad1..cd6f35b 100644 --- a/test/stronger_parameters/constraints/comparison_constraints_test.rb +++ b/test/stronger_parameters/constraints/comparison_constraints_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/constraints/date_constraint_test.rb b/test/stronger_parameters/constraints/date_constraint_test.rb index ce4056a..299c66f 100644 --- a/test/stronger_parameters/constraints/date_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_constraint_test.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'date parameter constraints' do +describe "date parameter constraints" do subject { ActionController::Parameters.date } permits Date.parse("2015-03-21"), as: Date.parse("2015-03-21") diff --git a/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb b/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb index e177aa3..18a54bc 100644 --- a/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_iso8601_constraint_test.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'date_iso8601 parameter constraints' do +describe "date_iso8601 parameter constraints" do subject { ActionController::Parameters.date_iso8601 } permits "2018-04-12", as: Date.iso8601("2018-04-12") diff --git a/test/stronger_parameters/constraints/date_time_constraint_test.rb b/test/stronger_parameters/constraints/date_time_constraint_test.rb index 9e1391c..cd1cda0 100644 --- a/test/stronger_parameters/constraints/date_time_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_time_constraint_test.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'datetime parameter constraints' do +describe "datetime parameter constraints" do subject { ActionController::Parameters.datetime } permits DateTime.parse("2015-03-31"), as: DateTime.parse("2015-03-31") diff --git a/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb b/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb index 0a02c67..ba2fa41 100644 --- a/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb +++ b/test/stronger_parameters/constraints/date_time_iso8601_constraint_test.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'datetime_iso8601 parameter constraints' do +describe "datetime_iso8601 parameter constraints" do subject { ActionController::Parameters.datetime_iso8601 } permits "2018-04-12", as: DateTime.iso8601("2018-04-12") diff --git a/test/stronger_parameters/constraints/decimal_constraint_test.rb b/test/stronger_parameters/constraints/decimal_constraint_test.rb index 169fc8c..0082310 100644 --- a/test/stronger_parameters/constraints/decimal_constraint_test.rb +++ b/test/stronger_parameters/constraints/decimal_constraint_test.rb @@ -1,86 +1,87 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'decimal parameter constraints' do - describe 'with 2 scale and 4 precision' do +describe "decimal parameter constraints" do + describe "with 2 scale and 4 precision" do subject { ActionController::Parameters.decimal(4, 2) } - permits '1.23', as: 1.23 - permits '-1.23', as: -1.23 + permits "1.23", as: 1.23 + permits "-1.23", as: -1.23 permits 1.23 permits(-1.23) - permits '12.34', as: 12.34 - permits '-12.34', as: -12.34 + permits "12.34", as: 12.34 + permits "-12.34", as: -12.34 permits 12.34 permits(-12.34) permits 1 permits(-1) - permits '1', as: 1 - permits '-1', as: -1 + permits "1", as: 1 + permits "-1", as: -1 - permits '1.2', as: 1.2 - permits '-1.2', as: -1.2 + permits "1.2", as: 1.2 + permits "-1.2", as: -1.2 permits 1.2 permits(-1.2) - rejects '123', as: 123 - rejects '-123', as: -123 + rejects "123", as: 123 + rejects "-123", as: -123 rejects 123 rejects(-123) - rejects 'abc' - rejects '1.2.3' - rejects '.3' - rejects '3.' + rejects "abc" + rejects "1.2.3" + rejects ".3" + rejects "3." rejects true - rejects '1234', as: 1234 - rejects '-1234', as: -1234 + rejects "1234", as: 1234 + rejects "-1234", as: -1234 rejects 1234 rejects(-1234) - rejects '1.234', as: 1.234 - rejects '-1.234', as: -1.234 + rejects "1.234", as: 1.234 + rejects "-1.234", as: -1.234 rejects 1.234 rejects(-1.234) - rejects '123.45', as: 123.45 - rejects '-123.45', as: 123.45 + rejects "123.45", as: 123.45 + rejects "-123.45", as: 123.45 rejects 123.45 rejects(-123.45) end - describe 'with 0 scale and 5 precision' do + describe "with 0 scale and 5 precision" do subject { ActionController::Parameters.decimal(5, 0) } permits 1 - permits '1', as: 1 + permits "1", as: 1 permits(-1) - permits '-1', as: -1 + permits "-1", as: -1 permits 12345 - permits '12345', as: 12345 + permits "12345", as: 12345 permits(-12345) - permits '-12345', as: -12345 + permits "-12345", as: -12345 - rejects 'abc' - rejects '1.2.3' - rejects '.3' - rejects '3.' + rejects "abc" + rejects "1.2.3" + rejects ".3" + rejects "3." rejects true - rejects '1.23', as: 1.23 - rejects '-1.23', as: -1.23 + rejects "1.23", as: 1.23 + rejects "-1.23", as: -1.23 rejects 1.23 rejects(-1.23) rejects 123456 - rejects '123456', as: 123456 + rejects "123456", as: 123456 rejects(-123456) - rejects '-123456', as: -123456 + rejects "-123456", as: -123456 end end diff --git a/test/stronger_parameters/constraints/enumeration_constraint_test.rb b/test/stronger_parameters/constraints/enumeration_constraint_test.rb index 601ab28..f0bb0c2 100644 --- a/test/stronger_parameters/constraints/enumeration_constraint_test.rb +++ b/test/stronger_parameters/constraints/enumeration_constraint_test.rb @@ -1,22 +1,23 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'enum parameter constraints' do - subject { ActionController::Parameters.enumeration('abc', 123) } +describe "enum parameter constraints" do + subject { ActionController::Parameters.enumeration("abc", 123) } - permits 'abc' + permits "abc" permits 123 - rejects 'abcd' - rejects '123' + rejects "abcd" + rejects "123" rejects 1234 rejects nil describe "#==" do it "is the same with same limit" do - subject.must_equal StrongerParameters::EnumerationConstraint.new('abc', 123) + subject.must_equal StrongerParameters::EnumerationConstraint.new("abc", 123) end it "is not the same with different limit" do diff --git a/test/stronger_parameters/constraints/file_constraint_test.rb b/test/stronger_parameters/constraints/file_constraint_test.rb index db9dc59..fc8163c 100644 --- a/test/stronger_parameters/constraints/file_constraint_test.rb +++ b/test/stronger_parameters/constraints/file_constraint_test.rb @@ -1,15 +1,16 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'io parameter constraints' do +describe "io parameter constraints" do subject { ActionController::Parameters.file } - permits StringIO.new('test') - permits File.new('.') - permits Rack::Test::UploadedFile.new('./README.md') - permits ActionDispatch::Http::UploadedFile.new(tempfile: Tempfile.new('test')) + permits StringIO.new("test") + permits File.new(".") + permits Rack::Test::UploadedFile.new("./README.md") + permits ActionDispatch::Http::UploadedFile.new(tempfile: Tempfile.new("test")) rejects 123 rejects Date.today diff --git a/test/stronger_parameters/constraints/float_constraint_test.rb b/test/stronger_parameters/constraints/float_constraint_test.rb index c4fbbee..156e788 100644 --- a/test/stronger_parameters/constraints/float_constraint_test.rb +++ b/test/stronger_parameters/constraints/float_constraint_test.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'float parameter constraints' do +describe "float parameter constraints" do subject { ActionController::Parameters.float } permits "1.2", as: 1.2 @@ -12,11 +13,11 @@ permits(-1.2) rejects 1 - rejects '1' - rejects '-1' - rejects 'abc' - rejects '1.2.3' - rejects '.3' - rejects '3.' + rejects "1" + rejects "-1" + rejects "abc" + rejects "1.2.3" + rejects ".3" + rejects "3." rejects true end diff --git a/test/stronger_parameters/constraints/hash_constraint_test.rb b/test/stronger_parameters/constraints/hash_constraint_test.rb index bba5edd..9ad570e 100644 --- a/test/stronger_parameters/constraints/hash_constraint_test.rb +++ b/test/stronger_parameters/constraints/hash_constraint_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! @@ -26,49 +27,49 @@ def self.permits(value, options = {}) constraint.value(foo: "bar").must_equal(expected) end - describe 'map parameter constraints' do - permits(id: 1, name: 'Mick') - permits({id: '1', name: 'Mick'}, as: {id: 1, name: 'Mick'}) + describe "map parameter constraints" do + permits(id: 1, name: "Mick") + permits({id: "1", name: "Mick"}, as: {id: 1, name: "Mick"}) permits(id: 1) - permits({id: '1'}, as: {id: 1}) - permits(name: 'Mick') + permits({id: "1"}, as: {id: 1}) + permits(name: "Mick") rejects({id: 1, name: 123}, key: :name) - rejects({id: 'Mick', name: 'Mick'}, key: :id) + rejects({id: "Mick", name: "Mick"}, key: :id) rejects(123) - rejects('abc') + rejects("abc") rejects nil end - describe 'open-ended map parameter constraints' do + describe "open-ended map parameter constraints" do subject { ActionController::Parameters.map } - permits(id: 1, name: 'Mick') - permits("id" => 1, "name" => 'Mick') + permits(id: 1, name: "Mick") + permits("id" => 1, "name" => "Mick") rejects("a string") rejects(123) rejects nil end - describe 'merged constraints' do + describe "merged constraints" do describe "hash" do subject do - ActionController::Parameters.map(id: ActionController::Parameters.integer). - merge(ActionController::Parameters.map(name: ActionController::Parameters.string)) + ActionController::Parameters.map(id: ActionController::Parameters.integer) + .merge(ActionController::Parameters.map(name: ActionController::Parameters.string)) end - permits(id: 1, name: 'Mick') - rejects({id: 'Mick', foo: 'Mick'}, key: :id) # TODO: key: :id is wrong + permits(id: 1, name: "Mick") + rejects({id: "Mick", foo: "Mick"}, key: :id) # TODO: key: :id is wrong end describe "other" do subject do - ActionController::Parameters.map(id: ActionController::Parameters.integer). - merge(name: ActionController::Parameters.string) + ActionController::Parameters.map(id: ActionController::Parameters.integer) + .merge(name: ActionController::Parameters.string) end - permits(id: 1, name: 'Mick') - rejects({id: 'Mick', foo: 'Mick'}, key: :id) # TODO: key: :id is wrong + permits(id: 1, name: "Mick") + rejects({id: "Mick", foo: "Mick"}, key: :id) # TODO: key: :id is wrong end end diff --git a/test/stronger_parameters/constraints/hex_constraint_test.rb b/test/stronger_parameters/constraints/hex_constraint_test.rb index b9666e2..d5ba402 100644 --- a/test/stronger_parameters/constraints/hex_constraint_test.rb +++ b/test/stronger_parameters/constraints/hex_constraint_test.rb @@ -1,16 +1,17 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'hexadecimal parameter constraints' do +describe "hexadecimal parameter constraints" do subject { ActionController::Parameters.hex } - permits 'DEADbeef' - permits 'abcdef0123456789' + permits "DEADbeef" + permits "abcdef0123456789" - rejects 'abcxyz' - rejects '' + rejects "abcxyz" + rejects "" rejects 123 rejects false rejects [1] diff --git a/test/stronger_parameters/constraints/integer_constraint_test.rb b/test/stronger_parameters/constraints/integer_constraint_test.rb index 9356fda..8d29e87 100644 --- a/test/stronger_parameters/constraints/integer_constraint_test.rb +++ b/test/stronger_parameters/constraints/integer_constraint_test.rb @@ -1,20 +1,21 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'integer parameter constraints' do +describe "integer parameter constraints" do subject { ActionController::Parameters.integer } permits 123 permits 2**64 - permits '123', as: 123 - permits '-123', as: -123 - permits ' 123', as: 123 + permits "123", as: 123 + permits "-123", as: -123 + permits " 123", as: 123 - rejects 'abc' + rejects "abc" rejects Date.today rejects Time.now rejects nil - rejects ' ' + rejects " " end diff --git a/test/stronger_parameters/constraints/nil_constraint_test.rb b/test/stronger_parameters/constraints/nil_constraint_test.rb index 073d5cc..d9f96cb 100644 --- a/test/stronger_parameters/constraints/nil_constraint_test.rb +++ b/test/stronger_parameters/constraints/nil_constraint_test.rb @@ -1,14 +1,15 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'nil parameter constraints' do +describe "nil parameter constraints" do subject { ActionController::Parameters.nil } permits nil - rejects 'abc' + rejects "abc" rejects 1 rejects false end diff --git a/test/stronger_parameters/constraints/nil_string_constraint_test.rb b/test/stronger_parameters/constraints/nil_string_constraint_test.rb index 30eca6a..cbe2b4b 100644 --- a/test/stronger_parameters/constraints/nil_string_constraint_test.rb +++ b/test/stronger_parameters/constraints/nil_string_constraint_test.rb @@ -1,14 +1,15 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'nil_string parameter constraints' do +describe "nil_string parameter constraints" do subject { ActionController::Parameters.nil_string } - permits '', as: nil - permits 'undefined', as: nil + permits "", as: nil + permits "undefined", as: nil permits nil - rejects 'foo' + rejects "foo" end diff --git a/test/stronger_parameters/constraints/regexp_constraint_test.rb b/test/stronger_parameters/constraints/regexp_constraint_test.rb index 98d901f..e20392b 100644 --- a/test/stronger_parameters/constraints/regexp_constraint_test.rb +++ b/test/stronger_parameters/constraints/regexp_constraint_test.rb @@ -1,17 +1,18 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'regexp parameter constraints' do +describe "regexp parameter constraints" do subject { ActionController::Parameters.regexp(/\Aab?c\Z/) } - permits 'abc' - permits 'ac' + permits "abc" + permits "ac" rejects 123 rejects nil - rejects 'abbc' + rejects "abbc" it "rejects non-strings with string constraint" do subject.value(123).message.must_equal "must be a string" diff --git a/test/stronger_parameters/constraints/string_constraint_test.rb b/test/stronger_parameters/constraints/string_constraint_test.rb index d479c73..eb9c8d6 100644 --- a/test/stronger_parameters/constraints/string_constraint_test.rb +++ b/test/stronger_parameters/constraints/string_constraint_test.rb @@ -1,25 +1,26 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! describe StrongerParameters::StringConstraint do subject { ActionController::Parameters.string } - permits 'abc' + permits "abc" rejects 123 rejects Date.today rejects Time.now rejects nil - rejects "\xA1".dup.force_encoding('UTF-8') + rejects (+"\xA1").force_encoding("UTF-8") - it 'rejects strings that are too long' do - assert_rejects(:value) { params(value: '123').permit(value: ActionController::Parameters.string(max_length: 2)) } + it "rejects strings that are too long" do + assert_rejects(:value) { params(value: "123").permit(value: ActionController::Parameters.string(max_length: 2)) } end - it 'rejects strings that are too short' do - assert_rejects(:value) { params(value: '1234').permit(value: ActionController::Parameters.string(min_length: 5)) } + it "rejects strings that are too short" do + assert_rejects(:value) { params(value: "1234").permit(value: ActionController::Parameters.string(min_length: 5)) } end describe "#==" do diff --git a/test/stronger_parameters/constraints/time_constraint_test.rb b/test/stronger_parameters/constraints/time_constraint_test.rb index f8804dc..317dcc0 100644 --- a/test/stronger_parameters/constraints/time_constraint_test.rb +++ b/test/stronger_parameters/constraints/time_constraint_test.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'time parameter constraints' do +describe "time parameter constraints" do subject { ActionController::Parameters.time } permits Time.parse("2015-03-31"), as: Time.parse("2015-03-31") diff --git a/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb b/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb index c08f64c..fb77863 100644 --- a/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb +++ b/test/stronger_parameters/constraints/time_iso8601_constraint_test.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! -describe 'date parameter constraints' do +describe "date parameter constraints" do subject { ActionController::Parameters.time_iso8601 } permits "2018-04-12T08:53:18+00:00", as: Time.iso8601("2018-04-12T08:53:18+00:00") diff --git a/test/stronger_parameters/constraints/ulid_constraint_test.rb b/test/stronger_parameters/constraints/ulid_constraint_test.rb index 3927760..3245054 100644 --- a/test/stronger_parameters/constraints/ulid_constraint_test.rb +++ b/test/stronger_parameters/constraints/ulid_constraint_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../../test_helper' + +require_relative "../../test_helper" SingleCov.covered! @@ -9,13 +10,13 @@ rejects Date.today rejects Time.now rejects nil - rejects '01GTJ6C0NF1MQX0KFZMS1RHTY' # short - rejects '01GTJ6C0NF1MQX0KFZMS1RHT-!' # special char - rejects '0IGTJ6C0NF1MQX0KFZMS1RHTYF' # i - rejects '0LGTJ6C0NF1MQX0KFZMS1RHTYF' # l - rejects 'O1GTJ6C0NF1MQX0KFZMS1RHTYF' # o - rejects '01GTJ6C0NF1MQX0KFZMS1RHTYU' # u + rejects "01GTJ6C0NF1MQX0KFZMS1RHTY" # short + rejects "01GTJ6C0NF1MQX0KFZMS1RHT-!" # special char + rejects "0IGTJ6C0NF1MQX0KFZMS1RHTYF" # i + rejects "0LGTJ6C0NF1MQX0KFZMS1RHTYF" # l + rejects "O1GTJ6C0NF1MQX0KFZMS1RHTYF" # o + rejects "01GTJ6C0NF1MQX0KFZMS1RHTYU" # u - permits '01GTJ6C0NF1MQX0KFZMS1RHTYF' - permits '01GTJ6C0NF1MQX0KFZMS1RHTYF'.downcase + permits "01GTJ6C0NF1MQX0KFZMS1RHTYF" + permits "01GTJ6C0NF1MQX0KFZMS1RHTYF".downcase end diff --git a/test/stronger_parameters/constraints_test.rb b/test/stronger_parameters/constraints_test.rb index dd30cde..9c001f3 100644 --- a/test/stronger_parameters/constraints_test.rb +++ b/test/stronger_parameters/constraints_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true -require_relative '../test_helper' + +require_relative "../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/controller_support/permitted_parameters_test.rb b/test/stronger_parameters/controller_support/permitted_parameters_test.rb index 9a7a113..79da5a0 100644 --- a/test/stronger_parameters/controller_support/permitted_parameters_test.rb +++ b/test/stronger_parameters/controller_support/permitted_parameters_test.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -require_relative '../../test_helper' -require 'stronger_parameters/controller_support/permitted_parameters' + +require_relative "../../test_helper" +require "stronger_parameters/controller_support/permitted_parameters" SingleCov.covered! @@ -43,23 +44,23 @@ def show WhitelistsController.log_unpermitted_parameters = false end - describe '.sugar' do - it 'turns Array into Parameters.array' do + describe ".sugar" do + it "turns Array into Parameters.array" do WhitelistsController.permitted_parameters :foo, ticket: [ActionController::Parameters.integer] constraint = WhitelistsController.permitted_parameters_for(:foo)[:ticket] assert_instance_of StrongerParameters::ArrayConstraint, constraint assert_equal ActionController::Parameters.integer, constraint.item_constraint end - it 'turns Hash into Parameters.map' do - WhitelistsController.permitted_parameters :foo, ticket: { id: ActionController::Parameters.integer } + it "turns Hash into Parameters.map" do + WhitelistsController.permitted_parameters :foo, ticket: {id: ActionController::Parameters.integer} constraint = WhitelistsController.permitted_parameters_for(:foo)[:ticket] assert_instance_of StrongerParameters::HashConstraint, constraint - assert_equal({ 'id' => ActionController::Parameters.integer }, constraint.constraints) + assert_equal({"id" => ActionController::Parameters.integer}, constraint.constraints) end end - describe '.permitted_parameters' do + describe ".permitted_parameters" do before do WhitelistsController.permitted_parameters :all, user_id: ActionController::Parameters.integer WhitelistsController.permitted_parameters :foo, ticket_id: ActionController::Parameters.integer @@ -68,12 +69,12 @@ def show WhitelistsController.permitted_parameters :bar, nested: {b: ActionController::Parameters.integer} end - it 'allows general whitelisting' do + it "allows general whitelisting" do WhitelistsController.permitted_parameters_for(:foo)[:user_id].must_equal ActionController::Parameters.integer WhitelistsController.permitted_parameters_for(:bar)[:user_id].must_equal ActionController::Parameters.integer end - it 'allows nested whitelisting' do + it "allows nested whitelisting" do WhitelistsController.permitted_parameters_for(:foo)[:ticket_id].must_equal ActionController::Parameters.integer WhitelistsController.permitted_parameters_for(:foo)[:group_id].must_be_nil @@ -81,13 +82,13 @@ def show WhitelistsController.permitted_parameters_for(:bar)[:ticket_id].must_be_nil end - it 'allows merging' do + it "allows merging" do WhitelistsController.permitted_parameters_for(:bar)[:nested].constraints.must_equal( "a" => ActionController::Parameters.integer, "b" => ActionController::Parameters.integer ) end - describe 'inheritance' do + describe "inheritance" do let(:child_controller) { Class.new(WhitelistsController) } before do @@ -96,38 +97,38 @@ def show child_controller.permitted_parameters :create, last: ActionController::Parameters.string end - it 'inherits from parent to child' do - WhitelistsController.permitted_parameters_for(:create)[:first]. - must_be_instance_of StrongerParameters::StringConstraint - child_controller.permitted_parameters_for(:create)[:first]. - must_be_instance_of StrongerParameters::StringConstraint + it "inherits from parent to child" do + WhitelistsController.permitted_parameters_for(:create)[:first] + .must_be_instance_of StrongerParameters::StringConstraint + child_controller.permitted_parameters_for(:create)[:first] + .must_be_instance_of StrongerParameters::StringConstraint assert_equal true, child_controller.log_unpermitted_parameters end - it 'does not inherit from child to parent' do + it "does not inherit from child to parent" do assert_nil WhitelistsController.permitted_parameters_for(:create)[:last] - child_controller.permitted_parameters_for(:create)[:last]. - must_be_instance_of StrongerParameters::StringConstraint + child_controller.permitted_parameters_for(:create)[:last] + .must_be_instance_of StrongerParameters::StringConstraint end end end - describe '#permit_parameters' do + describe "#permit_parameters" do def do_request - get :index, params: parameters, format: 'png' + get :index, params: parameters, format: "png" end - let(:parameters) { {id: '4', authenticity_token: 'auth'} } + let(:parameters) { {id: "4", authenticity_token: "auth"} } before do WhitelistsController.permitted_parameters( :index, something: ActionController::Parameters.anything, - user: { name: ActionController::Parameters.string } + user: {name: ActionController::Parameters.string} ) end - it 'does not filter default params' do + it "does not filter default params" do do_request assert_response :success @controller.params.to_h.must_equal( @@ -138,7 +139,7 @@ def do_request ) end - it 'filters request.params' do + it "filters request.params" do do_request assert_response :success @controller.request.params.must_equal( @@ -164,22 +165,22 @@ def do_request end it "does not remove invalid because they only raise and do not filter" do - parameters[:user] = {name: {so: "evil".dup}} + parameters[:user] = {name: {so: +"evil"}} do_request assert_response :success @controller.params.to_h["user"]["name"].must_equal("so" => "evil") end - it 'raises when action is not configured' do + it "raises when action is not configured" do assert_raises(KeyError) { get :show, params: {id: 1} } end - it 'raises proper exception even if action is not defined (and not configured)' do - @controller.params.merge!(action: 'ops_not_here', id: 1) + it "raises proper exception even if action is not defined (and not configured)" do + @controller.params.merge!(action: "ops_not_here", id: 1) assert_raises(KeyError) { @controller.send(:permit_parameters) } end - it 'overrides :skip' do + it "overrides :skip" do WhitelistsController.permitted_parameters :index, :skip WhitelistsController.permitted_parameters :index, bar: ActionController::Parameters.boolean get :index, params: {bar: true} @@ -189,7 +190,7 @@ def do_request describe "when raising on invalid params" do def do_request - get :index, params: {user: {name: ["123".dup]}} + get :index, params: {user: {name: [+"123"]}} end before { ActionController::Parameters.action_on_invalid_parameters = :raise } @@ -219,13 +220,13 @@ def do_request end end - describe 'headers' do - before { Rails.configuration.stronger_parameters_violation_header = 'X-StrongerParameters-API-Warn' } + describe "headers" do + before { Rails.configuration.stronger_parameters_violation_header = "X-StrongerParameters-API-Warn" } after { Rails.configuration.stronger_parameters_violation_header = nil } - it 'warns about filtered parms' do + it "warns about filtered parms" do do_request - @controller.response.headers['X-StrongerParameters-API-Warn'].must_equal( + @controller.response.headers["X-StrongerParameters-API-Warn"].must_equal( "Removed restricted keys [\"id\"] from parameters according to permitted list" ) end @@ -233,7 +234,7 @@ def do_request it "warns about unfiltered parameters" do WhitelistsController.log_unpermitted_parameters = true do_request - @controller.response.headers['X-StrongerParameters-API-Warn'].must_equal( + @controller.response.headers["X-StrongerParameters-API-Warn"].must_equal( "Found restricted keys [\"id\"] from parameters according to permitted list" ) end @@ -242,21 +243,21 @@ def do_request Rails.configuration.stub(:respond_to?, nil) do do_request end - refute @controller.response.headers['X-StrongerParameters-API-Warn'] + refute @controller.response.headers["X-StrongerParameters-API-Warn"] end - it 'warns about nil values' do + it "warns about nil values" do @controller.params[:id] = nil do_request - @controller.response.headers['X-StrongerParameters-API-Warn'].must_equal( + @controller.response.headers["X-StrongerParameters-API-Warn"].must_equal( "Removed restricted keys [\"id\"] from parameters according to permitted list" ) end - it 'does not warn when not configured' do + it "does not warn when not configured" do Rails.configuration.stronger_parameters_violation_header = nil do_request - refute @controller.response.headers.key?('X-StrongerParameters-API-Warn') + refute @controller.response.headers.key?("X-StrongerParameters-API-Warn") end end end diff --git a/test/stronger_parameters/errors_test.rb b/test/stronger_parameters/errors_test.rb index 56f5555..59f8a3b 100644 --- a/test/stronger_parameters/errors_test.rb +++ b/test/stronger_parameters/errors_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../test_helper' + +require_relative "../test_helper" SingleCov.covered! diff --git a/test/stronger_parameters/parameters_test.rb b/test/stronger_parameters/parameters_test.rb index fcf80da..7bfbc55 100644 --- a/test/stronger_parameters/parameters_test.rb +++ b/test/stronger_parameters/parameters_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../test_helper' + +require_relative "../test_helper" SingleCov.covered! uncovered: 3 # Covered in test/controller_test.rb @@ -7,7 +8,7 @@ describe ".anything" do subject { ActionController::Parameters.anything } - permits '1' + permits "1" permits 1 permits [] end @@ -166,59 +167,59 @@ describe ".bigid" do subject { ActionController::Parameters.bigid } - permits '1', as: 1 + permits "1", as: 1 permits 1 permits (2**63) - 1 rejects(-1) - rejects 'a' + rejects "a" rejects 2**63 end describe ".id" do subject { ActionController::Parameters.id } - permits '1', as: 1 + permits "1", as: 1 permits 1 permits (2**31) - 1 rejects(-1) - rejects 'a' + rejects "a" rejects 2**31 end describe ".ubigid" do subject { ActionController::Parameters.ubigid } - permits '1', as: 1 + permits "1", as: 1 permits 1 permits (2**64) - 1 rejects(-1) - rejects 'a' + rejects "a" rejects 2**64 end describe ".uid" do subject { ActionController::Parameters.uid } - permits '1', as: 1 + permits "1", as: 1 permits 1 permits (2**32) - 1 rejects(-1) - rejects 'a' + rejects "a" rejects 2**32 end describe ".integer32" do subject { ActionController::Parameters.integer32 } - permits '1', as: 1 + permits "1", as: 1 permits (2**31) - 1 permits(-2**31) - rejects 'a' + rejects "a" rejects 2**31 rejects(-2**31 - 1) end @@ -226,11 +227,11 @@ describe ".integer64" do subject { ActionController::Parameters.integer64 } - permits '1', as: 1 + permits "1", as: 1 permits (2**63) - 1 permits(-2**63) - rejects 'a' + rejects "a" rejects 2**63 rejects(-2**63 - 1) end @@ -291,8 +292,8 @@ end it "passes nested constraints in non-constraint" do - params(value: {key: 123}).permit(value: {key: ActionController::Parameters.integer32}).to_h. - must_equal "value" => {"key" => 123} + params(value: {key: 123}).permit(value: {key: ActionController::Parameters.integer32}).to_h + .must_equal "value" => {"key" => 123} end it "fails nested constraints in non-constraint" do @@ -302,8 +303,8 @@ end it "passes nested constraints in non-constraint array" do - params(value: [{key: 123}]).permit(value: [{key: ActionController::Parameters.integer32}]).to_h. - must_equal "value" => [{"key" => 123}] + params(value: [{key: 123}]).permit(value: [{key: ActionController::Parameters.integer32}]).to_h + .must_equal "value" => [{"key" => 123}] end it "fails nested constraints in non-constraint array" do @@ -327,7 +328,7 @@ def pass_nil_as_constrain params(value: nil).permit(value: ActionController::Parameters.integer32) end - def with_allow_nil_for_everything(value = true) # rubocop:disable Style/OptionalBooleanParameter + def with_allow_nil_for_everything(value = true) old = ActionController::Parameters.allow_nil_for_everything ActionController::Parameters.allow_nil_for_everything = value yield diff --git a/test/stronger_parameters/version_test.rb b/test/stronger_parameters/version_test.rb index 49d6814..2c4356d 100644 --- a/test/stronger_parameters/version_test.rb +++ b/test/stronger_parameters/version_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../test_helper' + +require_relative "../test_helper" SingleCov.not_covered! # loaded before SingleCov is loaded diff --git a/test/stronger_parameters_test.rb b/test/stronger_parameters_test.rb index e734cdb..1b9dddd 100644 --- a/test/stronger_parameters_test.rb +++ b/test/stronger_parameters_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true -require_relative 'test_helper' + +require_relative "test_helper" SingleCov.covered! diff --git a/test/test_helper.rb b/test/test_helper.rb index cc10dee..6594d8d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,29 +1,30 @@ # frozen_string_literal: true + ENV["RAILS_ENV"] = "test" -require 'bundler/setup' +require "bundler/setup" -require 'single_cov' +require "single_cov" SingleCov.setup :minitest -require 'maxitest/global_must' -require 'maxitest/autorun' -require 'rails' -require 'action_controller' -require 'rails/generators' +require "maxitest/global_must" +require "maxitest/autorun" +require "rails" +require "action_controller" +require "rails/generators" class FakeApplication < Rails::Application; end Rails.application = FakeApplication Rails.configuration.action_controller = ActiveSupport::OrderedOptions.new -Rails.configuration.secret_key_base = 'secret_key_base' +Rails.configuration.secret_key_base = "secret_key_base" Rails.logger = Logger.new("/dev/null") ActiveSupport.test_order = :random if ActiveSupport.respond_to?(:test_order=) -require 'action_pack' -require 'stronger_parameters' -require 'minitest/rails' +require "action_pack" +require "stronger_parameters" +require "minitest/rails" # Use ActionController::TestCase for Controllers Minitest::Spec::DSL::TYPES.unshift [/Controller$/, ActionController::TestCase]