From c41ec119e9d02c70627eb90605135ddb3d5c6149 Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Thu, 20 Nov 2014 14:06:08 -0700 Subject: [PATCH] Remove unnecessary file --- .../validate_length_of_matcher_spec.rb | 186 ------------------ 1 file changed, 186 deletions(-) delete mode 100644 spec/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb diff --git a/spec/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb b/spec/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb deleted file mode 100644 index 348a621c..00000000 --- a/spec/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +++ /dev/null @@ -1,186 +0,0 @@ -require 'unit_spec_helper' - -describe Shoulda::Matchers::ActiveModel do - describe '#ensure_length_of' do - it 'is aliased to #validate_length_of' do - allow(matchers).to receive(:validate_length_of) - - silence_warnings do - matchers.ensure_length_of(:attr) - expect(matchers).to have_received(:validate_length_of).with(:attr) - end - end - end - - def matchers - @_matchers ||= Object.new.extend(described_class) - end -end - -describe Shoulda::Matchers::ActiveModel::ValidateLengthOfMatcher do - context 'an attribute with a non-zero minimum length validation' do - it 'accepts ensuring the correct minimum length' do - expect(validating_length(minimum: 4)). - to validate_length_of(:attr).is_at_least(4) - end - - it 'rejects ensuring a lower minimum length with any message' do - expect(validating_length(minimum: 4)). - not_to validate_length_of(:attr).is_at_least(3).with_short_message(/.*/) - end - - it 'rejects ensuring a higher minimum length with any message' do - expect(validating_length(minimum: 4)). - not_to validate_length_of(:attr).is_at_least(5).with_short_message(/.*/) - end - - it 'does not override the default message with a blank' do - expect(validating_length(minimum: 4)). - to validate_length_of(:attr).is_at_least(4).with_short_message(nil) - end - end - - context 'an attribute with a minimum length validation of 0' do - it 'accepts ensuring the correct minimum length' do - expect(validating_length(minimum: 0)). - to validate_length_of(:attr).is_at_least(0) - end - end - - context 'an attribute with a maximum length' do - it 'accepts ensuring the correct maximum length' do - expect(validating_length(maximum: 4)). - to validate_length_of(:attr).is_at_most(4) - end - - it 'rejects ensuring a lower maximum length with any message' do - expect(validating_length(maximum: 4)). - not_to validate_length_of(:attr).is_at_most(3).with_long_message(/.*/) - end - - it 'rejects ensuring a higher maximum length with any message' do - expect(validating_length(maximum: 4)). - not_to validate_length_of(:attr).is_at_most(5).with_long_message(/.*/) - end - - it 'does not override the default message with a blank' do - expect(validating_length(maximum: 4)). - to validate_length_of(:attr).is_at_most(4).with_long_message(nil) - end - end - - context 'an attribute with a required exact length' do - it 'accepts ensuring the correct length' do - expect(validating_length(is: 4)). - to validate_length_of(:attr).is_equal_to(4) - end - - it 'rejects ensuring a lower maximum length with any message' do - expect(validating_length(is: 4)). - not_to validate_length_of(:attr).is_equal_to(3).with_message(/.*/) - end - - it 'rejects ensuring a higher maximum length with any message' do - expect(validating_length(is: 4)). - not_to validate_length_of(:attr).is_equal_to(5).with_message(/.*/) - end - - it 'does not override the default message with a blank' do - expect(validating_length(is: 4)). - to validate_length_of(:attr).is_equal_to(4).with_message(nil) - end - end - - context 'an attribute with a required exact length and another validation' do - it 'accepts ensuring the correct length' do - model = define_model(:example, attr: :string) do - validates_length_of :attr, is: 4 - validates_numericality_of :attr - end.new - - expect(model).to validate_length_of(:attr).is_equal_to(4) - end - end - - context 'an attribute with a custom minimum length validation' do - it 'accepts ensuring the correct minimum length' do - expect(validating_length(minimum: 4, too_short: 'foobar')). - to validate_length_of(:attr).is_at_least(4).with_short_message(/foo/) - end - end - - context 'an attribute with a custom maximum length validation' do - it 'accepts ensuring the correct minimum length' do - expect(validating_length(maximum: 4, too_long: 'foobar')). - to validate_length_of(:attr).is_at_most(4).with_long_message(/foo/) - end - end - - context 'an attribute with a custom equal validation' do - it 'accepts ensuring the correct exact length' do - expect(validating_length(is: 4, message: 'foobar')). - to validate_length_of(:attr).is_equal_to(4).with_message(/foo/) - end - end - - context 'an attribute without a length validation' do - it 'rejects ensuring a minimum length' do - expect(define_model(:example, attr: :string).new). - not_to validate_length_of(:attr).is_at_least(1) - end - end - - context 'using translations' do - after { I18n.backend.reload! } - - context "a too_long translation containing %{attribute}, %{model}" do - before do - stub_translation( - "activerecord.errors.messages.too_long", - "The %{attribute} of your %{model} is too long (maximum is %{count} characters)") - end - - it "does not raise an exception" do - expect { - expect(validating_length(maximum: 4)). - to validate_length_of(:attr).is_at_most(4) - }.to_not raise_exception - end - end - - context "a too_short translation containing %{attribute}, %{model}" do - before do - stub_translation( - "activerecord.errors.messages.too_short", - "The %{attribute} of your %{model} is too short (minimum is %{count} characters)") - end - - it "does not raise an exception" do - expect { - expect(validating_length(minimum: 4)).to validate_length_of(:attr).is_at_least(4) - }.to_not raise_exception - end - end - - context "a wrong_length translation containing %{attribute}, %{model}" do - before do - stub_translation( - "activerecord.errors.messages.wrong_length", - "The %{attribute} of your %{model} is the wrong length (should be %{count} characters)") - end - - it "does not raise an exception" do - expect { - expect(validating_length(is: 4)). - to validate_length_of(:attr).is_equal_to(4) - }.to_not raise_exception - end - end - end - - def validating_length(options = {}) - define_model(:example, attr: :string) do - validates_length_of :attr, options - end.new - end -end