# frozen_string_literal: true

RSpec.shared_examples "works with allow_blank" do
  let(:model_attribute) { :allow_blank }

  context "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 :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)
      when :total_size then matcher.less_than_or_equal_to(5.megabytes)
      when :pages then matcher.equal_to(5)
      end
    end

    context "and when provided with #allow_blank method" do
      subject(:configured_matcher) { matcher.allow_blank }

      it { is_expected_to_match_for(klass) }
    end

    context "and when not provided with #allow_blank method" do
      subject(:configured_matcher) { matcher }

      it { is_expected_to_match_for(klass) }
    end
  end
end
