From daf15d500513258d4516c46398b9e5abfc34ea69 Mon Sep 17 00:00:00 2001 From: Mathieu EUSTACHY Date: Tue, 4 Feb 2025 11:30:05 +0100 Subject: [PATCH] [Linter] Add rubocop to the gem (#319) --- .github/workflows/main.yml | 16 + .rubocop.yml | 37 ++ .rubocop_todo.yml | 13 + Gemfile | 7 +- Gemfile.lock | 46 ++- active_storage_validations.gemspec | 4 +- lib/active_storage_validations.rb | 44 +-- lib/active_storage_validations/analyzer.rb | 47 +-- .../analyzer/audio_analyzer.rb | 4 +- .../analyzer/content_type_analyzer.rb | 10 +- .../analyzer/image_analyzer/image_magick.rb | 1 - .../analyzer/image_analyzer/vips.rb | 1 - .../analyzer/video_analyzer.rb | 8 +- .../aspect_ratio_validator.rb | 36 +- .../attached_validator.rb | 6 +- .../base_comparison_validator.rb | 12 +- .../content_type_validator.rb | 24 +- .../dimension_validator.rb | 15 +- .../duration_validator.rb | 16 +- .../extensors/asv_blob_metadatable.rb | 16 +- .../extensors/asv_marcelable.rb | 2 +- .../limit_validator.rb | 46 ++- lib/active_storage_validations/matchers.rb | 20 +- .../aspect_ratio_validator_matcher.rb | 24 +- .../matchers/attached_validator_matcher.rb | 12 +- .../base_comparison_validator_matcher.rb | 14 +- .../content_type_validator_matcher.rb | 22 +- .../matchers/dimension_validator_matcher.rb | 16 +- .../matchers/duration_validator_matcher.rb | 4 +- .../matchers/limit_validator_matcher.rb | 16 +- .../processable_file_validator_matcher.rb | 14 +- .../matchers/shared/asv_active_storageable.rb | 2 +- .../matchers/shared/asv_allow_blankable.rb | 2 +- .../matchers/shared/asv_attachable.rb | 18 +- .../matchers/shared/asv_contextable.rb | 14 +- .../matchers/shared/asv_messageable.rb | 2 +- .../matchers/shared/asv_rspecable.rb | 4 +- .../matchers/shared/asv_validatable.rb | 4 +- .../matchers/size_validator_matcher.rb | 4 +- .../matchers/total_size_validator_matcher.rb | 6 +- .../processable_file_validator.rb | 74 ++-- lib/active_storage_validations/railtie.rb | 4 +- .../shared/asv_attachable.rb | 62 ++-- .../shared/asv_errorable.rb | 2 +- .../shared/asv_symbolizable.rb | 2 +- .../size_validator.rb | 2 +- .../total_size_validator.rb | 4 +- lib/active_storage_validations/version.rb | 2 +- test/active_storage_validations_test.rb | 328 +++++++++--------- test/analyzers/audio_analyzer_test.rb | 16 +- test/analyzers/content_type_analyzer_test.rb | 38 +- .../image_analyzers/image_magick_test.rb | 14 +- test/analyzers/image_analyzers/vips_test.rb | 14 +- ...s_the_right_metadata_for_any_attachable.rb | 20 +- test/analyzers/video_analyzer_test.rb | 10 +- .../active_storage_validations/check.rb | 2 +- test/dummy/app/models/application_record.rb | 97 +++--- test/dummy/app/models/aspect_ratio.rb | 2 +- test/dummy/app/models/aspect_ratio/matcher.rb | 8 +- .../app/models/aspect_ratio/validator.rb | 2 +- .../models/aspect_ratio/validator/check.rb | 8 +- .../validator/check_validity_proc_option.rb | 2 +- .../models/aspect_ratio/validator/with_if.rb | 4 +- .../aspect_ratio/validator/with_message.rb | 2 +- .../models/aspect_ratio/validator/with_on.rb | 2 +- test/dummy/app/models/attached.rb | 2 +- test/dummy/app/models/attached/matcher.rb | 6 +- test/dummy/app/models/attached/validator.rb | 2 +- .../app/models/attached/validator/with_if.rb | 4 +- .../models/attached/validator/with_message.rb | 2 +- .../app/models/attached/validator/with_on.rb | 2 +- test/dummy/app/models/content_type.rb | 2 +- test/dummy/app/models/content_type/matcher.rb | 20 +- .../app/models/content_type/validator.rb | 2 +- .../models/content_type/validator/check.rb | 30 +- .../check_validity_invalid_content_type_in.rb | 2 +- .../validator/check_validity_proc_option.rb | 2 +- ...validity_valid_content_type_ole_storage.rb | 1 - .../models/content_type/validator/with_if.rb | 4 +- .../content_type/validator/with_message.rb | 2 +- .../models/content_type/validator/with_on.rb | 2 +- test/dummy/app/models/dimension.rb | 2 +- test/dummy/app/models/dimension/matcher.rb | 26 +- test/dummy/app/models/dimension/validator.rb | 2 +- .../app/models/dimension/validator/check.rb | 16 +- .../check_validity_dimension_in_proc.rb | 3 +- .../check_validity_dimension_in_range.rb | 1 - .../check_validity_invalid_dimension_in.rb | 1 - .../validator/check_validity_invalid_max.rb | 1 - .../validator/check_validity_invalid_min.rb | 1 - .../validator/check_validity_max_proc.rb | 1 - .../validator/check_validity_max_range.rb | 1 - .../validator/check_validity_min_proc.rb | 1 - .../validator/check_validity_min_range.rb | 1 - .../app/models/dimension/validator/with_if.rb | 4 +- .../dimension/validator/with_message.rb | 2 +- .../app/models/dimension/validator/with_on.rb | 2 +- test/dummy/app/models/document.rb | 6 +- test/dummy/app/models/duration.rb | 2 +- test/dummy/app/models/duration/matcher.rb | 26 +- test/dummy/app/models/duration/validator.rb | 2 +- .../app/models/duration/validator/check.rb | 8 +- .../app/models/duration/validator/with_if.rb | 4 +- .../models/duration/validator/with_message.rb | 2 +- .../app/models/duration/validator/with_on.rb | 2 +- test/dummy/app/models/integration.rb | 2 +- test/dummy/app/models/integration/matcher.rb | 6 +- .../dummy/app/models/integration/validator.rb | 2 +- .../validator/based_on_a_file_property.rb | 4 +- test/dummy/app/models/limit.rb | 2 +- test/dummy/app/models/limit/matcher.rb | 12 +- test/dummy/app/models/limit/validator.rb | 2 +- .../models/limit/validator/check_max_proc.rb | 2 +- .../models/limit/validator/check_min_proc.rb | 2 +- .../app/models/limit/validator/check_range.rb | 1 - .../limit/validator/check_range_proc.rb | 3 +- .../check_validity_invalid_argument.rb | 2 +- .../validator/check_validity_proc_option.rb | 6 +- .../app/models/limit/validator/with_if.rb | 4 +- .../models/limit/validator/with_message.rb | 2 +- .../app/models/limit/validator/with_on.rb | 2 +- test/dummy/app/models/limit_attachment.rb | 2 +- test/dummy/app/models/only_image.rb | 8 +- test/dummy/app/models/processable_file.rb | 2 +- .../app/models/processable_file/matcher.rb | 6 +- .../app/models/processable_file/validator.rb | 2 +- .../processable_file/validator/with_if.rb | 4 +- .../validator/with_message.rb | 2 +- .../processable_file/validator/with_on.rb | 2 +- test/dummy/app/models/project.rb | 11 +- test/dummy/app/models/ratio_model.rb | 14 +- test/dummy/app/models/size.rb | 2 +- test/dummy/app/models/size/matcher.rb | 26 +- test/dummy/app/models/size/validator.rb | 2 +- test/dummy/app/models/size/validator/check.rb | 8 +- .../app/models/size/validator/with_if.rb | 4 +- .../app/models/size/validator/with_message.rb | 2 +- .../app/models/size/validator/with_on.rb | 2 +- test/dummy/app/models/total_size.rb | 2 +- test/dummy/app/models/total_size/matcher.rb | 24 +- test/dummy/app/models/total_size/validator.rb | 2 +- .../app/models/total_size/validator/check.rb | 8 +- .../models/total_size/validator/with_if.rb | 4 +- .../total_size/validator/with_message.rb | 2 +- .../models/total_size/validator/with_on.rb | 2 +- test/dummy/app/models/user.rb | 20 +- test/dummy/config/initializers/mime_types.rb | 2 +- test/dummy/db/schema.rb | 32 +- test/extensors/asv_blob_metadatable_test.rb | 18 +- .../global/active_storage_validations_test.rb | 4 +- .../aspect_ratio_validator_matcher_test.rb | 102 +++--- .../attached_validator_matcher_test.rb | 20 +- .../content_type_validator_matcher_test.rb | 152 ++++---- .../dimension_validator_matcher_test.rb | 72 ++-- .../duration_validator_matcher_test.rb | 94 ++--- test/matchers/integration/integration_test.rb | 36 +- test/matchers/limit_validator_matcher_test.rb | 32 +- ...processable_file_validator_matcher_test.rb | 20 +- .../base_comparison_validator_matcher.rb | 8 +- ..._if_is_a_valid_active_storage_attribute.rb | 6 +- .../shared_examples/checks_if_is_valid.rb | 8 +- .../shared_examples/has_custom_matcher.rb | 8 +- .../has_valid_rspec_message_methods.rb | 10 +- .../shared_examples/works_with_allow_blank.rb | 8 +- .../works_with_both_instance_and_class.rb | 6 +- .../shared_examples/works_with_context.rb | 36 +- .../works_with_custom_message.rb | 14 +- test/matchers/size_validator_matcher_test.rb | 94 ++--- test/matchers/support/matcher_helpers.rb | 6 +- .../total_size_validator_matcher_test.rb | 90 ++--- test/support/files.rb | 208 +++++------ test/support/mime_types.rb | 5 +- test/test_helper.rb | 36 +- .../validators/aspect_ratio_validator_test.rb | 66 ++-- test/validators/attached_validator_test.rb | 32 +- .../validators/content_type_validator_test.rb | 98 +++--- test/validators/dimension_validator_test.rb | 114 +++--- test/validators/duration_validator_test.rb | 128 +++---- .../integration/integration_test.rb | 44 +-- test/validators/limit_validator_test.rb | 68 ++-- .../processable_file_validator_test.rb | 34 +- .../checks_validator_validity.rb | 30 +- .../does_not_work_with_allow_blank_option.rb | 2 +- .../does_not_work_with_allow_nil_option.rb | 2 +- .../works_fine_with_attachables.rb | 76 ++-- ...ith_all_rails_common_validation_options.rb | 16 +- .../works_with_allow_blank_option.rb | 8 +- .../works_with_allow_nil_option.rb | 8 +- .../shared_examples/works_with_if_option.rb | 26 +- .../works_with_message_option.rb | 10 +- .../shared_examples/works_with_on_option.rb | 10 +- .../works_with_strict_option.rb | 8 +- .../works_with_unless_option.rb | 22 +- test/validators/size_validator_test.rb | 118 +++---- test/validators/support/validator_helpers.rb | 4 +- test/validators/total_size_validator_test.rb | 140 ++++---- 196 files changed, 2043 insertions(+), 1897 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6edb81bf..6ad13451 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,6 +2,22 @@ name: CI on: [push, pull_request] jobs: + linters: + name: Linters + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Ruby and install gems + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: Run linters + run: | + bundle exec rubocop --parallel + tests: name: Tests runs-on: ubuntu-latest diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..e2b48b35 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,37 @@ +inherit_from: .rubocop_todo.yml + +inherit_gem: + rubocop-rails-omakase: rubocop.yml + +AllCops: + TargetRubyVersion: 3.0.7 # We need to support all ruby versions in CI matrix + Exclude: + - 'bin/*' + - 'config/locales/*' + - 'gemfiles/*' + - 'lib/tasks/*' + - 'vendor/bundle/**/*' + NewCops: enable + +require: + - rubocop-performance + +# ============================================================================== +# Cops + +# Style cops + +Style/Documentation: + Enabled: false + +# Metrics cops + +Metrics/AbcSize: + Severity: warning + +Metrics/MethodLength: + Max: 15 + +Metrics/BlockLength: + Exclude: + - test/**/* diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..f19be187 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,13 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2025-02-03 15:23:42 UTC using RuboCop version 1.71.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + + +# Offense count: 16 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 25 diff --git a/Gemfile b/Gemfile index 38290265..5c3191ff 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } # Declare your gem's dependencies in active_storage_validations.gemspec. @@ -22,4 +22,9 @@ gemspec group :development, :test do # To use a debugger: # gem 'byebug' + + # Linters + gem "rubocop", "~> 1.71", ">= 1.71.1", require: false + gem "rubocop-performance", "~> 1.23", ">= 1.23.1", require: false + gem "rubocop-rails-omakase", "~> 1.0", ">= 1.0.0", require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 4426abfe..2036ec51 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -54,6 +54,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) + ast (2.4.2) base64 (0.2.0) bigdecimal (3.1.8) builder (3.3.0) @@ -74,7 +75,7 @@ GEM ffi (1.17.0) ffi (1.17.0-arm64-darwin) ffi (1.17.0-x86_64-darwin) - ffi (1.17.0-x86_64-linux-gnu) + ffi (1.17.0-x86_64-linux) globalid (1.2.1) activesupport (>= 6.1) hashdiff (1.1.1) @@ -84,6 +85,8 @@ GEM irb (1.14.1) rdoc (>= 4.0.0) reline (>= 0.4.2) + json (2.9.1) + language_server-protocol (3.17.0.4) logger (1.6.0) loofah (2.22.0) crass (~> 1.0.2) @@ -107,6 +110,10 @@ GEM racc (~> 1.4) nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) + parallel (1.26.3) + parser (3.3.7.0) + ast (~> 2.4.1) + racc pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -137,12 +144,43 @@ GEM rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) + rainbow (3.1.1) rake (13.2.1) rdoc (6.7.0) psych (>= 4.0.0) + regexp_parser (2.10.0) reline (0.5.11) io-console (~> 0.5) rexml (3.3.7) + rubocop (1.71.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.38.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.38.0) + parser (>= 3.3.1.0) + rubocop-minitest (0.36.0) + rubocop (>= 1.61, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-performance (1.23.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.29.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.52.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails-omakase (1.0.0) + rubocop + rubocop-minitest + rubocop-performance + rubocop-rails + ruby-progressbar (1.13.0) ruby-vips (2.2.2) ffi (~> 1.12) logger @@ -162,6 +200,9 @@ GEM timeout (0.4.2) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + unicode-display_width (3.1.4) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) webmock (3.23.1) addressable (>= 2.8.0) crack (>= 0.3.2) @@ -184,6 +225,9 @@ DEPENDENCIES minitest-mock_expectations (~> 1.2, >= 1.2.0) minitest-stub_any_instance (~> 1.0, >= 1.0.3) pry + rubocop (~> 1.71, >= 1.71.1) + rubocop-performance (~> 1.23, >= 1.23.1) + rubocop-rails-omakase (~> 1.0, >= 1.0.0) ruby-vips (>= 2.1.0) simplecov sqlite3 diff --git a/active_storage_validations.gemspec b/active_storage_validations.gemspec index 8ef72ce1..7e0c01f9 100644 --- a/active_storage_validations.gemspec +++ b/active_storage_validations.gemspec @@ -9,8 +9,8 @@ require 'active_storage_validations/version' Gem::Specification.new do |s| s.name = 'active_storage_validations' s.version = ActiveStorageValidations::VERSION - s.authors = ['Igor Kasyanchuk'] - s.email = ['igorkasyanchuk@gmail.com'] + s.authors = [ 'Igor Kasyanchuk' ] + s.email = [ 'igorkasyanchuk@gmail.com' ] s.homepage = 'https://github.com/igorkasyanchuk/active_storage_validations' s.summary = 'Validations for Active Storage' s.description = 'Validations for Active Storage (presence)' diff --git a/lib/active_storage_validations.rb b/lib/active_storage_validations.rb index c8266306..1c4f15b7 100644 --- a/lib/active_storage_validations.rb +++ b/lib/active_storage_validations.rb @@ -1,28 +1,28 @@ # frozen_string_literal: true -require 'active_model' -require 'active_support/concern' +require "active_model" +require "active_support/concern" -require 'active_storage_validations/analyzer' -require 'active_storage_validations/analyzer/image_analyzer' -require 'active_storage_validations/analyzer/image_analyzer/image_magick' -require 'active_storage_validations/analyzer/image_analyzer/vips' -require 'active_storage_validations/analyzer/null_analyzer' -require 'active_storage_validations/analyzer/video_analyzer' -require 'active_storage_validations/analyzer/audio_analyzer' +require "active_storage_validations/analyzer" +require "active_storage_validations/analyzer/image_analyzer" +require "active_storage_validations/analyzer/image_analyzer/image_magick" +require "active_storage_validations/analyzer/image_analyzer/vips" +require "active_storage_validations/analyzer/null_analyzer" +require "active_storage_validations/analyzer/video_analyzer" +require "active_storage_validations/analyzer/audio_analyzer" -require 'active_storage_validations/extensors/asv_blob_metadatable' -require 'active_storage_validations/extensors/asv_marcelable' +require "active_storage_validations/extensors/asv_blob_metadatable" +require "active_storage_validations/extensors/asv_marcelable" -require 'active_storage_validations/attached_validator' -require 'active_storage_validations/content_type_validator' -require 'active_storage_validations/limit_validator' -require 'active_storage_validations/dimension_validator' -require 'active_storage_validations/duration_validator' -require 'active_storage_validations/aspect_ratio_validator' -require 'active_storage_validations/processable_file_validator' -require 'active_storage_validations/size_validator' -require 'active_storage_validations/total_size_validator' +require "active_storage_validations/attached_validator" +require "active_storage_validations/content_type_validator" +require "active_storage_validations/limit_validator" +require "active_storage_validations/dimension_validator" +require "active_storage_validations/duration_validator" +require "active_storage_validations/aspect_ratio_validator" +require "active_storage_validations/processable_file_validator" +require "active_storage_validations/size_validator" +require "active_storage_validations/total_size_validator" -require 'active_storage_validations/engine' -require 'active_storage_validations/railtie' +require "active_storage_validations/engine" +require "active_storage_validations/railtie" diff --git a/lib/active_storage_validations/analyzer.rb b/lib/active_storage_validations/analyzer.rb index 511cb126..bb61b50c 100644 --- a/lib/active_storage_validations/analyzer.rb +++ b/lib/active_storage_validations/analyzer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_loggable' +require_relative "shared/asv_attachable" +require_relative "shared/asv_loggable" module ActiveStorageValidations # = Active Storage Validations \Analyzer @@ -37,29 +37,30 @@ def read_media raise NotImplementedError end + # rubocop:disable Metrics/MethodLength def media(tempfile) @media ||= case @attachable - when ActiveStorage::Blob, String - blob = @attachable.is_a?(String) ? ActiveStorage::Blob.find_signed!(@attachable) : @attachable - media_from_tempfile_path(tempfile, blob) - when Hash - io = @attachable[:io] - if io.is_a?(StringIO) - media_from_tempfile_path(tempfile, io) - else - File.open(io) do |file| - media_from_path(file.path) - end - end - when ActionDispatch::Http::UploadedFile, Rack::Test::UploadedFile - media_from_path(@attachable.path) - when File - supports_file_attachment? ? media_from_path(@attachable.path) : raise_rails_like_error(@attachable) - when Pathname - supports_pathname_attachment? ? media_from_path(@attachable.to_s) : raise_rails_like_error(@attachable) - else - raise_rails_like_error(@attachable) - end + when ActiveStorage::Blob, String + blob = @attachable.is_a?(String) ? ActiveStorage::Blob.find_signed!(@attachable) : @attachable + media_from_tempfile_path(tempfile, blob) + when Hash + io = @attachable[:io] + if io.is_a?(StringIO) + media_from_tempfile_path(tempfile, io) + else + File.open(io) do |file| + media_from_path(file.path) + end + end + when ActionDispatch::Http::UploadedFile, Rack::Test::UploadedFile + media_from_path(@attachable.path) + when File + supports_file_attachment? ? media_from_path(@attachable.path) : raise_rails_like_error(@attachable) + when Pathname + supports_pathname_attachment? ? media_from_path(@attachable.to_s) : raise_rails_like_error(@attachable) + else + raise_rails_like_error(@attachable) + end end def media_from_tempfile_path(tempfile, file_representation) diff --git a/lib/active_storage_validations/analyzer/audio_analyzer.rb b/lib/active_storage_validations/analyzer/audio_analyzer.rb index 8f071c55..ff272af0 100644 --- a/lib/active_storage_validations/analyzer/audio_analyzer.rb +++ b/lib/active_storage_validations/analyzer/audio_analyzer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'open3' -require_relative 'shared/asv_ff_probable' +require "open3" +require_relative "shared/asv_ff_probable" module ActiveStorageValidations # = ActiveStorageValidations Audio \Analyzer diff --git a/lib/active_storage_validations/analyzer/content_type_analyzer.rb b/lib/active_storage_validations/analyzer/content_type_analyzer.rb index 74fd5314..fd2a4946 100644 --- a/lib/active_storage_validations/analyzer/content_type_analyzer.rb +++ b/lib/active_storage_validations/analyzer/content_type_analyzer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'open3' +require "open3" module ActiveStorageValidations # = ActiveStorageValidations ContentType \Analyzer @@ -41,15 +41,15 @@ def read_media end end rescue Errno::ENOENT - raise FileCommandLineToolNotInstalledError, 'file command-line tool is not installed' + raise FileCommandLineToolNotInstalledError, "file command-line tool is not installed" end def media_from_path(path) instrument("file") do stdout, status = Open3.capture2( - 'file', - '-b', - '--mime-type', + "file", + "-b", + "--mime-type", path ) diff --git a/lib/active_storage_validations/analyzer/image_analyzer/image_magick.rb b/lib/active_storage_validations/analyzer/image_analyzer/image_magick.rb index 4c499070..ce708ff6 100644 --- a/lib/active_storage_validations/analyzer/image_analyzer/image_magick.rb +++ b/lib/active_storage_validations/analyzer/image_analyzer/image_magick.rb @@ -5,7 +5,6 @@ module ActiveStorageValidations # MiniMagick requires the {ImageMagick}[http://www.imagemagick.org] system library. # This is the default Rails image analyzer. class Analyzer::ImageAnalyzer::ImageMagick < Analyzer::ImageAnalyzer - private def read_media diff --git a/lib/active_storage_validations/analyzer/image_analyzer/vips.rb b/lib/active_storage_validations/analyzer/image_analyzer/vips.rb index d8da991f..03465788 100644 --- a/lib/active_storage_validations/analyzer/image_analyzer/vips.rb +++ b/lib/active_storage_validations/analyzer/image_analyzer/vips.rb @@ -4,7 +4,6 @@ module ActiveStorageValidations # This analyzer relies on the third-party {ruby-vips}[https://github.com/libvips/ruby-vips] gem. # Ruby-vips requires the {libvips}[https://libvips.github.io/libvips/] system library. class Analyzer::ImageAnalyzer::Vips < Analyzer::ImageAnalyzer - private def read_media diff --git a/lib/active_storage_validations/analyzer/video_analyzer.rb b/lib/active_storage_validations/analyzer/video_analyzer.rb index 2d91c273..5a869b5d 100644 --- a/lib/active_storage_validations/analyzer/video_analyzer.rb +++ b/lib/active_storage_validations/analyzer/video_analyzer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'open3' -require_relative 'shared/asv_ff_probable' +require "open3" +require_relative "shared/asv_ff_probable" module ActiveStorageValidations # = ActiveStorageValidations Video \Analyzer @@ -80,7 +80,7 @@ def display_aspect_ratio numerator = Integer(terms[0]) denominator = Integer(terms[1]) - [numerator, denominator] unless numerator == 0 + [ numerator, denominator ] unless numerator == 0 end end end @@ -127,4 +127,4 @@ def container @container ||= @media["format"] || {} end end -end \ No newline at end of file +end diff --git a/lib/active_storage_validations/aspect_ratio_validator.rb b/lib/active_storage_validations/aspect_ratio_validator.rb index 6134d042..e7d90db6 100644 --- a/lib/active_storage_validations/aspect_ratio_validator.rb +++ b/lib/active_storage_validations/aspect_ratio_validator.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_analyzable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_errorable' -require_relative 'shared/asv_optionable' -require_relative 'shared/asv_symbolizable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_analyzable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_errorable" +require_relative "shared/asv_optionable" +require_relative "shared/asv_symbolizable" module ActiveStorageValidations class AspectRatioValidator < ActiveModel::EachValidator # :nodoc @@ -48,7 +48,7 @@ def validate_each(record, attribute, _value) private def is_valid?(record, attribute, attachable, metadata) - !media_metadata_missing?(record, attribute, attachable, metadata) && + media_metadata_present?(record, attribute, attachable, metadata) && authorized_aspect_ratio?(record, attribute, attachable, metadata) end @@ -64,11 +64,10 @@ def authorized_aspect_ratio?(record, attribute, attachable, metadata) return true if attachable_aspect_ratio_is_authorized - errors_options = initialize_error_options(options, attachable) - error_type = aspect_ratio_error_mapping - errors_options[:authorized_aspect_ratios] = string_aspect_ratios + errors_options = initialize_and_populate_error_options(options, attachable) errors_options[:width] = metadata[:width] errors_options[:height] = metadata[:height] + error_type = aspect_ratio_error_mapping add_error(record, attribute, error_type, **errors_options) false end @@ -80,13 +79,18 @@ def aspect_ratio_error_mapping NAMED_ASPECT_RATIOS.include?(aspect_ratio) ? :"aspect_ratio_not_#{aspect_ratio}" : :aspect_ratio_not_x_y end - def media_metadata_missing?(record, attribute, attachable, metadata) - return false if metadata[:width].to_i > 0 && metadata[:height].to_i > 0 + def media_metadata_present?(record, attribute, attachable, metadata) + return true if metadata[:width].to_i > 0 && metadata[:height].to_i > 0 + errors_options = initialize_and_populate_error_options(options, attachable) + add_error(record, attribute, :media_metadata_missing, **errors_options) + false + end + + def initialize_and_populate_error_options(options, attachable) errors_options = initialize_error_options(options, attachable) errors_options[:authorized_aspect_ratios] = string_aspect_ratios - add_error(record, attribute, :media_metadata_missing, **errors_options) - true + errors_options end def valid_square_aspect_ratio?(metadata) @@ -112,7 +116,7 @@ def valid_regex_aspect_ratio?(aspect_ratio, metadata) def ensure_at_least_one_validator_option return if AVAILABLE_CHECKS.any? { |argument| options.key?(argument) } - raise ArgumentError, 'You must pass either :with or :in to the validator' + raise ArgumentError, "You must pass either :with or :in to the validator" end def ensure_aspect_ratio_validity @@ -148,7 +152,7 @@ def string_aspect_ratios "#{x}:#{y}" end - end.join(', ') + end.join(", ") end end end diff --git a/lib/active_storage_validations/attached_validator.rb b/lib/active_storage_validations/attached_validator.rb index 1557837e..87f4665d 100644 --- a/lib/active_storage_validations/attached_validator.rb +++ b/lib/active_storage_validations/attached_validator.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_errorable' -require_relative 'shared/asv_symbolizable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_errorable" +require_relative "shared/asv_symbolizable" module ActiveStorageValidations class AttachedValidator < ActiveModel::EachValidator # :nodoc: diff --git a/lib/active_storage_validations/base_comparison_validator.rb b/lib/active_storage_validations/base_comparison_validator.rb index 554e4097..94a6d42d 100644 --- a/lib/active_storage_validations/base_comparison_validator.rb +++ b/lib/active_storage_validations/base_comparison_validator.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_errorable' -require_relative 'shared/asv_optionable' -require_relative 'shared/asv_symbolizable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_errorable" +require_relative "shared/asv_optionable" +require_relative "shared/asv_symbolizable" module ActiveStorageValidations class BaseComparisonValidator < ActiveModel::EachValidator # :nodoc: @@ -22,14 +22,14 @@ class BaseComparisonValidator < ActiveModel::EachValidator # :nodoc: def initialize(*args) if self.class == BaseComparisonValidator - raise NotImplementedError, 'BaseComparisonValidator is an abstract class and cannot be instantiated directly.' + raise NotImplementedError, "BaseComparisonValidator is an abstract class and cannot be instantiated directly." end super end def check_validity! unless AVAILABLE_CHECKS.one? { |argument| options.key?(argument) } - raise ArgumentError, 'You must pass either :less_than(_or_equal_to), :greater_than(_or_equal_to), or :between to the validator' + raise ArgumentError, "You must pass either :less_than(_or_equal_to), :greater_than(_or_equal_to), or :between to the validator" end end diff --git a/lib/active_storage_validations/content_type_validator.rb b/lib/active_storage_validations/content_type_validator.rb index 50f2a556..d4362080 100644 --- a/lib/active_storage_validations/content_type_validator.rb +++ b/lib/active_storage_validations/content_type_validator.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_analyzable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_errorable' -require_relative 'shared/asv_optionable' -require_relative 'shared/asv_symbolizable' -require_relative 'analyzer/content_type_analyzer' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_analyzable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_errorable" +require_relative "shared/asv_optionable" +require_relative "shared/asv_symbolizable" +require_relative "analyzer/content_type_analyzer" module ActiveStorageValidations class ContentTypeValidator < ActiveModel::EachValidator # :nodoc: @@ -142,7 +142,7 @@ def attachable_content_type_intersects_detected_content_type? end def enlarged_content_type(content_type) - [content_type, *parent_content_types(content_type)].compact.uniq + [ content_type, *parent_content_types(content_type) ].compact.uniq end def parent_content_types(content_type) @@ -170,12 +170,12 @@ def content_type_to_human_format(content_type) end .flatten .compact - .join(', ') + .join(", ") end def ensure_exactly_one_validator_option unless AVAILABLE_CHECKS.one? { |argument| options.key?(argument) } - raise ArgumentError, 'You must pass either :with or :in to the validator' + raise ArgumentError, "You must pass either :with or :in to the validator" end end @@ -211,7 +211,7 @@ def invalid_option?(content_type) end def invalid_content_type?(content_type) - if content_type == 'image/jpg' + if content_type == "image/jpg" raise ArgumentError, "'image/jpg' is not a valid content type, you should use 'image/jpeg' instead" end @@ -226,7 +226,7 @@ def all_available_marcel_content_types end def invalid_extension?(content_type) - Marcel::MimeType.for(extension: content_type.to_s) == 'application/octet-stream' + Marcel::MimeType.for(extension: content_type.to_s) == "application/octet-stream" end end end diff --git a/lib/active_storage_validations/dimension_validator.rb b/lib/active_storage_validations/dimension_validator.rb index 4f7b3ca9..54613e98 100644 --- a/lib/active_storage_validations/dimension_validator.rb +++ b/lib/active_storage_validations/dimension_validator.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_analyzable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_errorable' -require_relative 'shared/asv_optionable' -require_relative 'shared/asv_symbolizable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_analyzable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_errorable" +require_relative "shared/asv_optionable" +require_relative "shared/asv_symbolizable" module ActiveStorageValidations class DimensionValidator < ActiveModel::EachValidator # :nodoc @@ -48,7 +48,7 @@ def validate_each(record, attribute, _value) def ensure_at_least_one_validator_option unless AVAILABLE_CHECKS.any? { |argument| options.key?(argument) } - raise ArgumentError, 'You must pass either :width, :height, :min or :max to the validator' + raise ArgumentError, "You must pass either :width, :height, :min or :max to the validator" end end @@ -113,6 +113,7 @@ def validate_width_height(record, attribute, metadata, flat_options, errors_opti end end + # rubocop:disable Metrics/BlockLength %i[min max].each do |bound| define_method("validate_#{bound}") do |record, attribute, metadata, flat_options, errors_options| if send(:"invalid_#{bound}?", flat_options, metadata) diff --git a/lib/active_storage_validations/duration_validator.rb b/lib/active_storage_validations/duration_validator.rb index 32adec8d..4a015403 100644 --- a/lib/active_storage_validations/duration_validator.rb +++ b/lib/active_storage_validations/duration_validator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'base_comparison_validator' +require_relative "base_comparison_validator" module ActiveStorageValidations class DurationValidator < BaseComparisonValidator @@ -34,10 +34,8 @@ def validate_each(record, attribute, _value) errors_options = initialize_error_options(options, attachable) populate_error_options(errors_options, flat_options) - errors_options[:duration] = format_bound_value(duration) - keys = AVAILABLE_CHECKS & flat_options.keys - error_type = "duration_not_#{keys.first}".to_sym + error_type = set_error_type(flat_options) add_error(record, attribute, error_type, **errors_options) end @@ -51,5 +49,15 @@ def format_bound_value(value) custom_value = value == value.to_i ? value.to_i : value ActiveSupport::Duration.build(custom_value).inspect end + + def populate_error_options(errors_options, flat_options) + super + errors_options[:duration] = format_bound_value(duration) + end + + def set_error_type(flat_options) + keys = AVAILABLE_CHECKS & flat_options.keys + "duration_not_#{keys.first}".to_sym + end end end diff --git a/lib/active_storage_validations/extensors/asv_blob_metadatable.rb b/lib/active_storage_validations/extensors/asv_blob_metadatable.rb index 49cf5600..e37f38e9 100644 --- a/lib/active_storage_validations/extensors/asv_blob_metadatable.rb +++ b/lib/active_storage_validations/extensors/asv_blob_metadatable.rb @@ -14,15 +14,15 @@ module ASVBlobMetadatable # Because of how the metadata is stored, we need to convert the values from String # to Integer or Boolean. def active_storage_validations_metadata - metadata.dig('custom') - &.select { |key, _| key.to_s.start_with?('asv_') } - &.transform_keys { |key| key.to_s.delete_prefix('asv_') } + metadata.dig("custom") + &.select { |key, _| key.to_s.start_with?("asv_") } + &.transform_keys { |key| key.to_s.delete_prefix("asv_") } &.transform_values do |value| case value when /\A\d+\z/ then value.to_i when /\A\d+\.\d+\z/ then value.to_f - when 'true' then true - when 'false' then false + when "true" then true + when "false" then false else value end end || {} @@ -34,14 +34,14 @@ def active_storage_validations_metadata def merge_into_active_storage_validations_metadata(hash) aws_compatible_metadata = normalize_active_storage_validations_metadata_for_aws(hash) - metadata['custom'] ||= {} - metadata['custom'].merge!(aws_compatible_metadata) + metadata["custom"] ||= {} + metadata["custom"].merge!(aws_compatible_metadata) active_storage_validations_metadata end def normalize_active_storage_validations_metadata_for_aws(hash) - hash.transform_keys { |key, _| key.to_s.start_with?('asv_') ? key : "asv_#{key}" } + hash.transform_keys { |key, _| key.to_s.start_with?("asv_") ? key : "asv_#{key}" } .transform_values(&:to_s) end end diff --git a/lib/active_storage_validations/extensors/asv_marcelable.rb b/lib/active_storage_validations/extensors/asv_marcelable.rb index 686db02a..2085d8eb 100644 --- a/lib/active_storage_validations/extensors/asv_marcelable.rb +++ b/lib/active_storage_validations/extensors/asv_marcelable.rb @@ -9,4 +9,4 @@ Marcel::MimeType.extend "video/theora", parents: %(video/ogg) # Add empty content type -Marcel::MimeType.extend "inode/x-empty", extensions: %w(empty) +Marcel::MimeType.extend "inode/x-empty", extensions: %w[empty] diff --git a/lib/active_storage_validations/limit_validator.rb b/lib/active_storage_validations/limit_validator.rb index 8fbe5788..e6c1ae9f 100644 --- a/lib/active_storage_validations/limit_validator.rb +++ b/lib/active_storage_validations/limit_validator.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_errorable' -require_relative 'shared/asv_optionable' -require_relative 'shared/asv_symbolizable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_errorable" +require_relative "shared/asv_optionable" +require_relative "shared/asv_symbolizable" module ActiveStorageValidations class LimitValidator < ActiveModel::EachValidator # :nodoc: @@ -31,18 +31,8 @@ def validate_each(record, attribute, _value) return if files_count_valid?(count, flat_options) - errors_options = initialize_error_options(options) - errors_options[:min] = flat_options[:min] - errors_options[:max] = flat_options[:max] - errors_options[:count] = count - error_type = if flat_options[:min] && flat_options[:max] - :limit_out_of_range - elsif flat_options[:min] && count < flat_options[:min] - :limit_min_not_reached - else - :limit_max_exceeded - end - + errors_options = initialize_and_populate_error_options(options, attachable) + error_type = set_error_type(flat_options, count) add_error(record, attribute, error_type, **errors_options) end @@ -60,15 +50,15 @@ def files_count_valid?(count, flat_options) def ensure_at_least_one_validator_option unless AVAILABLE_CHECKS.any? { |argument| options.key?(argument) } - raise ArgumentError, 'You must pass either :max or :min to the validator' + raise ArgumentError, "You must pass either :max or :min to the validator" end end def ensure_arguments_validity return true if min_max_are_proc? || min_or_max_is_proc_and_other_not_present? - raise ArgumentError, 'You must pass integers to :min and :max' if min_or_max_defined_and_not_integer? - raise ArgumentError, 'You must pass a higher value to :max than to :min' if min_higher_than_max? + raise ArgumentError, "You must pass integers to :min and :max" if min_or_max_defined_and_not_integer? + raise ArgumentError, "You must pass a higher value to :max than to :min" if min_higher_than_max? end def min_max_are_proc? @@ -88,5 +78,23 @@ def min_or_max_defined_and_not_integer? def min_higher_than_max? options[:min] > options[:max] if options[:min].is_a?(Integer) && options[:max].is_a?(Integer) end + + def initialize_and_populate_error_options(options, attachable) + errors_options = initialize_error_options(options) + errors_options[:min] = flat_options[:min] + errors_options[:max] = flat_options[:max] + errors_options[:count] = count + errors_options + end + + def set_error_type(flat_options, count) + if flat_options[:min] && flat_options[:max] + :limit_out_of_range + elsif flat_options[:min] && count < flat_options[:min] + :limit_min_not_reached + else + :limit_max_exceeded + end + end end end diff --git a/lib/active_storage_validations/matchers.rb b/lib/active_storage_validations/matchers.rb index 13eb3922..c333151a 100644 --- a/lib/active_storage_validations/matchers.rb +++ b/lib/active_storage_validations/matchers.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'active_storage_validations/matchers/aspect_ratio_validator_matcher' -require 'active_storage_validations/matchers/attached_validator_matcher' -require 'active_storage_validations/matchers/processable_file_validator_matcher' -require 'active_storage_validations/matchers/limit_validator_matcher' -require 'active_storage_validations/matchers/content_type_validator_matcher' -require 'active_storage_validations/matchers/dimension_validator_matcher' -require 'active_storage_validations/matchers/duration_validator_matcher' -require 'active_storage_validations/matchers/size_validator_matcher' -require 'active_storage_validations/matchers/total_size_validator_matcher' +require "active_storage_validations/matchers/aspect_ratio_validator_matcher" +require "active_storage_validations/matchers/attached_validator_matcher" +require "active_storage_validations/matchers/processable_file_validator_matcher" +require "active_storage_validations/matchers/limit_validator_matcher" +require "active_storage_validations/matchers/content_type_validator_matcher" +require "active_storage_validations/matchers/dimension_validator_matcher" +require "active_storage_validations/matchers/duration_validator_matcher" +require "active_storage_validations/matchers/size_validator_matcher" +require "active_storage_validations/matchers/total_size_validator_matcher" module ActiveStorageValidations module Matchers @@ -22,7 +22,7 @@ def self.stub_method(object, method, result) RSpec::Mocks.allow_message(object, method) { result } yield else - raise 'Need either Minitest::Mock or RSpec::Mocks to run this validator matcher' + raise "Need either Minitest::Mock or RSpec::Mocks to run this validator matcher" end end diff --git a/lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb b/lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb index 00a51e73..db383f54 100644 --- a/lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/aspect_ratio_validator_matcher.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_allow_blankable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_contextable' -require_relative 'shared/asv_messageable' -require_relative 'shared/asv_rspecable' -require_relative 'shared/asv_validatable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_allow_blankable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_contextable" +require_relative "shared/asv_messageable" +require_relative "shared/asv_rspecable" +require_relative "shared/asv_validatable" module ActiveStorageValidations module Matchers @@ -101,17 +101,17 @@ def mock_dimensions_for(attachment, width, height) def valid_width_and_height_for(aspect_ratio) case aspect_ratio - when :square then [100, 100] - when :portrait then [100, 200] - when :landscape then [200, 100] + when :square then [ 100, 100 ] + when :portrait then [ 100, 200 ] + when :landscape then [ 200, 100 ] when validator_class::ASPECT_RATIO_REGEX aspect_ratio =~ validator_class::ASPECT_RATIO_REGEX x = Regexp.last_match(1).to_i y = Regexp.last_match(2).to_i - [100 * x, 100 * y] + [ 100 * x, 100 * y ] else - [-1, -1] + [ -1, -1 ] end end end diff --git a/lib/active_storage_validations/matchers/attached_validator_matcher.rb b/lib/active_storage_validations/matchers/attached_validator_matcher.rb index adac52b1..b9379c97 100644 --- a/lib/active_storage_validations/matchers/attached_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/attached_validator_matcher.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_contextable' -require_relative 'shared/asv_messageable' -require_relative 'shared/asv_rspecable' -require_relative 'shared/asv_validatable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_contextable" +require_relative "shared/asv_messageable" +require_relative "shared/asv_rspecable" +require_relative "shared/asv_validatable" module ActiveStorageValidations module Matchers diff --git a/lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb b/lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb index a83c3c67..36314a04 100644 --- a/lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/base_comparison_validator_matcher.rb @@ -3,13 +3,13 @@ # Big thank you to the paperclip validation matchers: # https://github.com/thoughtbot/paperclip/blob/v6.1.0/lib/paperclip/matchers/validate_attachment_size_matcher.rb -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_allow_blankable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_contextable' -require_relative 'shared/asv_messageable' -require_relative 'shared/asv_rspecable' -require_relative 'shared/asv_validatable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_allow_blankable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_contextable" +require_relative "shared/asv_messageable" +require_relative "shared/asv_rspecable" +require_relative "shared/asv_validatable" module ActiveStorageValidations module Matchers diff --git a/lib/active_storage_validations/matchers/content_type_validator_matcher.rb b/lib/active_storage_validations/matchers/content_type_validator_matcher.rb index 8b607475..9b15c39c 100644 --- a/lib/active_storage_validations/matchers/content_type_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/content_type_validator_matcher.rb @@ -3,13 +3,13 @@ # Big thank you to the paperclip validation matchers: # https://github.com/thoughtbot/paperclip/blob/v6.1.0/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_allow_blankable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_contextable' -require_relative 'shared/asv_messageable' -require_relative 'shared/asv_rspecable' -require_relative 'shared/asv_validatable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_allow_blankable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_contextable" +require_relative "shared/asv_messageable" +require_relative "shared/asv_rspecable" +require_relative "shared/asv_validatable" module ActiveStorageValidations module Matchers @@ -40,7 +40,7 @@ def description end def failure_message - message = ["is expected to validate the content types of :#{@attribute_name}"] + message = [ "is expected to validate the content types of :#{@attribute_name}" ] build_failure_message(message) message.join("\n") end @@ -122,14 +122,14 @@ def is_custom_message_valid? end def attach_invalid_content_type_file - @subject.public_send(@attribute_name).attach(attachment_for('fake/fake')) + @subject.public_send(@attribute_name).attach(attachment_for("fake/fake")) end def attachment_for(content_type) - suffix = Marcel::TYPE_EXTS[content_type.to_s]&.first || 'fake' + suffix = Marcel::TYPE_EXTS[content_type.to_s]&.first || "fake" { - io: Tempfile.new('.'), + io: Tempfile.new("."), filename: "test.#{suffix}", content_type: content_type } diff --git a/lib/active_storage_validations/matchers/dimension_validator_matcher.rb b/lib/active_storage_validations/matchers/dimension_validator_matcher.rb index 5d4e977b..8954e96e 100644 --- a/lib/active_storage_validations/matchers/dimension_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/dimension_validator_matcher.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_allow_blankable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_contextable' -require_relative 'shared/asv_messageable' -require_relative 'shared/asv_rspecable' -require_relative 'shared/asv_validatable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_allow_blankable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_contextable" +require_relative "shared/asv_messageable" +require_relative "shared/asv_rspecable" +require_relative "shared/asv_validatable" module ActiveStorageValidations module Matchers @@ -37,7 +37,7 @@ def description end def failure_message - message = ["is expected to validate dimensions of :#{@attribute_name}"] + message = [ "is expected to validate dimensions of :#{@attribute_name}" ] build_failure_message(message) message.join("\n") end diff --git a/lib/active_storage_validations/matchers/duration_validator_matcher.rb b/lib/active_storage_validations/matchers/duration_validator_matcher.rb index ee2f1125..80f7c717 100644 --- a/lib/active_storage_validations/matchers/duration_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/duration_validator_matcher.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'base_comparison_validator_matcher' +require_relative "base_comparison_validator_matcher" module ActiveStorageValidations module Matchers @@ -14,7 +14,7 @@ def description end def failure_message - message = ["is expected to validate file duration of :#{@attribute_name}"] + message = [ "is expected to validate file duration of :#{@attribute_name}" ] build_failure_message(message) message.join("\n") end diff --git a/lib/active_storage_validations/matchers/limit_validator_matcher.rb b/lib/active_storage_validations/matchers/limit_validator_matcher.rb index 62e30c00..0482ec61 100644 --- a/lib/active_storage_validations/matchers/limit_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/limit_validator_matcher.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_allow_blankable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_contextable' -require_relative 'shared/asv_messageable' -require_relative 'shared/asv_rspecable' -require_relative 'shared/asv_validatable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_allow_blankable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_contextable" +require_relative "shared/asv_messageable" +require_relative "shared/asv_rspecable" +require_relative "shared/asv_validatable" module ActiveStorageValidations module Matchers @@ -37,7 +37,7 @@ def description end def failure_message - message = ["is expected to validate limit file of :#{@attribute_name}"] + message = [ "is expected to validate limit file of :#{@attribute_name}" ] build_failure_message(message) message.join("\n") end diff --git a/lib/active_storage_validations/matchers/processable_file_validator_matcher.rb b/lib/active_storage_validations/matchers/processable_file_validator_matcher.rb index 2cd584f1..b7393973 100644 --- a/lib/active_storage_validations/matchers/processable_file_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/processable_file_validator_matcher.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_allow_blankable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_contextable' -require_relative 'shared/asv_messageable' -require_relative 'shared/asv_rspecable' -require_relative 'shared/asv_validatable' +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_allow_blankable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_contextable" +require_relative "shared/asv_messageable" +require_relative "shared/asv_rspecable" +require_relative "shared/asv_validatable" module ActiveStorageValidations module Matchers diff --git a/lib/active_storage_validations/matchers/shared/asv_active_storageable.rb b/lib/active_storage_validations/matchers/shared/asv_active_storageable.rb index 57cc578e..3f8df875 100644 --- a/lib/active_storage_validations/matchers/shared/asv_active_storageable.rb +++ b/lib/active_storage_validations/matchers/shared/asv_active_storageable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_support/concern' +require "active_support/concern" module ActiveStorageValidations module Matchers diff --git a/lib/active_storage_validations/matchers/shared/asv_allow_blankable.rb b/lib/active_storage_validations/matchers/shared/asv_allow_blankable.rb index 3048b41b..28622e1b 100644 --- a/lib/active_storage_validations/matchers/shared/asv_allow_blankable.rb +++ b/lib/active_storage_validations/matchers/shared/asv_allow_blankable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_support/concern' +require "active_support/concern" module ActiveStorageValidations module Matchers diff --git a/lib/active_storage_validations/matchers/shared/asv_attachable.rb b/lib/active_storage_validations/matchers/shared/asv_attachable.rb index 4bcf6133..63d37e59 100644 --- a/lib/active_storage_validations/matchers/shared/asv_attachable.rb +++ b/lib/active_storage_validations/matchers/shared/asv_attachable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_support/concern' +require "active_support/concern" module ActiveStorageValidations module Matchers @@ -38,29 +38,29 @@ def dummy_blob def dummy_file { io: io, - filename: 'test.png', - content_type: 'image/png' + filename: "test.png", + content_type: "image/png" } end def processable_image { io: StringIO.new(image_data), - filename: 'processable_image.png', - content_type: 'image/png' + filename: "processable_image.png", + content_type: "image/png" } end def not_processable_image { - io: Tempfile.new('.'), - filename: 'not_processable_image.txt', - content_type: 'text/plain' + io: Tempfile.new("."), + filename: "not_processable_image.txt", + content_type: "text/plain" } end def io - @io ||= Tempfile.new('Hello world!') + @io ||= Tempfile.new("Hello world!") end def image_data diff --git a/lib/active_storage_validations/matchers/shared/asv_contextable.rb b/lib/active_storage_validations/matchers/shared/asv_contextable.rb index 0a7f4de9..a7d98c57 100644 --- a/lib/active_storage_validations/matchers/shared/asv_contextable.rb +++ b/lib/active_storage_validations/matchers/shared/asv_contextable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_support/concern' +require "active_support/concern" module ActiveStorageValidations module Matchers @@ -21,8 +21,8 @@ def on(context) def is_context_valid? return true if !@context && attribute_validators.none? { |validator| validator.options[:on] } - raise ArgumentError, "This validator matcher needs the #on option to work since its validator has one" if !@context && attribute_validators.all? { |validator| validator.options[:on] } - raise ArgumentError, "This validator matcher option only allows a symbol or an array" if !(@context.is_a?(Symbol) || @context.is_a?(Array)) + ensure_context_present! + ensure_context_valid! if @context.is_a?(Array) (validator_contexts & @context.map(&:to_s)) == validator_contexts || raise_context_not_listed_error @@ -31,6 +31,14 @@ def is_context_valid? end end + def ensure_context_present! + raise ArgumentError, "This validator matcher needs the #on option to work since its validator has one" if !@context && attribute_validators.all? { |validator| validator.options[:on] } + end + + def ensure_context_valid! + raise ArgumentError, "This validator matcher option only allows a symbol or an array" if !(@context.is_a?(Symbol) || @context.is_a?(Array)) + end + def validator_contexts attribute_validators.map do |validator| case validator.options[:on] diff --git a/lib/active_storage_validations/matchers/shared/asv_messageable.rb b/lib/active_storage_validations/matchers/shared/asv_messageable.rb index feac24c9..100fb2ba 100644 --- a/lib/active_storage_validations/matchers/shared/asv_messageable.rb +++ b/lib/active_storage_validations/matchers/shared/asv_messageable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_support/concern' +require "active_support/concern" module ActiveStorageValidations module Matchers diff --git a/lib/active_storage_validations/matchers/shared/asv_rspecable.rb b/lib/active_storage_validations/matchers/shared/asv_rspecable.rb index 7a640c0b..3c69ec88 100644 --- a/lib/active_storage_validations/matchers/shared/asv_rspecable.rb +++ b/lib/active_storage_validations/matchers/shared/asv_rspecable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_support/concern' +require "active_support/concern" module ActiveStorageValidations module Matchers @@ -20,7 +20,7 @@ def failure_message end def failure_message_when_negated - failure_message.sub(/is expected to validate/, 'is expected not to validate') + failure_message.sub(/is expected to validate/, "is expected not to validate") end end end diff --git a/lib/active_storage_validations/matchers/shared/asv_validatable.rb b/lib/active_storage_validations/matchers/shared/asv_validatable.rb index 554ef167..a1c66745 100644 --- a/lib/active_storage_validations/matchers/shared/asv_validatable.rb +++ b/lib/active_storage_validations/matchers/shared/asv_validatable.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_support/concern' +require "active_support/concern" module ActiveStorageValidations module Matchers @@ -33,7 +33,7 @@ def available_errors end def validator_class - self.class.name.gsub(/::Matchers|Matcher/, '').constantize + self.class.name.gsub(/::Matchers|Matcher/, "").constantize end def attribute_validator diff --git a/lib/active_storage_validations/matchers/size_validator_matcher.rb b/lib/active_storage_validations/matchers/size_validator_matcher.rb index c13775b7..f612c17c 100644 --- a/lib/active_storage_validations/matchers/size_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/size_validator_matcher.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'base_comparison_validator_matcher' +require_relative "base_comparison_validator_matcher" module ActiveStorageValidations module Matchers @@ -14,7 +14,7 @@ def description end def failure_message - message = ["is expected to validate file size of :#{@attribute_name}"] + message = [ "is expected to validate file size of :#{@attribute_name}" ] build_failure_message(message) message.join("\n") end diff --git a/lib/active_storage_validations/matchers/total_size_validator_matcher.rb b/lib/active_storage_validations/matchers/total_size_validator_matcher.rb index 0eac1069..4c5492e8 100644 --- a/lib/active_storage_validations/matchers/total_size_validator_matcher.rb +++ b/lib/active_storage_validations/matchers/total_size_validator_matcher.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'base_comparison_validator_matcher' +require_relative "base_comparison_validator_matcher" module ActiveStorageValidations module Matchers @@ -14,7 +14,7 @@ def description end def failure_message - message = ["is expected to validate total file size of :#{@attribute_name}"] + message = [ "is expected to validate total file size of :#{@attribute_name}" ] build_failure_message(message) message.join("\n") end @@ -23,7 +23,7 @@ def failure_message def attach_file # has_many_attached relation - @subject.public_send(@attribute_name).attach([dummy_blob]) + @subject.public_send(@attribute_name).attach([ dummy_blob ]) @subject.public_send(@attribute_name) end diff --git a/lib/active_storage_validations/processable_file_validator.rb b/lib/active_storage_validations/processable_file_validator.rb index a3f492c6..5ab1645d 100644 --- a/lib/active_storage_validations/processable_file_validator.rb +++ b/lib/active_storage_validations/processable_file_validator.rb @@ -1,37 +1,37 @@ -# frozen_string_literal: true - -require_relative 'shared/asv_active_storageable' -require_relative 'shared/asv_analyzable' -require_relative 'shared/asv_attachable' -require_relative 'shared/asv_errorable' -require_relative 'shared/asv_symbolizable' - -module ActiveStorageValidations - class ProcessableFileValidator < ActiveModel::EachValidator # :nodoc - include ASVActiveStorageable - include ASVAnalyzable - include ASVAttachable - include ASVErrorable - include ASVSymbolizable - - ERROR_TYPES = %i[ - file_not_processable - ].freeze - METADATA_KEYS = %i[].freeze - - def validate_each(record, attribute, _value) - return if no_attachments?(record, attribute) - - validate_changed_files_from_metadata(record, attribute, METADATA_KEYS) - end - - private - - def is_valid?(record, attribute, attachable, metadata) - return if !metadata.empty? - - errors_options = initialize_error_options(options, attachable) - add_error(record, attribute, ERROR_TYPES.first , **errors_options) - end - end -end +# frozen_string_literal: true + +require_relative "shared/asv_active_storageable" +require_relative "shared/asv_analyzable" +require_relative "shared/asv_attachable" +require_relative "shared/asv_errorable" +require_relative "shared/asv_symbolizable" + +module ActiveStorageValidations + class ProcessableFileValidator < ActiveModel::EachValidator # :nodoc + include ASVActiveStorageable + include ASVAnalyzable + include ASVAttachable + include ASVErrorable + include ASVSymbolizable + + ERROR_TYPES = %i[ + file_not_processable + ].freeze + METADATA_KEYS = %i[].freeze + + def validate_each(record, attribute, _value) + return if no_attachments?(record, attribute) + + validate_changed_files_from_metadata(record, attribute, METADATA_KEYS) + end + + private + + def is_valid?(record, attribute, attachable, metadata) + return if !metadata.empty? + + errors_options = initialize_error_options(options, attachable) + add_error(record, attribute, ERROR_TYPES.first, **errors_options) + end + end +end diff --git a/lib/active_storage_validations/railtie.rb b/lib/active_storage_validations/railtie.rb index a63e79dd..09c8d76b 100644 --- a/lib/active_storage_validations/railtie.rb +++ b/lib/active_storage_validations/railtie.rb @@ -2,13 +2,13 @@ module ActiveStorageValidations class Railtie < ::Rails::Railtie - initializer 'active_storage_validations.configure', after: :load_config_initializers do + initializer "active_storage_validations.configure", after: :load_config_initializers do ActiveSupport.on_load(:active_record) do send :include, ActiveStorageValidations end end - initializer 'active_storage_validations.extend_active_storage_blob' do + initializer "active_storage_validations.extend_active_storage_blob" do ActiveSupport.on_load(:active_storage_blob) do include(ActiveStorageValidations::ASVBlobMetadatable) end diff --git a/lib/active_storage_validations/shared/asv_attachable.rb b/lib/active_storage_validations/shared/asv_attachable.rb index af2967cf..3f395537 100644 --- a/lib/active_storage_validations/shared/asv_attachable.rb +++ b/lib/active_storage_validations/shared/asv_attachable.rb @@ -32,11 +32,7 @@ def validate_changed_files_from_metadata(record, attribute, metadata_keys) # Some file could be passed several times, we just need to perform the # analysis once on the file, therefore the use of #uniq. def attachables_and_blobs(record, attribute) - changes = if record.public_send(attribute).is_a?(ActiveStorage::Attached::One) - record.attachment_changes[attribute.to_s].presence || record.public_send(attribute) - else - record.attachment_changes[attribute.to_s] - end + changes = changes_for(record, attribute) return to_enum(:attachables_and_blobs, record, attribute) if changes.blank? || !block_given? @@ -49,7 +45,16 @@ def attachables_and_blobs(record, attribute) end end + def changes_for(record, attribute) + if record.public_send(attribute).is_a?(ActiveStorage::Attached::One) + record.attachment_changes[attribute.to_s].presence || record.public_send(attribute) + else + record.attachment_changes[attribute.to_s] + end + end + # Retrieve the full declared content_type from attachable. + # rubocop:disable Metrics/MethodLength def full_attachable_content_type(attachable) case attachable when ActiveStorage::Blob @@ -102,28 +107,30 @@ def attachable_media_type(attachable) end # Retrieve the io from attachable. + # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/AbcSize def attachable_io(attachable, max_byte_size: nil) io = case attachable - when ActiveStorage::Blob - (max_byte_size && supports_blob_download_chunk?) ? attachable.download_chunk(0...max_byte_size) : attachable.download - when ActionDispatch::Http::UploadedFile - max_byte_size ? attachable.read(max_byte_size) : attachable.read - when Rack::Test::UploadedFile - max_byte_size ? attachable.read(max_byte_size) : attachable.read - when String - blob = ActiveStorage::Blob.find_signed!(attachable) - (max_byte_size && supports_blob_download_chunk?) ? blob.download_chunk(0...max_byte_size) : blob.download - when Hash - max_byte_size ? attachable[:io].read(max_byte_size) : attachable[:io].read - when File - raise_rails_like_error(attachable) unless supports_file_attachment? - max_byte_size ? attachable.read(max_byte_size) : attachable.read - when Pathname - raise_rails_like_error(attachable) unless supports_pathname_attachment? - max_byte_size ? attachable.read(max_byte_size) : attachable.read - else - raise_rails_like_error(attachable) - end + when ActiveStorage::Blob + (max_byte_size && supports_blob_download_chunk?) ? attachable.download_chunk(0...max_byte_size) : attachable.download + when ActionDispatch::Http::UploadedFile + max_byte_size ? attachable.read(max_byte_size) : attachable.read + when Rack::Test::UploadedFile + max_byte_size ? attachable.read(max_byte_size) : attachable.read + when String + blob = ActiveStorage::Blob.find_signed!(attachable) + (max_byte_size && supports_blob_download_chunk?) ? blob.download_chunk(0...max_byte_size) : blob.download + when Hash + max_byte_size ? attachable[:io].read(max_byte_size) : attachable[:io].read + when File + raise_rails_like_error(attachable) unless supports_file_attachment? + max_byte_size ? attachable.read(max_byte_size) : attachable.read + when Pathname + raise_rails_like_error(attachable) unless supports_pathname_attachment? + max_byte_size ? attachable.read(max_byte_size) : attachable.read + else + raise_rails_like_error(attachable) + end rewind_attachable_io(attachable) io @@ -150,6 +157,7 @@ def rewind_attachable_io(attachable) end # Retrieve the declared filename from attachable. + # rubocop:disable Metrics/MethodLength def attachable_filename(attachable) case attachable when ActiveStorage::Blob @@ -185,7 +193,7 @@ def raise_rails_like_error(attachable) # # https://github.com/rails/rails/blob/7-1-stable/activestorage/CHANGELOG.md#rails-710rc1-september-27-2023 def supports_file_attachment? - Rails.gem_version >= Gem::Version.new('7.1.0.rc1') + Rails.gem_version >= Gem::Version.new("7.1.0.rc1") end alias :supports_pathname_attachment? :supports_file_attachment? @@ -193,7 +201,7 @@ def supports_file_attachment? # # https://github.com/rails/rails/blob/7-0-stable/activestorage/CHANGELOG.md#rails-700alpha1-september-15-2021 def supports_blob_download_chunk? - Rails.gem_version >= Gem::Version.new('7.0.0.alpha1') + Rails.gem_version >= Gem::Version.new("7.0.0.alpha1") end # Retrieve the content_type from the file name only diff --git a/lib/active_storage_validations/shared/asv_errorable.rb b/lib/active_storage_validations/shared/asv_errorable.rb index 88097dca..e003147b 100644 --- a/lib/active_storage_validations/shared/asv_errorable.rb +++ b/lib/active_storage_validations/shared/asv_errorable.rb @@ -5,7 +5,7 @@ module ASVErrorable extend ActiveSupport::Concern def initialize_error_options(options, file = nil) - not_explicitly_written_options = %i(with in) + not_explicitly_written_options = %i[with in] curated_options = options.except(*not_explicitly_written_options) active_storage_validations_options = { diff --git a/lib/active_storage_validations/shared/asv_symbolizable.rb b/lib/active_storage_validations/shared/asv_symbolizable.rb index c423907d..b8b36627 100644 --- a/lib/active_storage_validations/shared/asv_symbolizable.rb +++ b/lib/active_storage_validations/shared/asv_symbolizable.rb @@ -7,7 +7,7 @@ module ASVSymbolizable class_methods do def to_sym validator_class = self.name.split("::").last - validator_class.sub(/Validator/, '').underscore.to_sym + validator_class.sub(/Validator/, "").underscore.to_sym end end end diff --git a/lib/active_storage_validations/size_validator.rb b/lib/active_storage_validations/size_validator.rb index 7380be1c..52b0f2c0 100644 --- a/lib/active_storage_validations/size_validator.rb +++ b/lib/active_storage_validations/size_validator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'base_comparison_validator' +require_relative "base_comparison_validator" module ActiveStorageValidations class SizeValidator < BaseComparisonValidator diff --git a/lib/active_storage_validations/total_size_validator.rb b/lib/active_storage_validations/total_size_validator.rb index 404fd500..cd16f151 100644 --- a/lib/active_storage_validations/total_size_validator.rb +++ b/lib/active_storage_validations/total_size_validator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'base_comparison_validator' +require_relative "base_comparison_validator" module ActiveStorageValidations class TotalSizeValidator < BaseComparisonValidator @@ -40,7 +40,7 @@ def custom_check_validity!(record, attribute) # We can't perform this check in the #check_validity! hook because we do not # have enough data (only options & attributes are accessible) unless record.send(attribute).is_a?(ActiveStorage::Attached::Many) - raise ArgumentError, 'This validator is only available for has_many_attached relations' + raise ArgumentError, "This validator is only available for has_many_attached relations" end end diff --git a/lib/active_storage_validations/version.rb b/lib/active_storage_validations/version.rb index 9d4803e9..2916cae5 100755 --- a/lib/active_storage_validations/version.rb +++ b/lib/active_storage_validations/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ActiveStorageValidations - VERSION = '2.0.2' + VERSION = "2.0.2" end diff --git a/test/active_storage_validations_test.rb b/test/active_storage_validations_test.rb index 298fb1c2..657a1a9c 100644 --- a/test/active_storage_validations_test.rb +++ b/test/active_storage_validations_test.rb @@ -1,28 +1,28 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class ActiveStorageValidations::Test < ActiveSupport::TestCase - test 'validates presence' do - u = User.new(name: 'John Smith') - assert !u.valid? - assert_equal u.errors.full_messages, ["Avatar must not be blank", "Photos can't be blank", "Proc avatar must not be blank", "Proc photos can't be blank"] + test "validates presence" do + u = User.new(name: "John Smith") + assert_not u.valid? + assert_equal u.errors.full_messages, [ "Avatar must not be blank", "Photos can't be blank", "Proc avatar must not be blank", "Proc photos can't be blank" ] - u = User.new(name: 'John Smith') + u = User.new(name: "John Smith") u.avatar.attach(image_150x150_file) u.proc_avatar.attach(image_150x150_file) - assert !u.valid? - assert_equal u.errors.full_messages, ["Photos can't be blank", "Proc photos can't be blank"] + assert_not u.valid? + assert_equal u.errors.full_messages, [ "Photos can't be blank", "Proc photos can't be blank" ] - u = User.new(name: 'John Smith') + u = User.new(name: "John Smith") u.photos.attach(image_150x150_file) u.proc_photos.attach(image_150x150_file) - assert !u.valid? - assert_equal u.errors.full_messages, ["Avatar must not be blank", "Proc avatar must not be blank"] + assert_not u.valid? + assert_equal u.errors.full_messages, [ "Avatar must not be blank", "Proc avatar must not be blank" ] end - test 'validates content type' do - u = User.new(name: 'John Smith') + test "validates content type" do + u = User.new(name: "John Smith") u.avatar.attach(image_150x150_file) u.proc_avatar.attach(image_150x150_file) u.image_regex.attach(image_150x150_file) @@ -30,10 +30,10 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase u.photos.attach(bad_dummy_file) u.proc_photos.attach(bad_dummy_file) u.video.attach(video_file) - assert !u.valid? - assert_equal u.errors.full_messages, ['Photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)', 'Proc photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)'] + assert_not u.valid? + assert_equal u.errors.full_messages, [ 'Photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)', 'Proc photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)' ] - u = User.new(name: 'John Smith') + u = User.new(name: "John Smith") u.avatar.attach(bad_dummy_file) u.proc_avatar.attach(bad_dummy_file) u.image_regex.attach(image_150x150_file) @@ -41,31 +41,31 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase u.photos.attach(image_150x150_file) u.proc_photos.attach(image_150x150_file) u.video.attach(video_file) - assert !u.valid? - assert_equal u.errors.full_messages, ['Avatar has an invalid content type (authorized content type is PNG)', 'Proc avatar has an invalid content type (authorized content type is PNG)'] + assert_not u.valid? + assert_equal u.errors.full_messages, [ "Avatar has an invalid content type (authorized content type is PNG)", "Proc avatar has an invalid content type (authorized content type is PNG)" ] assert_equal u.errors.details, avatar: [ { error: :content_type_invalid, validator_type: :content_type, - authorized_human_content_types: 'PNG', - content_type: 'text/plain', - human_content_type: 'TXT', + authorized_human_content_types: "PNG", + content_type: "text/plain", + human_content_type: "TXT", count: 1, - filename: 'apple-touch-icon.png' + filename: "apple-touch-icon.png" } ], proc_avatar: [ { error: :content_type_invalid, validator_type: :content_type, - authorized_human_content_types: 'PNG', - content_type: 'text/plain', - human_content_type: 'TXT', + authorized_human_content_types: "PNG", + content_type: "text/plain", + human_content_type: "TXT", count: 1, - filename: 'apple-touch-icon.png' + filename: "apple-touch-icon.png" } ] - u = User.new(name: 'John Smith') + u = User.new(name: "John Smith") u.avatar.attach(image_150x150_file) u.proc_avatar.attach(image_150x150_file) u.image_regex.attach(image_150x150_file) @@ -75,7 +75,7 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase u.video.attach(video_file) assert u.valid? - u = User.new(name: 'John Smith') + u = User.new(name: "John Smith") u.avatar.attach(image_150x150_file) u.proc_avatar.attach(image_150x150_file) u.image_regex.attach(bad_dummy_file) @@ -83,10 +83,10 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase u.photos.attach(image_150x150_file) u.proc_photos.attach(image_150x150_file) u.video.attach(video_file) - assert !u.valid? - assert_equal u.errors.full_messages, ['Image regex has an invalid content type (authorized content type is \\Aimage/.*\\z)', 'Proc image regex has an invalid content type (authorized content type is \\Aimage/.*\\z)'] + assert_not u.valid? + assert_equal u.errors.full_messages, [ 'Image regex has an invalid content type (authorized content type is \\Aimage/.*\\z)', 'Proc image regex has an invalid content type (authorized content type is \\Aimage/.*\\z)' ] - u = User.new(name: 'John Smith') + u = User.new(name: "John Smith") u.avatar.attach(bad_dummy_file) u.proc_avatar.attach(bad_dummy_file) u.image_regex.attach(bad_dummy_file) @@ -94,10 +94,10 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase u.photos.attach(bad_dummy_file) u.proc_photos.attach(bad_dummy_file) u.video.attach(video_file) - assert !u.valid? - assert_equal u.errors.full_messages, ['Avatar has an invalid content type (authorized content type is PNG)', 'Photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)', 'Image regex has an invalid content type (authorized content type is \\Aimage/.*\\z)', 'Proc avatar has an invalid content type (authorized content type is PNG)', 'Proc photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)', 'Proc image regex has an invalid content type (authorized content type is \\Aimage/.*\\z)'] + assert_not u.valid? + assert_equal u.errors.full_messages, [ "Avatar has an invalid content type (authorized content type is PNG)", 'Photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)', 'Image regex has an invalid content type (authorized content type is \\Aimage/.*\\z)', "Proc avatar has an invalid content type (authorized content type is PNG)", 'Proc photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)', 'Proc image regex has an invalid content type (authorized content type is \\Aimage/.*\\z)' ] - u = User.new(name: 'Peter Griffin') + u = User.new(name: "Peter Griffin") u.avatar.attach(image_150x150_file) u.proc_avatar.attach(image_150x150_file) u.photos.attach(image_150x150_file) @@ -107,86 +107,86 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase assert u.valid? assert_equal u.errors.full_messages, [] - u = User.new(name: 'Peter Griffin') + u = User.new(name: "Peter Griffin") u.avatar.attach(bad_dummy_file) u.proc_avatar.attach(bad_dummy_file) u.photos.attach(bad_dummy_file) u.proc_photos.attach(image_150x150_file) u.conditional_image_2.attach(bad_dummy_file) u.video.attach(video_file) - assert !u.valid? - assert_equal u.errors.full_messages, ["Avatar has an invalid content type (authorized content type is PNG)", "Photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)", "Conditional image 2 has an invalid content type (authorized content type is \\Aimage/.*\\z)", "Proc avatar has an invalid content type (authorized content type is PNG)"] + assert_not u.valid? + assert_equal u.errors.full_messages, [ "Avatar has an invalid content type (authorized content type is PNG)", "Photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)", "Conditional image 2 has an invalid content type (authorized content type is \\Aimage/.*\\z)", "Proc avatar has an invalid content type (authorized content type is PNG)" ] end # trying to attach webp file with PNG extension, but real content type is detected - test 'webp content type 2' do - u = User.new(name: 'John Smith') + test "webp content type 2" do + u = User.new(name: "John Smith") u.avatar.attach(webp_file) u.proc_avatar.attach(webp_file) u.image_regex.attach(webp_file) u.proc_image_regex.attach(webp_file) u.photos.attach(webp_file) u.proc_photos.attach(webp_file) - assert !u.valid? - assert_equal u.errors.full_messages, ['Avatar has an invalid content type (authorized content type is PNG)', 'Photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)', 'Proc avatar has an invalid content type (authorized content type is PNG)', 'Proc photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)'] + assert_not u.valid? + assert_equal u.errors.full_messages, [ "Avatar has an invalid content type (authorized content type is PNG)", 'Photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)', "Proc avatar has an invalid content type (authorized content type is PNG)", 'Proc photos has an invalid content type (authorized content types are PNG, JPG, \\A.*/pdf\\z)' ] end - test 'validates microsoft office document' do + test "validates microsoft office document" do d = Document.new d.attachment.attach(docx_file) d.proc_attachment.attach(docx_file) assert d.valid? end - test 'validates microsoft office xlsx' do + test "validates microsoft office xlsx" do d = Document.new d.attachment.attach(xlsx_file) d.proc_attachment.attach(xlsx_file) assert d.valid? end - test 'validates apple office document' do + test "validates apple office document" do d = Document.new d.attachment.attach(pages_file) d.proc_attachment.attach(pages_file) assert d.valid? end - test 'validates apple office numbers' do + test "validates apple office numbers" do d = Document.new d.attachment.attach(numbers_file) d.proc_attachment.attach(numbers_file) assert d.valid? end - test 'validates archived content_type' do + test "validates archived content_type" do d = Document.new d.file.attach(tar_file) d.proc_file.attach(tar_file) assert d.valid? end - test 'validates maximum number of files' do - e = Project.new(title: 'Death Star') - e.documents.attach([pdf_file, pdf_file, pdf_file, pdf_file]) - e.proc_documents.attach([pdf_file, pdf_file, pdf_file, pdf_file]) - assert !e.valid? - assert_equal ['Documents total number of files must be between 1 and 3 files (there are 4 files attached)', 'Proc documents total number of files must be between 1 and 3 files (there are 4 files attached)'], e.errors.full_messages + test "validates maximum number of files" do + e = Project.new(title: "Death Star") + e.documents.attach([ pdf_file, pdf_file, pdf_file, pdf_file ]) + e.proc_documents.attach([ pdf_file, pdf_file, pdf_file, pdf_file ]) + assert_not e.valid? + assert_equal [ "Documents total number of files must be between 1 and 3 files (there are 4 files attached)", "Proc documents total number of files must be between 1 and 3 files (there are 4 files attached)" ], e.errors.full_messages end - test 'validates minimum number of files' do - e = Project.new(title: 'Death Star') + test "validates minimum number of files" do + e = Project.new(title: "Death Star") e.proc_documents.attach(pdf_file) - assert !e.valid? - assert_equal ["Documents no files attached (must have between 1 and 3 files)"], e.errors.full_messages + assert_not e.valid? + assert_equal [ "Documents no files attached (must have between 1 and 3 files)" ], e.errors.full_messages end - test 'validates number of files' do - la = LimitAttachment.create(name: 'klingon') - la.files.attach([pdf_file, pdf_file, pdf_file, pdf_file, pdf_file, pdf_file]) - la.proc_files.attach([pdf_file, pdf_file, pdf_file, pdf_file, pdf_file, pdf_file]) + test "validates number of files" do + la = LimitAttachment.create(name: "klingon") + la.files.attach([ pdf_file, pdf_file, pdf_file, pdf_file, pdf_file, pdf_file ]) + la.proc_files.attach([ pdf_file, pdf_file, pdf_file, pdf_file, pdf_file, pdf_file ]) - assert !la.valid? + assert_not la.valid? assert_equal 6, la.files.count assert_equal 6, la.proc_files.count @@ -194,16 +194,16 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase assert_equal 0, la.files_blobs.count assert_equal 0, la.proc_files_blobs.count - assert_equal ['Files too many files attached (maximum is 4 files, got 6)', 'Proc files too many files attached (maximum is 4 files, got 6)'], la.errors.full_messages + assert_equal [ "Files too many files attached (maximum is 4 files, got 6)", "Proc files too many files attached (maximum is 4 files, got 6)" ], la.errors.full_messages - assert !la.valid? - assert_equal ['Files too many files attached (maximum is 4 files, got 6)', 'Proc files too many files attached (maximum is 4 files, got 6)'], la.errors.full_messages + assert_not la.valid? + assert_equal [ "Files too many files attached (maximum is 4 files, got 6)", "Proc files too many files attached (maximum is 4 files, got 6)" ], la.errors.full_messages end - test 'validates number of files v2' do - la = LimitAttachment.create(name: 'klingon') - la.files.attach([pdf_file, pdf_file, pdf_file]) - la.proc_files.attach([pdf_file, pdf_file, pdf_file]) + test "validates number of files v2" do + la = LimitAttachment.create(name: "klingon") + la.files.attach([ pdf_file, pdf_file, pdf_file ]) + la.proc_files.attach([ pdf_file, pdf_file, pdf_file ]) assert la.valid? assert_equal 3, la.files.count @@ -222,23 +222,23 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase assert_equal 2, la.proc_files_blobs.count end - test 'validates number of files v3' do - la = LimitAttachment.create(name: 'klingon') - la.files.attach([pdf_file, pdf_file, pdf_file, pdf_file, pdf_file]) - la.proc_files.attach([pdf_file, pdf_file, pdf_file, pdf_file, pdf_file]) + test "validates number of files v3" do + la = LimitAttachment.create(name: "klingon") + la.files.attach([ pdf_file, pdf_file, pdf_file, pdf_file, pdf_file ]) + la.proc_files.attach([ pdf_file, pdf_file, pdf_file, pdf_file, pdf_file ]) - assert !la.valid? + assert_not la.valid? assert_equal 5, la.files.count assert_equal 5, la.proc_files.count - assert !la.save + assert_not la.save end - test 'dimensions and is image' do + test "dimensions and is image" do e = OnlyImage.new e.image.attach(html_file) e.proc_image.attach(html_file) - assert !e.valid? - assert_equal ["Image is not a valid media file", "Image is not a valid media file", "Image has an invalid content type (authorized content types are PNG, JPG)", "Proc image is not a valid media file", "Proc image is not a valid media file", "Proc image has an invalid content type (authorized content types are PNG, JPG)"], e.errors.full_messages + assert_not e.valid? + assert_equal [ "Image is not a valid media file", "Image is not a valid media file", "Image has an invalid content type (authorized content types are PNG, JPG)", "Proc image is not a valid media file", "Proc image is not a valid media file", "Proc image has an invalid content type (authorized content types are PNG, JPG)" ], e.errors.full_messages e = OnlyImage.new e.image.attach(image_1920x1080_file) @@ -249,15 +249,15 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase e = OnlyImage.new e.image.attach(pdf_file) e.proc_image.attach(pdf_file) - assert !e.valid? + assert_not e.valid? assert e.errors.full_messages.include?("Image has an invalid content type (authorized content types are PNG, JPG)") e = OnlyImage.new e.image.attach(image_1920x1080_file) e.proc_image.attach(image_1920x1080_file) e.another_image.attach(tar_file_with_image_content_type) - assert !e.valid? - assert_equal ["Another image is not identified as a valid media file"], e.errors.full_messages + assert_not e.valid? + assert_equal [ "Another image is not identified as a valid media file" ], e.errors.full_messages e = OnlyImage.new e.image.attach(image_1920x1080_file) @@ -270,7 +270,7 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase raise ex end - test 'dimensions with attached StringIO' do + test "dimensions with attached StringIO" do e = OnlyImage.new e.image.attach(image_string_io) e.proc_image.attach(image_string_io) @@ -279,16 +279,16 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase assert e.valid? end - test 'dimensions test' do - e = Project.new(title: 'Death Star') + test "dimensions test" do + e = Project.new(title: "Death Star") e.dimension_exact.attach(html_file) e.documents.attach(pdf_file) e.proc_documents.attach(pdf_file) e.proc_dimension_exact.attach(html_file) - assert !e.valid? - assert_equal ['Dimension exact is not a valid media file', 'Proc dimension exact is not a valid media file'], e.errors.full_messages + assert_not e.valid? + assert_equal [ "Dimension exact is not a valid media file", "Proc dimension exact is not a valid media file" ], e.errors.full_messages - e = Project.new(title: 'Death Star') + e = Project.new(title: "Death Star") e.documents.attach(pdf_file) e.proc_documents.attach(pdf_file) e.documents.attach(pdf_file) @@ -296,56 +296,56 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase e.valid? assert e.valid? - e = Project.new(title: 'Death Star') + e = Project.new(title: "Death Star") e.documents.attach(pdf_file) e.proc_documents.attach(pdf_file) e.dimension_exact.attach(image_150x150_file) # e.proc_dimension_exact.attach(image_150x150_file) - assert e.valid?, 'Dimension exact: width and height must be equal to 150 x 150 pixel.' + assert e.valid?, "Dimension exact: width and height must be equal to 150 x 150 pixel." - e = Project.new(title: 'Death Star') + e = Project.new(title: "Death Star") e.documents.attach(pdf_file) e.proc_documents.attach(pdf_file) e.dimension_range.attach(image_800x600_file) e.proc_dimension_range.attach(image_800x600_file) - assert e.valid?, 'Dimension range: width and height must be greater than or equal to 800 x 600 pixel.' + assert e.valid?, "Dimension range: width and height must be greater than or equal to 800 x 600 pixel." - e = Project.new(title: 'Death Star') + e = Project.new(title: "Death Star") e.documents.attach(pdf_file) e.proc_documents.attach(pdf_file) e.dimension_range.attach(image_1200x900_file) e.proc_dimension_range.attach(image_1200x900_file) - assert e.valid?, 'Dimension range: width and height must be less than or equal to 1200 x 900 pixel.' + assert e.valid?, "Dimension range: width and height must be less than or equal to 1200 x 900 pixel." - e = Project.new(title: 'Death Star') + e = Project.new(title: "Death Star") e.documents.attach(pdf_file) e.proc_documents.attach(pdf_file) e.dimension_min.attach(image_800x600_file) e.proc_dimension_min.attach(image_800x600_file) - assert e.valid?, 'Dimension min: width and height must be greater than or equal to 800 x 600 pixel.' + assert e.valid?, "Dimension min: width and height must be greater than or equal to 800 x 600 pixel." - e = Project.new(title: 'Death Star') + e = Project.new(title: "Death Star") e.documents.attach(pdf_file) e.proc_documents.attach(pdf_file) e.dimension_max.attach(image_1200x900_file) e.proc_dimension_max.attach(image_1200x900_file) - assert e.valid?, 'Dimension max: width and height must be greater than or equal to 1200 x 900 pixel.' + assert e.valid?, "Dimension max: width and height must be greater than or equal to 1200 x 900 pixel." - e = Project.new(title: 'Death Star') + e = Project.new(title: "Death Star") e.documents.attach(pdf_file) e.proc_documents.attach(pdf_file) - e.dimension_images.attach([image_800x600_file, image_1200x900_file]) - e.proc_dimension_images.attach([image_800x600_file, image_1200x900_file]) - assert e.valid?, 'Dimension many: width and height must be between or equal to 800 x 600 and 1200 x 900 pixel.' + e.dimension_images.attach([ image_800x600_file, image_1200x900_file ]) + e.proc_dimension_images.attach([ image_800x600_file, image_1200x900_file ]) + assert e.valid?, "Dimension many: width and height must be between or equal to 800 x 600 and 1200 x 900 pixel." - e = Project.new(title: 'Death Star') + e = Project.new(title: "Death Star") e.documents.attach(pdf_file) e.proc_documents.attach(pdf_file) - e.dimension_images.attach([image_800x600_file]) - e.proc_dimension_images.attach([image_800x600_file]) + e.dimension_images.attach([ image_800x600_file ]) + e.proc_dimension_images.attach([ image_800x600_file ]) e.save! - e.dimension_images.attach([image_800x600_file]) - e.proc_dimension_images.attach([image_800x600_file]) + e.dimension_images.attach([ image_800x600_file ]) + e.proc_dimension_images.attach([ image_800x600_file ]) e.title = "Changed" e.save! @@ -369,109 +369,115 @@ class ActiveStorageValidations::Test < ActiveSupport::TestCase raise ex end - test 'all dimension validation errors are shown together' do + test "all dimension validation errors are shown together" do # image dimensions are lower than the specified range - project = Project.new(title: 'Death Star') + project = Project.new(title: "Death Star") project.dimension_range.attach(image_700x500_file) assert_not project.valid? - assert_includes project.errors.full_messages, 'Dimension range width is not included between 800 and 1200 pixel' - assert_includes project.errors.full_messages, 'Dimension range height is not included between 600 and 900 pixel' + assert_includes project.errors.full_messages, "Dimension range width is not included between 800 and 1200 pixel" + assert_includes project.errors.full_messages, "Dimension range height is not included between 600 and 900 pixel" - project = Project.new(title: 'Death Star') - project.dimension_images.attach([image_700x500_file]) + project = Project.new(title: "Death Star") + project.dimension_images.attach([ image_700x500_file ]) assert_not project.valid? - assert_includes project.errors.full_messages, 'Dimension images width must be greater than or equal to 800 pixel' - assert_includes project.errors.full_messages, 'Dimension images height must be greater than or equal to 600 pixel' + assert_includes project.errors.full_messages, "Dimension images width must be greater than or equal to 800 pixel" + assert_includes project.errors.full_messages, "Dimension images height must be greater than or equal to 600 pixel" # image dimensions are greater than the specified range - project = Project.new(title: 'Death Star') + project = Project.new(title: "Death Star") project.dimension_range.attach(image_1300x1000_file) assert_not project.valid? - assert_includes project.errors.full_messages, 'Dimension range width is not included between 800 and 1200 pixel' - assert_includes project.errors.full_messages, 'Dimension range height is not included between 600 and 900 pixel' + assert_includes project.errors.full_messages, "Dimension range width is not included between 800 and 1200 pixel" + assert_includes project.errors.full_messages, "Dimension range height is not included between 600 and 900 pixel" - project = Project.new(title: 'Death Star') - project.dimension_images.attach([image_1300x1000_file]) + project = Project.new(title: "Death Star") + project.dimension_images.attach([ image_1300x1000_file ]) assert_not project.valid? - assert_includes project.errors.full_messages, 'Dimension images width must be less than or equal to 1200 pixel' - assert_includes project.errors.full_messages, 'Dimension images height must be less than or equal to 900 pixel' + assert_includes project.errors.full_messages, "Dimension images width must be less than or equal to 1200 pixel" + assert_includes project.errors.full_messages, "Dimension images height must be less than or equal to 900 pixel" rescue Exception => ex puts ex.message puts ex.backtrace.join("\n") raise ex end - test 'aspect ratio validation' do - e = RatioModel.new(name: 'Princess Leia') + test "aspect ratio validation" do + e = RatioModel.new(name: "Princess Leia") e.ratio_one.attach(image_150x150_file) e.proc_ratio_one.attach(image_150x150_file) - e.ratio_many.attach([image_600x800_file]) - e.proc_ratio_many.attach([image_600x800_file]) + e.ratio_many.attach([ image_600x800_file ]) + e.proc_ratio_many.attach([ image_600x800_file ]) e.ratio_in.attach(image_150x150_file) e.proc_ratio_in.attach(image_150x150_file) e.save! - e = RatioModel.new(name: 'Princess Leia') + e = RatioModel.new(name: "Princess Leia") e.ratio_one.attach(image_150x150_file) e.proc_ratio_one.attach(image_150x150_file) - e.ratio_many.attach([image_150x150_file]) - e.proc_ratio_many.attach([image_150x150_file]) + e.ratio_many.attach([ image_150x150_file ]) + e.proc_ratio_many.attach([ image_150x150_file ]) e.ratio_in.attach(image_150x150_file) e.proc_ratio_in.attach(image_150x150_file) e.save - assert !e.valid? - assert_equal ["Ratio many must be portrait (current file is 150x150px)", "Proc ratio many must be portrait (current file is 150x150px)"], e.errors.full_messages + assert_not e.valid? + assert_equal [ "Ratio many must be portrait (current file is 150x150px)", "Proc ratio many must be portrait (current file is 150x150px)" ], e.errors.full_messages - e = RatioModel.new(name: 'Princess Leia') + e = RatioModel.new(name: "Princess Leia") e.ratio_one.attach(image_150x150_file) e.proc_ratio_one.attach(image_150x150_file) - e.ratio_many.attach([image_600x800_file]) - e.proc_ratio_many.attach([image_600x800_file]) + e.ratio_many.attach([ image_600x800_file ]) + e.proc_ratio_many.attach([ image_600x800_file ]) e.image1.attach(image_150x150_file) e.proc_image1.attach(image_150x150_file) e.ratio_in.attach(image_150x150_file) e.proc_ratio_in.attach(image_150x150_file) - assert !e.valid? - assert_equal ["Image1 must be 16:9 (current file is 150x150px)", 'Proc image1 must be 16:9 (current file is 150x150px)'], e.errors.full_messages + assert_not e.valid? + assert_equal [ "Image1 must be 16:9 (current file is 150x150px)", "Proc image1 must be 16:9 (current file is 150x150px)" ], e.errors.full_messages - e = RatioModel.new(name: 'Princess Leia') + e = RatioModel.new(name: "Princess Leia") e.ratio_one.attach(html_file) e.proc_ratio_one.attach(html_file) - e.ratio_many.attach([image_600x800_file]) - e.proc_ratio_many.attach([image_600x800_file]) + e.ratio_many.attach([ image_600x800_file ]) + e.proc_ratio_many.attach([ image_600x800_file ]) e.image1.attach(image_1920x1080_file) e.proc_image1.attach(image_1920x1080_file) e.ratio_in.attach(image_150x150_file) e.proc_ratio_in.attach(image_150x150_file) - assert !e.valid? - assert_equal ["Ratio one is not a valid media file", 'Proc ratio one is not a valid media file'], e.errors.full_messages + assert_not e.valid? + assert_equal [ "Ratio one is not a valid media file", "Proc ratio one is not a valid media file" ], e.errors.full_messages - e = RatioModel.new(name: 'Princess Leia') + e = RatioModel.new(name: "Princess Leia") e.ratio_one.attach(image_150x150_file) e.proc_ratio_one.attach(image_150x150_file) - e.ratio_many.attach([image_600x800_file]) - e.proc_ratio_many.attach([image_600x800_file]) + e.ratio_many.attach([ image_600x800_file ]) + e.proc_ratio_many.attach([ image_600x800_file ]) e.ratio_in.attach(image_1920x1080_file) e.proc_ratio_in.attach(image_1920x1080_file) - assert !e.valid? - assert_equal({ ratio_in: [ + assert_not e.valid? + assert_equal( { - error: :aspect_ratio_invalid, - validator_type: :aspect_ratio, - filename: 'image_1920x1080_file.png', - authorized_aspect_ratios: 'square, portrait', - width: 1920, - height: 1080 - } - ], proc_ratio_in: [ - { - error: :aspect_ratio_invalid, - validator_type: :aspect_ratio, - filename: 'image_1920x1080_file.png', - authorized_aspect_ratios: 'square, portrait', - width: 1920, - height: 1080 - } - ]}, e.errors.details) + ratio_in: [ + { + error: :aspect_ratio_invalid, + validator_type: :aspect_ratio, + filename: "image_1920x1080_file.png", + authorized_aspect_ratios: "square, portrait", + width: 1920, + height: 1080 + } + ], + proc_ratio_in: [ + { + error: :aspect_ratio_invalid, + validator_type: :aspect_ratio, + filename: "image_1920x1080_file.png", + authorized_aspect_ratios: "square, portrait", + width: 1920, + height: 1080 + } + ] + }, + e.errors.details + ) end end diff --git a/test/analyzers/audio_analyzer_test.rb b/test/analyzers/audio_analyzer_test.rb index e2a8b132..07f385a1 100644 --- a/test/analyzers/audio_analyzer_test.rb +++ b/test/analyzers/audio_analyzer_test.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true require "test_helper" -require 'analyzers/support/analyzer_helpers' -require 'analyzers/shared_examples/returns_the_right_metadata_for_any_attachable' +require "analyzers/support/analyzer_helpers" +require "analyzers/shared_examples/returns_the_right_metadata_for_any_attachable" describe ActiveStorageValidations::Analyzer::AudioAnalyzer do include AnalyzerHelpers @@ -10,18 +10,18 @@ let(:analyzer_klass) { ActiveStorageValidations::Analyzer::AudioAnalyzer } let(:analyzer) { analyzer_klass.new(attachable) } - let(:media_extension) { '.mp3' } + let(:media_extension) { ".mp3" } let(:media_filename) { "audio#{media_extension}" } let(:media_filename_over_10ko) { "audio_2s#{media_extension}" } let(:media_filename_rotated) { "audio#{media_extension}" } let(:media_filename_0ko) { "audio_0ko#{media_extension}" } - let(:media_path) { Rails.root.join('public', media_filename) } + let(:media_path) { Rails.root.join("public", media_filename) } let(:media_io) { File.open(media_path) } - let(:media_content_type) { 'audio/mp3' } + let(:media_content_type) { "audio/mp3" } let(:media_content_type_rotated) { media_content_type } - let(:expected_metadata) { { duration: 1.0, bit_rate: 32000, sample_rate: 44100, tags: { "encoder" => "Lavc60.3."} } } - let(:expected_metadata_over_10ko) { { duration: 2.0, bit_rate: 107286, sample_rate: 44100, tags: { "encoder" => "LAME3.100"} } } - let(:expected_metadata_rotated) { { duration: 1.0, bit_rate: 32000, sample_rate: 44100, tags: { "encoder" => "Lavc60.3."} } } + let(:expected_metadata) { { duration: 1.0, bit_rate: 32000, sample_rate: 44100, tags: { "encoder" => "Lavc60.3." } } } + let(:expected_metadata_over_10ko) { { duration: 2.0, bit_rate: 107286, sample_rate: 44100, tags: { "encoder" => "LAME3.100" } } } + let(:expected_metadata_rotated) { { duration: 1.0, bit_rate: 32000, sample_rate: 44100, tags: { "encoder" => "Lavc60.3." } } } include ReturnsTheRightMetadataForAnyAttachable end diff --git a/test/analyzers/content_type_analyzer_test.rb b/test/analyzers/content_type_analyzer_test.rb index e4f09686..3f77e0f1 100644 --- a/test/analyzers/content_type_analyzer_test.rb +++ b/test/analyzers/content_type_analyzer_test.rb @@ -2,7 +2,7 @@ require "open-uri" require "test_helper" -require 'analyzers/support/analyzer_helpers' +require "analyzers/support/analyzer_helpers" describe ActiveStorageValidations::Analyzer::ContentTypeAnalyzer do include AnalyzerHelpers @@ -16,7 +16,7 @@ def is_expected_to_return_the_right_content_type end def is_expected_to_return_empty_content_type - assert_equal({ content_type: 'inode/x-empty' }, subject) + assert_equal({ content_type: "inode/x-empty" }, subject) end subject { analyzer.content_type } @@ -31,15 +31,15 @@ def is_expected_to_return_empty_content_type # File object # Pathname object - let(:media_extension) { '.png' } - let(:media_extension_rotated) { '.jpg' } + let(:media_extension) { ".png" } + let(:media_extension_rotated) { ".jpg" } let(:media_filename) { "image_150x150#{media_extension}" } let(:media_filename_over_10ko) { "image_150x150_28ko#{media_extension}" } - let(:media_path) { Rails.root.join('public', media_filename) } + let(:media_path) { Rails.root.join("public", media_filename) } let(:media_io) { File.open(media_path) } - let(:media_content_type) { 'image/png' } - let(:expected_content_type) { { content_type: 'image/png' } } - let(:expected_content_type_over_10ko) { { content_type: 'image/png' } } + let(:media_content_type) { "image/png" } + let(:expected_content_type) { { content_type: "image/png" } } + let(:expected_content_type_over_10ko) { { content_type: "image/png" } } describe "ActiveStorage::Blob object" do let(:attachable) do @@ -47,7 +47,7 @@ def is_expected_to_return_empty_content_type io: media_io, filename: media_filename, content_type: media_content_type, - service_name: 'test' + service_name: "test" ) end @@ -56,7 +56,7 @@ def is_expected_to_return_empty_content_type describe "ActionDispatch::Http::UploadedFile object" do let(:attachable) do - tempfile = Tempfile.new([media_filename, media_extension]) + tempfile = Tempfile.new([ media_filename, media_extension ]) tempfile.write(File.read(media_path)) tempfile.rewind @@ -101,7 +101,7 @@ def is_expected_to_return_empty_content_type describe "Remote file" do before do stub_request(:get, url) - .to_return(body: File.open(Rails.root.join('public', fetched_file)), status: 200) + .to_return(body: File.open(Rails.root.join("public", fetched_file)), status: 200) end let(:url) { "https://example_image.jpg" } @@ -147,7 +147,7 @@ def is_expected_to_return_empty_content_type io: media_io, filename: media_filename, content_type: media_content_type, - service_name: 'test' + service_name: "test" ) blob.signed_id end @@ -158,7 +158,7 @@ def is_expected_to_return_empty_content_type describe "File object" do let(:attachable) { media_io } - if Rails.gem_version >= Gem::Version.new('7.1.0.rc1') + if Rails.gem_version >= Gem::Version.new("7.1.0.rc1") it { is_expected_to_return_the_right_content_type } else it { is_expected_to_raise_error(ArgumentError, "Could not find or build blob: expected attachable, got #{attachable.inspect}") } @@ -168,7 +168,7 @@ def is_expected_to_return_empty_content_type describe "Pathname object" do let(:attachable) { Pathname.new(media_path) } - if Rails.gem_version >= Gem::Version.new('7.1.0.rc1') + if Rails.gem_version >= Gem::Version.new("7.1.0.rc1") it { is_expected_to_return_the_right_content_type } else it { is_expected_to_raise_error(ArgumentError, "Could not find or build blob: expected attachable, got #{attachable.inspect}") } @@ -185,10 +185,10 @@ def is_expected_to_return_empty_content_type describe "0 byte size file" do let(:attachable) do ActiveStorage::Blob.create_and_upload!( - io: File.open(Rails.root.join('public', "image_file_0ko.png")), + io: File.open(Rails.root.join("public", "image_file_0ko.png")), filename: "image_file_0ko.png", - content_type: 'image/png', - service_name: 'test' + content_type: "image/png", + service_name: "test" ) end @@ -198,7 +198,7 @@ def is_expected_to_return_empty_content_type describe "when the file command-line tool is not found" do let(:attachable) do { - io: File.open(Rails.root.join('public', "image_150x150.png")), + io: File.open(Rails.root.join("public", "image_150x150.png")), filename: "image_150x150.png", content_type: "image/png" } @@ -208,7 +208,7 @@ def is_expected_to_return_empty_content_type it "raises an explicit error" do Open3.stub(:capture2, proc { raise Errno::ENOENT }) do error = assert_raises(analyzer_error) { subject } - assert_equal('file command-line tool is not installed', error.message) + assert_equal("file command-line tool is not installed", error.message) end end end diff --git a/test/analyzers/image_analyzers/image_magick_test.rb b/test/analyzers/image_analyzers/image_magick_test.rb index b35eb213..54d46de2 100644 --- a/test/analyzers/image_analyzers/image_magick_test.rb +++ b/test/analyzers/image_analyzers/image_magick_test.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true require "test_helper" -require 'analyzers/support/analyzer_helpers' -require 'analyzers/shared_examples/returns_the_right_metadata_for_any_attachable' +require "analyzers/support/analyzer_helpers" +require "analyzers/shared_examples/returns_the_right_metadata_for_any_attachable" describe ActiveStorageValidations::Analyzer::ImageAnalyzer::ImageMagick do include AnalyzerHelpers @@ -13,16 +13,16 @@ # Using a jpg file to test rotation because the behaviour is uniform among OS, # we tried doing it with a png file but the result was different # between our local machine and the CI. - let(:media_extension) { '.png' } - let(:media_extension_rotated) { '.jpg' } + let(:media_extension) { ".png" } + let(:media_extension_rotated) { ".jpg" } let(:media_filename) { "image_150x150#{media_extension}" } let(:media_filename_over_10ko) { "image_150x150_28ko#{media_extension}" } let(:media_filename_rotated) { "image_700x500_rotated_90#{media_extension_rotated}" } let(:media_filename_0ko) { "image_file_0ko#{media_extension}" } - let(:media_path) { Rails.root.join('public', media_filename) } + let(:media_path) { Rails.root.join("public", media_filename) } let(:media_io) { File.open(media_path) } - let(:media_content_type) { 'image/png' } - let(:media_content_type_rotated) { 'image/jpeg' } + let(:media_content_type) { "image/png" } + let(:media_content_type_rotated) { "image/jpeg" } let(:expected_metadata) { { width: 150, height: 150 } } let(:expected_metadata_over_10ko) { { width: 150, height: 150 } } let(:expected_metadata_rotated) { { width: 700, height: 500 } } diff --git a/test/analyzers/image_analyzers/vips_test.rb b/test/analyzers/image_analyzers/vips_test.rb index b98f892c..9f6bc044 100644 --- a/test/analyzers/image_analyzers/vips_test.rb +++ b/test/analyzers/image_analyzers/vips_test.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true require "test_helper" -require 'analyzers/support/analyzer_helpers' -require 'analyzers/shared_examples/returns_the_right_metadata_for_any_attachable' +require "analyzers/support/analyzer_helpers" +require "analyzers/shared_examples/returns_the_right_metadata_for_any_attachable" describe ActiveStorageValidations::Analyzer::ImageAnalyzer::Vips do include AnalyzerHelpers @@ -25,16 +25,16 @@ # Using a jpg file to test rotation because the behaviour is uniform among OS, # we tried doing it with a png file but the result was different # between our local machine and the CI. - let(:media_extension) { '.png' } - let(:media_extension_rotated) { '.jpg' } + let(:media_extension) { ".png" } + let(:media_extension_rotated) { ".jpg" } let(:media_filename) { "image_150x150#{media_extension}" } let(:media_filename_over_10ko) { "image_150x150_28ko#{media_extension}" } let(:media_filename_rotated) { "image_700x500_rotated_90#{media_extension_rotated}" } let(:media_filename_0ko) { "image_file_0ko#{media_extension}" } - let(:media_path) { Rails.root.join('public', media_filename) } + let(:media_path) { Rails.root.join("public", media_filename) } let(:media_io) { File.open(media_path) } - let(:media_content_type) { 'image/png' } - let(:media_content_type_rotated) { 'image/jpeg' } + let(:media_content_type) { "image/png" } + let(:media_content_type_rotated) { "image/jpeg" } let(:expected_metadata) { { width: 150, height: 150 } } let(:expected_metadata_over_10ko) { { width: 150, height: 150 } } let(:expected_metadata_rotated) { { width: 700, height: 500 } } diff --git a/test/analyzers/shared_examples/returns_the_right_metadata_for_any_attachable.rb b/test/analyzers/shared_examples/returns_the_right_metadata_for_any_attachable.rb index aac34cd8..388278b3 100644 --- a/test/analyzers/shared_examples/returns_the_right_metadata_for_any_attachable.rb +++ b/test/analyzers/shared_examples/returns_the_right_metadata_for_any_attachable.rb @@ -33,7 +33,7 @@ def is_expected_to_return_empty_metadata io: media_io, filename: media_filename, content_type: media_content_type, - service_name: 'test' + service_name: "test" ) end @@ -42,7 +42,7 @@ def is_expected_to_return_empty_metadata describe "ActionDispatch::Http::UploadedFile object" do let(:attachable) do - tempfile = Tempfile.new([media_filename, media_extension]) + tempfile = Tempfile.new([ media_filename, media_extension ]) tempfile.write(File.read(media_path)) tempfile.rewind @@ -87,7 +87,7 @@ def is_expected_to_return_empty_metadata describe "Remote file" do before do stub_request(:get, url) - .to_return(body: File.open(Rails.root.join('public', fetched_file)), status: 200) + .to_return(body: File.open(Rails.root.join("public", fetched_file)), status: 200) end let(:url) { "https://example_image.jpg" } @@ -133,7 +133,7 @@ def is_expected_to_return_empty_metadata io: media_io, filename: media_filename, content_type: media_content_type, - service_name: 'test' + service_name: "test" ) blob.signed_id end @@ -144,7 +144,7 @@ def is_expected_to_return_empty_metadata describe "File object" do let(:attachable) { media_io } - if Rails.gem_version >= Gem::Version.new('7.1.0.rc1') + if Rails.gem_version >= Gem::Version.new("7.1.0.rc1") it { is_expected_to_return_the_right_metadata } else it { is_expected_to_raise_error(ArgumentError, "Could not find or build blob: expected attachable, got #{attachable.inspect}") } @@ -154,7 +154,7 @@ def is_expected_to_return_empty_metadata describe "Pathname object" do let(:attachable) { Pathname.new(media_path) } - if Rails.gem_version >= Gem::Version.new('7.1.0.rc1') + if Rails.gem_version >= Gem::Version.new("7.1.0.rc1") it { is_expected_to_return_the_right_metadata } else it { is_expected_to_raise_error(ArgumentError, "Could not find or build blob: expected attachable, got #{attachable.inspect}") } @@ -172,10 +172,10 @@ def is_expected_to_return_empty_metadata describe "rotated media" do let(:attachable) do ActiveStorage::Blob.create_and_upload!( - io: File.open(Rails.root.join('public', media_filename_rotated)), + io: File.open(Rails.root.join("public", media_filename_rotated)), filename: media_filename_rotated, content_type: media_content_type_rotated, - service_name: 'test' + service_name: "test" ) end let(:expected_metadata) { expected_metadata_rotated } @@ -186,10 +186,10 @@ def is_expected_to_return_empty_metadata describe "0 byte size file" do let(:attachable) do ActiveStorage::Blob.create_and_upload!( - io: File.open(Rails.root.join('public', media_filename_0ko)), + io: File.open(Rails.root.join("public", media_filename_0ko)), filename: media_filename_0ko, content_type: media_content_type, - service_name: 'test' + service_name: "test" ) end diff --git a/test/analyzers/video_analyzer_test.rb b/test/analyzers/video_analyzer_test.rb index 4bac7ad2..febee598 100644 --- a/test/analyzers/video_analyzer_test.rb +++ b/test/analyzers/video_analyzer_test.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true require "test_helper" -require 'analyzers/support/analyzer_helpers' -require 'analyzers/shared_examples/returns_the_right_metadata_for_any_attachable' +require "analyzers/support/analyzer_helpers" +require "analyzers/shared_examples/returns_the_right_metadata_for_any_attachable" describe ActiveStorageValidations::Analyzer::VideoAnalyzer do include AnalyzerHelpers @@ -10,14 +10,14 @@ let(:analyzer_klass) { ActiveStorageValidations::Analyzer::VideoAnalyzer } let(:analyzer) { analyzer_klass.new(attachable) } - let(:media_extension) { '.mp4' } + let(:media_extension) { ".mp4" } let(:media_filename) { "video_150x150#{media_extension}" } let(:media_filename_over_10ko) { "video_150x150_24ko#{media_extension}" } let(:media_filename_rotated) { "video_700x500_rotated_90#{media_extension}" } let(:media_filename_0ko) { "video_file_0ko#{media_extension}" } - let(:media_path) { Rails.root.join('public', media_filename) } + let(:media_path) { Rails.root.join("public", media_filename) } let(:media_io) { File.open(media_path) } - let(:media_content_type) { 'video/mp4' } + let(:media_content_type) { "video/mp4" } let(:media_content_type_rotated) { media_content_type } let(:expected_metadata) { { width: 150, height: 150, duration: 1.7, audio: false, video: true } } let(:expected_metadata_over_10ko) { { width: 150, height: 150, duration: 9.6, audio: false, video: true } } diff --git a/test/dummy/app/models/active_storage_validations/check.rb b/test/dummy/app/models/active_storage_validations/check.rb index a6caa834..e4ea2a67 100644 --- a/test/dummy/app/models/active_storage_validations/check.rb +++ b/test/dummy/app/models/active_storage_validations/check.rb @@ -19,5 +19,5 @@ class ActiveStorageValidations::Check < ApplicationRecord # This validator is related to a test to ensure that the developer can define # its own custom mime types has_one_attached :asv_test - validates :asv_test, content_type: 'application/asv_test' + validates :asv_test, content_type: "application/asv_test" end diff --git a/test/dummy/app/models/application_record.rb b/test/dummy/app/models/application_record.rb index 09912873..99aed7c6 100644 --- a/test/dummy/app/models/application_record.rb +++ b/test/dummy/app/models/application_record.rb @@ -4,61 +4,62 @@ class ApplicationRecord < ActiveRecord::Base # Class method that references the most common mime types. # After adding a new one, make sure to have the corresponding example file in # test/dummy/public/most_common_mime_types + # rubocop:disable Metrics/MethodLength def self.most_common_mime_types [ # Image - { media: 'image', type: :jpg }, - { media: 'image', type: :jpeg }, - { media: 'image', type: :png }, - { media: 'image', type: :gif }, - { media: 'image', type: :webp }, - { media: 'image', type: :svg }, - { media: 'image', type: :bmp }, - { media: 'image', type: :psd }, - { media: 'image', type: :tiff }, - { media: 'image', type: :heic }, + { media: "image", type: :jpg }, + { media: "image", type: :jpeg }, + { media: "image", type: :png }, + { media: "image", type: :gif }, + { media: "image", type: :webp }, + { media: "image", type: :svg }, + { media: "image", type: :bmp }, + { media: "image", type: :psd }, + { media: "image", type: :tiff }, + { media: "image", type: :heic }, # Video - { media: 'video', type: :mp4 }, - { media: 'video', type: :avi }, - { media: 'video', type: :wmv }, - { media: 'video', type: :mov }, - { media: 'video', type: :mkv }, - { media: 'video', type: :ogv }, - { media: 'video', type: :webm }, + { media: "video", type: :mp4 }, + { media: "video", type: :avi }, + { media: "video", type: :wmv }, + { media: "video", type: :mov }, + { media: "video", type: :mkv }, + { media: "video", type: :ogv }, + { media: "video", type: :webm }, # Audio - { media: 'audio', type: :mp3 }, - { media: 'audio', type: :m4a }, - { media: 'audio', type: :wav }, - { media: 'audio', type: :ogg }, - { media: 'audio', type: :aac }, - { media: 'audio', type: :flac }, + { media: "audio", type: :mp3 }, + { media: "audio", type: :m4a }, + { media: "audio", type: :wav }, + { media: "audio", type: :ogg }, + { media: "audio", type: :aac }, + { media: "audio", type: :flac }, # Text - { media: 'text', type: :txt }, - { media: 'text', type: :csv }, - { media: 'text', type: :html }, - { media: 'text', type: :css }, + { media: "text", type: :txt }, + { media: "text", type: :csv }, + { media: "text", type: :html }, + { media: "text", type: :css }, ## Application - { media: 'application', type: :json }, - { media: 'application', type: :xml }, - { media: 'application', type: :pdf }, - { media: 'application', type: :doc }, - { media: 'application', type: :docx }, - { media: 'application', type: :xls }, - { media: 'application', type: :xlsx }, - { media: 'application', type: :ppt }, - { media: 'application', type: :pptx }, - { media: 'application', type: :ppsx }, - { media: 'application', type: :odt }, - { media: 'application', type: :ods }, - { media: 'application', type: :odp }, - { media: 'application', type: :pages }, - { media: 'application', type: :numbers }, - { media: 'application', type: :key }, - { media: 'application', type: :zip }, - { media: 'application', type: :'7z' }, - { media: 'application', type: :rar }, - { media: 'application', type: :gz }, - { media: 'application', type: :tar } + { media: "application", type: :json }, + { media: "application", type: :xml }, + { media: "application", type: :pdf }, + { media: "application", type: :doc }, + { media: "application", type: :docx }, + { media: "application", type: :xls }, + { media: "application", type: :xlsx }, + { media: "application", type: :ppt }, + { media: "application", type: :pptx }, + { media: "application", type: :ppsx }, + { media: "application", type: :odt }, + { media: "application", type: :ods }, + { media: "application", type: :odp }, + { media: "application", type: :pages }, + { media: "application", type: :numbers }, + { media: "application", type: :key }, + { media: "application", type: :zip }, + { media: "application", type: :'7z' }, + { media: "application", type: :rar }, + { media: "application", type: :gz }, + { media: "application", type: :tar } ] end end diff --git a/test/dummy/app/models/aspect_ratio.rb b/test/dummy/app/models/aspect_ratio.rb index d5687b2d..0755782f 100644 --- a/test/dummy/app/models/aspect_ratio.rb +++ b/test/dummy/app/models/aspect_ratio.rb @@ -1,5 +1,5 @@ module AspectRatio def self.table_name_prefix - 'aspect_ratio_' + "aspect_ratio_" end end diff --git a/test/dummy/app/models/aspect_ratio/matcher.rb b/test/dummy/app/models/aspect_ratio/matcher.rb index 84e8edb6..a4dcc82a 100644 --- a/test/dummy/app/models/aspect_ratio/matcher.rb +++ b/test/dummy/app/models/aspect_ratio/matcher.rb @@ -27,7 +27,7 @@ class AspectRatio::Matcher < ApplicationRecord validates :allow_blank, aspect_ratio: :square, allow_blank: true has_one_attached :with_message - validates :with_message, aspect_ratio: { with: :square, message: 'Custom message' } + validates :with_message, aspect_ratio: { with: :square, message: "Custom message" } has_one_attached :with_context_symbol validates :with_context_symbol, aspect_ratio: :square, on: :update @@ -41,8 +41,8 @@ class AspectRatio::Matcher < ApplicationRecord validates :as_instance, aspect_ratio: :square has_one_attached :validatable_different_error_messages - validates :validatable_different_error_messages, aspect_ratio: { with: :portrait, message: 'Custom message 1' }, if: :title_is_quo_vadis? - validates :validatable_different_error_messages, aspect_ratio: { with: :square, message: 'Custom message 2' }, if: :title_is_american_psycho? + validates :validatable_different_error_messages, aspect_ratio: { with: :portrait, message: "Custom message 1" }, if: :title_is_quo_vadis? + validates :validatable_different_error_messages, aspect_ratio: { with: :square, message: "Custom message 2" }, if: :title_is_american_psycho? has_one_attached :failure_message validates :failure_message, aspect_ratio: :square @@ -51,5 +51,5 @@ class AspectRatio::Matcher < ApplicationRecord # Combinations has_one_attached :allowing_one_with_message - validates :allowing_one_with_message, aspect_ratio: { with: :portrait, message: 'Not authorized aspect ratio.' } + validates :allowing_one_with_message, aspect_ratio: { with: :portrait, message: "Not authorized aspect ratio." } end diff --git a/test/dummy/app/models/aspect_ratio/validator.rb b/test/dummy/app/models/aspect_ratio/validator.rb index 11fe4b87..6d544936 100644 --- a/test/dummy/app/models/aspect_ratio/validator.rb +++ b/test/dummy/app/models/aspect_ratio/validator.rb @@ -1,7 +1,7 @@ module AspectRatio module Validator def self.table_name_prefix - 'aspect_ratio_validator_' + "aspect_ratio_validator_" end end end diff --git a/test/dummy/app/models/aspect_ratio/validator/check.rb b/test/dummy/app/models/aspect_ratio/validator/check.rb index bb307ec0..c9152fb5 100644 --- a/test/dummy/app/models/aspect_ratio/validator/check.rb +++ b/test/dummy/app/models/aspect_ratio/validator/check.rb @@ -10,11 +10,11 @@ # class AspectRatio::Validator::Check < ApplicationRecord - %i(square portrait landscape).each do |named_aspect_ratio| + %i[square portrait landscape].each do |named_aspect_ratio| has_one_attached :"with_#{named_aspect_ratio}" has_one_attached :"with_#{named_aspect_ratio}_proc" validates :"with_#{named_aspect_ratio}", aspect_ratio: named_aspect_ratio - validates :"with_#{named_aspect_ratio}_proc", aspect_ratio: -> (record) { named_aspect_ratio } + validates :"with_#{named_aspect_ratio}_proc", aspect_ratio: ->(record) { named_aspect_ratio } end has_one_attached :with_regex has_one_attached :with_regex_proc @@ -26,6 +26,6 @@ class AspectRatio::Validator::Check < ApplicationRecord has_one_attached :in_aspect_ratios has_one_attached :in_aspect_ratios_proc - validates :in_aspect_ratios, aspect_ratio: %i(square portrait is_16_9) - validates :in_aspect_ratios_proc, aspect_ratio: -> (record) { %i(square portrait is_16_9) } + validates :in_aspect_ratios, aspect_ratio: %i[square portrait is_16_9] + validates :in_aspect_ratios_proc, aspect_ratio: ->(record) { %i[square portrait is_16_9] } end diff --git a/test/dummy/app/models/aspect_ratio/validator/check_validity_proc_option.rb b/test/dummy/app/models/aspect_ratio/validator/check_validity_proc_option.rb index 22a9be94..c690532f 100644 --- a/test/dummy/app/models/aspect_ratio/validator/check_validity_proc_option.rb +++ b/test/dummy/app/models/aspect_ratio/validator/check_validity_proc_option.rb @@ -11,5 +11,5 @@ class AspectRatio::Validator::CheckValidityProcOption < ApplicationRecord has_one_attached :invalid - validates :invalid, aspect_ratio: -> (record) { :invalid } + validates :invalid, aspect_ratio: ->(record) { :invalid } end diff --git a/test/dummy/app/models/aspect_ratio/validator/with_if.rb b/test/dummy/app/models/aspect_ratio/validator/with_if.rb index 98a561b0..461961bd 100644 --- a/test/dummy/app/models/aspect_ratio/validator/with_if.rb +++ b/test/dummy/app/models/aspect_ratio/validator/with_if.rb @@ -14,9 +14,9 @@ class AspectRatio::Validator::WithIf < ApplicationRecord has_one_attached :with_if has_one_attached :with_if_proc validates :with_if, aspect_ratio: :square, if: :title_is_image? - validates :with_if_proc, aspect_ratio: :square, if: -> { self.title == 'Right title' } + validates :with_if_proc, aspect_ratio: :square, if: -> { self.title == "Right title" } def title_is_image? - title == 'image' + title == "image" end end diff --git a/test/dummy/app/models/aspect_ratio/validator/with_message.rb b/test/dummy/app/models/aspect_ratio/validator/with_message.rb index c7a8b861..833c16f4 100644 --- a/test/dummy/app/models/aspect_ratio/validator/with_message.rb +++ b/test/dummy/app/models/aspect_ratio/validator/with_message.rb @@ -11,5 +11,5 @@ class AspectRatio::Validator::WithMessage < ApplicationRecord has_one_attached :with_message - validates :with_message, aspect_ratio: { with: :square , message: 'Custom message' } + validates :with_message, aspect_ratio: { with: :square, message: "Custom message" } end diff --git a/test/dummy/app/models/aspect_ratio/validator/with_on.rb b/test/dummy/app/models/aspect_ratio/validator/with_on.rb index 9d834628..aeae81de 100644 --- a/test/dummy/app/models/aspect_ratio/validator/with_on.rb +++ b/test/dummy/app/models/aspect_ratio/validator/with_on.rb @@ -11,5 +11,5 @@ class AspectRatio::Validator::WithOn < ApplicationRecord has_one_attached :with_on - validates :with_on, aspect_ratio: :square, on: %i(create update destroy custom) + validates :with_on, aspect_ratio: :square, on: %i[create update destroy custom] end diff --git a/test/dummy/app/models/attached.rb b/test/dummy/app/models/attached.rb index 1fe5ac84..1260ee5e 100644 --- a/test/dummy/app/models/attached.rb +++ b/test/dummy/app/models/attached.rb @@ -1,5 +1,5 @@ module Attached def self.table_name_prefix - 'attached_' + "attached_" end end diff --git a/test/dummy/app/models/attached/matcher.rb b/test/dummy/app/models/attached/matcher.rb index 7809e8d2..43d6cdcb 100644 --- a/test/dummy/app/models/attached/matcher.rb +++ b/test/dummy/app/models/attached/matcher.rb @@ -20,7 +20,7 @@ class Attached::Matcher < ApplicationRecord validates :required, attached: true has_one_attached :with_message - validates :with_message, attached: { message: 'Custom message' } + validates :with_message, attached: { message: "Custom message" } has_one_attached :with_context_symbol validates :with_context_symbol, attached: true, on: :update @@ -34,8 +34,8 @@ class Attached::Matcher < ApplicationRecord validates :as_instance, attached: true has_one_attached :validatable_different_error_messages - validates :validatable_different_error_messages, attached: { message: 'Custom message 1' }, if: :title_is_quo_vadis? - validates :validatable_different_error_messages, attached: { message: 'Custom message 2' }, if: :title_is_american_psycho? + validates :validatable_different_error_messages, attached: { message: "Custom message 1" }, if: :title_is_quo_vadis? + validates :validatable_different_error_messages, attached: { message: "Custom message 2" }, if: :title_is_american_psycho? has_one_attached :failure_message validates :failure_message, attached: true diff --git a/test/dummy/app/models/attached/validator.rb b/test/dummy/app/models/attached/validator.rb index 844e6593..97fa1270 100644 --- a/test/dummy/app/models/attached/validator.rb +++ b/test/dummy/app/models/attached/validator.rb @@ -1,7 +1,7 @@ module Attached module Validator def self.table_name_prefix - 'attached_validator_' + "attached_validator_" end end end diff --git a/test/dummy/app/models/attached/validator/with_if.rb b/test/dummy/app/models/attached/validator/with_if.rb index 73080915..34421292 100644 --- a/test/dummy/app/models/attached/validator/with_if.rb +++ b/test/dummy/app/models/attached/validator/with_if.rb @@ -14,9 +14,9 @@ class Attached::Validator::WithIf < ApplicationRecord has_one_attached :with_if has_one_attached :with_if_proc validates :with_if, attached: true, if: :title_is_image? - validates :with_if_proc, attached: true, if: -> { self.title == 'Right title' } + validates :with_if_proc, attached: true, if: -> { self.title == "Right title" } def title_is_image? - title == 'image' + title == "image" end end diff --git a/test/dummy/app/models/attached/validator/with_message.rb b/test/dummy/app/models/attached/validator/with_message.rb index 25c05aad..5d25a99b 100644 --- a/test/dummy/app/models/attached/validator/with_message.rb +++ b/test/dummy/app/models/attached/validator/with_message.rb @@ -11,5 +11,5 @@ class Attached::Validator::WithMessage < ApplicationRecord has_one_attached :with_message - validates :with_message, attached: { message: 'Custom message' } + validates :with_message, attached: { message: "Custom message" } end diff --git a/test/dummy/app/models/attached/validator/with_on.rb b/test/dummy/app/models/attached/validator/with_on.rb index fa0ed858..8963c8b5 100644 --- a/test/dummy/app/models/attached/validator/with_on.rb +++ b/test/dummy/app/models/attached/validator/with_on.rb @@ -11,5 +11,5 @@ class Attached::Validator::WithOn < ApplicationRecord has_one_attached :with_on - validates :with_on, attached: true, on: %i(create update destroy custom) + validates :with_on, attached: true, on: %i[create update destroy custom] end diff --git a/test/dummy/app/models/content_type.rb b/test/dummy/app/models/content_type.rb index 89d14b21..7afb7cff 100644 --- a/test/dummy/app/models/content_type.rb +++ b/test/dummy/app/models/content_type.rb @@ -1,5 +1,5 @@ module ContentType def self.table_name_prefix - 'content_type_' + "content_type_" end end diff --git a/test/dummy/app/models/content_type/matcher.rb b/test/dummy/app/models/content_type/matcher.rb index 4b300af1..0347b9f4 100644 --- a/test/dummy/app/models/content_type/matcher.rb +++ b/test/dummy/app/models/content_type/matcher.rb @@ -14,25 +14,25 @@ class ContentType::Matcher < ApplicationRecord include Validatable has_one_attached :custom_matcher - validates :custom_matcher, content_type: ['image/png'] + validates :custom_matcher, content_type: [ "image/png" ] has_one_attached :allowing_one validates :allowing_one, content_type: :png has_one_attached :allowing_several - validates :allowing_several, content_type: ['image/png', 'image/gif'] + validates :allowing_several, content_type: [ "image/png", "image/gif" ] has_one_attached :allowing_several_through_regex - validates :allowing_several_through_regex, content_type: [/\Aimage\/.*\z/] + validates :allowing_several_through_regex, content_type: [ /\Aimage\/.*\z/ ] has_one_attached :allowing_symbol validates :allowing_symbol, content_type: :png has_one_attached :allowing_sneaky_edge_cases - validates :allowing_sneaky_edge_cases, content_type: ["image/svg+xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"] + validates :allowing_sneaky_edge_cases, content_type: [ "image/svg+xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ] has_one_attached :allow_blank - validates :allow_blank, content_type: ['image/png'], allow_blank: true + validates :allow_blank, content_type: [ "image/png" ], allow_blank: true has_one_attached :with_message - validates :with_message, content_type: { in: ['image/png'], message: 'Custom message' } + validates :with_message, content_type: { in: [ "image/png" ], message: "Custom message" } has_one_attached :with_context_symbol validates :with_context_symbol, content_type: :png, on: :update @@ -46,8 +46,8 @@ class ContentType::Matcher < ApplicationRecord validates :as_instance, content_type: :png has_one_attached :validatable_different_error_messages - validates :validatable_different_error_messages, content_type: { with: :pdf, message: 'Custom message 1' }, if: :title_is_quo_vadis? - validates :validatable_different_error_messages, content_type: { with: :png, message: 'Custom message 2' }, if: :title_is_american_psycho? + validates :validatable_different_error_messages, content_type: { with: :pdf, message: "Custom message 1" }, if: :title_is_quo_vadis? + validates :validatable_different_error_messages, content_type: { with: :png, message: "Custom message 2" }, if: :title_is_american_psycho? has_one_attached :failure_message validates :failure_message, content_type: :png @@ -56,7 +56,7 @@ class ContentType::Matcher < ApplicationRecord # Combinations has_one_attached :allowing_one_with_message - validates :allowing_one_with_message, content_type: { in: ['application/pdf'], message: 'Not authorized file type.' } + validates :allowing_one_with_message, content_type: { in: [ "application/pdf" ], message: "Not authorized file type." } most_common_mime_types.reject { |common_mime_type| common_mime_type[:type] == :ogv } # issue with ogv .each do |content_type| @@ -65,5 +65,5 @@ class ContentType::Matcher < ApplicationRecord content_type: content_type[:type] end has_one_attached :video_ogv - validates :video_ogv, content_type: ['video/theora'] + validates :video_ogv, content_type: [ "video/theora" ] end diff --git a/test/dummy/app/models/content_type/validator.rb b/test/dummy/app/models/content_type/validator.rb index ac2a2afe..8801224d 100644 --- a/test/dummy/app/models/content_type/validator.rb +++ b/test/dummy/app/models/content_type/validator.rb @@ -1,7 +1,7 @@ module ContentType module Validator def self.table_name_prefix - 'content_type_validator_' + "content_type_validator_" end end end diff --git a/test/dummy/app/models/content_type/validator/check.rb b/test/dummy/app/models/content_type/validator/check.rb index 63e77d9b..519c7fc4 100644 --- a/test/dummy/app/models/content_type/validator/check.rb +++ b/test/dummy/app/models/content_type/validator/check.rb @@ -12,36 +12,36 @@ class ContentType::Validator::Check < ApplicationRecord def self.example_for(type, several: false) case type - when 'symbol' - several ? [:png, :gif] : :png - when 'string' - several ? ['png', 'image/gif'] : 'png' - when 'regex' - several ? [/\Aimage\/.*\z/, /\Afile\/.*\z/] : /\Aimage\/.*\z/ + when "symbol" + several ? [ :png, :gif ] : :png + when "string" + several ? [ "png", "image/gif" ] : "png" + when "regex" + several ? [ /\Aimage\/.*\z/, /\Afile\/.*\z/ ] : /\Aimage\/.*\z/ end end has_one_attached :extension_content_type_mismatch validates :extension_content_type_mismatch, content_type: :png has_one_attached :extension_two_extensions_docx - validates :extension_two_extensions_docx, content_type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' + validates :extension_two_extensions_docx, content_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" has_one_attached :extension_two_extensions_pdf - validates :extension_two_extensions_pdf, content_type: 'application/pdf' + validates :extension_two_extensions_pdf, content_type: "application/pdf" has_one_attached :extension_upcase_extension - validates :extension_upcase_extension, content_type: 'application/pdf' + validates :extension_upcase_extension, content_type: "application/pdf" has_one_attached :extension_missing_extension - validates :extension_missing_extension, content_type: 'application/pdf' + validates :extension_missing_extension, content_type: "application/pdf" - %w(symbol string regex).each do |type| + %w[symbol string regex].each do |type| has_one_attached :"with_#{type}" has_one_attached :"with_#{type}_proc" validates :"with_#{type}", content_type: self.example_for(type) - validates :"with_#{type}_proc", content_type: -> (record) { self.example_for(type) } + validates :"with_#{type}_proc", content_type: ->(record) { self.example_for(type) } has_one_attached :"in_#{type.pluralize}" has_one_attached :"in_#{type.pluralize}_proc" validates :"in_#{type.pluralize}", content_type: example_for(type, several: true) - validates :"in_#{type.pluralize}_proc", content_type: -> (record) { example_for(type, several: true) } + validates :"in_#{type.pluralize}_proc", content_type: ->(record) { example_for(type, several: true) } end most_common_mime_types.reject { |common_mime_type| common_mime_type[:type] == :ogv } # issue with ogv @@ -54,9 +54,9 @@ def self.example_for(type, several: false) content_type: { with: content_type[:type], spoofing_protection: true } end has_one_attached :video_ogv - validates :video_ogv, content_type: ['video/theora'] + validates :video_ogv, content_type: [ "video/theora" ] has_one_attached :video_ogv_spoof - validates :video_ogv_spoof, content_type: { with: 'video/theora', spoofing_protection: true } + validates :video_ogv_spoof, content_type: { with: "video/theora", spoofing_protection: true } has_one_attached :content_type_with_parameter validates :content_type_with_parameter, content_type: :rar diff --git a/test/dummy/app/models/content_type/validator/check_validity_invalid_content_type_in.rb b/test/dummy/app/models/content_type/validator/check_validity_invalid_content_type_in.rb index 2c881474..b0c77ded 100644 --- a/test/dummy/app/models/content_type/validator/check_validity_invalid_content_type_in.rb +++ b/test/dummy/app/models/content_type/validator/check_validity_invalid_content_type_in.rb @@ -11,5 +11,5 @@ class ContentType::Validator::CheckValidityInvalidContentTypeIn < ApplicationRecord has_one_attached :invalid - validates :invalid, content_type: ["xxx/invalid1", "xxx/invalid2"] + validates :invalid, content_type: [ "xxx/invalid1", "xxx/invalid2" ] end diff --git a/test/dummy/app/models/content_type/validator/check_validity_proc_option.rb b/test/dummy/app/models/content_type/validator/check_validity_proc_option.rb index ba7e48c5..e137dc07 100644 --- a/test/dummy/app/models/content_type/validator/check_validity_proc_option.rb +++ b/test/dummy/app/models/content_type/validator/check_validity_proc_option.rb @@ -11,5 +11,5 @@ class ContentType::Validator::CheckValidityProcOption < ApplicationRecord has_one_attached :invalid - validates :invalid, content_type: -> (record) { :invalid } + validates :invalid, content_type: ->(record) { :invalid } end diff --git a/test/dummy/app/models/content_type/validator/check_validity_valid_content_type_ole_storage.rb b/test/dummy/app/models/content_type/validator/check_validity_valid_content_type_ole_storage.rb index cad0bea8..73cb8dad 100644 --- a/test/dummy/app/models/content_type/validator/check_validity_valid_content_type_ole_storage.rb +++ b/test/dummy/app/models/content_type/validator/check_validity_valid_content_type_ole_storage.rb @@ -15,4 +15,3 @@ class ContentType::Validator::CheckValidityValidContentTypeOleStorage < Applicat has_one_attached :valid validates :valid, content_type: "application/x-ole-storage" end - diff --git a/test/dummy/app/models/content_type/validator/with_if.rb b/test/dummy/app/models/content_type/validator/with_if.rb index 06e01fe2..5888cc33 100644 --- a/test/dummy/app/models/content_type/validator/with_if.rb +++ b/test/dummy/app/models/content_type/validator/with_if.rb @@ -14,9 +14,9 @@ class ContentType::Validator::WithIf < ApplicationRecord has_one_attached :with_if has_one_attached :with_if_proc validates :with_if, content_type: :webp, if: :title_is_image? - validates :with_if_proc, content_type: :webp, if: -> { self.title == 'Right title' } + validates :with_if_proc, content_type: :webp, if: -> { self.title == "Right title" } def title_is_image? - title == 'image' + title == "image" end end diff --git a/test/dummy/app/models/content_type/validator/with_message.rb b/test/dummy/app/models/content_type/validator/with_message.rb index fb5a0680..fb6e94a5 100644 --- a/test/dummy/app/models/content_type/validator/with_message.rb +++ b/test/dummy/app/models/content_type/validator/with_message.rb @@ -11,5 +11,5 @@ class ContentType::Validator::WithMessage < ApplicationRecord has_one_attached :with_message - validates :with_message, content_type: { with: :webp, message: 'Custom message' } + validates :with_message, content_type: { with: :webp, message: "Custom message" } end diff --git a/test/dummy/app/models/content_type/validator/with_on.rb b/test/dummy/app/models/content_type/validator/with_on.rb index f54f6f20..2046a60b 100644 --- a/test/dummy/app/models/content_type/validator/with_on.rb +++ b/test/dummy/app/models/content_type/validator/with_on.rb @@ -11,5 +11,5 @@ class ContentType::Validator::WithOn < ApplicationRecord has_one_attached :with_on - validates :with_on, content_type: :webp, on: %i(create update destroy custom) + validates :with_on, content_type: :webp, on: %i[create update destroy custom] end diff --git a/test/dummy/app/models/dimension.rb b/test/dummy/app/models/dimension.rb index a1f2a046..b2ec8199 100644 --- a/test/dummy/app/models/dimension.rb +++ b/test/dummy/app/models/dimension.rb @@ -1,5 +1,5 @@ module Dimension def self.table_name_prefix - 'dimension_' + "dimension_" end end diff --git a/test/dummy/app/models/dimension/matcher.rb b/test/dummy/app/models/dimension/matcher.rb index 3e8d2ba6..eb32a88f 100644 --- a/test/dummy/app/models/dimension/matcher.rb +++ b/test/dummy/app/models/dimension/matcher.rb @@ -16,7 +16,7 @@ class Dimension::Matcher < ApplicationRecord has_one_attached :custom_matcher validates :custom_matcher, dimension: { width: 150, height: 150 } - %i(width height).each do |dimension| + %i[width height].each do |dimension| has_one_attached :"#{dimension}_exact" has_one_attached :"#{dimension}_in" has_one_attached :"#{dimension}_min" @@ -31,19 +31,19 @@ class Dimension::Matcher < ApplicationRecord has_one_attached :"#{dimension}_in_with_message" has_one_attached :"#{dimension}_min_with_message" has_one_attached :"#{dimension}_max_with_message" - validates :"#{dimension}_exact_with_message", dimension: { "#{dimension}": 150, message: 'Invalid dimensions.' } - validates :"#{dimension}_in_with_message", dimension: { "#{dimension}": { in: 800..1200 }, message: 'Invalid dimensions.' } - validates :"#{dimension}_min_with_message", dimension: { "#{dimension}": { min: 800 }, message: 'Invalid dimensions.' } - validates :"#{dimension}_max_with_message", dimension: { "#{dimension}": { max: 1200 }, message: 'Invalid dimensions.' } + validates :"#{dimension}_exact_with_message", dimension: { "#{dimension}": 150, message: "Invalid dimensions." } + validates :"#{dimension}_in_with_message", dimension: { "#{dimension}": { in: 800..1200 }, message: "Invalid dimensions." } + validates :"#{dimension}_min_with_message", dimension: { "#{dimension}": { min: 800 }, message: "Invalid dimensions." } + validates :"#{dimension}_max_with_message", dimension: { "#{dimension}": { max: 1200 }, message: "Invalid dimensions." } end - %i(min max).each do |bound| + %i[min max].each do |bound| has_one_attached :"#{bound}" validates :"#{bound}", dimension: { "#{bound}": 800..600 } # Combinations has_one_attached :"#{bound}_with_message" - validates :"#{bound}_with_message", dimension: { "#{bound}": 800..600, message: 'Invalid dimensions.' } + validates :"#{bound}_with_message", dimension: { "#{bound}": 800..600, message: "Invalid dimensions." } end has_one_attached :allow_blank @@ -51,7 +51,7 @@ class Dimension::Matcher < ApplicationRecord has_one_attached :with_message has_one_attached :without_message - validates :with_message, dimension: { width: 150, height: 150, message: 'Custom message' } + validates :with_message, dimension: { width: 150, height: 150, message: "Custom message" } validates :without_message, dimension: { width: 150, height: 150 } has_one_attached :with_context_symbol @@ -66,8 +66,8 @@ class Dimension::Matcher < ApplicationRecord validates :as_instance, dimension: { width: 150, height: 150 } has_one_attached :validatable_different_error_messages - validates :validatable_different_error_messages, dimension: { width: 150, message: 'Custom message 1' }, if: :title_is_quo_vadis? - validates :validatable_different_error_messages, dimension: { width: 150, message: 'Custom message 2' }, if: :title_is_american_psycho? + validates :validatable_different_error_messages, dimension: { width: 150, message: "Custom message 1" }, if: :title_is_quo_vadis? + validates :validatable_different_error_messages, dimension: { width: 150, message: "Custom message 2" }, if: :title_is_american_psycho? has_one_attached :failure_message validates :failure_message, dimension: { width: 150, height: 150 } @@ -78,15 +78,15 @@ class Dimension::Matcher < ApplicationRecord has_one_attached :width_and_height_exact has_one_attached :width_and_height_exact_with_message validates :width_and_height_exact, dimension: { width: 150, height: 150 } - validates :width_and_height_exact_with_message, dimension: { width: 150, height: 150, message: 'Invalid dimensions.' } + validates :width_and_height_exact_with_message, dimension: { width: 150, height: 150, message: "Invalid dimensions." } has_one_attached :width_and_height_in has_one_attached :width_and_height_in_with_message validates :width_and_height_in, dimension: { width: { in: 800..1200 }, height: { in: 600..900 } } - validates :width_and_height_in_with_message, dimension: { width: { in: 800..1200 }, height: { in: 600..900 }, message: 'Invalid dimensions.' } + validates :width_and_height_in_with_message, dimension: { width: { in: 800..1200 }, height: { in: 600..900 }, message: "Invalid dimensions." } has_one_attached :width_and_height_min_max has_one_attached :width_and_height_min_max_with_message validates :width_and_height_min_max, dimension: { width: { min: 800, max: 1200 }, height: { min: 600, max: 900 } } - validates :width_and_height_min_max_with_message, dimension: { width: { min: 800, max: 1200 }, height: { min: 600, max: 900 }, message: 'Invalid dimensions.' } + validates :width_and_height_min_max_with_message, dimension: { width: { min: 800, max: 1200 }, height: { min: 600, max: 900 }, message: "Invalid dimensions." } end diff --git a/test/dummy/app/models/dimension/validator.rb b/test/dummy/app/models/dimension/validator.rb index 83a91a34..f23b58dd 100644 --- a/test/dummy/app/models/dimension/validator.rb +++ b/test/dummy/app/models/dimension/validator.rb @@ -1,7 +1,7 @@ module Dimension module Validator def self.table_name_prefix - 'dimension_validator_' + "dimension_validator_" end end end diff --git a/test/dummy/app/models/dimension/validator/check.rb b/test/dummy/app/models/dimension/validator/check.rb index 9862bdae..7f48f4e5 100644 --- a/test/dummy/app/models/dimension/validator/check.rb +++ b/test/dummy/app/models/dimension/validator/check.rb @@ -10,7 +10,7 @@ # class Dimension::Validator::Check < ApplicationRecord - %w(width height).each do |dimension| + %w[width height].each do |dimension| has_one_attached :"#{dimension}" has_one_attached :"#{dimension}_min" has_one_attached :"#{dimension}_max" @@ -27,19 +27,19 @@ class Dimension::Validator::Check < ApplicationRecord has_one_attached :"#{dimension}_max_proc" has_one_attached :"#{dimension}_min_max_proc" has_one_attached :"#{dimension}_in_proc" - validates :"#{dimension}_proc", dimension: { "#{dimension}": -> (record) { 500 } } - validates :"#{dimension}_min_proc", dimension: { "#{dimension}": { min: -> (record) { 500 } } } - validates :"#{dimension}_max_proc", dimension: { "#{dimension}": { max: -> (record) { 500 } } } - validates :"#{dimension}_min_max_proc", dimension: { "#{dimension}": { min: -> (record) { 400 }, max: -> (record) { 600 } } } - validates :"#{dimension}_in_proc", dimension: { "#{dimension}": { in: -> (record) { 400..600 } } } + validates :"#{dimension}_proc", dimension: { "#{dimension}": ->(record) { 500 } } + validates :"#{dimension}_min_proc", dimension: { "#{dimension}": { min: ->(record) { 500 } } } + validates :"#{dimension}_max_proc", dimension: { "#{dimension}": { max: ->(record) { 500 } } } + validates :"#{dimension}_min_max_proc", dimension: { "#{dimension}": { min: ->(record) { 400 }, max: ->(record) { 600 } } } + validates :"#{dimension}_in_proc", dimension: { "#{dimension}": { in: ->(record) { 400..600 } } } end - %w(min max).each do |bound| + %w[min max].each do |bound| has_one_attached :"#{bound}" validates :"#{bound}", dimension: { "#{bound}": 500..500 } has_one_attached :"#{bound}_proc" - validates :"#{bound}_proc", dimension: { "#{bound}": -> (record) { 500..500 } } + validates :"#{bound}_proc", dimension: { "#{bound}": ->(record) { 500..500 } } end # Integration tests diff --git a/test/dummy/app/models/dimension/validator/check_validity_dimension_in_proc.rb b/test/dummy/app/models/dimension/validator/check_validity_dimension_in_proc.rb index 3297d5cd..891d9c66 100644 --- a/test/dummy/app/models/dimension/validator/check_validity_dimension_in_proc.rb +++ b/test/dummy/app/models/dimension/validator/check_validity_dimension_in_proc.rb @@ -11,6 +11,5 @@ class Dimension::Validator::CheckValidityDimensionInProc < ApplicationRecord has_one_attached :valid - validates :valid, dimension: { width: { in: -> (record) { 100..200 } } } + validates :valid, dimension: { width: { in: ->(record) { 100..200 } } } end - diff --git a/test/dummy/app/models/dimension/validator/check_validity_dimension_in_range.rb b/test/dummy/app/models/dimension/validator/check_validity_dimension_in_range.rb index 07f870a4..e5ff8234 100644 --- a/test/dummy/app/models/dimension/validator/check_validity_dimension_in_range.rb +++ b/test/dummy/app/models/dimension/validator/check_validity_dimension_in_range.rb @@ -13,4 +13,3 @@ class Dimension::Validator::CheckValidityDimensionInRange < ApplicationRecord has_one_attached :valid validates :valid, dimension: { width: { in: 100..200 } } end - diff --git a/test/dummy/app/models/dimension/validator/check_validity_invalid_dimension_in.rb b/test/dummy/app/models/dimension/validator/check_validity_invalid_dimension_in.rb index 46e7f47c..77997a5a 100644 --- a/test/dummy/app/models/dimension/validator/check_validity_invalid_dimension_in.rb +++ b/test/dummy/app/models/dimension/validator/check_validity_invalid_dimension_in.rb @@ -13,4 +13,3 @@ class Dimension::Validator::CheckValidityInvalidDimensionIn < ApplicationRecord has_one_attached :invalid validates :invalid, dimension: { width: { in: 15 } } end - diff --git a/test/dummy/app/models/dimension/validator/check_validity_invalid_max.rb b/test/dummy/app/models/dimension/validator/check_validity_invalid_max.rb index c897f956..5591117a 100644 --- a/test/dummy/app/models/dimension/validator/check_validity_invalid_max.rb +++ b/test/dummy/app/models/dimension/validator/check_validity_invalid_max.rb @@ -13,4 +13,3 @@ class Dimension::Validator::CheckValidityInvalidMax < ApplicationRecord has_one_attached :invalid validates :invalid, dimension: { max: 15 } end - diff --git a/test/dummy/app/models/dimension/validator/check_validity_invalid_min.rb b/test/dummy/app/models/dimension/validator/check_validity_invalid_min.rb index e32aea99..85af784d 100644 --- a/test/dummy/app/models/dimension/validator/check_validity_invalid_min.rb +++ b/test/dummy/app/models/dimension/validator/check_validity_invalid_min.rb @@ -13,4 +13,3 @@ class Dimension::Validator::CheckValidityInvalidMin < ApplicationRecord has_one_attached :invalid validates :invalid, dimension: { min: 15 } end - diff --git a/test/dummy/app/models/dimension/validator/check_validity_max_proc.rb b/test/dummy/app/models/dimension/validator/check_validity_max_proc.rb index 49340319..e109b95e 100644 --- a/test/dummy/app/models/dimension/validator/check_validity_max_proc.rb +++ b/test/dummy/app/models/dimension/validator/check_validity_max_proc.rb @@ -13,4 +13,3 @@ class Dimension::Validator::CheckValidityMaxProc < ApplicationRecord has_one_attached :invalid validates :invalid, dimension: { max: -> { 15 } } end - diff --git a/test/dummy/app/models/dimension/validator/check_validity_max_range.rb b/test/dummy/app/models/dimension/validator/check_validity_max_range.rb index 7ff1301a..52ac95b9 100644 --- a/test/dummy/app/models/dimension/validator/check_validity_max_range.rb +++ b/test/dummy/app/models/dimension/validator/check_validity_max_range.rb @@ -13,4 +13,3 @@ class Dimension::Validator::CheckValidityMaxRange < ApplicationRecord has_one_attached :invalid validates :invalid, dimension: { max: 15..100 } end - diff --git a/test/dummy/app/models/dimension/validator/check_validity_min_proc.rb b/test/dummy/app/models/dimension/validator/check_validity_min_proc.rb index 37af6dca..38916eb2 100644 --- a/test/dummy/app/models/dimension/validator/check_validity_min_proc.rb +++ b/test/dummy/app/models/dimension/validator/check_validity_min_proc.rb @@ -13,4 +13,3 @@ class Dimension::Validator::CheckValidityMinProc < ApplicationRecord has_one_attached :invalid validates :invalid, dimension: { min: -> { 15 } } end - diff --git a/test/dummy/app/models/dimension/validator/check_validity_min_range.rb b/test/dummy/app/models/dimension/validator/check_validity_min_range.rb index ba9434cc..1690712b 100644 --- a/test/dummy/app/models/dimension/validator/check_validity_min_range.rb +++ b/test/dummy/app/models/dimension/validator/check_validity_min_range.rb @@ -13,4 +13,3 @@ class Dimension::Validator::CheckValidityMinRange < ApplicationRecord has_one_attached :invalid validates :invalid, dimension: { min: 15..100 } end - diff --git a/test/dummy/app/models/dimension/validator/with_if.rb b/test/dummy/app/models/dimension/validator/with_if.rb index cf9754d6..153c4474 100644 --- a/test/dummy/app/models/dimension/validator/with_if.rb +++ b/test/dummy/app/models/dimension/validator/with_if.rb @@ -14,9 +14,9 @@ class Dimension::Validator::WithIf < ApplicationRecord has_one_attached :with_if has_one_attached :with_if_proc validates :with_if, dimension: { width: 150, height: 150 }, if: :title_is_image? - validates :with_if_proc, dimension: { width: 150, height: 150 }, if: -> { self.title == 'Right title' } + validates :with_if_proc, dimension: { width: 150, height: 150 }, if: -> { self.title == "Right title" } def title_is_image? - title == 'image' + title == "image" end end diff --git a/test/dummy/app/models/dimension/validator/with_message.rb b/test/dummy/app/models/dimension/validator/with_message.rb index b7d58709..1a30b892 100644 --- a/test/dummy/app/models/dimension/validator/with_message.rb +++ b/test/dummy/app/models/dimension/validator/with_message.rb @@ -11,5 +11,5 @@ class Dimension::Validator::WithMessage < ApplicationRecord has_one_attached :with_message - validates :with_message, dimension: { width: 150, height: 150, message: 'Custom message' } + validates :with_message, dimension: { width: 150, height: 150, message: "Custom message" } end diff --git a/test/dummy/app/models/dimension/validator/with_on.rb b/test/dummy/app/models/dimension/validator/with_on.rb index ede1810a..17b2890b 100644 --- a/test/dummy/app/models/dimension/validator/with_on.rb +++ b/test/dummy/app/models/dimension/validator/with_on.rb @@ -11,5 +11,5 @@ class Dimension::Validator::WithOn < ApplicationRecord has_one_attached :with_on - validates :with_on, dimension: { width: 150, height: 150 }, on: %i(create update destroy custom) + validates :with_on, dimension: { width: 150, height: 150 }, on: %i[create update destroy custom] end diff --git a/test/dummy/app/models/document.rb b/test/dummy/app/models/document.rb index cf2a9e9e..9e5c2445 100644 --- a/test/dummy/app/models/document.rb +++ b/test/dummy/app/models/document.rb @@ -5,7 +5,7 @@ class Document < ApplicationRecord has_one_attached :proc_file validates :attachment, content_type: %i[docx xlsx pages numbers] - validates :file, content_type: ["application/x-tar", "application/x-gtar"] - validates :proc_attachment, content_type: -> (record) {%i[docx xlsx pages numbers]} - validates :proc_file, content_type: -> (record) { ["application/x-tar", "application/x-gtar"] } + validates :file, content_type: [ "application/x-tar", "application/x-gtar" ] + validates :proc_attachment, content_type: ->(record) { %i[docx xlsx pages numbers] } + validates :proc_file, content_type: ->(record) { [ "application/x-tar", "application/x-gtar" ] } end diff --git a/test/dummy/app/models/duration.rb b/test/dummy/app/models/duration.rb index 5f3ea619..85df1fac 100644 --- a/test/dummy/app/models/duration.rb +++ b/test/dummy/app/models/duration.rb @@ -1,5 +1,5 @@ module Duration def self.table_name_prefix - 'duration_' + "duration_" end end diff --git a/test/dummy/app/models/duration/matcher.rb b/test/dummy/app/models/duration/matcher.rb index 80111cac..cf7a8191 100644 --- a/test/dummy/app/models/duration/matcher.rb +++ b/test/dummy/app/models/duration/matcher.rb @@ -35,18 +35,18 @@ class Duration::Matcher < ApplicationRecord has_one_attached :proc_greater_than_or_equal_to has_one_attached :proc_between has_many_attached :proc_many_greater_than - validates :proc_less_than, duration: { less_than: -> (record) { 2.seconds } } - validates :proc_less_than_or_equal_to, duration: { less_than_or_equal_to: -> (record) { 2.seconds } } - validates :proc_greater_than, duration: { greater_than: -> (record) { 7.seconds } } - validates :proc_greater_than_or_equal_to, duration: { greater_than_or_equal_to: -> (record) { 7.seconds } } + validates :proc_less_than, duration: { less_than: ->(record) { 2.seconds } } + validates :proc_less_than_or_equal_to, duration: { less_than_or_equal_to: ->(record) { 2.seconds } } + validates :proc_greater_than, duration: { greater_than: ->(record) { 7.seconds } } + validates :proc_greater_than_or_equal_to, duration: { greater_than_or_equal_to: ->(record) { 7.seconds } } validates :proc_between, duration: { between: -> { 2.seconds..7.seconds } } - validates :proc_many_greater_than, duration: { greater_than: -> (record) { 7.seconds } } + validates :proc_many_greater_than, duration: { greater_than: ->(record) { 7.seconds } } has_one_attached :allow_blank validates :allow_blank, duration: { less_than_or_equal_to: 5.minutes }, allow_blank: true has_one_attached :with_message - validates :with_message, duration: { less_than_or_equal_to: 5.minutes, message: 'Custom message' } + validates :with_message, duration: { less_than_or_equal_to: 5.minutes, message: "Custom message" } has_one_attached :with_context_symbol validates :with_context_symbol, duration: { less_than_or_equal_to: 5.minutes }, on: :update @@ -60,8 +60,8 @@ class Duration::Matcher < ApplicationRecord validates :as_instance, duration: { less_than_or_equal_to: 5.minutes } has_one_attached :validatable_different_error_messages - validates :validatable_different_error_messages, duration: { less_than: 20.minutes, message: 'Custom message 1' }, if: :title_is_quo_vadis? - validates :validatable_different_error_messages, duration: { less_than: 10.minutes, message: 'Custom message 2' }, if: :title_is_american_psycho? + validates :validatable_different_error_messages, duration: { less_than: 20.minutes, message: "Custom message 1" }, if: :title_is_quo_vadis? + validates :validatable_different_error_messages, duration: { less_than: 10.minutes, message: "Custom message 2" }, if: :title_is_american_psycho? has_one_attached :failure_message validates :failure_message, duration: { less_than_or_equal_to: 5.minutes } @@ -74,9 +74,9 @@ class Duration::Matcher < ApplicationRecord has_one_attached :greater_than_with_message has_one_attached :greater_than_or_equal_to_with_message has_one_attached :between_with_message - validates :less_than_with_message, duration: { less_than: 2.seconds, message: 'File is too long.' } - validates :less_than_or_equal_to_with_message, duration: { less_than_or_equal_to: 2.seconds, message: 'File is too long.' } - validates :greater_than_with_message, duration: { greater_than: 7.seconds, message: 'File is too short.' } - validates :greater_than_or_equal_to_with_message, duration: { greater_than_or_equal_to: 7.seconds, message: 'File is too short.' } - validates :between_with_message, duration: { between: 2.seconds..7.seconds, message: 'File is not in accepted duration range.' } + validates :less_than_with_message, duration: { less_than: 2.seconds, message: "File is too long." } + validates :less_than_or_equal_to_with_message, duration: { less_than_or_equal_to: 2.seconds, message: "File is too long." } + validates :greater_than_with_message, duration: { greater_than: 7.seconds, message: "File is too short." } + validates :greater_than_or_equal_to_with_message, duration: { greater_than_or_equal_to: 7.seconds, message: "File is too short." } + validates :between_with_message, duration: { between: 2.seconds..7.seconds, message: "File is not in accepted duration range." } end diff --git a/test/dummy/app/models/duration/validator.rb b/test/dummy/app/models/duration/validator.rb index b2c823f8..1bce94ab 100644 --- a/test/dummy/app/models/duration/validator.rb +++ b/test/dummy/app/models/duration/validator.rb @@ -1,7 +1,7 @@ module Duration module Validator def self.table_name_prefix - 'duration_validator_' + "duration_validator_" end end end diff --git a/test/dummy/app/models/duration/validator/check.rb b/test/dummy/app/models/duration/validator/check.rb index b3543d32..3d9f9525 100644 --- a/test/dummy/app/models/duration/validator/check.rb +++ b/test/dummy/app/models/duration/validator/check.rb @@ -26,9 +26,9 @@ class Duration::Validator::Check < ApplicationRecord has_one_attached :greater_than_proc has_one_attached :greater_than_or_equal_to_proc has_one_attached :between_proc - validates :less_than_proc, duration: { less_than: -> (record) { 2.seconds } } - validates :less_than_or_equal_to_proc, duration: { less_than_or_equal_to: -> (record) { 2.seconds } } - validates :greater_than_proc, duration: { greater_than: -> (record) { 7.seconds } } - validates :greater_than_or_equal_to_proc, duration: { greater_than_or_equal_to: -> (record) { 7.seconds } } + validates :less_than_proc, duration: { less_than: ->(record) { 2.seconds } } + validates :less_than_or_equal_to_proc, duration: { less_than_or_equal_to: ->(record) { 2.seconds } } + validates :greater_than_proc, duration: { greater_than: ->(record) { 7.seconds } } + validates :greater_than_or_equal_to_proc, duration: { greater_than_or_equal_to: ->(record) { 7.seconds } } validates :between_proc, duration: { between: -> { 2.seconds..7.seconds } } end diff --git a/test/dummy/app/models/duration/validator/with_if.rb b/test/dummy/app/models/duration/validator/with_if.rb index 663f6575..666dd366 100644 --- a/test/dummy/app/models/duration/validator/with_if.rb +++ b/test/dummy/app/models/duration/validator/with_if.rb @@ -14,9 +14,9 @@ class Duration::Validator::WithIf < ApplicationRecord has_one_attached :with_if has_one_attached :with_if_proc validates :with_if, duration: { less_than: 2.seconds }, if: :title_is_image? - validates :with_if_proc, duration: { less_than: 2.seconds }, if: -> { self.title == 'Right title' } + validates :with_if_proc, duration: { less_than: 2.seconds }, if: -> { self.title == "Right title" } def title_is_image? - title == 'image' + title == "image" end end diff --git a/test/dummy/app/models/duration/validator/with_message.rb b/test/dummy/app/models/duration/validator/with_message.rb index e3b196a0..e0f261f6 100644 --- a/test/dummy/app/models/duration/validator/with_message.rb +++ b/test/dummy/app/models/duration/validator/with_message.rb @@ -11,5 +11,5 @@ class Duration::Validator::WithMessage < ApplicationRecord has_one_attached :with_message - validates :with_message, duration: { less_than: 2.seconds , message: 'Custom message' } + validates :with_message, duration: { less_than: 2.seconds, message: "Custom message" } end diff --git a/test/dummy/app/models/duration/validator/with_on.rb b/test/dummy/app/models/duration/validator/with_on.rb index 56ed5005..07f6e862 100644 --- a/test/dummy/app/models/duration/validator/with_on.rb +++ b/test/dummy/app/models/duration/validator/with_on.rb @@ -11,5 +11,5 @@ class Duration::Validator::WithOn < ApplicationRecord has_one_attached :with_on - validates :with_on, duration: { less_than: 2.seconds }, on: %i(create update destroy custom) + validates :with_on, duration: { less_than: 2.seconds }, on: %i[create update destroy custom] end diff --git a/test/dummy/app/models/integration.rb b/test/dummy/app/models/integration.rb index 02c47a73..ce7bb750 100644 --- a/test/dummy/app/models/integration.rb +++ b/test/dummy/app/models/integration.rb @@ -1,5 +1,5 @@ module Integration def self.table_name_prefix - 'integration_' + "integration_" end end diff --git a/test/dummy/app/models/integration/matcher.rb b/test/dummy/app/models/integration/matcher.rb index f2918d75..2c1c40f5 100644 --- a/test/dummy/app/models/integration/matcher.rb +++ b/test/dummy/app/models/integration/matcher.rb @@ -11,12 +11,12 @@ class Integration::Matcher < ApplicationRecord has_one_attached :example_1 - validates :example_1, size: { less_than: 10.megabytes, message: 'must be less than 10 MB' }, - content_type: ['image/png', 'image/jpeg', 'image/jpeg'] + validates :example_1, size: { less_than: 10.megabytes, message: "must be less than 10 MB" }, + content_type: [ "image/png", "image/jpeg", "image/jpeg" ] has_one_attached :example_2 validates :example_2, aspect_ratio: :square, size: { less_than_or_equal_to: 2.megabytes }, - content_type: { in: ['image/png', 'image/jpeg'], spoofing_protection: true }, + content_type: { in: [ "image/png", "image/jpeg" ], spoofing_protection: true }, processable_file: true end diff --git a/test/dummy/app/models/integration/validator.rb b/test/dummy/app/models/integration/validator.rb index 3ef1e160..b90e1664 100644 --- a/test/dummy/app/models/integration/validator.rb +++ b/test/dummy/app/models/integration/validator.rb @@ -1,7 +1,7 @@ module Integration module Validator def self.table_name_prefix - 'integration_validator_' + "integration_validator_" end end end diff --git a/test/dummy/app/models/integration/validator/based_on_a_file_property.rb b/test/dummy/app/models/integration/validator/based_on_a_file_property.rb index 3d1c9886..0610510b 100644 --- a/test/dummy/app/models/integration/validator/based_on_a_file_property.rb +++ b/test/dummy/app/models/integration/validator/based_on_a_file_property.rb @@ -12,6 +12,6 @@ class Integration::Validator::BasedOnAFileProperty < ApplicationRecord has_one_attached :picture validates :picture, - content_type: ['image/png', 'image/jpeg', 'image/gif'], - size: { less_than: -> (record) { record.picture.blob.content_type == "image/png" ? 15.kilobytes : 5.kilobytes} } + content_type: [ "image/png", "image/jpeg", "image/gif" ], + size: { less_than: ->(record) { record.picture.blob.content_type == "image/png" ? 15.kilobytes : 5.kilobytes } } end diff --git a/test/dummy/app/models/limit.rb b/test/dummy/app/models/limit.rb index 8aaa1640..13965ff7 100644 --- a/test/dummy/app/models/limit.rb +++ b/test/dummy/app/models/limit.rb @@ -1,5 +1,5 @@ module Limit def self.table_name_prefix - 'limit_' + "limit_" end end diff --git a/test/dummy/app/models/limit/matcher.rb b/test/dummy/app/models/limit/matcher.rb index 10a1a1af..d89f8ddc 100644 --- a/test/dummy/app/models/limit/matcher.rb +++ b/test/dummy/app/models/limit/matcher.rb @@ -16,7 +16,7 @@ class Limit::Matcher < ApplicationRecord has_many_attached :custom_matcher validates :custom_matcher, limit: { min: 1, max: 5 } - %i(min max).each do |bound| + %i[min max].each do |bound| has_many_attached bound validates bound, limit: { "#{bound}": 3 } end @@ -26,7 +26,7 @@ class Limit::Matcher < ApplicationRecord has_many_attached :with_message has_many_attached :without_message - validates :with_message, limit: { min: 1, max: 5, message: 'Custom message' } + validates :with_message, limit: { min: 1, max: 5, message: "Custom message" } validates :without_message, limit: { min: 1, max: 5 } has_many_attached :with_context_symbol @@ -41,8 +41,8 @@ class Limit::Matcher < ApplicationRecord validates :as_instance, limit: { min: 1, max: 5 } has_many_attached :validatable_different_error_messages - validates :validatable_different_error_messages, limit: { min: 1, message: 'Custom message 1' }, if: :title_is_quo_vadis? - validates :validatable_different_error_messages, limit: { min: 1, message: 'Custom message 2' }, if: :title_is_american_psycho? + validates :validatable_different_error_messages, limit: { min: 1, message: "Custom message 1" }, if: :title_is_quo_vadis? + validates :validatable_different_error_messages, limit: { min: 1, message: "Custom message 2" }, if: :title_is_american_psycho? has_many_attached :failure_message validates :failure_message, limit: { min: 1, max: 5 } @@ -53,7 +53,7 @@ class Limit::Matcher < ApplicationRecord has_many_attached :min_max validates :min_max, limit: { min: 1, max: 5 } has_many_attached :min_with_message - validates :min_with_message, limit: { min: 1, message: 'Invalid limits.' } + validates :min_with_message, limit: { min: 1, message: "Invalid limits." } has_many_attached :max_with_message - validates :max_with_message, limit: { max: 5, message: 'Invalid limits.' } + validates :max_with_message, limit: { max: 5, message: "Invalid limits." } end diff --git a/test/dummy/app/models/limit/validator.rb b/test/dummy/app/models/limit/validator.rb index aad44aaf..fbf69509 100644 --- a/test/dummy/app/models/limit/validator.rb +++ b/test/dummy/app/models/limit/validator.rb @@ -1,7 +1,7 @@ module Limit module Validator def self.table_name_prefix - 'limit_validator_' + "limit_validator_" end end end diff --git a/test/dummy/app/models/limit/validator/check_max_proc.rb b/test/dummy/app/models/limit/validator/check_max_proc.rb index 58dc4072..a6d52592 100644 --- a/test/dummy/app/models/limit/validator/check_max_proc.rb +++ b/test/dummy/app/models/limit/validator/check_max_proc.rb @@ -11,5 +11,5 @@ class Limit::Validator::CheckMaxProc < ApplicationRecord has_many_attached :max_proc - validates :max_proc, limit: { max: -> (record) { 1 } } + validates :max_proc, limit: { max: ->(record) { 1 } } end diff --git a/test/dummy/app/models/limit/validator/check_min_proc.rb b/test/dummy/app/models/limit/validator/check_min_proc.rb index 8d2d79d8..ba53cab2 100644 --- a/test/dummy/app/models/limit/validator/check_min_proc.rb +++ b/test/dummy/app/models/limit/validator/check_min_proc.rb @@ -11,5 +11,5 @@ class Limit::Validator::CheckMinProc < ApplicationRecord has_many_attached :min_proc - validates :min_proc, limit: { min: -> (record) { 2 } } + validates :min_proc, limit: { min: ->(record) { 2 } } end diff --git a/test/dummy/app/models/limit/validator/check_range.rb b/test/dummy/app/models/limit/validator/check_range.rb index 9b686b1a..440e11f0 100644 --- a/test/dummy/app/models/limit/validator/check_range.rb +++ b/test/dummy/app/models/limit/validator/check_range.rb @@ -13,4 +13,3 @@ class Limit::Validator::CheckRange < ApplicationRecord has_many_attached :range validates :range, limit: { min: 1, max: 3 } end - diff --git a/test/dummy/app/models/limit/validator/check_range_proc.rb b/test/dummy/app/models/limit/validator/check_range_proc.rb index eb82d039..1c27404d 100644 --- a/test/dummy/app/models/limit/validator/check_range_proc.rb +++ b/test/dummy/app/models/limit/validator/check_range_proc.rb @@ -11,6 +11,5 @@ class Limit::Validator::CheckRangeProc < ApplicationRecord has_many_attached :range_proc - validates :range_proc, limit: { min: -> (record) { 1 }, max: -> (record) { 3 } } + validates :range_proc, limit: { min: ->(record) { 1 }, max: ->(record) { 3 } } end - diff --git a/test/dummy/app/models/limit/validator/check_validity_invalid_argument.rb b/test/dummy/app/models/limit/validator/check_validity_invalid_argument.rb index 0acccc84..ca475510 100644 --- a/test/dummy/app/models/limit/validator/check_validity_invalid_argument.rb +++ b/test/dummy/app/models/limit/validator/check_validity_invalid_argument.rb @@ -11,5 +11,5 @@ class Limit::Validator::CheckValidityInvalidArgument < ApplicationRecord has_one_attached :invalid - validates :invalid, limit: { min: '1' } + validates :invalid, limit: { min: "1" } end diff --git a/test/dummy/app/models/limit/validator/check_validity_proc_option.rb b/test/dummy/app/models/limit/validator/check_validity_proc_option.rb index f01f3e46..a3f6e557 100644 --- a/test/dummy/app/models/limit/validator/check_validity_proc_option.rb +++ b/test/dummy/app/models/limit/validator/check_validity_proc_option.rb @@ -13,7 +13,7 @@ class Limit::Validator::CheckValidityProcOption < ApplicationRecord has_one_attached :invalid_1 has_one_attached :invalid_2 has_one_attached :invalid_3 - validates :invalid_1, limit: { min: -> (record) { 'invalid' } } - validates :invalid_2, limit: { max: -> (record) { 'invalid' } } - validates :invalid_3, limit: { min: -> (record) { 'invalid' }, max: -> (record) { 'invalid' } } + validates :invalid_1, limit: { min: ->(record) { "invalid" } } + validates :invalid_2, limit: { max: ->(record) { "invalid" } } + validates :invalid_3, limit: { min: ->(record) { "invalid" }, max: ->(record) { "invalid" } } end diff --git a/test/dummy/app/models/limit/validator/with_if.rb b/test/dummy/app/models/limit/validator/with_if.rb index 84566714..1614858b 100644 --- a/test/dummy/app/models/limit/validator/with_if.rb +++ b/test/dummy/app/models/limit/validator/with_if.rb @@ -14,9 +14,9 @@ class Limit::Validator::WithIf < ApplicationRecord has_one_attached :with_if has_one_attached :with_if_proc validates :with_if, limit: { min: 1 }, if: :title_is_image? - validates :with_if_proc, limit: { min: 1 }, if: -> { self.title == 'Right title' } + validates :with_if_proc, limit: { min: 1 }, if: -> { self.title == "Right title" } def title_is_image? - title == 'image' + title == "image" end end diff --git a/test/dummy/app/models/limit/validator/with_message.rb b/test/dummy/app/models/limit/validator/with_message.rb index 2591fa17..856f30c5 100644 --- a/test/dummy/app/models/limit/validator/with_message.rb +++ b/test/dummy/app/models/limit/validator/with_message.rb @@ -11,5 +11,5 @@ class Limit::Validator::WithMessage < ApplicationRecord has_one_attached :with_message - validates :with_message, limit: { max: 0, message: 'Custom message' } + validates :with_message, limit: { max: 0, message: "Custom message" } end diff --git a/test/dummy/app/models/limit/validator/with_on.rb b/test/dummy/app/models/limit/validator/with_on.rb index f8e266af..378ad266 100644 --- a/test/dummy/app/models/limit/validator/with_on.rb +++ b/test/dummy/app/models/limit/validator/with_on.rb @@ -11,5 +11,5 @@ class Limit::Validator::WithOn < ApplicationRecord has_one_attached :with_on - validates :with_on, limit: { min: 1 }, on: %i(create update destroy custom) + validates :with_on, limit: { min: 1 }, on: %i[create update destroy custom] end diff --git a/test/dummy/app/models/limit_attachment.rb b/test/dummy/app/models/limit_attachment.rb index 2f232c65..72ec1454 100644 --- a/test/dummy/app/models/limit_attachment.rb +++ b/test/dummy/app/models/limit_attachment.rb @@ -2,5 +2,5 @@ class LimitAttachment < ApplicationRecord has_many_attached :files has_many_attached :proc_files validates :files, limit: { max: 4 } - validates :proc_files, limit: { max: -> (record) {4} } + validates :proc_files, limit: { max: ->(record) { 4 } } end diff --git a/test/dummy/app/models/only_image.rb b/test/dummy/app/models/only_image.rb index b1c87505..b5df3e35 100644 --- a/test/dummy/app/models/only_image.rb +++ b/test/dummy/app/models/only_image.rb @@ -6,10 +6,10 @@ class OnlyImage < ApplicationRecord validates :image, dimension: { width: { min: 100, max: 2000 }, height: { min: 100, max: 1500 } }, aspect_ratio: :is_16_9, - content_type: ['image/png', 'image/jpeg'] - validates :proc_image, dimension: { width: { min: -> (record) {100}, max: -> (record) {2000} }, height: { min: -> (record) {100}, max: -> (record) {1500} } }, - aspect_ratio: -> (record) {:is_16_9}, - content_type: -> (record) {['image/png', 'image/jpeg']} + content_type: [ "image/png", "image/jpeg" ] + validates :proc_image, dimension: { width: { min: ->(record) { 100 }, max: ->(record) { 2000 } }, height: { min: ->(record) { 100 }, max: ->(record) { 1500 } } }, + aspect_ratio: ->(record) { :is_16_9 }, + content_type: ->(record) { [ "image/png", "image/jpeg" ] } validates :another_image, processable_file: true validates :any_image, processable_file: false end diff --git a/test/dummy/app/models/processable_file.rb b/test/dummy/app/models/processable_file.rb index 001d367c..dc5fb603 100644 --- a/test/dummy/app/models/processable_file.rb +++ b/test/dummy/app/models/processable_file.rb @@ -1,5 +1,5 @@ module ProcessableFile def self.table_name_prefix - 'processable_file_' + "processable_file_" end end diff --git a/test/dummy/app/models/processable_file/matcher.rb b/test/dummy/app/models/processable_file/matcher.rb index 7e54d393..31553761 100644 --- a/test/dummy/app/models/processable_file/matcher.rb +++ b/test/dummy/app/models/processable_file/matcher.rb @@ -20,7 +20,7 @@ class ProcessableFile::Matcher < ApplicationRecord validates :processable, processable_file: true has_one_attached :with_message - validates :with_message, processable_file: { message: 'Custom message' } + validates :with_message, processable_file: { message: "Custom message" } has_one_attached :with_context_symbol validates :with_context_symbol, processable_file: true, on: :update @@ -34,8 +34,8 @@ class ProcessableFile::Matcher < ApplicationRecord validates :as_instance, processable_file: true has_one_attached :validatable_different_error_messages - validates :validatable_different_error_messages, processable_file: { message: 'Custom message 1' }, if: :title_is_quo_vadis? - validates :validatable_different_error_messages, processable_file: { message: 'Custom message 2' }, if: :title_is_american_psycho? + validates :validatable_different_error_messages, processable_file: { message: "Custom message 1" }, if: :title_is_quo_vadis? + validates :validatable_different_error_messages, processable_file: { message: "Custom message 2" }, if: :title_is_american_psycho? has_one_attached :failure_message validates :failure_message, processable_file: true diff --git a/test/dummy/app/models/processable_file/validator.rb b/test/dummy/app/models/processable_file/validator.rb index 3b342222..a78bb722 100644 --- a/test/dummy/app/models/processable_file/validator.rb +++ b/test/dummy/app/models/processable_file/validator.rb @@ -1,7 +1,7 @@ module ProcessableFile module Validator def self.table_name_prefix - 'processable_file_validator_' + "processable_file_validator_" end end end diff --git a/test/dummy/app/models/processable_file/validator/with_if.rb b/test/dummy/app/models/processable_file/validator/with_if.rb index 436831f5..86afeec7 100644 --- a/test/dummy/app/models/processable_file/validator/with_if.rb +++ b/test/dummy/app/models/processable_file/validator/with_if.rb @@ -14,9 +14,9 @@ class ProcessableFile::Validator::WithIf < ApplicationRecord has_one_attached :with_if has_one_attached :with_if_proc validates :with_if, processable_file: true, if: :title_is_image? - validates :with_if_proc, processable_file: true, if: -> { self.title == 'Right title' } + validates :with_if_proc, processable_file: true, if: -> { self.title == "Right title" } def title_is_image? - title == 'image' + title == "image" end end diff --git a/test/dummy/app/models/processable_file/validator/with_message.rb b/test/dummy/app/models/processable_file/validator/with_message.rb index 967e709d..c5fd8611 100644 --- a/test/dummy/app/models/processable_file/validator/with_message.rb +++ b/test/dummy/app/models/processable_file/validator/with_message.rb @@ -11,5 +11,5 @@ class ProcessableFile::Validator::WithMessage < ApplicationRecord has_one_attached :with_message - validates :with_message, processable_file: { message: 'Custom message' } + validates :with_message, processable_file: { message: "Custom message" } end diff --git a/test/dummy/app/models/processable_file/validator/with_on.rb b/test/dummy/app/models/processable_file/validator/with_on.rb index 1be2d357..da7f8b68 100644 --- a/test/dummy/app/models/processable_file/validator/with_on.rb +++ b/test/dummy/app/models/processable_file/validator/with_on.rb @@ -11,5 +11,5 @@ class ProcessableFile::Validator::WithOn < ApplicationRecord has_one_attached :with_on - validates :with_on, processable_file: true, on: %i(create update destroy custom) + validates :with_on, processable_file: true, on: %i[create update destroy custom] end diff --git a/test/dummy/app/models/project.rb b/test/dummy/app/models/project.rb index 4f5d8891..b7a6f945 100644 --- a/test/dummy/app/models/project.rb +++ b/test/dummy/app/models/project.rb @@ -11,7 +11,6 @@ # class Project < ApplicationRecord - has_one_attached :dimension_exact has_one_attached :dimension_exact_with_message has_one_attached :dimension_range @@ -38,11 +37,11 @@ class Project < ApplicationRecord validates :dimension_max, dimension: { max: 1200..900 } validates :dimension_images, dimension: { width: { min: 800, max: 1200 }, height: { min: 600, max: 900 } } - validates :proc_documents, limit: { min: -> (record) {1}, max: -> (record) {3} } + validates :proc_documents, limit: { min: ->(record) { 1 }, max: ->(record) { 3 } } - validates :proc_dimension_exact, dimension: { width: -> (record) {150}, height: -> (record) {150} } - validates :proc_dimension_range, dimension: { width: { in: -> (record) {800..1200} }, height: { in: -> (record) {600..900} } } - validates :proc_dimension_min, dimension: { min: -> (record) {800..600} } - validates :proc_dimension_max, dimension: { max: -> (record) {1200..900} } + validates :proc_dimension_exact, dimension: { width: ->(record) { 150 }, height: ->(record) { 150 } } + validates :proc_dimension_range, dimension: { width: { in: ->(record) { 800..1200 } }, height: { in: ->(record) { 600..900 } } } + validates :proc_dimension_min, dimension: { min: ->(record) { 800..600 } } + validates :proc_dimension_max, dimension: { max: ->(record) { 1200..900 } } # validates :proc_dimension_images, dimension: { width: { min: -> (record) {800}, max: -> (record) {1200} }, height: { min: -> (record) {600}, max: -> (record) {900} } } end diff --git a/test/dummy/app/models/ratio_model.rb b/test/dummy/app/models/ratio_model.rb index 2d30df89..dd258d5d 100644 --- a/test/dummy/app/models/ratio_model.rb +++ b/test/dummy/app/models/ratio_model.rb @@ -15,7 +15,7 @@ class RatioModel < ApplicationRecord validates :ratio_one, attached: true, aspect_ratio: :square validates :ratio_many, attached: true, aspect_ratio: :portrait # portrait - validates :ratio_in, attached: true, aspect_ratio: { in: [:square, :portrait] } + validates :ratio_in, attached: true, aspect_ratio: { in: [ :square, :portrait ] } validates :image1, aspect_ratio: :is_16_9 # portrait validates :portrait_image, aspect_ratio: :portrait @@ -23,10 +23,10 @@ class RatioModel < ApplicationRecord validates :squared_image, aspect_ratio: :square validates :widescreen_image, aspect_ratio: :is_16_9square - #validates :ratio_many, attached: true, aspect_ratio: :landscape - #validates :ratio_many, attached: true, aspect_ratio: :portrait # portrait - validates :proc_ratio_one, attached: true, aspect_ratio: -> (record) {:square} - validates :proc_ratio_many, attached: true, aspect_ratio: -> (record) {:portrait} # portrait - validates :proc_ratio_in, attached: true, aspect_ratio: -> (record) {[:square, :portrait]} - validates :proc_image1, aspect_ratio: -> (record) {:is_16_9} # portrait + # validates :ratio_many, attached: true, aspect_ratio: :landscape + # validates :ratio_many, attached: true, aspect_ratio: :portrait # portrait + validates :proc_ratio_one, attached: true, aspect_ratio: ->(record) { :square } + validates :proc_ratio_many, attached: true, aspect_ratio: ->(record) { :portrait } # portrait + validates :proc_ratio_in, attached: true, aspect_ratio: ->(record) { [ :square, :portrait ] } + validates :proc_image1, aspect_ratio: ->(record) { :is_16_9 } # portrait end diff --git a/test/dummy/app/models/size.rb b/test/dummy/app/models/size.rb index 0f23a17d..b413f9fb 100644 --- a/test/dummy/app/models/size.rb +++ b/test/dummy/app/models/size.rb @@ -1,5 +1,5 @@ module Size def self.table_name_prefix - 'size_' + "size_" end end diff --git a/test/dummy/app/models/size/matcher.rb b/test/dummy/app/models/size/matcher.rb index 0dc59115..37c0ef34 100644 --- a/test/dummy/app/models/size/matcher.rb +++ b/test/dummy/app/models/size/matcher.rb @@ -35,18 +35,18 @@ class Size::Matcher < ApplicationRecord has_one_attached :proc_greater_than_or_equal_to has_one_attached :proc_between has_many_attached :proc_many_greater_than - validates :proc_less_than, size: { less_than: -> (record) { 2.kilobytes } } - validates :proc_less_than_or_equal_to, size: { less_than_or_equal_to: -> (record) { 2.kilobytes } } - validates :proc_greater_than, size: { greater_than: -> (record) { 7.kilobytes } } - validates :proc_greater_than_or_equal_to, size: { greater_than_or_equal_to: -> (record) { 7.kilobytes } } + validates :proc_less_than, size: { less_than: ->(record) { 2.kilobytes } } + validates :proc_less_than_or_equal_to, size: { less_than_or_equal_to: ->(record) { 2.kilobytes } } + validates :proc_greater_than, size: { greater_than: ->(record) { 7.kilobytes } } + validates :proc_greater_than_or_equal_to, size: { greater_than_or_equal_to: ->(record) { 7.kilobytes } } validates :proc_between, size: { between: -> { 2.kilobytes..7.kilobytes } } - validates :proc_many_greater_than, size: { greater_than: -> (record) { 7.kilobytes } } + validates :proc_many_greater_than, size: { greater_than: ->(record) { 7.kilobytes } } has_one_attached :allow_blank validates :allow_blank, size: { less_than_or_equal_to: 5.megabytes }, allow_blank: true has_one_attached :with_message - validates :with_message, size: { less_than_or_equal_to: 5.megabytes, message: 'Custom message' } + validates :with_message, size: { less_than_or_equal_to: 5.megabytes, message: "Custom message" } has_one_attached :with_context_symbol validates :with_context_symbol, size: { less_than_or_equal_to: 5.megabytes }, on: :update @@ -60,8 +60,8 @@ class Size::Matcher < ApplicationRecord validates :as_instance, size: { less_than_or_equal_to: 5.megabytes } has_one_attached :validatable_different_error_messages - validates :validatable_different_error_messages, size: { less_than: 20.megabytes, message: 'Custom message 1' }, if: :title_is_quo_vadis? - validates :validatable_different_error_messages, size: { less_than: 10.megabytes, message: 'Custom message 2' }, if: :title_is_american_psycho? + validates :validatable_different_error_messages, size: { less_than: 20.megabytes, message: "Custom message 1" }, if: :title_is_quo_vadis? + validates :validatable_different_error_messages, size: { less_than: 10.megabytes, message: "Custom message 2" }, if: :title_is_american_psycho? has_one_attached :failure_message validates :failure_message, size: { less_than_or_equal_to: 5.megabytes } @@ -74,9 +74,9 @@ class Size::Matcher < ApplicationRecord has_one_attached :greater_than_with_message has_one_attached :greater_than_or_equal_to_with_message has_one_attached :between_with_message - validates :less_than_with_message, size: { less_than: 2.kilobytes, message: 'File is too big.' } - validates :less_than_or_equal_to_with_message, size: { less_than_or_equal_to: 2.kilobytes, message: 'File is too big.' } - validates :greater_than_with_message, size: { greater_than: 7.kilobytes, message: 'File is too small.' } - validates :greater_than_or_equal_to_with_message, size: { greater_than_or_equal_to: 7.kilobytes, message: 'File is too small.' } - validates :between_with_message, size: { between: 2.kilobytes..7.kilobytes, message: 'File is not in accepted size range.' } + validates :less_than_with_message, size: { less_than: 2.kilobytes, message: "File is too big." } + validates :less_than_or_equal_to_with_message, size: { less_than_or_equal_to: 2.kilobytes, message: "File is too big." } + validates :greater_than_with_message, size: { greater_than: 7.kilobytes, message: "File is too small." } + validates :greater_than_or_equal_to_with_message, size: { greater_than_or_equal_to: 7.kilobytes, message: "File is too small." } + validates :between_with_message, size: { between: 2.kilobytes..7.kilobytes, message: "File is not in accepted size range." } end diff --git a/test/dummy/app/models/size/validator.rb b/test/dummy/app/models/size/validator.rb index 04795006..355211f7 100644 --- a/test/dummy/app/models/size/validator.rb +++ b/test/dummy/app/models/size/validator.rb @@ -1,7 +1,7 @@ module Size module Validator def self.table_name_prefix - 'size_validator_' + "size_validator_" end end end diff --git a/test/dummy/app/models/size/validator/check.rb b/test/dummy/app/models/size/validator/check.rb index 3f9f1bc0..a3c55b31 100644 --- a/test/dummy/app/models/size/validator/check.rb +++ b/test/dummy/app/models/size/validator/check.rb @@ -26,9 +26,9 @@ class Size::Validator::Check < ApplicationRecord has_one_attached :greater_than_proc has_one_attached :greater_than_or_equal_to_proc has_one_attached :between_proc - validates :less_than_proc, size: { less_than: -> (record) { 2.kilobytes } } - validates :less_than_or_equal_to_proc, size: { less_than_or_equal_to: -> (record) { 2.kilobytes } } - validates :greater_than_proc, size: { greater_than: -> (record) { 7.kilobytes } } - validates :greater_than_or_equal_to_proc, size: { greater_than_or_equal_to: -> (record) { 7.kilobytes } } + validates :less_than_proc, size: { less_than: ->(record) { 2.kilobytes } } + validates :less_than_or_equal_to_proc, size: { less_than_or_equal_to: ->(record) { 2.kilobytes } } + validates :greater_than_proc, size: { greater_than: ->(record) { 7.kilobytes } } + validates :greater_than_or_equal_to_proc, size: { greater_than_or_equal_to: ->(record) { 7.kilobytes } } validates :between_proc, size: { between: -> { 2.kilobytes..7.kilobytes } } end diff --git a/test/dummy/app/models/size/validator/with_if.rb b/test/dummy/app/models/size/validator/with_if.rb index 2e35a7b1..a64ef5df 100644 --- a/test/dummy/app/models/size/validator/with_if.rb +++ b/test/dummy/app/models/size/validator/with_if.rb @@ -14,9 +14,9 @@ class Size::Validator::WithIf < ApplicationRecord has_one_attached :with_if has_one_attached :with_if_proc validates :with_if, size: { less_than: 2.kilobytes }, if: :title_is_image? - validates :with_if_proc, size: { less_than: 2.kilobytes }, if: -> { self.title == 'Right title' } + validates :with_if_proc, size: { less_than: 2.kilobytes }, if: -> { self.title == "Right title" } def title_is_image? - title == 'image' + title == "image" end end diff --git a/test/dummy/app/models/size/validator/with_message.rb b/test/dummy/app/models/size/validator/with_message.rb index ae4916b0..0945bd50 100644 --- a/test/dummy/app/models/size/validator/with_message.rb +++ b/test/dummy/app/models/size/validator/with_message.rb @@ -11,5 +11,5 @@ class Size::Validator::WithMessage < ApplicationRecord has_one_attached :with_message - validates :with_message, size: { less_than: 2.kilobytes , message: 'Custom message' } + validates :with_message, size: { less_than: 2.kilobytes, message: "Custom message" } end diff --git a/test/dummy/app/models/size/validator/with_on.rb b/test/dummy/app/models/size/validator/with_on.rb index 8094d037..184b4df6 100644 --- a/test/dummy/app/models/size/validator/with_on.rb +++ b/test/dummy/app/models/size/validator/with_on.rb @@ -11,5 +11,5 @@ class Size::Validator::WithOn < ApplicationRecord has_one_attached :with_on - validates :with_on, size: { less_than: 2.kilobytes }, on: %i(create update destroy custom) + validates :with_on, size: { less_than: 2.kilobytes }, on: %i[create update destroy custom] end diff --git a/test/dummy/app/models/total_size.rb b/test/dummy/app/models/total_size.rb index 0d55e3ea..d9aeec42 100644 --- a/test/dummy/app/models/total_size.rb +++ b/test/dummy/app/models/total_size.rb @@ -1,5 +1,5 @@ module TotalSize def self.table_name_prefix - 'total_size_' + "total_size_" end end diff --git a/test/dummy/app/models/total_size/matcher.rb b/test/dummy/app/models/total_size/matcher.rb index 38de8560..69e02a40 100644 --- a/test/dummy/app/models/total_size/matcher.rb +++ b/test/dummy/app/models/total_size/matcher.rb @@ -32,17 +32,17 @@ class TotalSize::Matcher < ApplicationRecord has_many_attached :proc_greater_than has_many_attached :proc_greater_than_or_equal_to has_many_attached :proc_between - validates :proc_less_than, total_size: { less_than: -> (record) { 2.kilobytes } } - validates :proc_less_than_or_equal_to, total_size: { less_than_or_equal_to: -> (record) { 2.kilobytes } } - validates :proc_greater_than, total_size: { greater_than: -> (record) { 7.kilobytes } } - validates :proc_greater_than_or_equal_to, total_size: { greater_than_or_equal_to: -> (record) { 7.kilobytes } } + validates :proc_less_than, total_size: { less_than: ->(record) { 2.kilobytes } } + validates :proc_less_than_or_equal_to, total_size: { less_than_or_equal_to: ->(record) { 2.kilobytes } } + validates :proc_greater_than, total_size: { greater_than: ->(record) { 7.kilobytes } } + validates :proc_greater_than_or_equal_to, total_size: { greater_than_or_equal_to: ->(record) { 7.kilobytes } } validates :proc_between, total_size: { between: -> { 2.kilobytes..7.kilobytes } } has_many_attached :allow_blank validates :allow_blank, total_size: { less_than_or_equal_to: 5.megabytes }, allow_blank: true has_many_attached :with_message - validates :with_message, total_size: { less_than_or_equal_to: 5.megabytes, message: 'Custom message' } + validates :with_message, total_size: { less_than_or_equal_to: 5.megabytes, message: "Custom message" } has_many_attached :with_context_symbol validates :with_context_symbol, total_size: { less_than_or_equal_to: 5.megabytes }, on: :update @@ -56,8 +56,8 @@ class TotalSize::Matcher < ApplicationRecord validates :as_instance, total_size: { less_than_or_equal_to: 5.megabytes } has_many_attached :validatable_different_error_messages - validates :validatable_different_error_messages, total_size: { less_than: 20.megabytes, message: 'Custom message 1' }, if: :title_is_quo_vadis? - validates :validatable_different_error_messages, total_size: { less_than: 10.megabytes, message: 'Custom message 2' }, if: :title_is_american_psycho? + validates :validatable_different_error_messages, total_size: { less_than: 20.megabytes, message: "Custom message 1" }, if: :title_is_quo_vadis? + validates :validatable_different_error_messages, total_size: { less_than: 10.megabytes, message: "Custom message 2" }, if: :title_is_american_psycho? has_many_attached :failure_message validates :failure_message, total_size: { less_than_or_equal_to: 5.megabytes } @@ -70,9 +70,9 @@ class TotalSize::Matcher < ApplicationRecord has_many_attached :greater_than_with_message has_many_attached :greater_than_or_equal_to_with_message has_many_attached :between_with_message - validates :less_than_with_message, total_size: { less_than: 2.kilobytes, message: 'Total file size is too big.' } - validates :less_than_or_equal_to_with_message, total_size: { less_than_or_equal_to: 2.kilobytes, message: 'Total file size is too big.' } - validates :greater_than_with_message, total_size: { greater_than: 7.kilobytes, message: 'Total file size is too small.' } - validates :greater_than_or_equal_to_with_message, total_size: { greater_than_or_equal_to: 7.kilobytes, message: 'Total file size is too small.' } - validates :between_with_message, total_size: { between: 2.kilobytes..7.kilobytes, message: 'Total file size is not in accepted size range.' } + validates :less_than_with_message, total_size: { less_than: 2.kilobytes, message: "Total file size is too big." } + validates :less_than_or_equal_to_with_message, total_size: { less_than_or_equal_to: 2.kilobytes, message: "Total file size is too big." } + validates :greater_than_with_message, total_size: { greater_than: 7.kilobytes, message: "Total file size is too small." } + validates :greater_than_or_equal_to_with_message, total_size: { greater_than_or_equal_to: 7.kilobytes, message: "Total file size is too small." } + validates :between_with_message, total_size: { between: 2.kilobytes..7.kilobytes, message: "Total file size is not in accepted size range." } end diff --git a/test/dummy/app/models/total_size/validator.rb b/test/dummy/app/models/total_size/validator.rb index d3f14136..b12f7089 100644 --- a/test/dummy/app/models/total_size/validator.rb +++ b/test/dummy/app/models/total_size/validator.rb @@ -1,7 +1,7 @@ module TotalSize module Validator def self.table_name_prefix - 'total_size_validator_' + "total_size_validator_" end end end diff --git a/test/dummy/app/models/total_size/validator/check.rb b/test/dummy/app/models/total_size/validator/check.rb index 6d059d45..154310d8 100644 --- a/test/dummy/app/models/total_size/validator/check.rb +++ b/test/dummy/app/models/total_size/validator/check.rb @@ -26,9 +26,9 @@ class TotalSize::Validator::Check < ApplicationRecord has_many_attached :greater_than_proc has_many_attached :greater_than_or_equal_to_proc has_many_attached :between_proc - validates :less_than_proc, total_size: { less_than: -> (record) { 2.kilobytes } } - validates :less_than_or_equal_to_proc, total_size: { less_than_or_equal_to: -> (record) { 2.kilobytes } } - validates :greater_than_proc, total_size: { greater_than: -> (record) { 7.kilobytes } } - validates :greater_than_or_equal_to_proc, total_size: { greater_than_or_equal_to: -> (record) { 7.kilobytes } } + validates :less_than_proc, total_size: { less_than: ->(record) { 2.kilobytes } } + validates :less_than_or_equal_to_proc, total_size: { less_than_or_equal_to: ->(record) { 2.kilobytes } } + validates :greater_than_proc, total_size: { greater_than: ->(record) { 7.kilobytes } } + validates :greater_than_or_equal_to_proc, total_size: { greater_than_or_equal_to: ->(record) { 7.kilobytes } } validates :between_proc, total_size: { between: -> { 2.kilobytes..7.kilobytes } } end diff --git a/test/dummy/app/models/total_size/validator/with_if.rb b/test/dummy/app/models/total_size/validator/with_if.rb index 943cd137..f7b54c4c 100644 --- a/test/dummy/app/models/total_size/validator/with_if.rb +++ b/test/dummy/app/models/total_size/validator/with_if.rb @@ -14,9 +14,9 @@ class TotalSize::Validator::WithIf < ApplicationRecord has_many_attached :with_if has_many_attached :with_if_proc validates :with_if, total_size: { less_than: 2.kilobytes }, if: :title_is_image? - validates :with_if_proc, total_size: { less_than: 2.kilobytes }, if: -> { self.title == 'Right title' } + validates :with_if_proc, total_size: { less_than: 2.kilobytes }, if: -> { self.title == "Right title" } def title_is_image? - title == 'image' + title == "image" end end diff --git a/test/dummy/app/models/total_size/validator/with_message.rb b/test/dummy/app/models/total_size/validator/with_message.rb index 6c946292..749d001b 100644 --- a/test/dummy/app/models/total_size/validator/with_message.rb +++ b/test/dummy/app/models/total_size/validator/with_message.rb @@ -11,5 +11,5 @@ class TotalSize::Validator::WithMessage < ApplicationRecord has_many_attached :with_message - validates :with_message, total_size: { less_than: 2.kilobytes , message: 'Custom message' } + validates :with_message, total_size: { less_than: 2.kilobytes, message: "Custom message" } end diff --git a/test/dummy/app/models/total_size/validator/with_on.rb b/test/dummy/app/models/total_size/validator/with_on.rb index 1eb23081..fba68317 100644 --- a/test/dummy/app/models/total_size/validator/with_on.rb +++ b/test/dummy/app/models/total_size/validator/with_on.rb @@ -11,5 +11,5 @@ class TotalSize::Validator::WithOn < ApplicationRecord has_many_attached :with_on - validates :with_on, total_size: { less_than: 2.kilobytes }, on: %i(create update destroy custom) + validates :with_on, total_size: { less_than: 2.kilobytes }, on: %i[create update destroy custom] end diff --git a/test/dummy/app/models/user.rb b/test/dummy/app/models/user.rb index e606a4f8..ecc7a49b 100644 --- a/test/dummy/app/models/user.rb +++ b/test/dummy/app/models/user.rb @@ -25,17 +25,17 @@ class User < ApplicationRecord validates :name, presence: true validates :avatar, attached: { message: "must not be blank" }, content_type: :png - validates :photos, attached: true, content_type: ['image/png', 'image/jpeg', /\A.*\/pdf\z/] - validates :photo_with_messages, content_type: { in: ['image/png', 'image/jpeg', /\A.*\/pdf\z/], message: "must be an authorized type" } + validates :photos, attached: true, content_type: [ "image/png", "image/jpeg", /\A.*\/pdf\z/ ] + validates :photo_with_messages, content_type: { in: [ "image/png", "image/jpeg", /\A.*\/pdf\z/ ], message: "must be an authorized type" } validates :image_regex, content_type: /\Aimage\/.*\z/ - validates :conditional_image, attached: true, if: -> { name == 'Foo' } - validates :conditional_image_2, attached: true, content_type: -> (record) {[/\Aimage\/.*\z/]}, size: { less_than: 10.megabytes }, if: -> { name == 'Peter Griffin' } - validates :video, content_type: [:mp4, :mpeg, :webm] + validates :conditional_image, attached: true, if: -> { name == "Foo" } + validates :conditional_image_2, attached: true, content_type: ->(record) { [ /\Aimage\/.*\z/ ] }, size: { less_than: 10.megabytes }, if: -> { name == "Peter Griffin" } + validates :video, content_type: [ :mp4, :mpeg, :webm ] - validates :moon_picture, content_type: ['image/png'], size: { greater_than: 0 } + validates :moon_picture, content_type: [ "image/png" ], size: { greater_than: 0 } - validates :proc_avatar, attached: { message: "must not be blank" }, content_type: -> (record) {:png} - validates :proc_photos, attached: true, content_type: -> (record) {['image/png', 'image/jpeg', /\A.*\/pdf\z/]} - validates :proc_photo_with_messages, content_type: { in: -> (record) {['image/png', 'image/jpeg', /\A.*\/pdf\z/]}, message: "must be an authorized type" } - validates :proc_image_regex, content_type: -> (record) {/\Aimage\/.*\z/} + validates :proc_avatar, attached: { message: "must not be blank" }, content_type: ->(record) { :png } + validates :proc_photos, attached: true, content_type: ->(record) { [ "image/png", "image/jpeg", /\A.*\/pdf\z/ ] } + validates :proc_photo_with_messages, content_type: { in: ->(record) { [ "image/png", "image/jpeg", /\A.*\/pdf\z/ ] }, message: "must be an authorized type" } + validates :proc_image_regex, content_type: ->(record) { /\Aimage\/.*\z/ } end diff --git a/test/dummy/config/initializers/mime_types.rb b/test/dummy/config/initializers/mime_types.rb index 7dfd2c59..cc20f708 100644 --- a/test/dummy/config/initializers/mime_types.rb +++ b/test/dummy/config/initializers/mime_types.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true # Define custom mime types for Marcel -Marcel::MimeType.extend 'application/asv_test', extensions: %w(asv_test) +Marcel::MimeType.extend "application/asv_test", extensions: %w[asv_test] diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 57d19aaa..f0a6e0ce 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -37,7 +37,7 @@ t.datetime :updated_at, null: false end - %i( + %i[ aspect_ratio attached content_type @@ -47,21 +47,21 @@ processable_file size total_size - ).each do |validator| + ].each do |validator| create_table :"#{validator}_matchers", force: :cascade do |t| t.string :title t.datetime :created_at, null: false t.datetime :updated_at, null: false end - %w(invalid_check no_check).each do |invalid_case| + %w[invalid_check no_check].each do |invalid_case| create_table :"#{validator}_validator_check_validity_#{invalid_case.pluralize}", force: :cascade do |t| t.datetime :created_at, null: false t.datetime :updated_at, null: false end end - if %i(content_type duration size total_size).include? validator + if %i[content_type duration size total_size].include? validator create_table :"#{validator}_validator_check_validity_several_checks", force: :cascade do |t| t.datetime :created_at, null: false t.datetime :updated_at, null: false @@ -73,7 +73,7 @@ t.datetime :updated_at, null: false end - %i(allow_nil allow_blank if on strict unless message).each do |option| + %i[allow_nil allow_blank if on strict unless message].each do |option| create_table :"#{validator}_validator_with_#{option.to_s.pluralize}", force: :cascade do |t| t.string :title if option == :if t.integer :rating if option == :unless @@ -83,60 +83,60 @@ end end - %i( + %i[ aspect_ratio content_type dimension processable_file - ).each do |validator| + ].each do |validator| create_table :"#{validator}_validator_using_attachables", force: :cascade do |t| t.datetime :created_at, null: false t.datetime :updated_at, null: false end end - %i( + %i[ aspect_ratio content_type dimension duration processable_file - ).each do |validator| + ].each do |validator| create_table :"#{validator}_validator_is_performance_optimizeds", force: :cascade do |t| t.datetime :created_at, null: false t.datetime :updated_at, null: false end end - %w(proc_option invalid_named_argument invalid_is_xy_argument).each do |invalid_case| + %w[proc_option invalid_named_argument invalid_is_xy_argument].each do |invalid_case| create_table :"aspect_ratio_validator_check_validity_#{invalid_case.pluralize}", force: :cascade do |t| t.datetime :created_at, null: false t.datetime :updated_at, null: false end end - %w(proc_option invalid_content_type_with invalid_content_type_in invalid_content_type_jpg valid_ct_ole_storage invalid_extension regex_option).each do |invalid_case| + %w[proc_option invalid_content_type_with invalid_content_type_in invalid_content_type_jpg valid_ct_ole_storage invalid_extension regex_option].each do |invalid_case| create_table :"content_type_validator_check_validity_#{invalid_case.pluralize}", force: :cascade do |t| t.datetime :created_at, null: false t.datetime :updated_at, null: false end end - %w(dimension_in_range dimension_in_proc invalid_dimension_in min_range min_proc invalid_min max_range max_proc invalid_max).each do |invalid_case| + %w[dimension_in_range dimension_in_proc invalid_dimension_in min_range min_proc invalid_min max_range max_proc invalid_max].each do |invalid_case| create_table :"dimension_validator_check_validity_#{invalid_case.pluralize}", force: :cascade do |t| t.datetime :created_at, null: false t.datetime :updated_at, null: false end end - %w(proc_option invalid_argument max_higher_than_min).each do |invalid_case| + %w[proc_option invalid_argument max_higher_than_min].each do |invalid_case| create_table :"limit_validator_check_validity_#{invalid_case.pluralize}", force: :cascade do |t| t.datetime :created_at, null: false t.datetime :updated_at, null: false end end - %w(min min_proc max max_proc range range_proc).each do |check| + %w[min min_proc max max_proc range range_proc].each do |check| create_table :"limit_validator_check_#{check.pluralize}", force: :cascade do |t| t.datetime :created_at, null: false t.datetime :updated_at, null: false @@ -158,11 +158,11 @@ t.datetime :updated_at, null: false end - %w( + %w[ based_on_a_file_property performance zero_byte_image - ).each do |integration_test| + ].each do |integration_test| create_table :"integration_validator_#{integration_test.pluralize}", force: :cascade do |t| t.datetime :created_at, null: false t.datetime :updated_at, null: false diff --git a/test/extensors/asv_blob_metadatable_test.rb b/test/extensors/asv_blob_metadatable_test.rb index a9280a55..bdd50515 100644 --- a/test/extensors/asv_blob_metadatable_test.rb +++ b/test/extensors/asv_blob_metadatable_test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" describe ActiveStorageValidations::ASVBlobMetadatable do let(:blob) { ActiveStorage::Blob.new } @@ -13,20 +13,20 @@ describe "#merge_into_active_storage_validations_metadata" do it "adds our gem's setter method to ActiveStorage::Blob custom metadata" do - if Rails.gem_version >= Gem::Version.new('7.0.0.rc1') - blob.custom_metadata = { 'asv_duration' => '1.0', 'asv_width' => '100' } + if Rails.gem_version >= Gem::Version.new("7.0.0.rc1") + blob.custom_metadata = { "asv_duration" => "1.0", "asv_width" => "100" } else - blob.metadata[:custom] = { 'asv_duration' => '1.0', 'asv_width' => '100' } + blob.metadata[:custom] = { "asv_duration" => "1.0", "asv_width" => "100" } end - blob.merge_into_active_storage_validations_metadata({ 'duration' => 2.0, 'audio' => false }) + blob.merge_into_active_storage_validations_metadata({ "duration" => 2.0, "audio" => false }) - assert blob.active_storage_validations_metadata == { 'duration' => 2.0, 'audio' => false, 'width' => 100 } + assert blob.active_storage_validations_metadata == { "duration" => 2.0, "audio" => false, "width" => 100 } - if Rails.gem_version >= Gem::Version.new('7.0.0.rc1') - assert blob.custom_metadata == { 'asv_duration' => '2.0', 'asv_audio' => 'false', 'asv_width' => '100' } + if Rails.gem_version >= Gem::Version.new("7.0.0.rc1") + assert blob.custom_metadata == { "asv_duration" => "2.0", "asv_audio" => "false", "asv_width" => "100" } else - assert blob.metadata[:custom] == { 'asv_duration' => '2.0', 'asv_audio' => 'false', 'asv_width' => '100' } + assert blob.metadata[:custom] == { "asv_duration" => "2.0", "asv_audio" => "false", "asv_width" => "100" } end end end diff --git a/test/global/active_storage_validations_test.rb b/test/global/active_storage_validations_test.rb index 4d0ce508..7f864ff3 100644 --- a/test/global/active_storage_validations_test.rb +++ b/test/global/active_storage_validations_test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" describe ActiveStorageValidations do let(:instance) { ActiveStorageValidations::Check.new } @@ -27,7 +27,7 @@ # If not working, it would throw an error at the app initialization because # of our validator check_validity! method. it "allows the developer to define its own custom marcel mime types" do - assert_equal(Marcel::MimeType.for(declared_type: 'application/asv_test'), 'application/asv_test') + assert_equal(Marcel::MimeType.for(declared_type: "application/asv_test"), "application/asv_test") end end end diff --git a/test/matchers/aspect_ratio_validator_matcher_test.rb b/test/matchers/aspect_ratio_validator_matcher_test.rb index 3f92c15b..f4f61db5 100644 --- a/test/matchers/aspect_ratio_validator_matcher_test.rb +++ b/test/matchers/aspect_ratio_validator_matcher_test.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'test_helper' -require 'matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute' -require 'matchers/shared_examples/checks_if_is_valid' -require 'matchers/shared_examples/has_custom_matcher' -require 'matchers/shared_examples/has_valid_rspec_message_methods' -require 'matchers/shared_examples/works_with_allow_blank' -require 'matchers/shared_examples/works_with_both_instance_and_class' -require 'matchers/shared_examples/works_with_context' -require 'matchers/shared_examples/works_with_custom_message' +require "test_helper" +require "matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute" +require "matchers/shared_examples/checks_if_is_valid" +require "matchers/shared_examples/has_custom_matcher" +require "matchers/shared_examples/has_valid_rspec_message_methods" +require "matchers/shared_examples/works_with_allow_blank" +require "matchers/shared_examples/works_with_both_instance_and_class" +require "matchers/shared_examples/works_with_context" +require "matchers/shared_examples/works_with_custom_message" describe ActiveStorageValidations::Matchers::AspectRatioValidatorMatcher do include MatcherHelpers @@ -26,22 +26,22 @@ include HasCustomMatcher end - describe '#allowing' do - describe 'one' do - describe 'named aspect ratio' do + describe "#allowing" do + describe "one" do + describe "named aspect ratio" do ActiveStorageValidations::AspectRatioValidator::NAMED_ASPECT_RATIOS.each do |aspect_ratio| describe ":#{aspect_ratio}" do let(:model_attribute) { :"allowing_one_#{aspect_ratio}" } let(:allowed_aspect_ratio) { aspect_ratio } - describe 'when provided with the exact named allowed aspect ratio' do + describe "when provided with the exact named allowed aspect ratio" do subject { matcher.allowing(allowed_aspect_ratio) } it { is_expected_to_match_for(klass) } end describe "when provided with a 'is_x_y' aspect ratio" do - describe 'that fits the named aspect ratio constraint' do + describe "that fits the named aspect ratio constraint" do subject { matcher.allowing(matching_is_x_y_aspect_ratio) } let(:matching_is_x_y_aspect_ratio) do @@ -55,7 +55,7 @@ it { is_expected_to_match_for(klass) } end - describe 'that does not fit the named aspect ratio constraint' do + describe "that does not fit the named aspect ratio constraint" do subject { matcher.allowing(not_matching_is_x_y_aspect_ratio) } let(:not_matching_is_x_y_aspect_ratio) do @@ -70,15 +70,15 @@ end end - describe 'when provided with any aspect ratio but the named allowed aspect ratio' do + describe "when provided with any aspect ratio but the named allowed aspect ratio" do subject { matcher.allowing(any_aspect_ratio) } - let(:any_aspect_ratio) { (ActiveStorageValidations::AspectRatioValidator::NAMED_ASPECT_RATIOS - [aspect_ratio]).sample } + let(:any_aspect_ratio) { (ActiveStorageValidations::AspectRatioValidator::NAMED_ASPECT_RATIOS - [ aspect_ratio ]).sample } it { is_expected_not_to_match_for(klass) } end - describe 'when provided with something that is not a valid named aspect ratio' do + describe "when provided with something that is not a valid named aspect ratio" do subject { matcher.allowing(not_valid_aspect_ratio) } let(:not_valid_aspect_ratio) { :not_valid } @@ -92,7 +92,7 @@ describe "'is_x_y' aspect ratio" do let(:model_attribute) { :allowing_one_is_x_y } - describe 'when provided with a regex compatible aspect ratio' do + describe "when provided with a regex compatible aspect ratio" do subject { matcher.allowing(allowed_aspect_ratio) } let(:allowed_aspect_ratio) { :is_16_9 } @@ -100,7 +100,7 @@ it { is_expected_to_match_for(klass) } end - describe 'when provided with something that is not a valid aspect ratio' do + describe "when provided with something that is not a valid aspect ratio" do subject { matcher.allowing(not_valid_aspect_ratio) } let(:not_valid_aspect_ratio) { :is_16 } @@ -111,32 +111,32 @@ end end - describe '#rejecting' do - describe 'one' do - describe 'named aspect ratio' do + describe "#rejecting" do + describe "one" do + describe "named aspect ratio" do ActiveStorageValidations::AspectRatioValidator::NAMED_ASPECT_RATIOS.each do |aspect_ratio| describe ":#{aspect_ratio}" do let(:model_attribute) { :"allowing_one_#{aspect_ratio}" } let(:allowed_aspect_ratio) { aspect_ratio } - describe 'when provided with the exact allowed named aspect ratio' do + describe "when provided with the exact allowed named aspect ratio" do subject { matcher.rejecting(allowed_aspect_ratio) } it { is_expected_not_to_match_for(klass) } end - describe 'when provided with any aspect ratio but the allowed named aspect ratio' do + describe "when provided with any aspect ratio but the allowed named aspect ratio" do subject { matcher.rejecting(any_aspect_ratio) } - let(:any_aspect_ratio) { (ActiveStorageValidations::AspectRatioValidator::NAMED_ASPECT_RATIOS - [aspect_ratio]).sample } + let(:any_aspect_ratio) { (ActiveStorageValidations::AspectRatioValidator::NAMED_ASPECT_RATIOS - [ aspect_ratio ]).sample } it { is_expected_to_match_for(klass) } end - describe 'when provided with something that is not a valid named aspect ratio' do + describe "when provided with something that is not a valid named aspect ratio" do subject { matcher.rejecting(not_valid_aspect_ratio) } - let(:not_valid_aspect_ratio) { 'not_valid' } + let(:not_valid_aspect_ratio) { "not_valid" } it { is_expected_to_match_for(klass) } end @@ -147,7 +147,7 @@ describe "'is_x_y' aspect ratio" do let(:model_attribute) { :allowing_one_is_x_y } - describe 'when provided with the exact allowed aspect ratio' do + describe "when provided with the exact allowed aspect ratio" do subject { matcher.rejecting(allowed_aspect_ratio) } let(:allowed_aspect_ratio) { :is_16_9 } @@ -155,18 +155,18 @@ it { is_expected_not_to_match_for(klass) } end - describe 'when provided with any aspect ratio but the allowed aspect ratio' do + describe "when provided with any aspect ratio but the allowed aspect ratio" do subject { matcher.rejecting(any_aspect_ratio) } - let(:any_aspect_ratio) { (ActiveStorageValidations::AspectRatioValidator::NAMED_ASPECT_RATIOS + [:is_4_5]).sample } + let(:any_aspect_ratio) { (ActiveStorageValidations::AspectRatioValidator::NAMED_ASPECT_RATIOS + [ :is_4_5 ]).sample } it { is_expected_to_match_for(klass) } end - describe 'when provided with something that is not a valid aspect ratio' do + describe "when provided with something that is not a valid aspect ratio" do subject { matcher.allowing(not_valid_aspect_ratio) } - let(:not_valid_aspect_ratio) { 'not_valid' } + let(:not_valid_aspect_ratio) { "not_valid" } it { is_expected_not_to_match_for(klass) } end @@ -174,16 +174,16 @@ end end - describe 'Combinations' do - describe '#allowing + #with_message' do + describe "Combinations" do + describe "#allowing + #with_message" do let(:model_attribute) { :allowing_one_with_message } let(:allowed_aspect_ratio) { :portrait } - describe 'when provided with the exact allowed type' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact allowed type" do + describe "and when provided with the message specified in the model validations" do subject do matcher.allowing(allowed_aspect_ratio) - matcher.with_message('Not authorized aspect ratio.') + matcher.with_message("Not authorized aspect ratio.") end it { is_expected_to_match_for(klass) } @@ -191,15 +191,15 @@ end end - describe '#rejecting + #with_message' do + describe "#rejecting + #with_message" do let(:model_attribute) { :allowing_one_with_message } let(:not_allowed_aspect_ratio) { :square } - describe 'when provided with a not allowed aspect ratio' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with a not allowed aspect ratio" do + describe "and when provided with the message specified in the model validations" do subject do matcher.rejecting(not_allowed_aspect_ratio) - matcher.with_message('Not authorized aspect ratio.') + matcher.with_message("Not authorized aspect ratio.") end it { is_expected_to_match_for(klass) } @@ -207,13 +207,13 @@ end end - describe '#allowing + #rejecting' do + describe "#allowing + #rejecting" do let(:model_attribute) { :allowing_one_square } let(:allowed_aspect_ratio) { :square } let(:not_allowed_aspect_ratio) { :portrait } - describe 'when provided with the exact allowed aspect ratio' do - describe 'and when provided with a not allowed aspect ratio specified in the model validations' do + describe "when provided with the exact allowed aspect ratio" do + describe "and when provided with a not allowed aspect ratio specified in the model validations" do subject do matcher.allowing(allowed_aspect_ratio) matcher.rejecting(not_allowed_aspect_ratio) @@ -224,18 +224,18 @@ end end - describe '#allowing + #rejecting + #with_message' do + describe "#allowing + #rejecting + #with_message" do let(:model_attribute) { :allowing_one_with_message } let(:allowed_aspect_ratio) { :portrait } let(:not_allowed_aspect_ratio) { :landscape } - describe 'when provided with the exact allowed aspect ratio' do - describe 'and when provided with a not allowed aspect ratio' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact allowed aspect ratio" do + describe "and when provided with a not allowed aspect ratio" do + describe "and when provided with the message specified in the model validations" do subject do matcher.allowing(allowed_aspect_ratio) matcher.rejecting(not_allowed_aspect_ratio) - matcher.with_message('Not authorized aspect ratio.') + matcher.with_message("Not authorized aspect ratio.") end it { is_expected_to_match_for(klass) } @@ -249,7 +249,7 @@ include WorksWithAllowBlank end - describe '#with_message' do + describe "#with_message" do include WorksWithCustomMessage end diff --git a/test/matchers/attached_validator_matcher_test.rb b/test/matchers/attached_validator_matcher_test.rb index 88f771ea..05217eae 100644 --- a/test/matchers/attached_validator_matcher_test.rb +++ b/test/matchers/attached_validator_matcher_test.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'test_helper' -require 'matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute' -require 'matchers/shared_examples/checks_if_is_valid' -require 'matchers/shared_examples/has_custom_matcher' -require 'matchers/shared_examples/has_valid_rspec_message_methods' -require 'matchers/shared_examples/works_with_both_instance_and_class' -require 'matchers/shared_examples/works_with_context' -require 'matchers/shared_examples/works_with_custom_message' +require "test_helper" +require "matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute" +require "matchers/shared_examples/checks_if_is_valid" +require "matchers/shared_examples/has_custom_matcher" +require "matchers/shared_examples/has_valid_rspec_message_methods" +require "matchers/shared_examples/works_with_both_instance_and_class" +require "matchers/shared_examples/works_with_context" +require "matchers/shared_examples/works_with_custom_message" describe ActiveStorageValidations::Matchers::AttachedValidatorMatcher do include MatcherHelpers @@ -25,7 +25,7 @@ include HasCustomMatcher end - describe 'when the passed model attribute does not have an `attached: true` constraint' do + describe "when the passed model attribute does not have an `attached: true` constraint" do subject { matcher } let(:model_attribute) { :not_required } @@ -33,7 +33,7 @@ it { is_expected_not_to_match_for(klass) } end - describe '#with_message' do + describe "#with_message" do include WorksWithCustomMessage end diff --git a/test/matchers/content_type_validator_matcher_test.rb b/test/matchers/content_type_validator_matcher_test.rb index 5e486f3f..bad244b4 100644 --- a/test/matchers/content_type_validator_matcher_test.rb +++ b/test/matchers/content_type_validator_matcher_test.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'test_helper' -require 'matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute' -require 'matchers/shared_examples/checks_if_is_valid' -require 'matchers/shared_examples/has_custom_matcher' -require 'matchers/shared_examples/has_valid_rspec_message_methods' -require 'matchers/shared_examples/works_with_allow_blank' -require 'matchers/shared_examples/works_with_both_instance_and_class' -require 'matchers/shared_examples/works_with_context' -require 'matchers/shared_examples/works_with_custom_message' +require "test_helper" +require "matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute" +require "matchers/shared_examples/checks_if_is_valid" +require "matchers/shared_examples/has_custom_matcher" +require "matchers/shared_examples/has_valid_rspec_message_methods" +require "matchers/shared_examples/works_with_allow_blank" +require "matchers/shared_examples/works_with_both_instance_and_class" +require "matchers/shared_examples/works_with_context" +require "matchers/shared_examples/works_with_custom_message" describe ActiveStorageValidations::Matchers::ContentTypeValidatorMatcher do include MatcherHelpers @@ -26,102 +26,102 @@ include HasCustomMatcher end - describe '#allowing' do - describe 'one' do + describe "#allowing" do + describe "one" do let(:model_attribute) { :allowing_one } - let(:allowed_type) { 'image/png' } + let(:allowed_type) { "image/png" } - describe 'when provided with the exact allowed type' do + describe "when provided with the exact allowed type" do subject { matcher.allowing(allowed_type) } it { is_expected_to_match_for(klass) } end - describe 'when provided with something that is not a valid type' do + describe "when provided with something that is not a valid type" do subject { matcher.allowing(not_valid_type) } - let(:not_valid_type) { 'not_valid' } + let(:not_valid_type) { "not_valid" } it { is_expected_not_to_match_for(klass) } end end - describe 'several' do + describe "several" do let(:model_attribute) { :allowing_several } - let(:allowed_types) { ['image/png', 'image/gif'] } - let(:not_allowed_types) { ['video/x-matroska', 'application/pdf'] } + let(:allowed_types) { [ "image/png", "image/gif" ] } + let(:not_allowed_types) { [ "video/x-matroska", "application/pdf" ] } - describe 'when provided with the exact allowed types' do + describe "when provided with the exact allowed types" do subject { matcher.allowing(*allowed_types) } it { is_expected_to_match_for(klass) } end - describe 'when provided with only allowed types but not all types' do + describe "when provided with only allowed types but not all types" do subject { matcher.allowing(allowed_types.sample) } it { is_expected_to_match_for(klass) } end - describe 'when provided with allowed and not allowed types' do + describe "when provided with allowed and not allowed types" do subject { matcher.allowing(allowed_types.sample, not_allowed_types.sample) } it { is_expected_not_to_match_for(klass) } end - describe 'when provided with only not allowed types' do + describe "when provided with only not allowed types" do subject { matcher.allowing(*not_allowed_types) } it { is_expected_not_to_match_for(klass) } end - describe 'when provided with something that is not a valid type' do + describe "when provided with something that is not a valid type" do subject { matcher.allowing(not_valid_type) } - let(:not_valid_type) { 'not_valid' } + let(:not_valid_type) { "not_valid" } it { is_expected_not_to_match_for(klass) } end end - describe 'several through regex' do + describe "several through regex" do let(:model_attribute) { :allowing_several_through_regex } - let(:some_allowed_types) { ['image/png', 'image/gif'] } - let(:not_allowed_types) { ['video/x-matroska', 'application/pdf'] } + let(:some_allowed_types) { [ "image/png", "image/gif" ] } + let(:not_allowed_types) { [ "video/x-matroska", "application/pdf" ] } - describe 'when provided with only allowed types but not all types' do + describe "when provided with only allowed types but not all types" do subject { matcher.allowing(*some_allowed_types) } it { is_expected_to_match_for(klass) } end - describe 'when provided with allowed and not allowed types' do + describe "when provided with allowed and not allowed types" do subject { matcher.allowing(some_allowed_types.sample, not_allowed_types.sample) } it { is_expected_not_to_match_for(klass) } end - describe 'when provided with only not allowed types' do + describe "when provided with only not allowed types" do subject { matcher.allowing(*not_allowed_types) } it { is_expected_not_to_match_for(klass) } end - describe 'when provided with something that is not a valid type' do + describe "when provided with something that is not a valid type" do subject { matcher.allowing(not_valid_type) } - let(:not_valid_type) { 'not_valid' } + let(:not_valid_type) { "not_valid" } it { is_expected_not_to_match_for(klass) } end end - describe 'Edge cases' do + describe "Edge cases" do describe "when the passed content_type is a symbol (e.g. :png)" do let(:model_attribute) { :allowing_symbol } let(:allowed_type) { :png } - describe 'when provided with the exact allowed type' do + describe "when provided with the exact allowed type" do subject { matcher.allowing(allowed_type) } it { is_expected_to_match_for(klass) } @@ -130,9 +130,9 @@ describe "when the content_type specifier (e.g. 'svg+xml') is not strictly equal to the file extension (e.g. '.svg')" do let(:model_attribute) { :allowing_sneaky_edge_cases } - let(:allowed_types) { ["image/svg+xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"] } + let(:allowed_types) { [ "image/svg+xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ] } - describe 'when provided with the exact allowed types' do + describe "when provided with the exact allowed types" do subject { matcher.allowing(*allowed_types) } it { is_expected_to_match_for(klass) } @@ -141,48 +141,48 @@ end end - describe '#rejecting' do + describe "#rejecting" do let(:model_attribute) { :allowing_one } - let(:allowed_type) { 'image/png' } + let(:allowed_type) { "image/png" } - describe 'one' do - describe 'when provided with the exact allowed type' do + describe "one" do + describe "when provided with the exact allowed type" do subject { matcher.rejecting(allowed_type) } it { is_expected_not_to_match_for(klass) } end - describe 'when provided with any type but the allowed type' do + describe "when provided with any type but the allowed type" do subject { matcher.rejecting(any_type) } - let(:any_type) { 'video/x-matroska' } + let(:any_type) { "video/x-matroska" } it { is_expected_to_match_for(klass) } end - describe 'when provided with something that is not a valid type' do + describe "when provided with something that is not a valid type" do subject { matcher.rejecting(not_valid_type) } - let(:not_valid_type) { 'not_valid' } + let(:not_valid_type) { "not_valid" } it { is_expected_to_match_for(klass) } end end - describe 'several' do - describe 'when provided with any types but the allowed type' do + describe "several" do + describe "when provided with any types but the allowed type" do subject { matcher.rejecting(*any_types) } - let(:any_types) { ['video/x-matroska', 'image/gif'] } + let(:any_types) { [ "video/x-matroska", "image/gif" ] } it { is_expected_to_match_for(klass) } end - describe 'when provided with any types and the allowed type' do + describe "when provided with any types and the allowed type" do subject { matcher.rejecting(*types) } - let(:any_types) { ['video/x-matroska', 'image/gif'] } - let(:types) { any_types + [allowed_type] } + let(:any_types) { [ "video/x-matroska", "image/gif" ] } + let(:types) { any_types + [ allowed_type ] } it { is_expected_not_to_match_for(klass) } end @@ -193,7 +193,7 @@ include WorksWithAllowBlank end - describe '#with_message' do + describe "#with_message" do include WorksWithCustomMessage end @@ -201,16 +201,16 @@ include WorksWithContext end - describe 'Combinations' do - describe '#allowing + #with_message' do + describe "Combinations" do + describe "#allowing + #with_message" do let(:model_attribute) { :allowing_one_with_message } - let(:allowed_type) { 'application/pdf' } + let(:allowed_type) { "application/pdf" } - describe 'when provided with the exact allowed type' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact allowed type" do + describe "and when provided with the message specified in the model validations" do subject do matcher.allowing(allowed_type) - matcher.with_message('Not authorized file type.') + matcher.with_message("Not authorized file type.") end it { is_expected_to_match_for(klass) } @@ -218,15 +218,15 @@ end end - describe '#rejecting + #with_message' do + describe "#rejecting + #with_message" do let(:model_attribute) { :allowing_one_with_message } - let(:not_allowed_type) { 'video/x-matroska' } + let(:not_allowed_type) { "video/x-matroska" } - describe 'when provided with a not allowed type' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with a not allowed type" do + describe "and when provided with the message specified in the model validations" do subject do matcher.rejecting(not_allowed_type) - matcher.with_message('Not authorized file type.') + matcher.with_message("Not authorized file type.") end it { is_expected_to_match_for(klass) } @@ -234,13 +234,13 @@ end end - describe '#allowing + #rejecting' do + describe "#allowing + #rejecting" do let(:model_attribute) { :allowing_one } - let(:allowed_type) { 'image/png' } - let(:not_allowed_type) { 'video/x-matroska' } + let(:allowed_type) { "image/png" } + let(:not_allowed_type) { "video/x-matroska" } - describe 'when provided with the exact allowed type' do - describe 'and when provided with a not allowed type specified in the model validations' do + describe "when provided with the exact allowed type" do + describe "and when provided with a not allowed type specified in the model validations" do subject do matcher.allowing(allowed_type) matcher.rejecting(not_allowed_type) @@ -251,18 +251,18 @@ end end - describe '#allowing + #rejecting + #with_message' do + describe "#allowing + #rejecting + #with_message" do let(:model_attribute) { :allowing_one_with_message } - let(:allowed_type) { 'application/pdf' } - let(:not_allowed_type) { 'video/x-matroska' } + let(:allowed_type) { "application/pdf" } + let(:not_allowed_type) { "video/x-matroska" } - describe 'when provided with the exact allowed type' do - describe 'and when provided with a not allowed type' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact allowed type" do + describe "and when provided with a not allowed type" do + describe "and when provided with the message specified in the model validations" do subject do matcher.allowing(allowed_type) matcher.rejecting(not_allowed_type) - matcher.with_message('Not authorized file type.') + matcher.with_message("Not authorized file type.") end it { is_expected_to_match_for(klass) } @@ -278,10 +278,10 @@ subject { matcher.allowing(allowed_type) } let(:allowed_type) { common_mime_type[:mime_type] } - let(:media) { common_mime_type[:mime_type].split('/').first } + let(:media) { common_mime_type[:mime_type].split("/").first } let(:content) { common_mime_type[:extension].underscore } - let(:model_attribute) { [media, content].join('_') } # e.g. image_jpeg + let(:model_attribute) { [ media, content ].join("_") } # e.g. image_jpeg it { is_expected_to_match_for(klass) } end diff --git a/test/matchers/dimension_validator_matcher_test.rb b/test/matchers/dimension_validator_matcher_test.rb index 17b0b0f5..4a083801 100644 --- a/test/matchers/dimension_validator_matcher_test.rb +++ b/test/matchers/dimension_validator_matcher_test.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'test_helper' -require 'matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute' -require 'matchers/shared_examples/checks_if_is_valid' -require 'matchers/shared_examples/has_custom_matcher' -require 'matchers/shared_examples/has_valid_rspec_message_methods' -require 'matchers/shared_examples/works_with_allow_blank' -require 'matchers/shared_examples/works_with_both_instance_and_class' -require 'matchers/shared_examples/works_with_context' -require 'matchers/shared_examples/works_with_custom_message' +require "test_helper" +require "matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute" +require "matchers/shared_examples/checks_if_is_valid" +require "matchers/shared_examples/has_custom_matcher" +require "matchers/shared_examples/has_valid_rspec_message_methods" +require "matchers/shared_examples/works_with_allow_blank" +require "matchers/shared_examples/works_with_both_instance_and_class" +require "matchers/shared_examples/works_with_context" +require "matchers/shared_examples/works_with_custom_message" module DimensionValidatorMatcherTest module DoesNotMatchWithAnyValues @@ -28,7 +28,7 @@ module DoesNotMatchWhenLowerValueThanLowerRangeBoundValue included do let(:lower_than_lower_range_bound_value) { matcher_method.match?(/_between/) ? 150..200 : 150 } - describe 'when provided with a lower width than the lower range bound width specified in the model validations' do + describe "when provided with a lower width than the lower range bound width specified in the model validations" do subject { matcher.public_send(matcher_method, lower_than_lower_range_bound_value) } it { is_expected_not_to_match_for(klass) } @@ -42,7 +42,7 @@ module DoesNotMatchWhenValueEqualToLowerRangeBoundValue included do let(:lower_range_bound_value) { matcher_method.match?(/_between/) ? 800..1000 : 800 } - describe 'when provided with the exact lower range bound width specified in the model validations' do + describe "when provided with the exact lower range bound width specified in the model validations" do subject { matcher.public_send(matcher_method, lower_range_bound_value) } it { is_expected_not_to_match_for(klass) } @@ -56,7 +56,7 @@ module DoesNotMatchWhenValueEqualToHigherRangeBoundValue included do let(:higher_range_bound_value) { matcher_method.match?(/_between/) ? 1200..1500 : 1200 } - describe 'when provided with the exact higher range bound width specified in the model validations' do + describe "when provided with the exact higher range bound width specified in the model validations" do subject { matcher.public_send(matcher_method, higher_range_bound_value) } it { is_expected_not_to_match_for(klass) } @@ -70,7 +70,7 @@ module DoesNotMatchWhenHigherValueThanHigherRangeBoundValue included do let(:higher_than_higher_range_bound_value) { matcher_method.match?(/_between/) ? 9999..10000 : 9999 } - describe 'when provided with a higher width than the higher range bound width specified in the model validations' do + describe "when provided with a higher width than the higher range bound width specified in the model validations" do subject { matcher.public_send(matcher_method, higher_than_higher_range_bound_value) } it { is_expected_not_to_match_for(klass) } @@ -82,19 +82,19 @@ module OnlyMatchWhenExactValue extend ActiveSupport::Concern included do - describe 'when provided with a lower width than the width specified in the model validations' do + describe "when provided with a lower width than the width specified in the model validations" do subject { matcher.public_send(matcher_method, 1) } it { is_expected_not_to_match_for(klass) } end - describe 'when provided with the exact width specified in the model validations' do + describe "when provided with the exact width specified in the model validations" do subject { matcher.public_send(matcher_method, validator_value) } it { is_expected_to_match_for(klass) } end - describe 'when provided with a higher width than the width specified in the model validations' do + describe "when provided with a higher width than the width specified in the model validations" do subject { matcher.public_send(matcher_method, 9999) } it { is_expected_not_to_match_for(klass) } @@ -106,7 +106,7 @@ module OnlyMatchWhenExactValues extend ActiveSupport::Concern included do - %i(width height).each do |dimension| + %i[width height].each do |dimension| describe "when provided with a lower #{dimension} than the #{dimension} specified in the model validations" do subject do matcher.width(dimension == :width ? 1 : 150) @@ -117,7 +117,7 @@ module OnlyMatchWhenExactValues end end - describe 'when provided with the exact width and height specified in the model validations' do + describe "when provided with the exact width and height specified in the model validations" do subject do matcher.width(150) matcher.height(150) @@ -126,7 +126,7 @@ module OnlyMatchWhenExactValues it { is_expected_to_match_for(klass) } end - %i(width height).each do |dimension| + %i[width height].each do |dimension| describe "when provided with a higher #{dimension} than the #{dimension} specified in the model validations" do subject do matcher.width(dimension == :width ? 9999 : 150) @@ -156,7 +156,7 @@ module OnlyMatchWhenExactValues include HasCustomMatcher end - %i(width height).each do |dimension| + %i[width height].each do |dimension| describe "##{dimension}" do let(:matcher_method) { dimension } @@ -336,7 +336,7 @@ module OnlyMatchWhenExactValues include WorksWithAllowBlank end - describe '#with_message' do + describe "#with_message" do include WorksWithCustomMessage end @@ -345,7 +345,7 @@ module OnlyMatchWhenExactValues end describe "Combinations" do - %i(width height).each do |dimension| + %i[width height].each do |dimension| describe "##{dimension} + #with_message" do let(:dimension_matcher_method) { dimension } let(:model_attribute) { :"#{dimension}_exact_with_message" } @@ -354,7 +354,7 @@ module OnlyMatchWhenExactValues describe "and when provided with the exact #{dimension} and message specified in the model validations" do subject do matcher.public_send(dimension_matcher_method, 150) - matcher.with_message('Invalid dimensions.') + matcher.with_message("Invalid dimensions.") end it { is_expected_to_match_for(klass) } @@ -370,7 +370,7 @@ module OnlyMatchWhenExactValues describe "and when provided with the exact #{dimension} range and message specified in the model validations" do subject do matcher.public_send(dimension_matcher_method, 800..1200) - matcher.with_message('Invalid dimensions.') + matcher.with_message("Invalid dimensions.") end it { is_expected_to_match_for(klass) } @@ -386,7 +386,7 @@ module OnlyMatchWhenExactValues describe "and when provided with the min #{dimension} and message specified in the model validations" do subject do matcher.public_send(dimension_matcher_method, 800) - matcher.with_message('Invalid dimensions.') + matcher.with_message("Invalid dimensions.") end it { is_expected_to_match_for(klass) } @@ -402,7 +402,7 @@ module OnlyMatchWhenExactValues describe "and when provided with the max #{dimension} and message specified in the model validations" do subject do matcher.public_send(dimension_matcher_method, 1200) - matcher.with_message('Invalid dimensions.') + matcher.with_message("Invalid dimensions.") end it { is_expected_to_match_for(klass) } @@ -411,7 +411,7 @@ module OnlyMatchWhenExactValues end end - %i(min max).each do |bound| + %i[min max].each do |bound| describe "#width_#{bound} + #height_#{bound}" do let(:model_attribute) { :"#{bound}" } @@ -424,7 +424,7 @@ module OnlyMatchWhenExactValues it { is_expected_not_to_match_for(klass) } end - %i(width height).each do |dimension| + %i[width height].each do |dimension| describe "when provided with a lower #{dimension} than the #{dimension} specified in the model validations" do subject do matcher.public_send(:"width_#{bound}", dimension == :width ? 1 : 800) @@ -444,7 +444,7 @@ module OnlyMatchWhenExactValues it { is_expected_to_match_for(klass) } end - %i(width height).each do |dimension| + %i[width height].each do |dimension| describe "when provided with a higher #{dimension} than the #{dimension} specified in the model validations" do subject do matcher.public_send(:"width_#{bound}", dimension == :width ? 9999 : 800) @@ -473,7 +473,7 @@ module OnlyMatchWhenExactValues subject do matcher.public_send(:"width_#{bound}", 800) matcher.public_send(:"height_#{bound}", 600) - matcher.with_message('Invalid dimensions.') + matcher.with_message("Invalid dimensions.") end it { is_expected_to_match_for(klass) } @@ -482,23 +482,23 @@ module OnlyMatchWhenExactValues end end - describe '#width + #height' do - describe 'when used on a width exact and height exact validator (e.g. dimension: { width: 150, height: 150 })' do + describe "#width + #height" do + describe "when used on a width exact and height exact validator (e.g. dimension: { width: 150, height: 150 })" do let(:model_attribute) { :width_and_height_exact } include DimensionValidatorMatcherTest::OnlyMatchWhenExactValues end end - describe '#width + #height + #with_message' do + describe "#width + #height + #with_message" do let(:model_attribute) { :width_and_height_exact_with_message } describe "when used on a width exact and height exact with message validator (e.g. dimension: { width: 150, height: 150, message: 'Invalid dimensions.' })" do - describe 'and when provided with the exact width, height and message specified in the model validations' do + describe "and when provided with the exact width, height and message specified in the model validations" do subject do matcher.width(150) matcher.height(150) - matcher.with_message('Invalid dimensions.') + matcher.with_message("Invalid dimensions.") end it { is_expected_to_match_for(klass) } @@ -533,7 +533,7 @@ module OnlyMatchWhenExactValues subject do matcher.width_between(800..1200) matcher.height_between(600..900) - matcher.with_message('Invalid dimensions.') + matcher.with_message("Invalid dimensions.") end it { is_expected_to_match_for(klass) } diff --git a/test/matchers/duration_validator_matcher_test.rb b/test/matchers/duration_validator_matcher_test.rb index ece408bb..b354f7e1 100644 --- a/test/matchers/duration_validator_matcher_test.rb +++ b/test/matchers/duration_validator_matcher_test.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'test_helper' -require 'matchers/shared_examples/base_comparison_validator_matcher' -require 'matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute' -require 'matchers/shared_examples/checks_if_is_valid' -require 'matchers/shared_examples/has_custom_matcher' -require 'matchers/shared_examples/has_valid_rspec_message_methods' -require 'matchers/shared_examples/works_with_allow_blank' -require 'matchers/shared_examples/works_with_both_instance_and_class' -require 'matchers/shared_examples/works_with_context' -require 'matchers/shared_examples/works_with_custom_message' +require "test_helper" +require "matchers/shared_examples/base_comparison_validator_matcher" +require "matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute" +require "matchers/shared_examples/checks_if_is_valid" +require "matchers/shared_examples/has_custom_matcher" +require "matchers/shared_examples/has_valid_rspec_message_methods" +require "matchers/shared_examples/works_with_allow_blank" +require "matchers/shared_examples/works_with_both_instance_and_class" +require "matchers/shared_examples/works_with_context" +require "matchers/shared_examples/works_with_custom_message" describe ActiveStorageValidations::Matchers::DurationValidatorMatcher do include MatcherHelpers @@ -27,7 +27,7 @@ include HasCustomMatcher end - describe '#less_than' do + describe "#less_than" do let(:matcher_method) { :less_than } let(:model_attribute) { matcher_method } let(:validator_value) { 2.seconds } @@ -35,7 +35,7 @@ include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe '#less_than_or_equal_to' do + describe "#less_than_or_equal_to" do let(:matcher_method) { :less_than_or_equal_to } let(:model_attribute) { matcher_method } let(:validator_value) { 2.seconds } @@ -43,24 +43,24 @@ include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe '#greater_than' do + describe "#greater_than" do let(:matcher_method) { :greater_than } let(:validator_value) { 7.seconds } - describe 'with has_one_attached' do + describe "with has_one_attached" do let(:model_attribute) { matcher_method } include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe 'with has_many_attached' do + describe "with has_many_attached" do let(:model_attribute) { :many_greater_than } include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end end - describe '#greater_than_or_equal_to' do + describe "#greater_than_or_equal_to" do let(:matcher_method) { :greater_than_or_equal_to } let(:model_attribute) { matcher_method } let(:validator_value) { 7.seconds } @@ -68,44 +68,44 @@ include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe '#between' do + describe "#between" do let(:model_attribute) { :between } - describe 'when provided with the exact durations specified in the model validations' do + describe "when provided with the exact durations specified in the model validations" do subject { matcher.between 2.seconds..7.seconds } it { is_expected_to_match_for(klass) } end - describe 'when provided with a higher duration than the duration specified in the model validations' do - describe 'for the highest possible duration' do + describe "when provided with a higher duration than the duration specified in the model validations" do + describe "for the highest possible duration" do subject { matcher.between 2.seconds..10.seconds } it { is_expected_not_to_match_for(klass) } end - describe 'for the lowest possible duration' do + describe "for the lowest possible duration" do subject { matcher.between 5.seconds..7.seconds } it { is_expected_not_to_match_for(klass) } end end - describe 'when provided with a lower duration than the duration specified in the model validations' do - describe 'for the highest possible duration' do + describe "when provided with a lower duration than the duration specified in the model validations" do + describe "for the highest possible duration" do subject { matcher.between 1.seconds..7.seconds } it { is_expected_not_to_match_for(klass) } end - describe 'for the lowest possible duration' do + describe "for the lowest possible duration" do subject { matcher.between 1.seconds..7.seconds } it { is_expected_not_to_match_for(klass) } end end - describe 'when provided with both lowest and highest possible durations different than the model validations' do + describe "when provided with both lowest and highest possible durations different than the model validations" do subject { matcher.between 4.seconds..20.seconds } it { is_expected_not_to_match_for(klass) } @@ -116,7 +116,7 @@ include WorksWithAllowBlank end - describe '#with_message' do + describe "#with_message" do include WorksWithCustomMessage end @@ -124,15 +124,15 @@ include WorksWithContext end - describe 'Combinations' do - describe '#less_than + #with_message' do + describe "Combinations" do + describe "#less_than + #with_message" do let(:model_attribute) { :less_than_with_message } - describe 'when provided with the exact duration' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact duration" do + describe "and when provided with the message specified in the model validations" do subject do matcher.less_than 2.seconds - matcher.with_message('File is too long.') + matcher.with_message("File is too long.") end it { is_expected_to_match_for(klass) } @@ -140,14 +140,14 @@ end end - describe '#less_than_or_equal_to + #with_message' do + describe "#less_than_or_equal_to + #with_message" do let(:model_attribute) { :less_than_or_equal_to_with_message } - describe 'when provided with the exact duration' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact duration" do + describe "and when provided with the message specified in the model validations" do subject do matcher.less_than_or_equal_to 2.seconds - matcher.with_message('File is too long.') + matcher.with_message("File is too long.") end it { is_expected_to_match_for(klass) } @@ -155,14 +155,14 @@ end end - describe '#greater_than + #with_message' do + describe "#greater_than + #with_message" do let(:model_attribute) { :greater_than_with_message } - describe 'when provided with the exact duration' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact duration" do + describe "and when provided with the message specified in the model validations" do subject do matcher.greater_than 7.seconds - matcher.with_message('File is too short.') + matcher.with_message("File is too short.") end it { is_expected_to_match_for(klass) } @@ -170,14 +170,14 @@ end end - describe '#greater_than_or_equal_to + #with_message' do + describe "#greater_than_or_equal_to + #with_message" do let(:model_attribute) { :greater_than_or_equal_to_with_message } - describe 'when provided with the exact duration' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact duration" do + describe "and when provided with the message specified in the model validations" do subject do matcher.greater_than_or_equal_to 7.seconds - matcher.with_message('File is too short.') + matcher.with_message("File is too short.") end it { is_expected_to_match_for(klass) } @@ -185,14 +185,14 @@ end end - describe '#between + #with_message' do + describe "#between + #with_message" do let(:model_attribute) { :between_with_message } - describe 'when provided with the exact duration' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact duration" do + describe "and when provided with the message specified in the model validations" do subject do matcher.between 2.seconds..7.seconds - matcher.with_message('File is not in accepted duration range.') + matcher.with_message("File is not in accepted duration range.") end it { is_expected_to_match_for(klass) } diff --git a/test/matchers/integration/integration_test.rb b/test/matchers/integration/integration_test.rb index 47d39a34..5eea97d7 100644 --- a/test/matchers/integration/integration_test.rb +++ b/test/matchers/integration/integration_test.rb @@ -1,38 +1,38 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" -describe 'Integration tests' do +describe "Integration tests" do include MatcherHelpers let(:klass) { Integration::Matcher } let(:matcher_class) { "ActiveStorageValidations::Matchers::#{matcher_type.to_s.camelize}ValidatorMatcher".constantize } let(:matcher) { matcher_class.new(model_attribute) } - describe 'example_1' do + describe "example_1" do # validates :example_1, size: { less_than: 10.megabytes, message: 'must be less than 10 MB' }, # content_type: ['image/png', 'image/jpeg', 'image/jpeg'] let(:model_attribute) { :example_1 } - describe 'size matcher' do + describe "size matcher" do let(:matcher_type) { :size } - describe 'when provided with the size value and size message specified in the model validations' do + describe "when provided with the size value and size message specified in the model validations" do subject do matcher.less_than(10.megabytes) - matcher.with_message('must be less than 10 MB') + matcher.with_message("must be less than 10 MB") end it { is_expected_to_match_for(klass) } end end - describe 'content_type matcher' do + describe "content_type matcher" do let(:matcher_type) { :content_type } - describe 'when provided with the content_type value specified in the model validations' do + describe "when provided with the content_type value specified in the model validations" do subject do - matcher.allowing('image/png', 'image/jpeg', 'image/jpeg') + matcher.allowing("image/png", "image/jpeg", "image/jpeg") end it { is_expected_to_match_for(klass) } @@ -43,10 +43,10 @@ describe "example_2" do let(:model_attribute) { :example_2 } - describe 'aspect_ratio matcher' do + describe "aspect_ratio matcher" do let(:matcher_type) { :aspect_ratio } - describe 'when provided with the aspect_ratio value specified in the model validations' do + describe "when provided with the aspect_ratio value specified in the model validations" do subject do matcher.allowing(:square) end @@ -55,10 +55,10 @@ end end - describe 'size matcher' do + describe "size matcher" do let(:matcher_type) { :size } - describe 'when provided with the size value specified in the model validations' do + describe "when provided with the size value specified in the model validations" do subject do matcher.less_than_or_equal_to(2.megabytes) end @@ -67,22 +67,22 @@ end end - describe 'content_type matcher' do + describe "content_type matcher" do let(:matcher_type) { :content_type } - describe 'when provided with the content_type value specified in the model validations' do + describe "when provided with the content_type value specified in the model validations" do subject do - matcher.allowing('image/png', 'image/jpeg') + matcher.allowing("image/png", "image/jpeg") end it { is_expected_to_match_for(klass) } end end - describe 'processable_file matcher' do + describe "processable_file matcher" do let(:matcher_type) { :processable_file } - describe 'when provided with the processable_file value specified in the model validations' do + describe "when provided with the processable_file value specified in the model validations" do subject do matcher end diff --git a/test/matchers/limit_validator_matcher_test.rb b/test/matchers/limit_validator_matcher_test.rb index da57e0e0..a731f7e3 100644 --- a/test/matchers/limit_validator_matcher_test.rb +++ b/test/matchers/limit_validator_matcher_test.rb @@ -1,33 +1,33 @@ # frozen_string_literal: true -require 'test_helper' -require 'matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute' -require 'matchers/shared_examples/checks_if_is_valid' -require 'matchers/shared_examples/has_custom_matcher' -require 'matchers/shared_examples/has_valid_rspec_message_methods' -require 'matchers/shared_examples/works_with_allow_blank' -require 'matchers/shared_examples/works_with_both_instance_and_class' -require 'matchers/shared_examples/works_with_context' -require 'matchers/shared_examples/works_with_custom_message' +require "test_helper" +require "matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute" +require "matchers/shared_examples/checks_if_is_valid" +require "matchers/shared_examples/has_custom_matcher" +require "matchers/shared_examples/has_valid_rspec_message_methods" +require "matchers/shared_examples/works_with_allow_blank" +require "matchers/shared_examples/works_with_both_instance_and_class" +require "matchers/shared_examples/works_with_context" +require "matchers/shared_examples/works_with_custom_message" module LimitValidatorMatcherTest module OnlyMatchWhenExactValue extend ActiveSupport::Concern included do - describe 'when provided with a lower file count than the bound file count specified in the model validations' do + describe "when provided with a lower file count than the bound file count specified in the model validations" do subject { matcher.public_send(matcher_method, 1) } it { is_expected_not_to_match_for(klass) } end - describe 'when provided with the exact bound file count specified in the model validations' do + describe "when provided with the exact bound file count specified in the model validations" do subject { matcher.public_send(matcher_method, validator_value) } it { is_expected_to_match_for(klass) } end - describe 'when provided with a higher file count than the bound file count specified in the model validations' do + describe "when provided with a higher file count than the bound file count specified in the model validations" do subject { matcher.public_send(matcher_method, 9) } it { is_expected_not_to_match_for(klass) } @@ -52,7 +52,7 @@ module OnlyMatchWhenExactValue include HasCustomMatcher end - %i(min max).each do |bound| + %i[min max].each do |bound| describe "##{bound}" do let(:matcher_method) { bound } @@ -69,7 +69,7 @@ module OnlyMatchWhenExactValue include WorksWithAllowBlank end - describe '#with_message' do + describe "#with_message" do include WorksWithCustomMessage end @@ -100,7 +100,7 @@ module OnlyMatchWhenExactValue describe "and when provided with the :min file count and :message specified in the model validations" do subject do matcher.public_send(:min, 1) - matcher.with_message('Invalid limits.') + matcher.with_message("Invalid limits.") end it { is_expected_to_match_for(klass) } @@ -115,7 +115,7 @@ module OnlyMatchWhenExactValue describe "and when provided with the :max and :message specified in the model validations" do subject do matcher.public_send(:max, 5) - matcher.with_message('Invalid limits.') + matcher.with_message("Invalid limits.") end it { is_expected_to_match_for(klass) } diff --git a/test/matchers/processable_file_validator_matcher_test.rb b/test/matchers/processable_file_validator_matcher_test.rb index 436a448a..dd596e09 100644 --- a/test/matchers/processable_file_validator_matcher_test.rb +++ b/test/matchers/processable_file_validator_matcher_test.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'test_helper' -require 'matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute' -require 'matchers/shared_examples/checks_if_is_valid' -require 'matchers/shared_examples/has_custom_matcher' -require 'matchers/shared_examples/has_valid_rspec_message_methods' -require 'matchers/shared_examples/works_with_both_instance_and_class' -require 'matchers/shared_examples/works_with_context' -require 'matchers/shared_examples/works_with_custom_message' +require "test_helper" +require "matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute" +require "matchers/shared_examples/checks_if_is_valid" +require "matchers/shared_examples/has_custom_matcher" +require "matchers/shared_examples/has_valid_rspec_message_methods" +require "matchers/shared_examples/works_with_both_instance_and_class" +require "matchers/shared_examples/works_with_context" +require "matchers/shared_examples/works_with_custom_message" describe ActiveStorageValidations::Matchers::ProcessableFileValidatorMatcher do include MatcherHelpers @@ -25,7 +25,7 @@ include HasCustomMatcher end - describe 'when the passed model attribute does not have a `processable: true` constraint' do + describe "when the passed model attribute does not have a `processable: true` constraint" do subject { matcher } let(:model_attribute) { :not_required } @@ -33,7 +33,7 @@ it { is_expected_not_to_match_for(klass) } end - describe '#with_message' do + describe "#with_message" do include WorksWithCustomMessage end diff --git a/test/matchers/shared_examples/base_comparison_validator_matcher.rb b/test/matchers/shared_examples/base_comparison_validator_matcher.rb index d0729c6d..3036b2d0 100644 --- a/test/matchers/shared_examples/base_comparison_validator_matcher.rb +++ b/test/matchers/shared_examples/base_comparison_validator_matcher.rb @@ -3,7 +3,7 @@ module OnlyMatchWhenExactValue extend ActiveSupport::Concern included do - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe value_type do let(:matcher_class) do "ActiveStorageValidations::Matchers::#{klass.name.split('::').first}ValidatorMatcher".constantize @@ -22,19 +22,19 @@ module OnlyMatchWhenExactValue end end - describe 'when provided with a lower value than the value specified in the model validations' do + describe "when provided with a lower value than the value specified in the model validations" do subject { matcher.public_send(matcher_method, lower_value) } it { is_expected_not_to_match_for(klass) } end - describe 'when provided with the exact value specified in the model validations' do + describe "when provided with the exact value specified in the model validations" do subject { matcher.public_send(matcher_method, validator_value) } it { is_expected_to_match_for(klass) } end - describe 'when provided with a higher value than the value specified in the model validations' do + describe "when provided with a higher value than the value specified in the model validations" do subject { matcher.public_send(matcher_method, higher_value) } it { is_expected_not_to_match_for(klass) } diff --git a/test/matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute.rb b/test/matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute.rb index 361074b0..5742b85d 100644 --- a/test/matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute.rb +++ b/test/matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute.rb @@ -2,8 +2,8 @@ module ChecksIfIsAValidActiveStorageAttribute extend ActiveSupport::Concern included do - describe 'when the passed model attribute' do - describe 'does not exist' do + describe "when the passed model attribute" do + describe "does not exist" do subject { matcher } let(:model_attribute) { :not_present_in_model } @@ -11,7 +11,7 @@ module ChecksIfIsAValidActiveStorageAttribute it { is_expected_not_to_match_for(klass) } end - describe 'is not an active storage attribute' do + describe "is not an active storage attribute" do subject { matcher } let(:model_attribute) { :title } diff --git a/test/matchers/shared_examples/checks_if_is_valid.rb b/test/matchers/shared_examples/checks_if_is_valid.rb index 60bc7b81..cafac009 100644 --- a/test/matchers/shared_examples/checks_if_is_valid.rb +++ b/test/matchers/shared_examples/checks_if_is_valid.rb @@ -2,14 +2,14 @@ module ChecksIfIsValid extend ActiveSupport::Concern included do - describe 'Edge cases' do - describe 'when the validator is used several times on the same attributes' do - describe 'and is provided with different error messages' do + describe "Edge cases" do + describe "when the validator is used several times on the same attributes" do + describe "and is provided with different error messages" do before do case validator_sym when :aspect_ratio then matcher.allowing(:square) when :attached then matcher - when :content_type then matcher.rejecting('image/jpg') + when :content_type then matcher.rejecting("image/jpg") when :processable_file then matcher when :limit then matcher.min(1) when :dimension then matcher.width(150) diff --git a/test/matchers/shared_examples/has_custom_matcher.rb b/test/matchers/shared_examples/has_custom_matcher.rb index 451a839a..5a5f62ea 100644 --- a/test/matchers/shared_examples/has_custom_matcher.rb +++ b/test/matchers/shared_examples/has_custom_matcher.rb @@ -4,7 +4,7 @@ module HasCustomMatcher included do let(:model_attribute) { :custom_matcher } - describe 'using custom matcher' do + describe "using custom matcher" do before do class ActiveSupport::TestCase extend ActiveStorageValidations::Matchers @@ -15,7 +15,7 @@ class ActiveSupport::TestCase when :attached then custom_matcher_builder.validate_attached_of(model_attribute) when :processable_file then custom_matcher_builder.validate_processable_file_of(model_attribute) when :limit then custom_matcher_builder.validate_limits_of(model_attribute).min(1).max(5) - when :content_type then custom_matcher_builder.validate_content_type_of(model_attribute).allowing('image/png') + when :content_type then custom_matcher_builder.validate_content_type_of(model_attribute).allowing("image/png") when :dimension then custom_matcher_builder.validate_dimensions_of(model_attribute).width(150).height(150) when :duration then custom_matcher_builder.validate_duration_of(model_attribute).less_than_or_equal_to(5.minutes) when :size then custom_matcher_builder.validate_size_of(model_attribute).less_than_or_equal_to(5.megabytes) @@ -27,8 +27,8 @@ class ActiveSupport::TestCase let(:custom_matcher_builder) { ActiveSupport::TestCase } - it 'makes the method available for use' do - refute(custom_matcher_builder.nil?) + it "makes the method available for use" do + assert_not(custom_matcher_builder.nil?) end end end diff --git a/test/matchers/shared_examples/has_valid_rspec_message_methods.rb b/test/matchers/shared_examples/has_valid_rspec_message_methods.rb index 45ab6972..72d5bb84 100644 --- a/test/matchers/shared_examples/has_valid_rspec_message_methods.rb +++ b/test/matchers/shared_examples/has_valid_rspec_message_methods.rb @@ -2,14 +2,14 @@ module HasValidRspecMessageMethods extend ActiveSupport::Concern included do - describe 'when the matcher returns a failure message to the dev' do + describe "when the matcher returns a failure message to the dev" do before do case validator_sym when :aspect_ratio then matcher.rejecting(:square) when :attached then matcher when :processable_file then matcher when :limit then matcher.min(0).max(6) - when :content_type then matcher.rejecting('image/png') + when :content_type then matcher.rejecting("image/png") when :dimension then matcher.width(75).height(75) when :duration then matcher.less_than_or_equal_to(7.minutes) when :size then matcher.less_than_or_equal_to(7.megabytes) @@ -83,14 +83,14 @@ module HasValidRspecMessageMethods it { is_expected_to_have_failure_message(expected_failure_message) } end - describe 'when the matcher returns a negated failure message to the dev' do + describe "when the matcher returns a negated failure message to the dev" do before do case validator_sym when :aspect_ratio then matcher.allowing(:square) when :attached then matcher when :processable_file then matcher when :limit then matcher.min(1).max(5) - when :content_type then matcher.allowing('image/png') + when :content_type then matcher.allowing("image/png") when :dimension then matcher.width(150).height(150) when :duration then matcher.less_than_or_equal_to(5.minutes) when :size then matcher.less_than_or_equal_to(5.megabytes) @@ -164,7 +164,7 @@ module HasValidRspecMessageMethods it { is_expected_to_have_failure_message_when_negated(expected_failure_message) } end - describe 'when the dev asks for a description of the matcher' do + describe "when the dev asks for a description of the matcher" do subject { matcher.description } let(:model_attribute) { :failure_message_when_negated } diff --git a/test/matchers/shared_examples/works_with_allow_blank.rb b/test/matchers/shared_examples/works_with_allow_blank.rb index cbb4ce46..300f8d5e 100644 --- a/test/matchers/shared_examples/works_with_allow_blank.rb +++ b/test/matchers/shared_examples/works_with_allow_blank.rb @@ -4,11 +4,11 @@ module WorksWithAllowBlank included do let(:model_attribute) { :allow_blank } - describe 'when provided with the other validator requirements' do + describe "when provided with the other validator requirements" do before do case validator_sym when :aspect_ratio then matcher.allowing(:square) - when :content_type then matcher.allowing('image/png') + when :content_type then matcher.allowing("image/png") when :dimension then matcher.width(150).height(150) when :duration then matcher.less_than_or_equal_to(5.minutes) when :size then matcher.less_than_or_equal_to(5.megabytes) @@ -16,13 +16,13 @@ module WorksWithAllowBlank end end - describe 'and when provided with #allow_blank method' do + describe "and when provided with #allow_blank method" do subject { matcher.allow_blank } it { is_expected_to_match_for(klass) } end - describe 'and when not provided with #allow_blank method' do + describe "and when not provided with #allow_blank method" do subject { matcher } it { is_expected_to_match_for(klass) } diff --git a/test/matchers/shared_examples/works_with_both_instance_and_class.rb b/test/matchers/shared_examples/works_with_both_instance_and_class.rb index d1bef01c..39e6c595 100644 --- a/test/matchers/shared_examples/works_with_both_instance_and_class.rb +++ b/test/matchers/shared_examples/works_with_both_instance_and_class.rb @@ -2,14 +2,14 @@ module WorksWithBothInstanceAndClass extend ActiveSupport::Concern included do - describe 'when provided with the other validator requirements' do + describe "when provided with the other validator requirements" do before do case validator_sym when :aspect_ratio then matcher.allowing(:square) when :attached then nil when :processable_file then nil when :limit then matcher.min(1).max(5) - when :content_type then matcher.allowing('image/png') + when :content_type then matcher.allowing("image/png") when :dimension then matcher.width(150).height(150) when :duration then matcher.less_than_or_equal_to(5.minutes) when :size then matcher.less_than_or_equal_to(5.megabytes) @@ -17,7 +17,7 @@ module WorksWithBothInstanceAndClass end end - describe 'when the matcher is provided with an instance' do + describe "when the matcher is provided with an instance" do subject { matcher } let(:model_attribute) { :as_instance } diff --git a/test/matchers/shared_examples/works_with_context.rb b/test/matchers/shared_examples/works_with_context.rb index ef49fa6c..44f3e375 100644 --- a/test/matchers/shared_examples/works_with_context.rb +++ b/test/matchers/shared_examples/works_with_context.rb @@ -2,9 +2,9 @@ module WorksWithContext extend ActiveSupport::Concern included do - describe 'when the model attribute has a context' do - describe 'and the matcher is provided with the model attribute validator context' do - describe 'which is an symbol' do + describe "when the model attribute has a context" do + describe "and the matcher is provided with the model attribute validator context" do + describe "which is an symbol" do subject { matcher.on(:update) } let(:model_attribute) { :with_context_symbol } @@ -12,7 +12,7 @@ module WorksWithContext it { is_expected_to_match_for(klass) } end - describe 'which is an array' do + describe "which is an array" do subject { matcher.on(%i[update custom]) } let(:model_attribute) { :with_context_array } @@ -21,37 +21,37 @@ module WorksWithContext end end - describe 'and the matcher is provided with a different context than the model attribute validator context' do - describe 'which is an symbol' do + describe "and the matcher is provided with a different context than the model attribute validator context" do + describe "which is an symbol" do subject { matcher.on(:custom2) } let(:model_attribute) { :with_context_symbol } - it { is_expected_to_raise_error(ArgumentError, 'One of the provided contexts to the #on method is not found in any of the listed contexts for this attribute') } + it { is_expected_to_raise_error(ArgumentError, "One of the provided contexts to the #on method is not found in any of the listed contexts for this attribute") } end - describe 'which is an array' do + describe "which is an array" do subject { matcher.on(%i[update custom2]) } let(:model_attribute) { :with_context_array } - it { is_expected_to_raise_error(ArgumentError, 'One of the provided contexts to the #on method is not found in any of the listed contexts for this attribute') } + it { is_expected_to_raise_error(ArgumentError, "One of the provided contexts to the #on method is not found in any of the listed contexts for this attribute") } end end - describe 'but the matcher is not provided with the #on method' do + describe "but the matcher is not provided with the #on method" do subject { matcher } let(:model_attribute) { :with_context_symbol } - it { is_expected_to_raise_error(ArgumentError, 'This validator matcher needs the #on option to work since its validator has one') } + it { is_expected_to_raise_error(ArgumentError, "This validator matcher needs the #on option to work since its validator has one") } end end - describe 'when the model attribute uses an active_storage_validation validator several times' do - describe 'with several contexts' do - describe 'and the matcher is provided with' do - describe 'one of the model attribute validators contexts' do + describe "when the model attribute uses an active_storage_validation validator several times" do + describe "with several contexts" do + describe "and the matcher is provided with" do + describe "one of the model attribute validators contexts" do subject { matcher.on(:custom) } let(:model_attribute) { :with_several_validators_and_contexts } @@ -59,7 +59,7 @@ module WorksWithContext it { is_expected_to_match_for(klass) } end - describe 'all of the model attribute validators contexts' do + describe "all of the model attribute validators contexts" do subject { matcher.on(%i[update custom]) } let(:model_attribute) { :with_several_validators_and_contexts } @@ -67,12 +67,12 @@ module WorksWithContext it { is_expected_to_match_for(klass) } end - describe 'one context that is not present in the model attribute validators contexts' do + describe "one context that is not present in the model attribute validators contexts" do subject { matcher.on(:not_present) } let(:model_attribute) { :with_several_validators_and_contexts } - it { is_expected_to_raise_error(ArgumentError, 'One of the provided contexts to the #on method is not found in any of the listed contexts for this attribute') } + it { is_expected_to_raise_error(ArgumentError, "One of the provided contexts to the #on method is not found in any of the listed contexts for this attribute") } end end end diff --git a/test/matchers/shared_examples/works_with_custom_message.rb b/test/matchers/shared_examples/works_with_custom_message.rb index cb812fc6..00b80b23 100644 --- a/test/matchers/shared_examples/works_with_custom_message.rb +++ b/test/matchers/shared_examples/works_with_custom_message.rb @@ -4,14 +4,14 @@ module WorksWithCustomMessage included do let(:model_attribute) { :with_message } - describe 'when provided with the other validator requirements' do + describe "when provided with the other validator requirements" do before do case validator_sym when :aspect_ratio then matcher.allowing(:square) when :attached then nil when :processable_file then nil when :limit then matcher.min(1).max(5) - when :content_type then matcher.allowing('image/png') + when :content_type then matcher.allowing("image/png") when :dimension then matcher.width(150).height(150) when :duration then matcher.less_than_or_equal_to(5.minutes) when :size then matcher.less_than_or_equal_to(5.megabytes) @@ -19,19 +19,19 @@ module WorksWithCustomMessage end end - describe 'and when provided with the model validation message' do - subject { matcher.with_message('Custom message') } + describe "and when provided with the model validation message" do + subject { matcher.with_message("Custom message") } it { is_expected_to_match_for(klass) } end - describe 'and when provided with a different message than the model validation message' do - subject { matcher.with_message('') } + describe "and when provided with a different message than the model validation message" do + subject { matcher.with_message("") } it { is_expected_not_to_match_for(klass) } end - describe 'and when not provided with the #with_message matcher method' do + describe "and when not provided with the #with_message matcher method" do subject { matcher } it { is_expected_to_match_for(klass) } diff --git a/test/matchers/size_validator_matcher_test.rb b/test/matchers/size_validator_matcher_test.rb index 34a98794..420ac9d0 100644 --- a/test/matchers/size_validator_matcher_test.rb +++ b/test/matchers/size_validator_matcher_test.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'test_helper' -require 'matchers/shared_examples/base_comparison_validator_matcher' -require 'matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute' -require 'matchers/shared_examples/checks_if_is_valid' -require 'matchers/shared_examples/has_custom_matcher' -require 'matchers/shared_examples/has_valid_rspec_message_methods' -require 'matchers/shared_examples/works_with_allow_blank' -require 'matchers/shared_examples/works_with_both_instance_and_class' -require 'matchers/shared_examples/works_with_context' -require 'matchers/shared_examples/works_with_custom_message' +require "test_helper" +require "matchers/shared_examples/base_comparison_validator_matcher" +require "matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute" +require "matchers/shared_examples/checks_if_is_valid" +require "matchers/shared_examples/has_custom_matcher" +require "matchers/shared_examples/has_valid_rspec_message_methods" +require "matchers/shared_examples/works_with_allow_blank" +require "matchers/shared_examples/works_with_both_instance_and_class" +require "matchers/shared_examples/works_with_context" +require "matchers/shared_examples/works_with_custom_message" describe ActiveStorageValidations::Matchers::SizeValidatorMatcher do include MatcherHelpers @@ -27,7 +27,7 @@ include HasCustomMatcher end - describe '#less_than' do + describe "#less_than" do let(:matcher_method) { :less_than } let(:model_attribute) { matcher_method } let(:validator_value) { 2.kilobytes } @@ -35,7 +35,7 @@ include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe '#less_than_or_equal_to' do + describe "#less_than_or_equal_to" do let(:matcher_method) { :less_than_or_equal_to } let(:model_attribute) { matcher_method } let(:validator_value) { 2.kilobytes } @@ -43,24 +43,24 @@ include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe '#greater_than' do + describe "#greater_than" do let(:matcher_method) { :greater_than } let(:validator_value) { 7.kilobytes } - describe 'with has_one_attached' do + describe "with has_one_attached" do let(:model_attribute) { matcher_method } include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe 'with has_many_attached' do + describe "with has_many_attached" do let(:model_attribute) { :many_greater_than } include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end end - describe '#greater_than_or_equal_to' do + describe "#greater_than_or_equal_to" do let(:matcher_method) { :greater_than_or_equal_to } let(:model_attribute) { matcher_method } let(:validator_value) { 7.kilobytes } @@ -68,44 +68,44 @@ include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe '#between' do + describe "#between" do let(:model_attribute) { :between } - describe 'when provided with the exact sizes specified in the model validations' do + describe "when provided with the exact sizes specified in the model validations" do subject { matcher.between 2.kilobytes..7.kilobytes } it { is_expected_to_match_for(klass) } end - describe 'when provided with a higher size than the size specified in the model validations' do - describe 'for the highest possible size' do + describe "when provided with a higher size than the size specified in the model validations" do + describe "for the highest possible size" do subject { matcher.between 2.kilobytes..10.kilobytes } it { is_expected_not_to_match_for(klass) } end - describe 'for the lowest possible size' do + describe "for the lowest possible size" do subject { matcher.between 5.kilobytes..7.kilobytes } it { is_expected_not_to_match_for(klass) } end end - describe 'when provided with a lower size than the size specified in the model validations' do - describe 'for the highest possible size' do + describe "when provided with a lower size than the size specified in the model validations" do + describe "for the highest possible size" do subject { matcher.between 1.kilobytes..7.kilobytes } it { is_expected_not_to_match_for(klass) } end - describe 'for the lowest possible size' do + describe "for the lowest possible size" do subject { matcher.between 1.kilobytes..7.kilobytes } it { is_expected_not_to_match_for(klass) } end end - describe 'when provided with both lowest and highest possible sizes different than the model validations' do + describe "when provided with both lowest and highest possible sizes different than the model validations" do subject { matcher.between 4.kilobytes..20.kilobytes } it { is_expected_not_to_match_for(klass) } @@ -116,7 +116,7 @@ include WorksWithAllowBlank end - describe '#with_message' do + describe "#with_message" do include WorksWithCustomMessage end @@ -124,15 +124,15 @@ include WorksWithContext end - describe 'Combinations' do - describe '#less_than + #with_message' do + describe "Combinations" do + describe "#less_than + #with_message" do let(:model_attribute) { :less_than_with_message } - describe 'when provided with the exact size' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact size" do + describe "and when provided with the message specified in the model validations" do subject do matcher.less_than 2.kilobytes - matcher.with_message('File is too big.') + matcher.with_message("File is too big.") end it { is_expected_to_match_for(klass) } @@ -140,14 +140,14 @@ end end - describe '#less_than_or_equal_to + #with_message' do + describe "#less_than_or_equal_to + #with_message" do let(:model_attribute) { :less_than_or_equal_to_with_message } - describe 'when provided with the exact size' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact size" do + describe "and when provided with the message specified in the model validations" do subject do matcher.less_than_or_equal_to 2.kilobytes - matcher.with_message('File is too big.') + matcher.with_message("File is too big.") end it { is_expected_to_match_for(klass) } @@ -155,14 +155,14 @@ end end - describe '#greater_than + #with_message' do + describe "#greater_than + #with_message" do let(:model_attribute) { :greater_than_with_message } - describe 'when provided with the exact size' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact size" do + describe "and when provided with the message specified in the model validations" do subject do matcher.greater_than 7.kilobytes - matcher.with_message('File is too small.') + matcher.with_message("File is too small.") end it { is_expected_to_match_for(klass) } @@ -170,14 +170,14 @@ end end - describe '#greater_than_or_equal_to + #with_message' do + describe "#greater_than_or_equal_to + #with_message" do let(:model_attribute) { :greater_than_or_equal_to_with_message } - describe 'when provided with the exact size' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact size" do + describe "and when provided with the message specified in the model validations" do subject do matcher.greater_than_or_equal_to 7.kilobytes - matcher.with_message('File is too small.') + matcher.with_message("File is too small.") end it { is_expected_to_match_for(klass) } @@ -185,14 +185,14 @@ end end - describe '#between + #with_message' do + describe "#between + #with_message" do let(:model_attribute) { :between_with_message } - describe 'when provided with the exact size' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact size" do + describe "and when provided with the message specified in the model validations" do subject do matcher.between 2.kilobyte..7.kilobytes - matcher.with_message('File is not in accepted size range.') + matcher.with_message("File is not in accepted size range.") end it { is_expected_to_match_for(klass) } diff --git a/test/matchers/support/matcher_helpers.rb b/test/matchers/support/matcher_helpers.rb index 6767e603..b7f56a3e 100644 --- a/test/matchers/support/matcher_helpers.rb +++ b/test/matchers/support/matcher_helpers.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true module MatcherHelpers - require 'active_storage_validations/matchers' + require "active_storage_validations/matchers" def is_expected_to_match_for(klass) subject && assert(subject.matches?(klass)) end def is_expected_not_to_match_for(klass) - subject && refute(subject.matches?(klass)) + subject && assert_not(subject.matches?(klass)) end def is_expected_to_raise_error(error_class, message) @@ -33,7 +33,7 @@ def is_expected_to_have_failure_message_when_negated(expected_failure_message) end def validator_class - subject.class.name.sub(/::Matchers/, '').sub(/Matcher/, '').constantize + subject.class.name.sub(/::Matchers/, "").sub(/Matcher/, "").constantize end def validator_sym diff --git a/test/matchers/total_size_validator_matcher_test.rb b/test/matchers/total_size_validator_matcher_test.rb index 3949e5fb..b8c95ce3 100644 --- a/test/matchers/total_size_validator_matcher_test.rb +++ b/test/matchers/total_size_validator_matcher_test.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'test_helper' -require 'matchers/shared_examples/base_comparison_validator_matcher' -require 'matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute' -require 'matchers/shared_examples/checks_if_is_valid' -require 'matchers/shared_examples/has_custom_matcher' -require 'matchers/shared_examples/has_valid_rspec_message_methods' -require 'matchers/shared_examples/works_with_allow_blank' -require 'matchers/shared_examples/works_with_both_instance_and_class' -require 'matchers/shared_examples/works_with_context' -require 'matchers/shared_examples/works_with_custom_message' +require "test_helper" +require "matchers/shared_examples/base_comparison_validator_matcher" +require "matchers/shared_examples/checks_if_is_a_valid_active_storage_attribute" +require "matchers/shared_examples/checks_if_is_valid" +require "matchers/shared_examples/has_custom_matcher" +require "matchers/shared_examples/has_valid_rspec_message_methods" +require "matchers/shared_examples/works_with_allow_blank" +require "matchers/shared_examples/works_with_both_instance_and_class" +require "matchers/shared_examples/works_with_context" +require "matchers/shared_examples/works_with_custom_message" describe ActiveStorageValidations::Matchers::TotalSizeValidatorMatcher do include MatcherHelpers @@ -27,7 +27,7 @@ include HasCustomMatcher end - describe '#less_than' do + describe "#less_than" do let(:matcher_method) { :less_than } let(:model_attribute) { matcher_method } let(:validator_value) { 2.kilobytes } @@ -35,7 +35,7 @@ include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe '#less_than_or_equal_to' do + describe "#less_than_or_equal_to" do let(:matcher_method) { :less_than_or_equal_to } let(:model_attribute) { matcher_method } let(:validator_value) { 2.kilobytes } @@ -43,7 +43,7 @@ include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe '#greater_than' do + describe "#greater_than" do let(:matcher_method) { :greater_than } let(:model_attribute) { matcher_method } let(:validator_value) { 7.kilobytes } @@ -51,7 +51,7 @@ include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe '#greater_than_or_equal_to' do + describe "#greater_than_or_equal_to" do let(:matcher_method) { :greater_than_or_equal_to } let(:model_attribute) { matcher_method } let(:validator_value) { 7.kilobytes } @@ -59,44 +59,44 @@ include BaseComparisonValidatorMatcher::OnlyMatchWhenExactValue end - describe '#between' do + describe "#between" do let(:model_attribute) { :between } - describe 'when provided with the exact sizes specified in the model validations' do + describe "when provided with the exact sizes specified in the model validations" do subject { matcher.between 2.kilobytes..7.kilobytes } it { is_expected_to_match_for(klass) } end - describe 'when provided with a higher size than the size specified in the model validations' do - describe 'for the highest possible size' do + describe "when provided with a higher size than the size specified in the model validations" do + describe "for the highest possible size" do subject { matcher.between 2.kilobytes..10.kilobytes } it { is_expected_not_to_match_for(klass) } end - describe 'for the lowest possible size' do + describe "for the lowest possible size" do subject { matcher.between 5.kilobytes..7.kilobytes } it { is_expected_not_to_match_for(klass) } end end - describe 'when provided with a lower size than the size specified in the model validations' do - describe 'for the highest possible size' do + describe "when provided with a lower size than the size specified in the model validations" do + describe "for the highest possible size" do subject { matcher.between 1.kilobytes..7.kilobytes } it { is_expected_not_to_match_for(klass) } end - describe 'for the lowest possible size' do + describe "for the lowest possible size" do subject { matcher.between 1.kilobytes..7.kilobytes } it { is_expected_not_to_match_for(klass) } end end - describe 'when provided with both lowest and highest possible sizes different than the model validations' do + describe "when provided with both lowest and highest possible sizes different than the model validations" do subject { matcher.between 4.kilobytes..20.kilobytes } it { is_expected_not_to_match_for(klass) } @@ -107,7 +107,7 @@ include WorksWithAllowBlank end - describe '#with_message' do + describe "#with_message" do include WorksWithCustomMessage end @@ -115,15 +115,15 @@ include WorksWithContext end - describe 'Combinations' do - describe '#less_than + #with_message' do + describe "Combinations" do + describe "#less_than + #with_message" do let(:model_attribute) { :less_than_with_message } - describe 'when provided with the exact size' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact size" do + describe "and when provided with the message specified in the model validations" do subject do matcher.less_than 2.kilobytes - matcher.with_message('Total file size is too big.') + matcher.with_message("Total file size is too big.") end it { is_expected_to_match_for(klass) } @@ -131,14 +131,14 @@ end end - describe '#less_than_or_equal_to + #with_message' do + describe "#less_than_or_equal_to + #with_message" do let(:model_attribute) { :less_than_or_equal_to_with_message } - describe 'when provided with the exact size' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact size" do + describe "and when provided with the message specified in the model validations" do subject do matcher.less_than_or_equal_to 2.kilobytes - matcher.with_message('Total file size is too big.') + matcher.with_message("Total file size is too big.") end it { is_expected_to_match_for(klass) } @@ -146,14 +146,14 @@ end end - describe '#greater_than + #with_message' do + describe "#greater_than + #with_message" do let(:model_attribute) { :greater_than_with_message } - describe 'when provided with the exact size' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact size" do + describe "and when provided with the message specified in the model validations" do subject do matcher.greater_than 7.kilobytes - matcher.with_message('Total file size is too small.') + matcher.with_message("Total file size is too small.") end it { is_expected_to_match_for(klass) } @@ -161,14 +161,14 @@ end end - describe '#greater_than_or_equal_to + #with_message' do + describe "#greater_than_or_equal_to + #with_message" do let(:model_attribute) { :greater_than_or_equal_to_with_message } - describe 'when provided with the exact size' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact size" do + describe "and when provided with the message specified in the model validations" do subject do matcher.greater_than_or_equal_to 7.kilobytes - matcher.with_message('Total file size is too small.') + matcher.with_message("Total file size is too small.") end it { is_expected_to_match_for(klass) } @@ -176,14 +176,14 @@ end end - describe '#between + #with_message' do + describe "#between + #with_message" do let(:model_attribute) { :between_with_message } - describe 'when provided with the exact size' do - describe 'and when provided with the message specified in the model validations' do + describe "when provided with the exact size" do + describe "and when provided with the message specified in the model validations" do subject do matcher.between 2.kilobyte..7.kilobytes - matcher.with_message('Total file size is not in accepted size range.') + matcher.with_message("Total file size is not in accepted size range.") end it { is_expected_to_match_for(klass) } diff --git a/test/support/files.rb b/test/support/files.rb index 8a741088..cf09de78 100644 --- a/test/support/files.rb +++ b/test/support/files.rb @@ -1,276 +1,276 @@ def bad_dummy_file { - io: File.open(Rails.root.join('public', 'apple-touch-icon.png')), - filename: 'apple-touch-icon.png', - content_type: 'text/plain' + io: File.open(Rails.root.join("public", "apple-touch-icon.png")), + filename: "apple-touch-icon.png", + content_type: "text/plain" } end alias :extension_content_type_mismatch_file :bad_dummy_file def image_150x150_file { - io: File.open(Rails.root.join('public', 'image_150x150.png')), - filename: 'image_150x150_file.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_150x150.png")), + filename: "image_150x150_file.png", + content_type: "image/png" } end alias :square_image_file :image_150x150_file def image_500x500_file { - io: File.open(Rails.root.join('public', 'image_500x500.png')), - filename: 'image_500x500_file.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_500x500.png")), + filename: "image_500x500_file.png", + content_type: "image/png" } end def image_600x600_file { - io: File.open(Rails.root.join('public', 'image_600x600.png')), - filename: 'image_600x600_file.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_600x600.png")), + filename: "image_600x600_file.png", + content_type: "image/png" } end def image_500x700_file { - io: File.open(Rails.root.join('public', 'image_500x700.png')), - filename: 'image_500x700_file.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_500x700.png")), + filename: "image_500x700_file.png", + content_type: "image/png" } end def image_700x500_file { - io: File.open(Rails.root.join('public', 'image_700x500.png')), - filename: 'image_700x500_file.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_700x500.png")), + filename: "image_700x500_file.png", + content_type: "image/png" } end alias :landscape_image_file :image_700x500_file def image_800x600_file { - io: File.open(Rails.root.join('public', 'image_800x600.png')), - filename: 'image_800x600_file.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_800x600.png")), + filename: "image_800x600_file.png", + content_type: "image/png" } end def image_600x800_file { - io: File.open(Rails.root.join('public', 'image_600x800.png')), - filename: 'image_600x800_file.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_600x800.png")), + filename: "image_600x800_file.png", + content_type: "image/png" } end alias :portrait_image_file :image_600x800_file def image_1200x900_file { - io: File.open(Rails.root.join('public', 'image_1200x900.png')), - filename: 'image_1200x900_file.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_1200x900.png")), + filename: "image_1200x900_file.png", + content_type: "image/png" } end alias :is_4_3_image_file :image_1200x900_file def image_1300x1000_file { - io: File.open(Rails.root.join('public', 'image_1300x1000.png')), - filename: 'image_1300x1000_file.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_1300x1000.png")), + filename: "image_1300x1000_file.png", + content_type: "image/png" } end def image_1920x1080_file { - io: File.open(Rails.root.join('public', 'image_1920x1080.png')), - filename: 'image_1920x1080_file.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_1920x1080.png")), + filename: "image_1920x1080_file.png", + content_type: "image/png" } end alias :is_16_9_image_file :image_1920x1080_file def tar_file_with_image_content_type { - io: File.open(Rails.root.join('public', '404.html.tar')), - filename: '404.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "404.html.tar")), + filename: "404.png", + content_type: "image/png" } end def image_string_io - string_io = StringIO.new().tap {|io| io.binmode } - IO.copy_stream(File.open(Rails.root.join('public', 'image_1920x1080.png')), string_io) + string_io = StringIO.new().tap { |io| io.binmode } + IO.copy_stream(File.open(Rails.root.join("public", "image_1920x1080.png")), string_io) string_io.rewind { io: string_io, - filename: 'image_1920x1080.png', - content_type: 'image/png' + filename: "image_1920x1080.png", + content_type: "image/png" } end def image_file_0ko { - io: File.open(Rails.root.join('public', 'image_file_0ko.png')), - filename: 'image_file_0ko.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_file_0ko.png")), + filename: "image_file_0ko.png", + content_type: "image/png" } end def file_1ko { - io: File.open(Rails.root.join('public', 'file_1ko.png')), - filename: 'file_1ko.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "file_1ko.png")), + filename: "file_1ko.png", + content_type: "image/png" } end alias :file_1ko_and_png :file_1ko def file_2ko { - io: File.open(Rails.root.join('public', 'file_2ko')), - filename: 'file_2ko', - content_type: 'text/html' + io: File.open(Rails.root.join("public", "file_2ko")), + filename: "file_2ko", + content_type: "text/html" } end def file_5ko { - io: File.open(Rails.root.join('public', 'file_5ko')), - filename: 'file_5ko', - content_type: 'text/html' + io: File.open(Rails.root.join("public", "file_5ko")), + filename: "file_5ko", + content_type: "text/html" } end def file_7ko { - io: File.open(Rails.root.join('public', 'file_7ko')), - filename: 'file_7ko', - content_type: 'text/html' + io: File.open(Rails.root.join("public", "file_7ko")), + filename: "file_7ko", + content_type: "text/html" } end def file_7ko_and_jpg { - io: File.open(Rails.root.join('public', 'file_7ko_and_jpg.jpg')), - filename: 'file_7ko_and_jpg', - content_type: 'image/jpeg' + io: File.open(Rails.root.join("public", "file_7ko_and_jpg.jpg")), + filename: "file_7ko_and_jpg", + content_type: "image/jpeg" } end def file_10ko { - io: File.open(Rails.root.join('public', 'file_10ko.png')), - filename: 'file_10ko', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "file_10ko.png")), + filename: "file_10ko", + content_type: "image/png" } end def file_17ko_and_png { - io: File.open(Rails.root.join('public', 'file_17ko_and_png.png')), - filename: 'file_17ko_and_png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "file_17ko_and_png.png")), + filename: "file_17ko_and_png", + content_type: "image/png" } end def file_28ko { - io: File.open(Rails.root.join('public', 'file_28ko.png')), - filename: 'file_28ko', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "file_28ko.png")), + filename: "file_28ko", + content_type: "image/png" } end def image_150x150_28ko { - io: File.open(Rails.root.join('public', 'image_150x150_28ko.png')), - filename: 'image_150x150_28ko', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_150x150_28ko.png")), + filename: "image_150x150_28ko", + content_type: "image/png" } end def spoofed_jpeg { - io: File.open(Rails.root.join('public', 'spoofed.jpg')), - filename: 'spoofed.jpg', - content_type: 'image/jpeg' + io: File.open(Rails.root.join("public", "spoofed.jpg")), + filename: "spoofed.jpg", + content_type: "image/jpeg" } end def spoofed_extension_jpeg { - io: File.open(Rails.root.join('public', 'most_common_mime_types', 'example.jpeg')), - filename: 'example.png', - content_type: 'image/jpeg' + io: File.open(Rails.root.join("public", "most_common_mime_types", "example.jpeg")), + filename: "example.png", + content_type: "image/jpeg" } end def empty_io_file { - io: StringIO.new(''), - filename: 'example.jpeg', - content_type: 'image/jpeg' + io: StringIO.new(""), + filename: "example.jpeg", + content_type: "image/jpeg" } end def not_identifiable_io_file { - io: StringIO.new('💎'), - filename: 'example.jpeg', - content_type: 'image/jpeg' + io: StringIO.new("💎"), + filename: "example.jpeg", + content_type: "image/jpeg" } end def audio_file { - io: File.open(Rails.root.join('public', 'audio.mp3')), - filename: 'audio', - content_type: 'audio/mp3' + io: File.open(Rails.root.join("public", "audio.mp3")), + filename: "audio", + content_type: "audio/mp3" } end alias :audio_1s :audio_file def audio_2s { - io: File.open(Rails.root.join('public', 'audio_2s.mp3')), - filename: 'audio_2s', - content_type: 'audio/mp3' + io: File.open(Rails.root.join("public", "audio_2s.mp3")), + filename: "audio_2s", + content_type: "audio/mp3" } end def audio_5s { - io: File.open(Rails.root.join('public', 'audio_5s.mp3')), - filename: 'audio_5s', - content_type: 'audio/mp3' + io: File.open(Rails.root.join("public", "audio_5s.mp3")), + filename: "audio_5s", + content_type: "audio/mp3" } end def audio_7s { - io: File.open(Rails.root.join('public', 'audio_7s.mp3')), - filename: 'audio_7s', - content_type: 'audio/mp3' + io: File.open(Rails.root.join("public", "audio_7s.mp3")), + filename: "audio_7s", + content_type: "audio/mp3" } end def audio_10s { - io: File.open(Rails.root.join('public', 'audio_10s.mp3')), - filename: 'audio_10s', - content_type: 'audio/mp3' + io: File.open(Rails.root.join("public", "audio_10s.mp3")), + filename: "audio_10s", + content_type: "audio/mp3" } end def video_file { - io: File.open(Rails.root.join('public', 'video.mp4')), - filename: 'video', - content_type: 'video/mp4' + io: File.open(Rails.root.join("public", "video.mp4")), + filename: "video", + content_type: "video/mp4" } end @@ -279,16 +279,16 @@ def create_blob_from_file(file) io: file[:io], filename: file[:filename], content_type: file[:content_type], - service_name: 'test' + service_name: "test" ) end def create_blob(size: 1) ActiveStorage::Blob.create_and_upload!( - io: StringIO.new('a' * size.kilobytes), + io: StringIO.new("a" * size.kilobytes), filename: "file_#{size}ko", - content_type: 'text/plain', - service_name: 'test' + content_type: "text/plain", + service_name: "test" ) end diff --git a/test/support/mime_types.rb b/test/support/mime_types.rb index ff559d1e..ebf194e2 100644 --- a/test/support/mime_types.rb +++ b/test/support/mime_types.rb @@ -1,6 +1,7 @@ # Lists partially based on # https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types +# rubocop:disable Metrics/MethodLength def most_common_mime_types [ # Image @@ -63,7 +64,7 @@ def most_common_mime_types { mime_type: "application/x-7z-compressed", extension: "7z" }, { mime_type: "application/x-rar-compressed", extension: "rar" }, { mime_type: "application/gzip", extension: "gz" }, - { mime_type: "application/x-tar", extension: "tar" }, + { mime_type: "application/x-tar", extension: "tar" } ] end @@ -119,7 +120,7 @@ def most_common_mime_types most_common_mime_types.each do |mime_type| define_method(:"#{mime_type[:extension]}_file") do { - io: File.open(Rails.root.join('public', 'most_common_mime_types', "example.#{mime_type[:extension]}")), + io: File.open(Rails.root.join("public", "most_common_mime_types", "example.#{mime_type[:extension]}")), filename: "example.#{mime_type[:extension]}", content_type: mime_type[:mime_type] } diff --git a/test/test_helper.rb b/test/test_helper.rb index fdc5ad2e..ad1c0cf8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,48 +1,48 @@ # frozen_string_literal: true -require 'simplecov' +require "simplecov" SimpleCov.start # Previous content of test helper now starts here # Configure Rails Environment -ENV['RAILS_ENV'] = 'test' +ENV["RAILS_ENV"] = "test" # Load dummy rails application with combustion gem -require 'combustion' -Combustion.path = 'test/dummy' +require "combustion" +Combustion.path = "test/dummy" Combustion.initialize! :active_record, :active_storage, :active_job do - config.active_storage.variant_processor = ENV['IMAGE_PROCESSOR']&.to_sym + config.active_storage.variant_processor = ENV["IMAGE_PROCESSOR"]&.to_sym config.active_job.queue_adapter = :inline end # Load other test helpers -require 'rails/test_help' -require 'minitest/focus' -require 'minitest/mock' +require "rails/test_help" +require "minitest/focus" +require "minitest/mock" require "minitest/mock_expectations" -require 'minitest/spec' -require 'minitest/stub_any_instance' -require 'webmock/minitest' +require "minitest/spec" +require "minitest/stub_any_instance" +require "webmock/minitest" # Filter out Minitest backtrace while allowing backtrace from other libraries # to be shown. Minitest.backtrace_filter = Minitest::BacktraceFilter.new -require 'rails/test_unit/reporter' -Rails::TestUnitReporter.executable = 'bin/test' +require "rails/test_unit/reporter" +Rails::TestUnitReporter.executable = "bin/test" # Load fixtures from the engine if ActiveSupport::TestCase.respond_to?(:fixture_path=) - ActiveSupport::TestCase.fixture_path = File.expand_path('fixtures', __dir__) + ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__) ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path - ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + '/files' + ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files" ActiveSupport::TestCase.fixtures :all end # Load test support files -Dir[File.join('test/support/*.rb')].map { |path| path.sub('test/', '') }.each { |f| require f } -Dir[File.join('test/matchers/support/*.rb')].map { |path| path.sub('test/', '') }.each { |f| require f } -Dir[File.join('test/validators/support/*.rb')].map { |path| path.sub('test/', '') }.each { |f| require f } +Dir[File.join("test/support/*.rb")].map { |path| path.sub("test/", "") }.each { |f| require f } +Dir[File.join("test/matchers/support/*.rb")].map { |path| path.sub("test/", "") }.each { |f| require f } +Dir[File.join("test/validators/support/*.rb")].map { |path| path.sub("test/", "") }.each { |f| require f } puts "Running tests with Rails v.#{Rails.version}" diff --git a/test/validators/aspect_ratio_validator_test.rb b/test/validators/aspect_ratio_validator_test.rb index 269d4803..e76c0a63 100644 --- a/test/validators/aspect_ratio_validator_test.rb +++ b/test/validators/aspect_ratio_validator_test.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'test_helper' -require 'validators/shared_examples/checks_validator_validity' -require 'validators/shared_examples/is_performance_optimized' -require 'validators/shared_examples/works_fine_with_attachables' -require 'validators/shared_examples/works_with_all_rails_common_validation_options' +require "test_helper" +require "validators/shared_examples/checks_validator_validity" +require "validators/shared_examples/is_performance_optimized" +require "validators/shared_examples/works_fine_with_attachables" +require "validators/shared_examples/works_with_all_rails_common_validation_options" describe ActiveStorageValidations::AspectRatioValidator do include ValidatorHelpers @@ -12,11 +12,11 @@ let(:validator_test_class) { AspectRatio::Validator } let(:params) { {} } - describe '#check_validity!' do + describe "#check_validity!" do include ChecksValidatorValidity - describe 'aspect ratio validity' do - describe 'when the passed option is an invalid' do + describe "aspect ratio validity" do + describe "when the passed option is an invalid" do let(:error_message) do <<~ERROR_MESSAGE You must pass a valid aspect ratio to the validator @@ -25,34 +25,34 @@ ERROR_MESSAGE end - describe 'named aspect ratio' do + describe "named aspect ratio" do subject { validator_test_class::CheckValidityInvalidNamedArgument.new(params) } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end - describe 'is_x_y aspect ratio' do + describe "is_x_y aspect ratio" do subject { validator_test_class::CheckValidityInvalidIsXyArgument.new(params) } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end end - describe 'when the passed option is a Proc' do + describe "when the passed option is a Proc" do subject { validator_test_class::CheckValidityProcOption.new(params) } - it 'does not perform a check, and therefore is valid' do + it "does not perform a check, and therefore is valid" do assert_nothing_raised { subject } end end end end - describe 'ASPECT_RATIO_REGEX' do + describe "ASPECT_RATIO_REGEX" do let(:aspect_ratio_regex) { ActiveStorageValidations::AspectRatioValidator::ASPECT_RATIO_REGEX } let(:accepted_is_x_y_strings) do %w[ @@ -85,7 +85,7 @@ end end - describe 'Validator checks' do + describe "Validator checks" do include WorksFineWithAttachables let(:model) { validator_test_class::Check.new(params) } @@ -97,13 +97,13 @@ # validates :with_named_square_proc, aspect_ratio: -> (record) { :square } # validates :with_named_portrait_proc, aspect_ratio: -> (record) { :portrait } # validates :with_named_landscape_proc, aspect_ratio: -> (record) { :landscape } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "named aspect_ratio" do - %i(square portrait landscape).each do |named_aspect_ratio| + %i[square portrait landscape].each do |named_aspect_ratio| describe ":#{named_aspect_ratio}" do let(:attribute) { :"with_#{named_aspect_ratio}#{'_proc' if value_type == 'proc'}" } - describe 'when provided with an allowed aspect_ratio file' do + describe "when provided with an allowed aspect_ratio file" do subject { model.public_send(attribute).attach(allowed_file) and model } let(:allowed_file) do @@ -117,7 +117,7 @@ it { is_expected_to_be_valid } end - describe 'when provided with a not allowed aspect_ratio file' do + describe "when provided with a not allowed aspect_ratio file" do subject { model.public_send(attribute).attach(not_allowed_file) and model } let(:not_allowed_file) do @@ -161,7 +161,7 @@ describe "regex aspect_ratio" do let(:attribute) { :"with_regex#{'_proc' if value_type == 'proc'}" } - describe 'when provided with an allowed aspect_ratio file' do + describe "when provided with an allowed aspect_ratio file" do subject { model.public_send(attribute).attach(allowed_file) and model } let(:allowed_file) { is_16_9_image_file } @@ -169,7 +169,7 @@ it { is_expected_to_be_valid } end - describe 'when provided with a not allowed aspect_ratio file' do + describe "when provided with a not allowed aspect_ratio file" do subject { model.public_send(attribute).attach(not_allowed_file) and model } let(:not_allowed_file) { is_4_3_image_file } @@ -190,27 +190,27 @@ end end - describe ':in' do + describe ":in" do %w[value proc].each do |value_type| describe value_type do let(:attribute) { :"in_aspect_ratios#{'_proc' if value_type == 'proc'}" } - describe 'when provided with an allowed aspect_ratio file' do + describe "when provided with an allowed aspect_ratio file" do subject { model.public_send(attribute).attach(allowed_file) and model } - let(:allowed_file) { [square_image_file, portrait_image_file, is_16_9_image_file].sample } + let(:allowed_file) { [ square_image_file, portrait_image_file, is_16_9_image_file ].sample } it { is_expected_to_be_valid } end - describe 'when provided with a not allowed aspect_ratio file' do + describe "when provided with a not allowed aspect_ratio file" do subject { model.public_send(attribute).attach(not_allowed_file) and model } let(:not_allowed_file) { is_4_3_image_file } let(:error_options) do { - authorized_aspect_ratios: 'square, portrait, 16:9', + authorized_aspect_ratios: "square, portrait, 16:9", width: 1200, height: 900, filename: not_allowed_file[:filename] @@ -218,7 +218,7 @@ end it { is_expected_not_to_be_valid } - it { is_expected_to_include_error_message('aspect_ratio_invalid', error_options: error_options) } + it { is_expected_to_include_error_message("aspect_ratio_invalid", error_options: error_options) } it { is_expected_to_have_error_options(error_options) } end end @@ -243,19 +243,19 @@ end end - describe 'Blob Metadata' do + describe "Blob Metadata" do let(:attachable) do { - io: File.open(Rails.root.join('public', 'image_150x150.png')), - filename: 'image_150x150.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_150x150.png")), + filename: "image_150x150.png", + content_type: "image/png" } end include IsPerformanceOptimized end - describe 'Rails options' do + describe "Rails options" do include WorksWithAllRailsCommonValidationOptions end end diff --git a/test/validators/attached_validator_test.rb b/test/validators/attached_validator_test.rb index 38b446a2..e29113b5 100644 --- a/test/validators/attached_validator_test.rb +++ b/test/validators/attached_validator_test.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'test_helper' -require 'validators/shared_examples/does_not_work_with_allow_blank_option' -require 'validators/shared_examples/does_not_work_with_allow_nil_option' -require 'validators/shared_examples/works_with_if_option' -require 'validators/shared_examples/works_with_message_option' -require 'validators/shared_examples/works_with_on_option' -require 'validators/shared_examples/works_with_unless_option' -require 'validators/shared_examples/works_with_strict_option' +require "test_helper" +require "validators/shared_examples/does_not_work_with_allow_blank_option" +require "validators/shared_examples/does_not_work_with_allow_nil_option" +require "validators/shared_examples/works_with_if_option" +require "validators/shared_examples/works_with_message_option" +require "validators/shared_examples/works_with_on_option" +require "validators/shared_examples/works_with_unless_option" +require "validators/shared_examples/works_with_strict_option" describe ActiveStorageValidations::AttachedValidator do include ValidatorHelpers @@ -15,21 +15,21 @@ let(:validator_test_class) { Attached::Validator } let(:params) { {} } - describe '#check_validity!' do + describe "#check_validity!" do # Checked by Rails options tests end - describe 'Validator checks' do + describe "Validator checks" do let(:model) { validator_test_class::Check.new(params) } - describe 'when provided with a file' do + describe "when provided with a file" do # validates :has_to_be_attached, attached: true subject { model.has_to_be_attached.attach(image_1920x1080_file) and model } it { is_expected_to_be_valid } end - describe 'when not provided with a file' do + describe "when not provided with a file" do # validates :has_to_be_attached, attached: true subject { model } @@ -37,7 +37,7 @@ it { is_expected_to_include_error_message("blank", error_options: {}) } end - describe 'when provided with a file that is marked for destruction' do + describe "when provided with a file that is marked for destruction" do # validates :has_to_be_attached, attached: true subject { model.has_to_be_attached.attach(image_1920x1080_file) and model.has_to_be_attached.mark_for_destruction and model } @@ -46,14 +46,14 @@ end end - describe 'Rails options' do - %i(allow_nil allow_blank).each do |unsupported_validation_option| + describe "Rails options" do + %i[allow_nil allow_blank].each do |unsupported_validation_option| describe ":#{unsupported_validation_option}" do include "DoesNotWorkWith#{unsupported_validation_option.to_s.camelize}Option".constantize end end - %i(if on strict unless message).each do |supported_validation_option| + %i[if on strict unless message].each do |supported_validation_option| describe ":#{supported_validation_option}" do include "WorksWith#{supported_validation_option.to_s.camelize}Option".constantize end diff --git a/test/validators/content_type_validator_test.rb b/test/validators/content_type_validator_test.rb index 751a5cc2..db2cf090 100644 --- a/test/validators/content_type_validator_test.rb +++ b/test/validators/content_type_validator_test.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'test_helper' -require 'validators/shared_examples/checks_validator_validity' -require 'validators/shared_examples/is_performance_optimized' -require 'validators/shared_examples/works_fine_with_attachables' -require 'validators/shared_examples/works_with_all_rails_common_validation_options' +require "test_helper" +require "validators/shared_examples/checks_validator_validity" +require "validators/shared_examples/is_performance_optimized" +require "validators/shared_examples/works_fine_with_attachables" +require "validators/shared_examples/works_with_all_rails_common_validation_options" describe ActiveStorageValidations::ContentTypeValidator do include ValidatorHelpers @@ -12,11 +12,11 @@ let(:validator_test_class) { ContentType::Validator } let(:params) { {} } - describe '#check_validity!' do + describe "#check_validity!" do include ChecksValidatorValidity - describe 'content type validity' do - describe 'when the passed option is an invalid content type' do + describe "content type validity" do + describe "when the passed option is an invalid content type" do describe ":with" do subject { validator_test_class::CheckValidityInvalidContentTypeWith.new(params) } @@ -28,7 +28,7 @@ end let(:invalid_content_type) { "xxx/invalid" } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end @@ -44,7 +44,7 @@ end let(:invalid_content_type) { "xxx/invalid1" } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end @@ -57,7 +57,7 @@ "'image/jpg' is not a valid content type, you should use 'image/jpeg' instead" end - it 'raises an error at model initialization' do + it "raises an error at model initialization" do error = assert_raises(ArgumentError) { subject } assert_equal(error_message, error.message) end @@ -66,48 +66,48 @@ describe "when the passed option is in Marcel::MAGIC (e.g. 'application/x-ole-storage')" do subject { validator_test_class::CheckValidityValidContentTypeOleStorage.new(params) } - it 'does not raise an error at model initialization' do + it "does not raise an error at model initialization" do assert_nothing_raised { subject } end end end end - describe 'when the passed option is an invalid extension' do + describe "when the passed option is an invalid extension" do subject { validator_test_class::CheckValidityInvalidExtension.new(params) } let(:error_message) do <<~ERROR_MESSAGE You must pass valid content types extensions to the validator - '#{invalid_extension.to_s}' is not found in Marcel::EXTENSIONS + '#{invalid_extension}' is not found in Marcel::EXTENSIONS ERROR_MESSAGE end let(:invalid_extension) { :invalid } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end - describe 'when the passed option is a Regex' do + describe "when the passed option is a Regex" do subject { validator_test_class::CheckValidityRegexOption.new(params) } - it 'does not perform a check, and therefore is valid' do + it "does not perform a check, and therefore is valid" do assert_nothing_raised { subject } end end - describe 'when the passed option is a Proc' do + describe "when the passed option is a Proc" do subject { validator_test_class::CheckValidityProcOption.new(params) } - it 'does not perform a check, and therefore is valid' do + it "does not perform a check, and therefore is valid" do assert_nothing_raised { subject } end end end end - describe 'Validator checks' do + describe "Validator checks" do include WorksFineWithAttachables # when using spoofing_protection let(:model) { validator_test_class::Check.new(params) } @@ -215,13 +215,13 @@ # validates :with_string_proc, content_type: -> (record) { 'png' } # validates :with_symbol_proc, content_type: -> (record) { :png } # validates :with_regex_proc, content_type: -> (record) { /\Aimage\/.*\z/ } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe value_type do - %w(string symbol regex).each do |type| + %w[string symbol regex].each do |type| describe type do let(:attribute) { :"with_#{type}#{'_proc' if value_type == 'proc'}" } - describe 'when provided with an allowed type file' do + describe "when provided with an allowed type file" do subject { model.public_send(attribute).attach(allowed_file) and model } let(:allowed_file) { png_file } @@ -229,11 +229,11 @@ it { is_expected_to_be_valid } end - describe 'when provided with a not allowed type file' do + describe "when provided with a not allowed type file" do subject { model.public_send(attribute).attach(not_allowed_file) and model } let(:not_allowed_file) { numbers_file } - let(:authorized_human_content_types) { type == 'regex' ? '\\Aimage/.*\\z' : 'PNG' } + let(:authorized_human_content_types) { type == "regex" ? '\\Aimage/.*\\z' : "PNG" } let(:error_options) do { authorized_human_content_types: authorized_human_content_types, @@ -260,25 +260,25 @@ # validates :in_strings_proc, content_type: -> (record) { ['png', 'gif'] } # validates :in_symbols_proc, content_type: -> (record) { [:png, :gif] } # validates :in_regexes_proc, content_type: -> (record) { [/\Aimage\/.*\z/, /\Afile\/.*\z/] } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe value_type do - %w(string symbol regex).each do |type| + %w[string symbol regex].each do |type| describe type do let(:attribute) { :"in_#{type.pluralize}#{'_proc' if value_type == 'proc'}" } - describe 'when provided with an allowed type file' do + describe "when provided with an allowed type file" do subject { model.public_send(attribute).attach(allowed_file) and model } - let(:allowed_file) { [png_file, gif_file].sample } + let(:allowed_file) { [ png_file, gif_file ].sample } it { is_expected_to_be_valid } end - describe 'when provided with a not allowed type file' do + describe "when provided with a not allowed type file" do subject { model.public_send(attribute).attach(not_allowed_file) and model } let(:not_allowed_file) { numbers_file } - let(:authorized_human_content_types) { type == 'regex' ? '\\Aimage/.*\\z, \\Afile/.*\\z' : 'PNG, GIF' } + let(:authorized_human_content_types) { type == "regex" ? '\\Aimage/.*\\z, \\Afile/.*\\z' : "PNG, GIF" } let(:error_options) do { authorized_human_content_types: authorized_human_content_types, @@ -303,12 +303,12 @@ describe "'#{common_mime_type[:mime_type]}' file (.#{common_mime_type[:extension]})" do subject { model.public_send(attribute).attach(allowed_file) and model } - let(:media) { common_mime_type[:mime_type].split('/').first } + let(:media) { common_mime_type[:mime_type].split("/").first } let(:content) { common_mime_type[:extension].underscore } - let(:attribute) { [media, content].join('_') } # e.g. image_jpeg + let(:attribute) { [ media, content ].join("_") } # e.g. image_jpeg let(:allowed_file) do { - io: File.open(Rails.root.join('public', "most_common_mime_types", "example.#{common_mime_type[:extension]}")), + io: File.open(Rails.root.join("public", "most_common_mime_types", "example.#{common_mime_type[:extension]}")), filename: "example.#{common_mime_type[:extension]}", content_type: common_mime_type[:mime_type] } @@ -330,7 +330,7 @@ end end - describe ':spoofing_protection' do + describe ":spoofing_protection" do # Further testing performed by content_type_spoof_detector_test.rb describe "when the protection is enabled (spoofing_protection: true option)" do @@ -348,7 +348,7 @@ count: 1, detected_content_type: "text/plain", detected_human_content_type: "TXT", - filename: spoofed_jpeg[:filename], + filename: spoofed_jpeg[:filename] } end @@ -370,7 +370,7 @@ count: 1, detected_content_type: "inode/x-empty", detected_human_content_type: "EMPTY", - filename: empty_file[:filename], + filename: empty_file[:filename] } end @@ -406,12 +406,12 @@ describe "'#{common_mime_type[:mime_type]}' file (.#{common_mime_type[:extension]})" do subject { model.public_send(attribute).attach(okay_file) and model } - let(:media) { common_mime_type[:mime_type].split('/').first } + let(:media) { common_mime_type[:mime_type].split("/").first } let(:content) { common_mime_type[:extension].underscore } - let(:attribute) { [media, content, 'spoof'].join('_') } # e.g. image_jpeg_spoof + let(:attribute) { [ media, content, "spoof" ].join("_") } # e.g. image_jpeg_spoof let(:okay_file) do { - io: File.open(Rails.root.join('public', "most_common_mime_types", "example.#{common_mime_type[:extension]}")), + io: File.open(Rails.root.join("public", "most_common_mime_types", "example.#{common_mime_type[:extension]}")), filename: "example.#{common_mime_type[:extension]}", content_type: common_mime_type[:mime_type] } @@ -425,13 +425,13 @@ end # validates :many_spoofing_protection, content_type: :jpg - describe 'with has_many_attached relationship' do + describe "with has_many_attached relationship" do let(:attribute) { :many_spoofing_protection } describe "when the files are okay" do subject { model.public_send(attribute).attach(okay_files) and model } - let(:okay_files) { [okay_jpg_1, okay_jpg_2] } + let(:okay_files) { [ okay_jpg_1, okay_jpg_2 ] } let(:okay_jpg_1) { create_blob_from_file(jpeg_file) } let(:okay_jpg_2) { create_blob_from_file(jpeg_file) } @@ -441,7 +441,7 @@ describe "when one of the file is spoofed" do subject { model.public_send(attribute).attach(files) and model } - let(:files) { [okay_jpg, spoofed_jpeg_file] } + let(:files) { [ okay_jpg, spoofed_jpeg_file ] } let(:okay_jpg) { create_blob_from_file(jpeg_file) } let(:spoofed_jpeg_file) { create_blob_from_file(spoofed_jpeg) } let(:error_options) do @@ -452,7 +452,7 @@ count: 1, detected_content_type: "text/plain", detected_human_content_type: "TXT", - filename: spoofed_jpeg[:filename], + filename: spoofed_jpeg[:filename] } end @@ -477,19 +477,19 @@ end end - describe 'Blob Metadata' do + describe "Blob Metadata" do let(:attachable) do { - io: File.open(Rails.root.join('public', 'image_150x150.png')), - filename: 'image_150x150.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_150x150.png")), + filename: "image_150x150.png", + content_type: "image/png" } end include IsPerformanceOptimized end - describe 'Rails options' do + describe "Rails options" do include WorksWithAllRailsCommonValidationOptions end end diff --git a/test/validators/dimension_validator_test.rb b/test/validators/dimension_validator_test.rb index 550c1fad..89fccd81 100644 --- a/test/validators/dimension_validator_test.rb +++ b/test/validators/dimension_validator_test.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'test_helper' -require 'validators/shared_examples/checks_validator_validity' -require 'validators/shared_examples/is_performance_optimized' -require 'validators/shared_examples/works_fine_with_attachables' -require 'validators/shared_examples/works_with_all_rails_common_validation_options' +require "test_helper" +require "validators/shared_examples/checks_validator_validity" +require "validators/shared_examples/is_performance_optimized" +require "validators/shared_examples/works_fine_with_attachables" +require "validators/shared_examples/works_with_all_rails_common_validation_options" describe ActiveStorageValidations::DimensionValidator do include ValidatorHelpers @@ -12,61 +12,61 @@ let(:validator_test_class) { Dimension::Validator } let(:params) { {} } - describe '#check_validity!' do + describe "#check_validity!" do include ChecksValidatorValidity - describe '#ensure_dimension_in_option_validity' do - describe 'when the passed option is a Range' do + describe "#ensure_dimension_in_option_validity" do + describe "when the passed option is a Range" do subject { validator_test_class::CheckValidityDimensionInRange.new(params) } - it 'does not perform a check, and therefore is valid' do + it "does not perform a check, and therefore is valid" do assert_nothing_raised { subject } end end - describe 'when the passed option is a Proc' do + describe "when the passed option is a Proc" do subject { validator_test_class::CheckValidityDimensionInProc.new(params) } - it 'does not perform a check, and therefore is valid' do + it "does not perform a check, and therefore is valid" do assert_nothing_raised { subject } end end - describe 'when the passed option is neither a Range nor a Proc' do + describe "when the passed option is neither a Range nor a Proc" do subject { validator_test_class::CheckValidityInvalidDimensionIn.new(params) } let(:error_message) { "{ width: { in: value } } value must be a Range (min..max)" } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end end - describe '#ensure_min_max_option_validity' do + describe "#ensure_min_max_option_validity" do %i[min max].each do |bound| - describe 'when the passed option is a Range' do + describe "when the passed option is a Range" do subject { "#{validator_test_class}::CheckValidity#{bound.to_s.capitalize}Range".constantize.new(params) } - it 'does not perform a check, and therefore is valid' do + it "does not perform a check, and therefore is valid" do assert_nothing_raised { subject } end end - describe 'when the passed option is a Proc' do + describe "when the passed option is a Proc" do subject { "#{validator_test_class}::CheckValidity#{bound.to_s.capitalize}Proc".constantize.new(params) } - it 'does not perform a check, and therefore is valid' do + it "does not perform a check, and therefore is valid" do assert_nothing_raised { subject } end end - describe 'when the passed option is neither a Range nor a Proc' do + describe "when the passed option is neither a Range nor a Proc" do subject { "#{validator_test_class}::CheckValidityInvalid#{bound.to_s.capitalize}".constantize.new(params) } let(:error_message) { "{ #{bound}: value } value must be a Range (#{bound}_width..#{bound}_height)" } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end @@ -74,14 +74,14 @@ end end - describe 'Validator checks' do + describe "Validator checks" do include WorksFineWithAttachables let(:model) { validator_test_class::Check.new(params) } - %w(width height).each do |dimension| + %w[width height].each do |dimension| describe ":#{dimension} option" do - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe value_type do describe ":#{dimension} (e.g { #{dimension}: 500 })" do # validates :width, dimension: { width: 500 } @@ -96,8 +96,8 @@ let(:error_options) do { length: 500, - "#{dimension}": value_type == 'value' ? 500 : -> (record) { 500 }, - filename: 'image_150x150_file.png' + "#{dimension}": value_type == "value" ? 500 : ->(record) { 500 }, + filename: "image_150x150_file.png" } end @@ -118,8 +118,8 @@ let(:error_options) do { length: 500, - "#{dimension}": value_type == 'value' ? 500 : -> (record) { 500 }, - filename: 'image_600x800_file.png' + "#{dimension}": value_type == "value" ? 500 : ->(record) { 500 }, + filename: "image_600x800_file.png" } end @@ -142,8 +142,8 @@ let(:error_options) do { length: 500, - "#{dimension}": { min: value_type == 'value' ? 500 : -> (record) { 500 } }, - filename: 'image_150x150_file.png' + "#{dimension}": { min: value_type == "value" ? 500 : ->(record) { 500 } }, + filename: "image_150x150_file.png" } end @@ -190,8 +190,8 @@ let(:error_options) do { length: 500, - "#{dimension}": { max: value_type == 'value' ? 500 : -> (record) { 500 } }, - filename: 'image_600x800_file.png' + "#{dimension}": { max: value_type == "value" ? 500 : ->(record) { 500 } }, + filename: "image_600x800_file.png" } end @@ -214,8 +214,8 @@ let(:error_options) do { length: 400, - "#{dimension}": { min: value_type == 'value' ? 400 : -> (record) { 400 }, max: value_type == 'value' ? 600 : -> (record) { 600 } }, - filename: 'image_150x150_file.png' + "#{dimension}": { min: value_type == "value" ? 400 : ->(record) { 400 }, max: value_type == "value" ? 600 : ->(record) { 600 } }, + filename: "image_150x150_file.png" } end @@ -236,8 +236,8 @@ let(:error_options) do { length: 600, - "#{dimension}": { min: value_type == 'value' ? 400 : -> (record) { 400 }, max: value_type == 'value' ? 600 : -> (record) { 600 } }, - filename: 'image_1200x900_file.png' + "#{dimension}": { min: value_type == "value" ? 400 : ->(record) { 400 }, max: value_type == "value" ? 600 : ->(record) { 600 } }, + filename: "image_1200x900_file.png" } end @@ -259,10 +259,10 @@ let(:error_options) do { - "#{dimension}": { in: value_type == 'value' ? 400..600 : -> (record) { 400..600 } }, + "#{dimension}": { in: value_type == "value" ? 400..600 : ->(record) { 400..600 } }, min: 400, max: 600, - filename: 'image_150x150_file.png' + filename: "image_150x150_file.png" } end @@ -282,10 +282,10 @@ let(:error_options) do { - "#{dimension}": { in: value_type == 'value' ? 400..600 : -> (record) { 400..600 } }, + "#{dimension}": { in: value_type == "value" ? 400..600 : ->(record) { 400..600 } }, min: 400, max: 600, - filename: 'image_1200x900_file.png' + filename: "image_1200x900_file.png" } end @@ -300,7 +300,7 @@ end describe ":min option" do - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe value_type do describe ":min (e.g { min: 500..500 })" do # validates :min, dimension: { min: 500..500 } @@ -314,7 +314,7 @@ { width: 500, height: 500, - filename: 'image_150x150_file.png' + filename: "image_150x150_file.png" } end @@ -340,7 +340,7 @@ end describe ":max option" do - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe value_type do describe ":max (e.g { max: 500..500 })" do # validates :max, dimension: { max: 500..500 } @@ -366,7 +366,7 @@ { width: 500, height: 500, - filename: 'image_600x800_file.png' + filename: "image_600x800_file.png" } end @@ -397,7 +397,7 @@ width: 600, height: 600, length: 600, - filename: 'image_800x600_file.png' + filename: "image_800x600_file.png" } end @@ -414,7 +414,7 @@ width: 600, height: 600, length: 600, - filename: 'image_600x800_file.png' + filename: "image_600x800_file.png" } end @@ -431,7 +431,7 @@ width: 600, height: 600, length: 600, - filename: 'image_1200x900_file.png' + filename: "image_1200x900_file.png" } end @@ -456,11 +456,11 @@ let(:error_options) do { - width: { in: 550..750}, + width: { in: 550..750 }, height: { in: 550..750 }, min: 550, max: 750, - filename: 'image_500x700_file.png' + filename: "image_500x700_file.png" } end @@ -474,11 +474,11 @@ let(:error_options) do { - width: { in: 550..750}, + width: { in: 550..750 }, height: { in: 550..750 }, min: 550, max: 750, - filename: 'image_700x500_file.png' + filename: "image_700x500_file.png" } end @@ -492,11 +492,11 @@ let(:error_options) do { - width: { in: 550..750}, + width: { in: 550..750 }, height: { in: 550..750 }, min: 550, max: 750, - filename: 'image_500x500_file.png' + filename: "image_500x500_file.png" } end @@ -526,19 +526,19 @@ end end - describe 'Blob Metadata' do + describe "Blob Metadata" do let(:attachable) do { - io: File.open(Rails.root.join('public', 'image_150x150.png')), - filename: 'image_150x150.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_150x150.png")), + filename: "image_150x150.png", + content_type: "image/png" } end include IsPerformanceOptimized end - describe 'Rails options' do + describe "Rails options" do include WorksWithAllRailsCommonValidationOptions end end diff --git a/test/validators/duration_validator_test.rb b/test/validators/duration_validator_test.rb index a616777b..ebd1b5d8 100644 --- a/test/validators/duration_validator_test.rb +++ b/test/validators/duration_validator_test.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'test_helper' -require 'validators/shared_examples/checks_validator_validity' -require 'validators/shared_examples/is_performance_optimized' -require 'validators/shared_examples/works_with_all_rails_common_validation_options' +require "test_helper" +require "validators/shared_examples/checks_validator_validity" +require "validators/shared_examples/is_performance_optimized" +require "validators/shared_examples/works_with_all_rails_common_validation_options" describe ActiveStorageValidations::DurationValidator do include ValidatorHelpers @@ -11,33 +11,33 @@ let(:validator_test_class) { Duration::Validator } let(:params) { {} } - describe '#check_validity!' do + describe "#check_validity!" do include ChecksValidatorValidity end - describe 'Validator checks' do + describe "Validator checks" do let(:model) { validator_test_class::Check.new(params) } - describe ':less_than' do + describe ":less_than" do # validates :less_than, duration: { less_than: 2.seconds } # validates :less_than_proc, duration: { less_than: -> (record) { 2.seconds } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower duration than the duration specified in the model validations' do + describe "when provided with a lower duration than the duration specified in the model validations" do subject { model.less_than.attach(audio_1s) and model } it { is_expected_to_be_valid } end - describe 'when provided with the exact duration specified in the model validations' do + describe "when provided with the exact duration specified in the model validations" do subject { model.less_than.attach(audio_2s) and model } let(:error_options) do { - duration: '2 seconds', - filename: 'audio_2s', + duration: "2 seconds", + filename: "audio_2s", min: nil, - max: '2 seconds' + max: "2 seconds" } end @@ -46,15 +46,15 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with a higher duration than the duration specified in the model validations' do + describe "when provided with a higher duration than the duration specified in the model validations" do subject { model.less_than.attach(audio_5s) and model } let(:error_options) do { - duration: '5 seconds', - filename: 'audio_5s', + duration: "5 seconds", + filename: "audio_5s", min: nil, - max: '2 seconds' + max: "2 seconds" } end @@ -66,32 +66,32 @@ end end - describe ':less_than_or_equal_to' do + describe ":less_than_or_equal_to" do # validates :less_than_or_equal_to, duration: { less_than_or_equal_to: 2.seconds } # validates :less_than_or_equal_to_proc, duration: { less_than_or_equal_to: -> (record) { 2.seconds } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower duration than the duration specified in the model validations' do + describe "when provided with a lower duration than the duration specified in the model validations" do subject { model.less_than_or_equal_to.attach(audio_1s) and model } it { is_expected_to_be_valid } end - describe 'when provided with the exact duration specified in the model validations' do + describe "when provided with the exact duration specified in the model validations" do subject { model.less_than_or_equal_to.attach(audio_2s) and model } it { is_expected_to_be_valid } end - describe 'when provided with a higher duration than the duration specified in the model validations' do + describe "when provided with a higher duration than the duration specified in the model validations" do subject { model.less_than_or_equal_to.attach(audio_5s) and model } let(:error_options) do { - duration: '5 seconds', - filename: 'audio_5s', + duration: "5 seconds", + filename: "audio_5s", min: nil, - max: '2 seconds' + max: "2 seconds" } end @@ -103,19 +103,19 @@ end end - describe ':greater_than' do + describe ":greater_than" do # validates :greater_than, duration: { greater_than: 7.seconds } # validates :greater_than_proc, duration: { greater_than: -> (record) { 7.seconds } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower duration than the duration specified in the model validations' do + describe "when provided with a lower duration than the duration specified in the model validations" do subject { model.greater_than.attach(audio_1s) and model } let(:error_options) do { - duration: '1 second', - filename: 'audio', - min: '7 seconds', + duration: "1 second", + filename: "audio", + min: "7 seconds", max: nil } end @@ -125,14 +125,14 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with the exact duration specified in the model validations' do + describe "when provided with the exact duration specified in the model validations" do subject { model.greater_than.attach(audio_7s) and model } let(:error_options) do { - duration: '7 seconds', - filename: 'audio_7s', - min: '7 seconds', + duration: "7 seconds", + filename: "audio_7s", + min: "7 seconds", max: nil } end @@ -142,7 +142,7 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with a higher duration than the duration specified in the model validations' do + describe "when provided with a higher duration than the duration specified in the model validations" do subject { model.greater_than.attach(audio_10s) and model } it { is_expected_to_be_valid } @@ -151,19 +151,19 @@ end end - describe ':greater_than_or_equal_to' do + describe ":greater_than_or_equal_to" do # validates :greater_than_or_equal_to, duration: { greater_than_or_equal_to: 7.seconds } # validates :greater_than_or_equal_to_proc, duration: { greater_than_or_equal_to: -> (record) { 7.seconds } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower duration than the duration specified in the model validations' do + describe "when provided with a lower duration than the duration specified in the model validations" do subject { model.greater_than_or_equal_to.attach(audio_1s) and model } let(:error_options) do { - duration: '1 second', - filename: 'audio', - min: '7 seconds', + duration: "1 second", + filename: "audio", + min: "7 seconds", max: nil } end @@ -173,13 +173,13 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with the exact duration specified in the model validations' do + describe "when provided with the exact duration specified in the model validations" do subject { model.greater_than_or_equal_to.attach(audio_7s) and model } it { is_expected_to_be_valid } end - describe 'when provided with a higher duration than the duration specified in the model validations' do + describe "when provided with a higher duration than the duration specified in the model validations" do subject { model.greater_than_or_equal_to.attach(audio_10s) and model } it { is_expected_to_be_valid } @@ -188,20 +188,20 @@ end end - describe ':between' do + describe ":between" do # validates :between, duration: { between: 2.seconds..7.seconds } # validates :between_proc, duration: { between: -> (record) { 2.seconds..7.seconds } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower duration than the duration specified in the model validations' do + describe "when provided with a lower duration than the duration specified in the model validations" do subject { model.between.attach(audio_1s) and model } let(:error_options) do { - duration: '1 second', - filename: 'audio', - min: '2 seconds', - max: '7 seconds' + duration: "1 second", + filename: "audio", + min: "2 seconds", + max: "7 seconds" } end @@ -210,33 +210,33 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with the exact lower duration specified in the model validations' do + describe "when provided with the exact lower duration specified in the model validations" do subject { model.between.attach(audio_2s) and model } it { is_expected_to_be_valid } end - describe 'when provided with a duration between the durations specified in the model validations' do + describe "when provided with a duration between the durations specified in the model validations" do subject { model.between.attach(audio_5s) and model } it { is_expected_to_be_valid } end - describe 'when provided with the exact higher duration specified in the model validations' do + describe "when provided with the exact higher duration specified in the model validations" do subject { model.between.attach(audio_7s) and model } it { is_expected_to_be_valid } end - describe 'when provided with a higher duration than the duration specified in the model validations' do + describe "when provided with a higher duration than the duration specified in the model validations" do subject { model.between.attach(audio_10s) and model } let(:error_options) do { - duration: '10 seconds', - filename: 'audio_10s', - min: '2 seconds', - max: '7 seconds' + duration: "10 seconds", + filename: "audio_10s", + min: "2 seconds", + max: "7 seconds" } end @@ -249,19 +249,19 @@ end end - describe 'Blob Metadata' do + describe "Blob Metadata" do let(:attachable) do { - io: File.open(Rails.root.join('public', 'audio.mp3')), - filename: 'audio.mp3', - content_type: 'audio/mp3' + io: File.open(Rails.root.join("public", "audio.mp3")), + filename: "audio.mp3", + content_type: "audio/mp3" } end include IsPerformanceOptimized end - describe 'Rails options' do + describe "Rails options" do include WorksWithAllRailsCommonValidationOptions end end diff --git a/test/validators/integration/integration_test.rb b/test/validators/integration/integration_test.rb index cc64a59a..169f2020 100644 --- a/test/validators/integration/integration_test.rb +++ b/test/validators/integration/integration_test.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" -describe 'Integration tests' do +describe "Integration tests" do include ValidatorHelpers let(:integration_test_class) { Integration::Validator } let(:params) { {} } - describe 'zero byte image' do + describe "zero byte image" do let(:model) { integration_test_class::ZeroByteImage.new(params) } - describe 'when provided with a zero byte image' do + describe "when provided with a zero byte image" do subject { model.zero_byte_image.attach(zero_byte_image_file) and model } let(:zero_byte_image_file) { image_file_0ko } @@ -28,10 +28,10 @@ end end - describe 'based on a file property' do + describe "based on a file property" do let(:model) { integration_test_class::BasedOnAFileProperty.new(params) } - describe 'when setting size constraints based on the content type' do + describe "when setting size constraints based on the content type" do describe "when passed a file with the right size and content content type" do subject { model.picture.attach(file_1ko_and_png) and model } @@ -44,9 +44,9 @@ let(:error_options) do { - file_size: '17 KB', + file_size: "17 KB", min: nil, - max: '15 KB' + max: "15 KB" } end @@ -62,9 +62,9 @@ let(:error_options) do { - file_size: '7 KB', + file_size: "7 KB", min: nil, - max: '5 KB' + max: "5 KB" } end @@ -83,16 +83,16 @@ describe "which uses the same metadata keys (e.g. width & height)" do let(:attachable_1) do { - io: File.open(Rails.root.join('public', 'image_150x150.png')), - filename: 'image_150x150.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_150x150.png")), + filename: "image_150x150.png", + content_type: "image/png" } end let(:attachable_2) do { - io: File.open(Rails.root.join('public', 'image_150x150.png')), - filename: 'image_150x150_2.png', - content_type: 'image/png' + io: File.open(Rails.root.join("public", "image_150x150.png")), + filename: "image_150x150_2.png", + content_type: "image/png" } end @@ -111,16 +111,16 @@ describe "which uses different metadata keys (e.g. width & height + duration)" do let(:attachable_1) do { - io: File.open(Rails.root.join('public', 'video_150x150.mp4')), - filename: 'video_150x150.mp4', - content_type: 'video/mp4' + io: File.open(Rails.root.join("public", "video_150x150.mp4")), + filename: "video_150x150.mp4", + content_type: "video/mp4" } end let(:attachable_2) do { - io: File.open(Rails.root.join('public', 'video_150x150.mp4')), - filename: 'video_150x150_2.mp4', - content_type: 'video/mp4' + io: File.open(Rails.root.join("public", "video_150x150.mp4")), + filename: "video_150x150_2.mp4", + content_type: "video/mp4" } end let(:expected_saved_metadata) do diff --git a/test/validators/limit_validator_test.rb b/test/validators/limit_validator_test.rb index a2e8dbbf..e85e9d29 100644 --- a/test/validators/limit_validator_test.rb +++ b/test/validators/limit_validator_test.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'test_helper' -require 'validators/shared_examples/checks_validator_validity' -require 'validators/shared_examples/works_with_all_rails_common_validation_options' +require "test_helper" +require "validators/shared_examples/checks_validator_validity" +require "validators/shared_examples/works_with_all_rails_common_validation_options" describe ActiveStorageValidations::LimitValidator do include ValidatorHelpers @@ -10,51 +10,51 @@ let(:validator_test_class) { Limit::Validator } let(:params) { {} } - describe '#check_validity!' do + describe "#check_validity!" do include ChecksValidatorValidity - describe 'arguments validity' do - describe 'when the passed argument to min or max is not an integer' do + describe "arguments validity" do + describe "when the passed argument to min or max is not an integer" do subject { validator_test_class::CheckValidityInvalidArgument.new(params) } - let(:error_message) { 'You must pass integers to :min and :max' } + let(:error_message) { "You must pass integers to :min and :max" } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end - describe 'when min is higher than max' do + describe "when min is higher than max" do subject { validator_test_class::CheckValidityMaxHigherThanMin.new(params) } - let(:error_message) { 'You must pass a higher value to :max than to :min' } + let(:error_message) { "You must pass a higher value to :max than to :min" } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end - describe 'when the passed min and/or max are/is a Proc' do + describe "when the passed min and/or max are/is a Proc" do subject { validator_test_class::CheckValidityProcOption.new(params) } - it 'does not perform a check, and therefore is valid' do + it "does not perform a check, and therefore is valid" do assert_nothing_raised { subject } end end end end - describe 'Validator checks' do - describe ':min' do + describe "Validator checks" do + describe ":min" do # validates :min, limit: { min: 2 } # validates :min_proc, limit: { min: -> (record) { 2 } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe value_type do let(:model) { "#{validator_test_class}::CheckMin#{'Proc' if value_type == 'proc'}".constantize.new(params) } let(:attribute) { :"min#{'_proc' if value_type == 'proc'}" } - describe 'when provided with a right number of files' do - subject { model.public_send(attribute).attach([file_1, file_2]) and model } + describe "when provided with a right number of files" do + subject { model.public_send(attribute).attach([ file_1, file_2 ]) and model } let(:file_1) { png_file } let(:file_2) { gif_file } @@ -62,7 +62,7 @@ it { is_expected_to_be_valid } end - describe 'when provided with a wrong number of files' do + describe "when provided with a wrong number of files" do subject { model.public_send(attribute).attach(file_1) and model } let(:file_1) { png_file } @@ -82,15 +82,15 @@ end end - describe ':max' do + describe ":max" do # validates :max, limit: { max: 1 } # validates :max_proc, limit: { max: -> (record) { 1 } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe value_type do let(:model) { "#{validator_test_class}::CheckMax#{'Proc' if value_type == 'proc'}".constantize.new(params) } let(:attribute) { :"max#{'_proc' if value_type == 'proc'}" } - describe 'when provided with a right number of files' do + describe "when provided with a right number of files" do subject { model.public_send(attribute).attach(file_1) and model } let(:file_1) { png_file } @@ -98,8 +98,8 @@ it { is_expected_to_be_valid } end - describe 'when provided with a wrong number of files' do - subject { model.public_send(attribute).attach([file_1, file_2]) and model } + describe "when provided with a wrong number of files" do + subject { model.public_send(attribute).attach([ file_1, file_2 ]) and model } let(:file_1) { png_file } let(:file_2) { gif_file } @@ -119,17 +119,17 @@ end end - describe 'Combinations' do - describe ':min + :max' do + describe "Combinations" do + describe ":min + :max" do # validates :range, limit: { min: 1, max: 3 } # validates :range_proc, limit: { min: -> (record) { 1 }, max: -> (record) { 3 } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe value_type do let(:model) { "#{validator_test_class}::CheckRange#{'Proc' if value_type == 'proc'}".constantize.new(params) } let(:attribute) { :"range#{'_proc' if value_type == 'proc'}" } - describe 'when provided with a right number of files' do - subject { model.public_send(attribute).attach([file_1, file_2]) and model } + describe "when provided with a right number of files" do + subject { model.public_send(attribute).attach([ file_1, file_2 ]) and model } let(:file_1) { png_file } let(:file_2) { gif_file } @@ -137,8 +137,8 @@ it { is_expected_to_be_valid } end - describe 'when provided with a wrong number of files' do - describe 'that is below the lower bound (:max)' do + describe "when provided with a wrong number of files" do + describe "that is below the lower bound (:max)" do subject { model } @@ -155,8 +155,8 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'that is over the upper bound (:max)' do - subject { model.public_send(attribute).attach([file_1, file_1, file_1, file_1]) and model } + describe "that is over the upper bound (:max)" do + subject { model.public_send(attribute).attach([ file_1, file_1, file_1, file_1 ]) and model } let(:file_1) { png_file } let(:error_options) do @@ -178,7 +178,7 @@ end end - describe 'Rails options' do + describe "Rails options" do include WorksWithAllRailsCommonValidationOptions end end diff --git a/test/validators/processable_file_validator_test.rb b/test/validators/processable_file_validator_test.rb index b7142b13..2e2d0f03 100644 --- a/test/validators/processable_file_validator_test.rb +++ b/test/validators/processable_file_validator_test.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'test_helper' -require 'validators/shared_examples/is_performance_optimized' -require 'validators/shared_examples/works_fine_with_attachables' -require 'validators/shared_examples/works_with_all_rails_common_validation_options' +require "test_helper" +require "validators/shared_examples/is_performance_optimized" +require "validators/shared_examples/works_fine_with_attachables" +require "validators/shared_examples/works_with_all_rails_common_validation_options" describe ActiveStorageValidations::ProcessableFileValidator do include ValidatorHelpers @@ -11,21 +11,21 @@ let(:validator_test_class) { ProcessableFile::Validator } let(:params) { {} } - describe 'Validator checks' do + describe "Validator checks" do include WorksFineWithAttachables let(:model) { validator_test_class::Check.new(params) } - %w(image video audio).each do |media_type| + %w[image video audio].each do |media_type| describe "when provided with a #{media_type} that is processable" do # validates :has_to_be_processable, processable_file: true subject { model.has_to_be_processable.attach(processable_file) and model } let(:processable_file) do case media_type - when 'image' then image_1920x1080_file - when 'video' then video_file - when 'audio' then audio_file + when "image" then image_1920x1080_file + when "video" then video_file + when "audio" then audio_file end end @@ -33,13 +33,13 @@ end end - describe 'when provided with a file that is not processable' do + describe "when provided with a file that is not processable" do # validates :has_to_be_processable, processable_file: true subject { model.has_to_be_processable.attach(tar_file_with_image_content_type) and model } let(:error_options) do { - filename: '404.png' + filename: "404.png" } end @@ -48,7 +48,7 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with a StringIO that is an image' do + describe "when provided with a StringIO that is an image" do # validates :has_to_be_processable, processable_file: true subject { model.has_to_be_processable.attach(image_string_io) and model } @@ -56,19 +56,19 @@ end end - describe 'Blob Metadata' do + describe "Blob Metadata" do let(:attachable) do { - io: File.open(Rails.root.join('public', 'audio.mp3')), - filename: 'audio.mp3', - content_type: 'audio/mp3' + io: File.open(Rails.root.join("public", "audio.mp3")), + filename: "audio.mp3", + content_type: "audio/mp3" } end include IsPerformanceOptimized end - describe 'Rails options' do + describe "Rails options" do include WorksWithAllRailsCommonValidationOptions end end diff --git a/test/validators/shared_examples/checks_validator_validity.rb b/test/validators/shared_examples/checks_validator_validity.rb index 8b8aa125..d6d5b786 100644 --- a/test/validators/shared_examples/checks_validator_validity.rb +++ b/test/validators/shared_examples/checks_validator_validity.rb @@ -5,43 +5,43 @@ module ChecksValidatorValidity # Here we do not want to call subject until the test because its initialization # will raise an error let(:validator_klass) { "ActiveStorageValidations::#{validator_test_class.name.sub(/::/, '')}".constantize } - let(:not_applicable) { raise ArgumentError, 'Not applicable to this validator'} + let(:not_applicable) { raise ArgumentError, "Not applicable to this validator" } let(:error_message) do case validator_klass.to_sym - when :aspect_ratio then 'You must pass :with to the validator' + when :aspect_ratio then "You must pass :with to the validator" when :attached then not_applicable - when :content_type then 'You must pass either :with or :in to the validator' - when :dimension then 'You must pass either :width, :height, :min or :max to the validator' - when :duration then 'You must pass either :less_than(_or_equal_to), :greater_than(_or_equal_to), or :between to the validator' - when :limit then 'You must pass either :max or :min to the validator' + when :content_type then "You must pass either :with or :in to the validator" + when :dimension then "You must pass either :width, :height, :min or :max to the validator" + when :duration then "You must pass either :less_than(_or_equal_to), :greater_than(_or_equal_to), or :between to the validator" + when :limit then "You must pass either :max or :min to the validator" when :processable_file then not_applicable - when :size then 'You must pass either :less_than(_or_equal_to), :greater_than(_or_equal_to), or :between to the validator' - when :total_size then 'You must pass either :less_than(_or_equal_to), :greater_than(_or_equal_to), or :between to the validator' + when :size then "You must pass either :less_than(_or_equal_to), :greater_than(_or_equal_to), or :between to the validator" + when :total_size then "You must pass either :less_than(_or_equal_to), :greater_than(_or_equal_to), or :between to the validator" end end - describe 'when the validator has an invalid check' do + describe "when the validator has an invalid check" do subject { validator_test_class::CheckValidityInvalidCheck.new(params) } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end - describe 'when the validator does not have checks' do + describe "when the validator does not have checks" do subject { validator_test_class::CheckValidityNoCheck.new(params) } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end - if %i(content_type size total_size).include? module_parent.to_sym - describe 'when the validator has several checks' do + if %i[content_type size total_size].include? module_parent.to_sym + describe "when the validator has several checks" do subject { validator_test_class::CheckValiditySeveralChecks.new(params) } - it 'raises an error at model initialization' do + it "raises an error at model initialization" do assert_raises(ArgumentError, error_message) { subject } end end diff --git a/test/validators/shared_examples/does_not_work_with_allow_blank_option.rb b/test/validators/shared_examples/does_not_work_with_allow_blank_option.rb index e1735ee0..f82c4919 100644 --- a/test/validators/shared_examples/does_not_work_with_allow_blank_option.rb +++ b/test/validators/shared_examples/does_not_work_with_allow_blank_option.rb @@ -6,7 +6,7 @@ module DoesNotWorkWithAllowBlankOption included do subject { validator_test_class::WithAllowBlank.new(params) } - describe 'when used with :allow_blank option' do + describe "when used with :allow_blank option" do it do is_expected_to_raise_error( ArgumentError, diff --git a/test/validators/shared_examples/does_not_work_with_allow_nil_option.rb b/test/validators/shared_examples/does_not_work_with_allow_nil_option.rb index 51ba01f1..56f44b3c 100644 --- a/test/validators/shared_examples/does_not_work_with_allow_nil_option.rb +++ b/test/validators/shared_examples/does_not_work_with_allow_nil_option.rb @@ -6,7 +6,7 @@ module DoesNotWorkWithAllowNilOption included do subject { validator_test_class::WithAllowNil.new(params) } - describe 'when used with :allow_nil option' do + describe "when used with :allow_nil option" do it do is_expected_to_raise_error( ArgumentError, diff --git a/test/validators/shared_examples/works_fine_with_attachables.rb b/test/validators/shared_examples/works_fine_with_attachables.rb index 87621bea..f94127db 100644 --- a/test/validators/shared_examples/works_fine_with_attachables.rb +++ b/test/validators/shared_examples/works_fine_with_attachables.rb @@ -7,7 +7,7 @@ module WorksFineWithAttachables class_methods do def file_fixture_path - @file_fixture_path ||= Rails.root.join('test/fixtures/files').to_s + @file_fixture_path ||= Rails.root.join("test/fixtures/files").to_s end end @@ -28,7 +28,7 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) let(:model) { validator_test_class::UsingAttachable.new(params) } let(:validator_class) { "ActiveStorageValidations::#{validator_test_class.name.delete('::')}".constantize } - let(:png_image) { Rails.root.join('public', 'image_150x150.png') } + let(:png_image) { Rails.root.join("public", "image_150x150.png") } describe "working with all attachable formats" do # As stated in ActiveStorage documentation, attachables can either be a: @@ -40,11 +40,11 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) # File object # Pathname object - %w(one many).each do |relationship_type| + %w[one many].each do |relationship_type| describe relationship_type do let(:attribute) { :"using_attachable#{'s' if relationship_type == 'many'}" } let(:attachables) do - relationship_type == 'one' ? attachable : [attachable, attachable] + relationship_type == "one" ? attachable : [ attachable, attachable ] end describe "ActiveStorage::Blob object" do @@ -53,9 +53,9 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) let(:attachable) do ActiveStorage::Blob.create_and_upload!( io: File.open(png_image), - filename: 'image_150x150.png', - content_type: 'image/png', - service_name: 'test' + filename: "image_150x150.png", + content_type: "image/png", + service_name: "test" ) end @@ -66,14 +66,14 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) subject { model.public_send(attribute).attach(attachables) and model } let(:attachable) do - tempfile = Tempfile.new(['image_150x150', '.png']) + tempfile = Tempfile.new([ "image_150x150", ".png" ]) tempfile.write(File.read(png_image)) tempfile.rewind ActionDispatch::Http::UploadedFile.new({ tempfile: tempfile, - filename: 'image_150x150.png', - type: 'image/png' + filename: "image_150x150.png", + type: "image/png" }) end @@ -83,7 +83,7 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) describe "Rack::Test::UploadedFile object" do subject { model.public_send(attribute).attach(attachables) and model } - let(:attachable) { Rack::Test::UploadedFile.new(png_image, 'image/png') } + let(:attachable) { Rack::Test::UploadedFile.new(png_image, "image/png") } it { is_expected_to_be_valid } end @@ -94,8 +94,8 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) let(:attachable) do { io: File.open(png_image), - filename: 'image_150x150.png', - content_type: 'image/png' + filename: "image_150x150.png", + content_type: "image/png" } end @@ -105,7 +105,7 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) let(:attachable) do { io: File.open(png_image), - filename: 'image_150x150.png' + filename: "image_150x150.png" } end @@ -115,7 +115,7 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) describe "Remote file" do before do stub_request(:get, url) - .to_return(body: File.open(Rails.root.join('public', fetched_file)), status: 200) + .to_return(body: File.open(Rails.root.join("public", fetched_file)), status: 200) end let(:url) { "https://example_image.jpg" } @@ -124,14 +124,14 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) { io: io, filename: fetched_file, - content_type: 'image/png' + content_type: "image/png" } end describe "using StringIO constructor as io" do let(:io) { StringIO.new(remote_image.to_s) } let(:remote_image) { Net::HTTP.get(uri) } - let(:fetched_file) { 'image_150x150.png' } + let(:fetched_file) { "image_150x150.png" } it { is_expected_to_be_valid } end @@ -140,13 +140,13 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) let(:io) { uri.open } describe "Opening small images (< 10ko) resulting in OpenUri returning a StringIO" do - let(:fetched_file) { 'image_150x150.png' } + let(:fetched_file) { "image_150x150.png" } it { is_expected_to_be_valid } end describe "Opening large images (>= 10ko) resulting in OpenUri returning a Tempfile" do - let(:fetched_file) { 'file_28ko.png' } + let(:fetched_file) { "file_28ko.png" } it { is_expected_to_be_valid } end @@ -160,9 +160,9 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) let(:attachable) do blob = ActiveStorage::Blob.create_and_upload!( io: File.open(png_image), - filename: 'image_150x150.png', - content_type: 'image/png', - service_name: 'test' + filename: "image_150x150.png", + content_type: "image/png", + service_name: "test" ) blob.signed_id end @@ -175,7 +175,7 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) let(:attachable) { File.open(png_image) } - if Rails.gem_version >= Gem::Version.new('7.1.0.rc1') + if Rails.gem_version >= Gem::Version.new("7.1.0.rc1") it { is_expected_to_be_valid } else it { is_expected_to_raise_error(ArgumentError, "Could not find or build blob: expected attachable, got #{attachable.inspect}") } @@ -187,7 +187,7 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) let(:attachable) { Pathname.new(png_image) } - if Rails.gem_version >= Gem::Version.new('7.1.0.rc1') + if Rails.gem_version >= Gem::Version.new("7.1.0.rc1") it { is_expected_to_be_valid } else it { is_expected_to_raise_error(ArgumentError, "Could not find or build blob: expected attachable, got #{attachable.inspect}") } @@ -208,9 +208,9 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) describe "rewinding the attachable io" do let(:attachable) do { - io: File.open(png_image, 'rb'), # read as binary to prevent encoding mismatch - filename: 'image_150x150.png', - content_type: 'image/png' + io: File.open(png_image, "rb"), # read as binary to prevent encoding mismatch + filename: "image_150x150.png", + content_type: "image/png" } end @@ -241,12 +241,12 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) let(:attachable) do { io: File.open(png_image), - filename: 'image_150x150.png', - content_type: 'image/png' + filename: "image_150x150.png", + content_type: "image/png" } end - before { subject.using_attachables.attach([attachable, attachable]) } + before { subject.using_attachables.attach([ attachable, attachable ]) } it "only performs the validation once for these files" do assert_called_on_instance_of(validator_class, :is_valid?, times: 1) do @@ -257,28 +257,28 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) describe "when doing an update" do before do - subject.using_attachables.attach([attachable_1]) + subject.using_attachables.attach([ attachable_1 ]) subject.save! end let(:attachable_1) do { io: File.open(png_image), - filename: 'image_150x150.png', - content_type: 'image/png' + filename: "image_150x150.png", + content_type: "image/png" } end let(:attachable_2) do ActiveStorage::Blob.create_and_upload!( io: File.open(png_image), - filename: 'image_150x150.png', - content_type: 'image/png', - service_name: 'test' + filename: "image_150x150.png", + content_type: "image/png", + service_name: "test" ) end it "updates the attribute accordingly and does not break" do - subject.using_attachables.attach([attachable_2]) + subject.using_attachables.attach([ attachable_2 ]) subject.save! assert(subject.valid?) end @@ -302,7 +302,7 @@ def fixture_file_upload(filename, mime_type = nil, binary = false) end describe "when using `file_fixture_upload` (or its alias `fixture_file_upload`)" do - let(:attachable) { fixture_file_upload('image_150x150.png', 'image/png') } + let(:attachable) { fixture_file_upload("image_150x150.png", "image/png") } before { subject.using_attachable.attach(attachable) } diff --git a/test/validators/shared_examples/works_with_all_rails_common_validation_options.rb b/test/validators/shared_examples/works_with_all_rails_common_validation_options.rb index 7c2867ab..105d7dce 100644 --- a/test/validators/shared_examples/works_with_all_rails_common_validation_options.rb +++ b/test/validators/shared_examples/works_with_all_rails_common_validation_options.rb @@ -1,10 +1,10 @@ -require 'validators/shared_examples/works_with_allow_blank_option' -require 'validators/shared_examples/works_with_allow_nil_option' -require 'validators/shared_examples/works_with_if_option' -require 'validators/shared_examples/works_with_message_option' -require 'validators/shared_examples/works_with_on_option' -require 'validators/shared_examples/works_with_unless_option' -require 'validators/shared_examples/works_with_strict_option' +require "validators/shared_examples/works_with_allow_blank_option" +require "validators/shared_examples/works_with_allow_nil_option" +require "validators/shared_examples/works_with_if_option" +require "validators/shared_examples/works_with_message_option" +require "validators/shared_examples/works_with_on_option" +require "validators/shared_examples/works_with_unless_option" +require "validators/shared_examples/works_with_strict_option" module WorksWithAllRailsCommonValidationOptions extend ActiveSupport::Concern @@ -13,7 +13,7 @@ module WorksWithAllRailsCommonValidationOptions # https://guides.rubyonrails.org/active_record_validations.html#common-validation-options included do - %i(allow_nil allow_blank if on strict unless message).each do |validation_option| + %i[allow_nil allow_blank if on strict unless message].each do |validation_option| describe ":#{validation_option}" do include "WorksWith#{validation_option.to_s.camelize}Option".constantize end diff --git a/test/validators/shared_examples/works_with_allow_blank_option.rb b/test/validators/shared_examples/works_with_allow_blank_option.rb index 23519168..8c503bdd 100644 --- a/test/validators/shared_examples/works_with_allow_blank_option.rb +++ b/test/validators/shared_examples/works_with_allow_blank_option.rb @@ -14,7 +14,7 @@ module WorksWithAllowBlankOption when :limit then nil when :processable_file then image_150x150_file when :size then file_1ko - when :total_size then [blob_file_0_5ko, blob_file_0_5ko] + when :total_size then [ blob_file_0_5ko, blob_file_0_5ko ] end end let(:file_not_matching_requirements) do @@ -27,17 +27,17 @@ module WorksWithAllowBlankOption when :limit then file_5ko when :processable_file then tar_file_with_image_content_type when :size then file_5ko - when :total_size then [blob_file_5ko, blob_file_5ko] + when :total_size then [ blob_file_5ko, blob_file_5ko ] end end - describe 'when passed a file matching the requirements' do + describe "when passed a file matching the requirements" do before { subject.with_allow_blank.attach(file_matching_requirements) } it { is_expected_to_be_valid } end - describe 'when passed a file not matching the requirements' do + describe "when passed a file not matching the requirements" do let(:error_options) { { allow_blank: true } } before { subject.with_allow_blank.attach(file_not_matching_requirements) } diff --git a/test/validators/shared_examples/works_with_allow_nil_option.rb b/test/validators/shared_examples/works_with_allow_nil_option.rb index 54bfccee..91afc2d6 100644 --- a/test/validators/shared_examples/works_with_allow_nil_option.rb +++ b/test/validators/shared_examples/works_with_allow_nil_option.rb @@ -14,7 +14,7 @@ module WorksWithAllowNilOption when :limit then nil when :processable_file then image_150x150_file when :size then file_1ko - when :total_size then [blob_file_0_5ko, blob_file_0_5ko] + when :total_size then [ blob_file_0_5ko, blob_file_0_5ko ] end end let(:file_not_matching_requirements) do @@ -27,17 +27,17 @@ module WorksWithAllowNilOption when :limit then file_5ko when :processable_file then tar_file_with_image_content_type when :size then file_5ko - when :total_size then [blob_file_5ko, blob_file_5ko] + when :total_size then [ blob_file_5ko, blob_file_5ko ] end end - describe 'when passed a file matching the requirements' do + describe "when passed a file matching the requirements" do before { subject.with_allow_nil.attach(file_matching_requirements) } it { is_expected_to_be_valid } end - describe 'when passed a file not matching the requirements' do + describe "when passed a file not matching the requirements" do let(:error_options) { { allow_nil: true } } before { subject.with_allow_nil.attach(file_not_matching_requirements) } diff --git a/test/validators/shared_examples/works_with_if_option.rb b/test/validators/shared_examples/works_with_if_option.rb index c839898c..9f60d66c 100644 --- a/test/validators/shared_examples/works_with_if_option.rb +++ b/test/validators/shared_examples/works_with_if_option.rb @@ -14,7 +14,7 @@ module WorksWithIfOption when :limit then image_150x150_file when :processable_file then image_150x150_file when :size then file_1ko - when :total_size then [blob_file_0_5ko, blob_file_0_5ko] + when :total_size then [ blob_file_0_5ko, blob_file_0_5ko ] end end let(:file_not_matching_requirements) do @@ -27,21 +27,21 @@ module WorksWithIfOption when :limit then nil when :processable_file then tar_file_with_image_content_type when :size then file_5ko - when :total_size then [blob_file_5ko, blob_file_5ko] + when :total_size then [ blob_file_5ko, blob_file_5ko ] end end - describe 'when the :if condition is a method' do - describe 'and the condition is met' do - let(:params) { { title: 'image' } } + describe "when the :if condition is a method" do + describe "and the condition is met" do + let(:params) { { title: "image" } } - describe 'and when passed a file matching the requirements' do + describe "and when passed a file matching the requirements" do before { subject.with_if.attach(file_matching_requirements) } it { is_expected_to_be_valid } end - describe 'and when passed a file not matching the requirements' do + describe "and when passed a file not matching the requirements" do let(:error_options) { { if: :title_is_image? } } before { subject.with_if.attach(file_not_matching_requirements) } @@ -52,18 +52,18 @@ module WorksWithIfOption end end - describe 'when the :if condition is a Proc' do - describe 'and the condition is met' do - let(:params) { { title: 'Right title' } } + describe "when the :if condition is a Proc" do + describe "and the condition is met" do + let(:params) { { title: "Right title" } } - describe 'and when passed a file matching the requirements' do + describe "and when passed a file matching the requirements" do before { subject.with_if_proc.attach(file_matching_requirements) } it { is_expected_to_be_valid } end - describe 'and when passed a file not matching the requirements' do - let(:error_options) { { if: -> { self.title == 'Right title' } } } + describe "and when passed a file not matching the requirements" do + let(:error_options) { { if: -> { self.title == "Right title" } } } before { subject.with_if_proc.attach(file_not_matching_requirements) } diff --git a/test/validators/shared_examples/works_with_message_option.rb b/test/validators/shared_examples/works_with_message_option.rb index a5f5a80d..c8ccffc9 100644 --- a/test/validators/shared_examples/works_with_message_option.rb +++ b/test/validators/shared_examples/works_with_message_option.rb @@ -14,7 +14,7 @@ module WorksWithMessageOption when :limit then nil when :processable_file then image_150x150_file when :size then file_1ko - when :total_size then [blob_file_0_5ko, blob_file_0_5ko] + when :total_size then [ blob_file_0_5ko, blob_file_0_5ko ] end end let(:file_not_matching_requirements) do @@ -27,18 +27,18 @@ module WorksWithMessageOption when :limit then file_5ko when :processable_file then tar_file_with_image_content_type when :size then file_5ko - when :total_size then [blob_file_5ko, blob_file_5ko] + when :total_size then [ blob_file_5ko, blob_file_5ko ] end end - describe 'when passed a file matching the requirements' do + describe "when passed a file matching the requirements" do before { subject.with_message.attach(file_matching_requirements) } it { is_expected_to_be_valid } end - describe 'when passed a file not matching the requirements' do - let(:error_options) { { custom_message: 'Custom message' } } + describe "when passed a file not matching the requirements" do + let(:error_options) { { custom_message: "Custom message" } } before { subject.with_message.attach(file_not_matching_requirements) } diff --git a/test/validators/shared_examples/works_with_on_option.rb b/test/validators/shared_examples/works_with_on_option.rb index ccd35375..6c1c3e86 100644 --- a/test/validators/shared_examples/works_with_on_option.rb +++ b/test/validators/shared_examples/works_with_on_option.rb @@ -14,7 +14,7 @@ module WorksWithOnOption when :limit then image_150x150_file when :processable_file then image_150x150_file when :size then file_1ko - when :total_size then [blob_file_0_5ko, blob_file_0_5ko] + when :total_size then [ blob_file_0_5ko, blob_file_0_5ko ] end end let(:file_not_matching_requirements) do @@ -27,19 +27,19 @@ module WorksWithOnOption when :limit then nil when :processable_file then tar_file_with_image_content_type when :size then file_5ko - when :total_size then [blob_file_5ko, blob_file_5ko] + when :total_size then [ blob_file_5ko, blob_file_5ko ] end end - %i(create update destroy custom).each do |context| + %i[create update destroy custom].each do |context| describe ":#{context}" do - describe 'when passed a file matching the requirements' do + describe "when passed a file matching the requirements" do before { subject.with_on.attach(file_matching_requirements) } it { is_expected_to_be_valid(context: context) } end - describe 'when passed a file not matching the requirements' do + describe "when passed a file not matching the requirements" do let(:error_options) { { on: %i[create update destroy custom] } } before { subject.with_on.attach(file_not_matching_requirements) } diff --git a/test/validators/shared_examples/works_with_strict_option.rb b/test/validators/shared_examples/works_with_strict_option.rb index 6a7e2c63..71d6f922 100644 --- a/test/validators/shared_examples/works_with_strict_option.rb +++ b/test/validators/shared_examples/works_with_strict_option.rb @@ -14,7 +14,7 @@ module WorksWithStrictOption when :limit then image_150x150_file when :processable_file then image_150x150_file when :size then file_1ko - when :total_size then [blob_file_0_5ko, blob_file_0_5ko] + when :total_size then [ blob_file_0_5ko, blob_file_0_5ko ] end end let(:file_not_matching_requirements) do @@ -27,17 +27,17 @@ module WorksWithStrictOption when :limit then nil when :processable_file then tar_file_with_image_content_type when :size then file_5ko - when :total_size then [blob_file_5ko, blob_file_5ko] + when :total_size then [ blob_file_5ko, blob_file_5ko ] end end - describe 'when passed a file matching the requirements' do + describe "when passed a file matching the requirements" do before { subject.with_strict.attach(file_matching_requirements) } it { is_expected_to_be_valid } end - describe 'when passed a file not matching the requirements' do + describe "when passed a file not matching the requirements" do let(:error_class) { subject.class::StrictException } let(:error_options) { { strict: error_class } } diff --git a/test/validators/shared_examples/works_with_unless_option.rb b/test/validators/shared_examples/works_with_unless_option.rb index e31f24af..3f5a2d5a 100644 --- a/test/validators/shared_examples/works_with_unless_option.rb +++ b/test/validators/shared_examples/works_with_unless_option.rb @@ -14,7 +14,7 @@ module WorksWithUnlessOption when :limit then image_150x150_file when :processable_file then image_150x150_file when :size then file_1ko - when :total_size then [blob_file_0_5ko, blob_file_0_5ko] + when :total_size then [ blob_file_0_5ko, blob_file_0_5ko ] end end let(:file_not_matching_requirements) do @@ -27,22 +27,22 @@ module WorksWithUnlessOption when :limit then nil when :processable_file then tar_file_with_image_content_type when :size then file_5ko - when :total_size then [blob_file_5ko, blob_file_5ko] + when :total_size then [ blob_file_5ko, blob_file_5ko ] end end - describe 'when the :unless condition is a method' do - describe 'and the condition is not met' do + describe "when the :unless condition is a method" do + describe "and the condition is not met" do # Here 0 is important to only trigger the #with_unless attribute let(:params) { { rating: 0 } } - describe 'and when passed a file matching the requirements' do + describe "and when passed a file matching the requirements" do before { subject.with_unless.attach(file_matching_requirements) } it { is_expected_to_be_valid } end - describe 'and when passed a file not matching the requirements' do + describe "and when passed a file not matching the requirements" do let(:error_options) { { unless: :rating_is_good? } } before { subject.with_unless.attach(file_not_matching_requirements) } @@ -53,18 +53,18 @@ module WorksWithUnlessOption end end - describe 'when the :unless condition is a Proc' do - describe 'and the condition is not met' do - # Here 4 is important to only trigger the #with_unless_proc attribute + describe "when the :unless condition is a Proc" do + describe "and the condition is not met" do + # Here 4 is important to only trigger the #with_unless_proc attribute let(:params) { { rating: 4 } } - describe 'and when passed a file matching the requirements' do + describe "and when passed a file matching the requirements" do before { subject.with_unless_proc.attach(file_matching_requirements) } it { is_expected_to_be_valid } end - describe 'and when passed a file not matching the requirements' do + describe "and when passed a file not matching the requirements" do let(:error_options) { { unless: -> { self.rating == 0 } } } before { subject.with_unless_proc.attach(file_not_matching_requirements) } diff --git a/test/validators/size_validator_test.rb b/test/validators/size_validator_test.rb index ef386e29..a68e713d 100644 --- a/test/validators/size_validator_test.rb +++ b/test/validators/size_validator_test.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'test_helper' -require 'validators/shared_examples/checks_validator_validity' -require 'validators/shared_examples/works_with_all_rails_common_validation_options' +require "test_helper" +require "validators/shared_examples/checks_validator_validity" +require "validators/shared_examples/works_with_all_rails_common_validation_options" describe ActiveStorageValidations::SizeValidator do include ValidatorHelpers @@ -10,33 +10,33 @@ let(:validator_test_class) { Size::Validator } let(:params) { {} } - describe '#check_validity!' do + describe "#check_validity!" do include ChecksValidatorValidity end - describe 'Validator checks' do + describe "Validator checks" do let(:model) { validator_test_class::Check.new(params) } - describe ':less_than' do + describe ":less_than" do # validates :less_than, size: { less_than: 2.kilobytes } # validates :less_than_proc, size: { less_than: -> (record) { 2.kilobytes } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower size than the size specified in the model validations' do + describe "when provided with a lower size than the size specified in the model validations" do subject { model.less_than.attach(file_1ko) and model } it { is_expected_to_be_valid } end - describe 'when provided with the exact size specified in the model validations' do + describe "when provided with the exact size specified in the model validations" do subject { model.less_than.attach(file_2ko) and model } let(:error_options) do { - file_size: '2 KB', - filename: 'file_2ko', + file_size: "2 KB", + filename: "file_2ko", min: nil, - max: '2 KB' + max: "2 KB" } end @@ -45,15 +45,15 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with a higher size than the size specified in the model validations' do + describe "when provided with a higher size than the size specified in the model validations" do subject { model.less_than.attach(file_5ko) and model } let(:error_options) do { - file_size: '5 KB', - filename: 'file_5ko', + file_size: "5 KB", + filename: "file_5ko", min: nil, - max: '2 KB' + max: "2 KB" } end @@ -65,32 +65,32 @@ end end - describe ':less_than_or_equal_to' do + describe ":less_than_or_equal_to" do # validates :less_than_or_equal_to, size: { less_than_or_equal_to: 2.kilobytes } # validates :less_than_or_equal_to_proc, size: { less_than_or_equal_to: -> (record) { 2.kilobytes } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower size than the size specified in the model validations' do + describe "when provided with a lower size than the size specified in the model validations" do subject { model.less_than_or_equal_to.attach(file_1ko) and model } it { is_expected_to_be_valid } end - describe 'when provided with the exact size specified in the model validations' do + describe "when provided with the exact size specified in the model validations" do subject { model.less_than_or_equal_to.attach(file_2ko) and model } it { is_expected_to_be_valid } end - describe 'when provided with a higher size than the size specified in the model validations' do + describe "when provided with a higher size than the size specified in the model validations" do subject { model.less_than_or_equal_to.attach(file_5ko) and model } let(:error_options) do { - file_size: '5 KB', - filename: 'file_5ko', + file_size: "5 KB", + filename: "file_5ko", min: nil, - max: '2 KB' + max: "2 KB" } end @@ -102,19 +102,19 @@ end end - describe ':greater_than' do + describe ":greater_than" do # validates :greater_than, size: { greater_than: 7.kilobytes } # validates :greater_than_proc, size: { greater_than: -> (record) { 7.kilobytes } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower size than the size specified in the model validations' do + describe "when provided with a lower size than the size specified in the model validations" do subject { model.greater_than.attach(file_1ko) and model } let(:error_options) do { - file_size: '1 KB', - filename: 'file_1ko.png', - min: '7 KB', + file_size: "1 KB", + filename: "file_1ko.png", + min: "7 KB", max: nil } end @@ -124,14 +124,14 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with the exact size specified in the model validations' do + describe "when provided with the exact size specified in the model validations" do subject { model.greater_than.attach(file_7ko) and model } let(:error_options) do { - file_size: '7 KB', - filename: 'file_7ko', - min: '7 KB', + file_size: "7 KB", + filename: "file_7ko", + min: "7 KB", max: nil } end @@ -141,7 +141,7 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with a higher size than the size specified in the model validations' do + describe "when provided with a higher size than the size specified in the model validations" do subject { model.greater_than.attach(file_10ko) and model } it { is_expected_to_be_valid } @@ -150,19 +150,19 @@ end end - describe ':greater_than_or_equal_to' do + describe ":greater_than_or_equal_to" do # validates :greater_than_or_equal_to, size: { greater_than_or_equal_to: 7.kilobytes } # validates :greater_than_or_equal_to_proc, size: { greater_than_or_equal_to: -> (record) { 7.kilobytes } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower size than the size specified in the model validations' do + describe "when provided with a lower size than the size specified in the model validations" do subject { model.greater_than_or_equal_to.attach(file_1ko) and model } let(:error_options) do { - file_size: '1 KB', - filename: 'file_1ko.png', - min: '7 KB', + file_size: "1 KB", + filename: "file_1ko.png", + min: "7 KB", max: nil } end @@ -172,13 +172,13 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with the exact size specified in the model validations' do + describe "when provided with the exact size specified in the model validations" do subject { model.greater_than_or_equal_to.attach(file_7ko) and model } it { is_expected_to_be_valid } end - describe 'when provided with a higher size than the size specified in the model validations' do + describe "when provided with a higher size than the size specified in the model validations" do subject { model.greater_than_or_equal_to.attach(file_10ko) and model } it { is_expected_to_be_valid } @@ -187,20 +187,20 @@ end end - describe ':between' do + describe ":between" do # validates :between, size: { between: 2.kilobytes..7.kilobytes } # validates :between_proc, size: { between: -> (record) { 2.kilobytes..7.kilobytes } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower size than the size specified in the model validations' do + describe "when provided with a lower size than the size specified in the model validations" do subject { model.between.attach(file_1ko) and model } let(:error_options) do { - file_size: '1 KB', - filename: 'file_1ko.png', - min: '2 KB', - max: '7 KB' + file_size: "1 KB", + filename: "file_1ko.png", + min: "2 KB", + max: "7 KB" } end @@ -209,33 +209,33 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with the exact lower size specified in the model validations' do + describe "when provided with the exact lower size specified in the model validations" do subject { model.between.attach(file_2ko) and model } it { is_expected_to_be_valid } end - describe 'when provided with a size between the sizes specified in the model validations' do + describe "when provided with a size between the sizes specified in the model validations" do subject { model.between.attach(file_5ko) and model } it { is_expected_to_be_valid } end - describe 'when provided with the exact higher size specified in the model validations' do + describe "when provided with the exact higher size specified in the model validations" do subject { model.between.attach(file_7ko) and model } it { is_expected_to_be_valid } end - describe 'when provided with a higher size than the size specified in the model validations' do + describe "when provided with a higher size than the size specified in the model validations" do subject { model.between.attach(file_10ko) and model } let(:error_options) do { - file_size: '10.2 KB', - filename: 'file_10ko', - min: '2 KB', - max: '7 KB' + file_size: "10.2 KB", + filename: "file_10ko", + min: "2 KB", + max: "7 KB" } end @@ -248,7 +248,7 @@ end end - describe 'Rails options' do + describe "Rails options" do include WorksWithAllRailsCommonValidationOptions end end diff --git a/test/validators/support/validator_helpers.rb b/test/validators/support/validator_helpers.rb index c9905141..c545377f 100644 --- a/test/validators/support/validator_helpers.rb +++ b/test/validators/support/validator_helpers.rb @@ -6,7 +6,7 @@ def is_expected_to_be_valid(**kwargs) end def is_expected_not_to_be_valid(**kwargs) - subject && refute(subject.valid?(kwargs[:context])) + subject && assert_not(subject.valid?(kwargs[:context])) end def is_expected_to_have_error_options(error_options, **kwargs) @@ -79,7 +79,7 @@ def value_is_equal_or_both_are_procs?(value_1, value_2) # Comparing Procs is tricky, let's just ensure that both values are procs # for now to check equality, if necessary we will investigate a better # solution - (value_1 == value_2) || + (value_1 == value_2) || (value_1.is_a?(Proc) && value_2.is_a?(Proc)) || (value_1.is_a?(Hash) && value_2.is_a?(Hash) && value_1.values.all?(Proc) && value_2.values.all?(Proc)) # e.g. { width: { min: -> (record) { 500 } } } end diff --git a/test/validators/total_size_validator_test.rb b/test/validators/total_size_validator_test.rb index 8968e47c..624c6b0f 100644 --- a/test/validators/total_size_validator_test.rb +++ b/test/validators/total_size_validator_test.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'test_helper' -require 'validators/shared_examples/checks_validator_validity' -require 'validators/shared_examples/works_with_all_rails_common_validation_options' +require "test_helper" +require "validators/shared_examples/checks_validator_validity" +require "validators/shared_examples/works_with_all_rails_common_validation_options" describe ActiveStorageValidations::TotalSizeValidator do include ValidatorHelpers @@ -10,7 +10,7 @@ let(:validator_test_class) { TotalSize::Validator } let(:params) { {} } - describe '#(custom_)check_validity!' do + describe "#(custom_)check_validity!" do include ChecksValidatorValidity describe "when used with has_one_attached" do @@ -18,34 +18,34 @@ let(:instance) { validator_test_class::CheckValidityHasManyAttachedOnly.new(params) } - it 'raises an error at model initialization' do - assert_raises(ArgumentError, 'This validator is only available for has_many_attached relations') { subject.valid? } + it "raises an error at model initialization" do + assert_raises(ArgumentError, "This validator is only available for has_many_attached relations") { subject.valid? } end end end - describe 'Validator checks' do + describe "Validator checks" do let(:model) { validator_test_class::Check.new(params) } - describe ':less_than' do + describe ":less_than" do # validates :less_than, total_size: { less_than: 2.kilobytes } # validates :less_than_proc, total_size: { less_than: -> (record) { 2.kilobytes } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower total_size than the total_size specified in the model validations' do - subject { model.less_than.attach([blob_file_0_5ko, blob_file_0_5ko]) and model } + describe "when provided with a lower total_size than the total_size specified in the model validations" do + subject { model.less_than.attach([ blob_file_0_5ko, blob_file_0_5ko ]) and model } it { is_expected_to_be_valid } end - describe 'when provided with the exact total_size specified in the model validations' do - subject { model.less_than.attach([blob_file_1ko, blob_file_1ko]) and model } + describe "when provided with the exact total_size specified in the model validations" do + subject { model.less_than.attach([ blob_file_1ko, blob_file_1ko ]) and model } let(:error_options) do { - total_file_size: '2 KB', + total_file_size: "2 KB", min: nil, - max: '2 KB' + max: "2 KB" } end @@ -54,14 +54,14 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with a higher total_size than the total_size specified in the model validations' do - subject { model.less_than.attach([blob_file_5ko, blob_file_5ko]) and model } + describe "when provided with a higher total_size than the total_size specified in the model validations" do + subject { model.less_than.attach([ blob_file_5ko, blob_file_5ko ]) and model } let(:error_options) do { - total_file_size: '10 KB', + total_file_size: "10 KB", min: nil, - max: '2 KB' + max: "2 KB" } end @@ -73,31 +73,31 @@ end end - describe ':less_than_or_equal_to' do + describe ":less_than_or_equal_to" do # validates :less_than_or_equal_to, total_size: { less_than_or_equal_to: 2.kilobytes } # validates :less_than_or_equal_to_proc, total_size: { less_than_or_equal_to: -> (record) { 2.kilobytes } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower total_size than the total_size specified in the model validations' do - subject { model.less_than_or_equal_to.attach([blob_file_0_5ko, blob_file_0_5ko]) and model } + describe "when provided with a lower total_size than the total_size specified in the model validations" do + subject { model.less_than_or_equal_to.attach([ blob_file_0_5ko, blob_file_0_5ko ]) and model } it { is_expected_to_be_valid } end - describe 'when provided with the exact total_size specified in the model validations' do - subject { model.less_than_or_equal_to.attach([blob_file_1ko, blob_file_1ko]) and model } + describe "when provided with the exact total_size specified in the model validations" do + subject { model.less_than_or_equal_to.attach([ blob_file_1ko, blob_file_1ko ]) and model } it { is_expected_to_be_valid } end - describe 'when provided with a higher total_size than the total_size specified in the model validations' do - subject { model.less_than_or_equal_to.attach([blob_file_1ko, blob_file_5ko]) and model } + describe "when provided with a higher total_size than the total_size specified in the model validations" do + subject { model.less_than_or_equal_to.attach([ blob_file_1ko, blob_file_5ko ]) and model } let(:error_options) do { - total_file_size: '6 KB', + total_file_size: "6 KB", min: nil, - max: '2 KB' + max: "2 KB" } end @@ -109,18 +109,18 @@ end end - describe ':greater_than' do + describe ":greater_than" do # validates :greater_than, total_size: { greater_than: 7.kilobytes } # validates :greater_than_proc, total_size: { greater_than: -> (record) { 7.kilobytes } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower total_size than the total_size specified in the model validations' do - subject { model.greater_than.attach([blob_file_1ko, blob_file_1ko]) and model } + describe "when provided with a lower total_size than the total_size specified in the model validations" do + subject { model.greater_than.attach([ blob_file_1ko, blob_file_1ko ]) and model } let(:error_options) do { - total_file_size: '2 KB', - min: '7 KB', + total_file_size: "2 KB", + min: "7 KB", max: nil } end @@ -130,13 +130,13 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with the exact total_size specified in the model validations' do - subject { model.greater_than.attach([blob_file_5ko, blob_file_2ko]) and model } + describe "when provided with the exact total_size specified in the model validations" do + subject { model.greater_than.attach([ blob_file_5ko, blob_file_2ko ]) and model } let(:error_options) do { - total_file_size: '7 KB', - min: '7 KB', + total_file_size: "7 KB", + min: "7 KB", max: nil } end @@ -146,8 +146,8 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with a higher total_size than the total_size specified in the model validations' do - subject { model.greater_than.attach([blob_file_5ko, blob_file_5ko]) and model } + describe "when provided with a higher total_size than the total_size specified in the model validations" do + subject { model.greater_than.attach([ blob_file_5ko, blob_file_5ko ]) and model } it { is_expected_to_be_valid } end @@ -155,18 +155,18 @@ end end - describe ':greater_than_or_equal_to' do + describe ":greater_than_or_equal_to" do # validates :greater_than_or_equal_to, total_size: { greater_than_or_equal_to: 7.kilobytes } # validates :greater_than_or_equal_to_proc, total_size: { greater_than_or_equal_to: -> (record) { 7.kilobytes } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower total_size than the total_size specified in the model validations' do - subject { model.greater_than_or_equal_to.attach([blob_file_1ko, blob_file_1ko]) and model } + describe "when provided with a lower total_size than the total_size specified in the model validations" do + subject { model.greater_than_or_equal_to.attach([ blob_file_1ko, blob_file_1ko ]) and model } let(:error_options) do { - total_file_size: '2 KB', - min: '7 KB', + total_file_size: "2 KB", + min: "7 KB", max: nil } end @@ -176,14 +176,14 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with the exact total_size specified in the model validations' do - subject { model.greater_than_or_equal_to.attach([blob_file_5ko, blob_file_2ko]) and model } + describe "when provided with the exact total_size specified in the model validations" do + subject { model.greater_than_or_equal_to.attach([ blob_file_5ko, blob_file_2ko ]) and model } it { is_expected_to_be_valid } end - describe 'when provided with a higher total_size than the total_size specified in the model validations' do - subject { model.greater_than_or_equal_to.attach([blob_file_5ko, blob_file_5ko]) and model } + describe "when provided with a higher total_size than the total_size specified in the model validations" do + subject { model.greater_than_or_equal_to.attach([ blob_file_5ko, blob_file_5ko ]) and model } it { is_expected_to_be_valid } end @@ -191,19 +191,19 @@ end end - describe ':between' do + describe ":between" do # validates :between, total_size: { between: 2.kilobytes..7.kilobytes } # validates :between_proc, total_size: { between: -> (record) { 2.kilobytes..7.kilobytes } } - %w(value proc).each do |value_type| + %w[value proc].each do |value_type| describe "#{value_type} validator" do - describe 'when provided with a lower total_size than the total_size specified in the model validations' do - subject { model.between.attach([blob_file_1ko, blob_file_0_5ko]) and model } + describe "when provided with a lower total_size than the total_size specified in the model validations" do + subject { model.between.attach([ blob_file_1ko, blob_file_0_5ko ]) and model } let(:error_options) do { - total_file_size: '1.5 KB', - min: '2 KB', - max: '7 KB' + total_file_size: "1.5 KB", + min: "2 KB", + max: "7 KB" } end @@ -212,32 +212,32 @@ it { is_expected_to_have_error_options(error_options) } end - describe 'when provided with the exact lower total_size specified in the model validations' do - subject { model.between.attach([blob_file_1ko, blob_file_1ko]) and model } + describe "when provided with the exact lower total_size specified in the model validations" do + subject { model.between.attach([ blob_file_1ko, blob_file_1ko ]) and model } it { is_expected_to_be_valid } end - describe 'when provided with a total_size between the total_sizes specified in the model validations' do - subject { model.between.attach([blob_file_2ko, blob_file_1ko]) and model } + describe "when provided with a total_size between the total_sizes specified in the model validations" do + subject { model.between.attach([ blob_file_2ko, blob_file_1ko ]) and model } it { is_expected_to_be_valid } end - describe 'when provided with the exact higher total_size specified in the model validations' do - subject { model.between.attach([blob_file_5ko, blob_file_2ko]) and model } + describe "when provided with the exact higher total_size specified in the model validations" do + subject { model.between.attach([ blob_file_5ko, blob_file_2ko ]) and model } it { is_expected_to_be_valid } end - describe 'when provided with a higher total_size than the total_size specified in the model validations' do - subject { model.between.attach([blob_file_5ko, blob_file_5ko]) and model } + describe "when provided with a higher total_size than the total_size specified in the model validations" do + subject { model.between.attach([ blob_file_5ko, blob_file_5ko ]) and model } let(:error_options) do { - total_file_size: '10 KB', - min: '2 KB', - max: '7 KB' + total_file_size: "10 KB", + min: "2 KB", + max: "7 KB" } end @@ -250,7 +250,7 @@ end end - describe 'Rails options' do + describe "Rails options" do include WorksWithAllRailsCommonValidationOptions end end