diff --git a/test/dummy/app/models/aspect_ratio/validator.rb b/test/dummy/app/models/aspect_ratio/validator.rb index b59cb555..11fe4b87 100644 --- a/test/dummy/app/models/aspect_ratio/validator.rb +++ b/test/dummy/app/models/aspect_ratio/validator.rb @@ -1,15 +1,7 @@ -# frozen_string_literal: true - -# == Schema Information -# -# Table name: aspect_ratio_validators -# -# id :integer not null, primary key -# created_at :datetime not null -# updated_at :datetime not null -# - -class AspectRatio::Validator < ApplicationRecord - has_one_attached :with_context - validates :with_context, aspect_ratio: :square, on: %i(create update destroy custom) +module AspectRatio + module Validator + def self.table_name_prefix + 'aspect_ratio_validator_' + end + end 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 new file mode 100644 index 00000000..813952ca --- /dev/null +++ b/test/dummy/app/models/aspect_ratio/validator/with_if.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: aspect_ratio_validator_with_ifs +# +# title :string +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class AspectRatio::Validator::WithIf < ApplicationRecord + has_one_attached :with_if + validates :with_if, aspect_ratio: :square, if: -> { self.title == 'Right title' } +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 new file mode 100644 index 00000000..9d834628 --- /dev/null +++ b/test/dummy/app/models/aspect_ratio/validator/with_on.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: aspect_ratio_validator_with_ons +# +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class AspectRatio::Validator::WithOn < ApplicationRecord + has_one_attached :with_on + validates :with_on, aspect_ratio: :square, on: %i(create update destroy custom) +end diff --git a/test/dummy/app/models/attached/validator.rb b/test/dummy/app/models/attached/validator.rb index 7e0daca4..844e6593 100644 --- a/test/dummy/app/models/attached/validator.rb +++ b/test/dummy/app/models/attached/validator.rb @@ -1,15 +1,7 @@ -# frozen_string_literal: true - -# == Schema Information -# -# Table name: attached_validators -# -# id :integer not null, primary key -# created_at :datetime not null -# updated_at :datetime not null -# - -class Attached::Validator < ApplicationRecord - has_one_attached :with_context - validates :with_context, attached: true, on: %i(create update destroy custom) +module Attached + module Validator + def self.table_name_prefix + '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 new file mode 100644 index 00000000..b027cf6c --- /dev/null +++ b/test/dummy/app/models/attached/validator/with_if.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: attached_validator_with_ifs +# +# title :string +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class Attached::Validator::WithIf < ApplicationRecord + has_one_attached :with_if + validates :with_if, attached: true, if: -> { self.title == 'Right title' } +end diff --git a/test/dummy/app/models/attached/validator/with_on.rb b/test/dummy/app/models/attached/validator/with_on.rb new file mode 100644 index 00000000..fa0ed858 --- /dev/null +++ b/test/dummy/app/models/attached/validator/with_on.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: attached_validator_with_ons +# +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class Attached::Validator::WithOn < ApplicationRecord + has_one_attached :with_on + validates :with_on, attached: true, on: %i(create update destroy custom) +end diff --git a/test/dummy/app/models/content_type/validator.rb b/test/dummy/app/models/content_type/validator.rb index d2b49dc5..ac2a2afe 100644 --- a/test/dummy/app/models/content_type/validator.rb +++ b/test/dummy/app/models/content_type/validator.rb @@ -1,15 +1,7 @@ -# frozen_string_literal: true - -# == Schema Information -# -# Table name: content_type_validators -# -# id :integer not null, primary key -# created_at :datetime not null -# updated_at :datetime not null -# - -class ContentType::Validator < ApplicationRecord - has_one_attached :with_context - validates :with_context, content_type: :webp, on: %i(create update destroy custom) +module ContentType + module Validator + def self.table_name_prefix + 'content_type_validator_' + end + end 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 new file mode 100644 index 00000000..06ec316c --- /dev/null +++ b/test/dummy/app/models/content_type/validator/with_if.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: content_type_validator_with_ifs +# +# title :string +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class ContentType::Validator::WithIf < ApplicationRecord + has_one_attached :with_if + validates :with_if, content_type: :webp, if: -> { self.title == 'Right title' } +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 new file mode 100644 index 00000000..f54f6f20 --- /dev/null +++ b/test/dummy/app/models/content_type/validator/with_on.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: content_type_validator_with_on +# +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class ContentType::Validator::WithOn < ApplicationRecord + has_one_attached :with_on + validates :with_on, content_type: :webp, on: %i(create update destroy custom) +end diff --git a/test/dummy/app/models/dimension/validator.rb b/test/dummy/app/models/dimension/validator.rb index 8428619b..83a91a34 100644 --- a/test/dummy/app/models/dimension/validator.rb +++ b/test/dummy/app/models/dimension/validator.rb @@ -1,15 +1,7 @@ -# frozen_string_literal: true - -# == Schema Information -# -# Table name: dimension_validators -# -# id :integer not null, primary key -# created_at :datetime not null -# updated_at :datetime not null -# - -class Dimension::Validator < ApplicationRecord - has_one_attached :with_context - validates :with_context, dimension: { width: 150, height: 150 }, on: %i(create update destroy custom) +module Dimension + module Validator + def self.table_name_prefix + 'dimension_validator_' + end + end end diff --git a/test/dummy/app/models/dimension/validator/with_if.rb b/test/dummy/app/models/dimension/validator/with_if.rb new file mode 100644 index 00000000..0937a48f --- /dev/null +++ b/test/dummy/app/models/dimension/validator/with_if.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: dimension_validator_with_ifs +# +# title :string +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class Dimension::Validator::WithIf < ApplicationRecord + has_one_attached :with_if + validates :with_if, dimension: { width: 150, height: 150 }, if: -> { self.title == 'Right title' } +end diff --git a/test/dummy/app/models/dimension/validator/with_on.rb b/test/dummy/app/models/dimension/validator/with_on.rb new file mode 100644 index 00000000..ede1810a --- /dev/null +++ b/test/dummy/app/models/dimension/validator/with_on.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: dimension_validator_with_ons +# +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class Dimension::Validator::WithOn < ApplicationRecord + has_one_attached :with_on + validates :with_on, dimension: { width: 150, height: 150 }, on: %i(create update destroy custom) +end diff --git a/test/dummy/app/models/limit/validator.rb b/test/dummy/app/models/limit/validator.rb index 00516af5..aad44aaf 100644 --- a/test/dummy/app/models/limit/validator.rb +++ b/test/dummy/app/models/limit/validator.rb @@ -1,15 +1,7 @@ -# frozen_string_literal: true - -# == Schema Information -# -# Table name: limit_validators -# -# id :integer not null, primary key -# created_at :datetime not null -# updated_at :datetime not null -# - -class Limit::Validator < ApplicationRecord - has_one_attached :with_context - validates :with_context, limit: { min: 1 }, on: %i(create update destroy custom) +module Limit + module Validator + def self.table_name_prefix + 'limit_validator_' + end + end end diff --git a/test/dummy/app/models/limit/validator/with_if.rb b/test/dummy/app/models/limit/validator/with_if.rb new file mode 100644 index 00000000..6700a0eb --- /dev/null +++ b/test/dummy/app/models/limit/validator/with_if.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: limit_validator_with_ifs +# +# title :string +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class Limit::Validator::WithIf < ApplicationRecord + has_one_attached :with_if + validates :with_if, limit: { min: 1 }, if: -> { self.title == 'Right title' } +end diff --git a/test/dummy/app/models/limit/validator/with_on.rb b/test/dummy/app/models/limit/validator/with_on.rb new file mode 100644 index 00000000..f8e266af --- /dev/null +++ b/test/dummy/app/models/limit/validator/with_on.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: limit_validator_with_ons +# +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class Limit::Validator::WithOn < ApplicationRecord + has_one_attached :with_on + validates :with_on, limit: { min: 1 }, on: %i(create update destroy custom) +end diff --git a/test/dummy/app/models/processable_image/validator.rb b/test/dummy/app/models/processable_image/validator.rb index 7d15af6e..e5b75217 100644 --- a/test/dummy/app/models/processable_image/validator.rb +++ b/test/dummy/app/models/processable_image/validator.rb @@ -1,15 +1,7 @@ -# frozen_string_literal: true - -# == Schema Information -# -# Table name: processable_image_validators -# -# id :integer not null, primary key -# created_at :datetime not null -# updated_at :datetime not null -# - -class ProcessableImage::Validator < ApplicationRecord - has_one_attached :with_context - validates :with_context, processable_image: true, on: %i(create update destroy custom) +module ProcessableImage + module Validator + def self.table_name_prefix + 'processable_image_validator_' + end + end end diff --git a/test/dummy/app/models/processable_image/validator/with_if.rb b/test/dummy/app/models/processable_image/validator/with_if.rb new file mode 100644 index 00000000..45aaa11a --- /dev/null +++ b/test/dummy/app/models/processable_image/validator/with_if.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: processable_image_validator_with_ifs +# +# title :string +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class ProcessableImage::Validator::WithIf < ApplicationRecord + has_one_attached :with_if + validates :with_if, processable_image: true, if: -> { self.title == 'Right title' } +end diff --git a/test/dummy/app/models/processable_image/validator/with_on.rb b/test/dummy/app/models/processable_image/validator/with_on.rb new file mode 100644 index 00000000..61e89839 --- /dev/null +++ b/test/dummy/app/models/processable_image/validator/with_on.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: processable_image_validator_with_ons +# +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class ProcessableImage::Validator::WithOn < ApplicationRecord + has_one_attached :with_on + validates :with_on, processable_image: true, on: %i(create update destroy custom) +end diff --git a/test/dummy/app/models/size/validator.rb b/test/dummy/app/models/size/validator.rb index ff69a2bb..04795006 100644 --- a/test/dummy/app/models/size/validator.rb +++ b/test/dummy/app/models/size/validator.rb @@ -1,15 +1,7 @@ -# frozen_string_literal: true - -# == Schema Information -# -# Table name: size_validators -# -# id :integer not null, primary key -# created_at :datetime not null -# updated_at :datetime not null -# - -class Size::Validator < ApplicationRecord - has_one_attached :with_context - validates :with_context, size: { less_than: 2.kilobytes }, on: %i(create update destroy custom) +module Size + module Validator + def self.table_name_prefix + 'size_validator_' + end + end end diff --git a/test/dummy/app/models/size/validator/with_if.rb b/test/dummy/app/models/size/validator/with_if.rb new file mode 100644 index 00000000..4b923218 --- /dev/null +++ b/test/dummy/app/models/size/validator/with_if.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: size_validator_with_ifs +# +# title :string +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class Size::Validator::WithIf < ApplicationRecord + has_one_attached :with_if + validates :with_if, size: { less_than: 2.kilobytes }, if: -> { self.title == 'Right title' } +end diff --git a/test/dummy/app/models/size/validator/with_on.rb b/test/dummy/app/models/size/validator/with_on.rb new file mode 100644 index 00000000..8094d037 --- /dev/null +++ b/test/dummy/app/models/size/validator/with_on.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: size_validator_with_ons +# +# id :integer not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# + +class Size::Validator::WithOn < ApplicationRecord + has_one_attached :with_on + validates :with_on, size: { less_than: 2.kilobytes }, on: %i(create update destroy custom) +end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 5b5e4699..084b1d02 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -34,7 +34,13 @@ end end - create_table :aspect_ratio_validators, force: :cascade do |t| + create_table :aspect_ratio_validator_with_ons, force: :cascade do |t| + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + end + + create_table :aspect_ratio_validator_with_ifs, force: :cascade do |t| + t.string :title t.datetime :created_at, null: false t.datetime :updated_at, null: false end @@ -44,7 +50,13 @@ t.datetime :updated_at, null: false end - create_table :attached_validators, force: :cascade do |t| + create_table :attached_validator_with_ons, force: :cascade do |t| + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + end + + create_table :attached_validator_with_ifs, force: :cascade do |t| + t.string :title t.datetime :created_at, null: false t.datetime :updated_at, null: false end @@ -54,7 +66,13 @@ t.datetime :updated_at, null: false end - create_table :content_type_validators, force: :cascade do |t| + create_table :content_type_validator_with_ons, force: :cascade do |t| + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + end + + create_table :content_type_validator_with_ifs, force: :cascade do |t| + t.string :title t.datetime :created_at, null: false t.datetime :updated_at, null: false end @@ -64,7 +82,13 @@ t.datetime :updated_at, null: false end - create_table :dimension_validators, force: :cascade do |t| + create_table :dimension_validator_with_ons, force: :cascade do |t| + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + end + + create_table :dimension_validator_with_ifs, force: :cascade do |t| + t.string :title t.datetime :created_at, null: false t.datetime :updated_at, null: false end @@ -83,7 +107,13 @@ t.string :name end - create_table :limit_validators, force: :cascade do |t| + create_table :limit_validator_with_ons, force: :cascade do |t| + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + end + + create_table :limit_validator_with_ifs, force: :cascade do |t| + t.string :title t.datetime :created_at, null: false t.datetime :updated_at, null: false end @@ -93,7 +123,13 @@ t.datetime :updated_at, precision: 6, null: false end - create_table :processable_image_validators, force: :cascade do |t| + create_table :processable_image_validator_with_ons, force: :cascade do |t| + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + end + + create_table :processable_image_validator_with_ifs, force: :cascade do |t| + t.string :title t.datetime :created_at, null: false t.datetime :updated_at, null: false end @@ -133,7 +169,13 @@ t.datetime :updated_at, null: false end - create_table :size_validators, force: :cascade do |t| + create_table :size_validator_with_ons, force: :cascade do |t| + t.datetime :created_at, null: false + t.datetime :updated_at, null: false + end + + create_table :size_validator_with_ifs, force: :cascade do |t| + t.string :title t.datetime :created_at, null: false t.datetime :updated_at, null: false end diff --git a/test/validators/aspect_ratio_validator_test.rb b/test/validators/aspect_ratio_validator_test.rb index 296b91b0..bc91cf20 100644 --- a/test/validators/aspect_ratio_validator_test.rb +++ b/test/validators/aspect_ratio_validator_test.rb @@ -1,17 +1,24 @@ # frozen_string_literal: true require 'test_helper' +require 'validators/shared_examples/works_with_if_option' require 'validators/shared_examples/works_with_on_option' describe ActiveStorageValidations::AspectRatioValidator do include ValidatorHelpers - subject { AspectRatio::Validator.new(params) } - let(:params) { {} } describe 'Rails options' do + describe '#if' do + subject { AspectRatio::Validator::WithIf.new(params) } + + include WorksWithIfOption + end + describe '#on' do + subject { AspectRatio::Validator::WithOn.new(params) } + include WorksWithOnOption end end diff --git a/test/validators/attached_validator_test.rb b/test/validators/attached_validator_test.rb index 48751f5d..48af7531 100644 --- a/test/validators/attached_validator_test.rb +++ b/test/validators/attached_validator_test.rb @@ -1,17 +1,24 @@ # frozen_string_literal: true require 'test_helper' +require 'validators/shared_examples/works_with_if_option' require 'validators/shared_examples/works_with_on_option' describe ActiveStorageValidations::AttachedValidator do include ValidatorHelpers - subject { Attached::Validator.new(params) } - let(:params) { {} } describe 'Rails options' do + describe '#if' do + subject { Attached::Validator::WithIf.new(params) } + + include WorksWithIfOption + end + describe '#on' do + subject { Attached::Validator::WithOn.new(params) } + include WorksWithOnOption end end diff --git a/test/validators/content_type_validator_test.rb b/test/validators/content_type_validator_test.rb index 9e1401dd..7eb673af 100644 --- a/test/validators/content_type_validator_test.rb +++ b/test/validators/content_type_validator_test.rb @@ -1,17 +1,24 @@ # frozen_string_literal: true require 'test_helper' +require 'validators/shared_examples/works_with_if_option' require 'validators/shared_examples/works_with_on_option' describe ActiveStorageValidations::ContentTypeValidator do include ValidatorHelpers - subject { ContentType::Validator.new(params) } - let(:params) { {} } describe 'Rails options' do + describe '#if' do + subject { ContentType::Validator::WithIf.new(params) } + + include WorksWithIfOption + end + describe '#on' do + subject { ContentType::Validator::WithOn.new(params) } + include WorksWithOnOption end end diff --git a/test/validators/dimension_validator_test.rb b/test/validators/dimension_validator_test.rb index 9cd3044a..ec24edc4 100644 --- a/test/validators/dimension_validator_test.rb +++ b/test/validators/dimension_validator_test.rb @@ -1,17 +1,24 @@ # frozen_string_literal: true require 'test_helper' +require 'validators/shared_examples/works_with_if_option' require 'validators/shared_examples/works_with_on_option' describe ActiveStorageValidations::DimensionValidator do include ValidatorHelpers - subject { Dimension::Validator.new(params) } - let(:params) { {} } describe 'Rails options' do + describe '#if' do + subject { Dimension::Validator::WithIf.new(params) } + + include WorksWithIfOption + end + describe '#on' do + subject { Dimension::Validator::WithOn.new(params) } + include WorksWithOnOption end end diff --git a/test/validators/limit_validator_test.rb b/test/validators/limit_validator_test.rb index 90027158..24374a37 100644 --- a/test/validators/limit_validator_test.rb +++ b/test/validators/limit_validator_test.rb @@ -1,17 +1,24 @@ # frozen_string_literal: true require 'test_helper' +require 'validators/shared_examples/works_with_if_option' require 'validators/shared_examples/works_with_on_option' describe ActiveStorageValidations::LimitValidator do include ValidatorHelpers - subject { Limit::Validator.new(params) } - let(:params) { {} } describe 'Rails options' do + describe '#if' do + subject { Limit::Validator::WithIf.new(params) } + + include WorksWithIfOption + end + describe '#on' do + subject { Limit::Validator::WithOn.new(params) } + include WorksWithOnOption end end diff --git a/test/validators/processable_image_validator_test.rb b/test/validators/processable_image_validator_test.rb index 1dbbbe2b..d1b92d29 100644 --- a/test/validators/processable_image_validator_test.rb +++ b/test/validators/processable_image_validator_test.rb @@ -1,17 +1,24 @@ # frozen_string_literal: true require 'test_helper' +require 'validators/shared_examples/works_with_if_option' require 'validators/shared_examples/works_with_on_option' describe ActiveStorageValidations::ProcessableImageValidator do include ValidatorHelpers - subject { ProcessableImage::Validator.new(params) } - let(:params) { {} } describe 'Rails options' do + describe '#if' do + subject { ProcessableImage::Validator::WithIf.new(params) } + + include WorksWithIfOption + end + describe '#on' do + subject { ProcessableImage::Validator::WithOn.new(params) } + include WorksWithOnOption end end diff --git a/test/validators/shared_examples/works_with_if_option.rb b/test/validators/shared_examples/works_with_if_option.rb new file mode 100644 index 00000000..5e45717d --- /dev/null +++ b/test/validators/shared_examples/works_with_if_option.rb @@ -0,0 +1,44 @@ +module WorksWithIfOption + extend ActiveSupport::Concern + + included do + let(:file_matching_requirements) do + case validator_sym + when :aspect_ratio then image_150x150_file + when :attached then image_150x150_file + when :content_type then webp_file + when :dimension then image_150x150_file + when :limit then image_150x150_file + when :processable_image then image_150x150_file + when :size then file_1ko + end + end + let(:file_not_matching_requirements) do + case validator_sym + when :aspect_ratio then image_700x500_file + when :attached then nil + when :content_type then html_file + when :dimension then image_700x500_file + when :limit then nil + when :processable_image then tar_file_with_image_content_type + when :size then file_5ko + end + end + + describe 'when the :if condition is met' do + let(:params) { { title: 'Right title' } } + + 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 + before { subject.with_if.attach(file_not_matching_requirements) } + + it { is_expected_not_to_be_valid } + end + end + end +end diff --git a/test/validators/shared_examples/works_with_on_option.rb b/test/validators/shared_examples/works_with_on_option.rb index b7f402b7..fe0e7079 100644 --- a/test/validators/shared_examples/works_with_on_option.rb +++ b/test/validators/shared_examples/works_with_on_option.rb @@ -28,13 +28,13 @@ module WorksWithOnOption %i(create update destroy custom).each do |context| describe ":#{context}" do describe 'when passed a file matching the requirements' do - before { subject.with_context.attach(file_matching_requirements) } + 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 - before { subject.with_context.attach(file_not_matching_requirements) } + before { subject.with_on.attach(file_not_matching_requirements) } it { is_expected_not_to_be_valid(context: context) } end diff --git a/test/validators/size_validator_test.rb b/test/validators/size_validator_test.rb index 2a1a0ed1..ef422711 100644 --- a/test/validators/size_validator_test.rb +++ b/test/validators/size_validator_test.rb @@ -1,17 +1,24 @@ # frozen_string_literal: true require 'test_helper' +require 'validators/shared_examples/works_with_if_option' require 'validators/shared_examples/works_with_on_option' describe ActiveStorageValidations::SizeValidator do include ValidatorHelpers - subject { Size::Validator.new(params) } - let(:params) { {} } describe 'Rails options' do + describe '#if' do + subject { Size::Validator::WithIf.new(params) } + + include WorksWithIfOption + end + describe '#on' do + subject { Size::Validator::WithOn.new(params) } + include WorksWithOnOption end end diff --git a/test/validators/support/validator_helpers.rb b/test/validators/support/validator_helpers.rb index 4a3624c0..0f04f939 100644 --- a/test/validators/support/validator_helpers.rb +++ b/test/validators/support/validator_helpers.rb @@ -7,7 +7,11 @@ def is_expected_not_to_be_valid(**kwargs) subject && refute(subject.valid?(kwargs[:context])) end + def validator_class + "ActiveStorageValidations::#{subject.class.name.sub(/::/, '').sub(/::.+/, '')}".constantize + end + def validator_sym - "ActiveStorageValidations::#{subject.class.name.sub(/::/, '')}".constantize.to_sym + validator_class.to_sym end end