Sha256: f45083710dcfba903919f2007f3f10881b534013d63003eab1c9f2cc1422ac8f

Contents?: true

Size: 1.96 KB

Versions: 15

Compression:

Stored size: 1.96 KB

Contents

require 'teststrap'
require 'whyvalidationssuckin96/attribute_based_validation'

context "attribute based validation mixin" do
  context "when mixed into a class" do
    
    setup do
      Class.new(WhyValidationsSuckIn96::Validation) do
        include WhyValidationsSuckIn96::SkippableValidation
        include WhyValidationsSuckIn96::AttributeBasedValidation
        
        def validate
          super
          pass
        end
        
      end # Class.new
    end   # setup
    
    should "fail if no attribute is specified during construction" do
      topic.new(Object.new)
    end.raises(ArgumentError, "The attribute to validate must be specified as :attribute")
    
    should "add an attribute accessor" do
      topic.new(Object.new, :attribute => :foo).attribute
    end.equals(:foo)
    
    context "when using :allow_nil" do
      
      should "skip validation if the validatable object is #nil?" do
        inst = topic.new(OpenStruct.new(:test => nil), :allow_nil => true, :attribute => :test)
        inst.validates?
        inst.has_run?
      end.equals(false)
      
      should "not skip validation of the validatable object is non-#nil?" do
        inst = topic.new(OpenStruct.new(:test => Object.new), :allow_nil => true, :attribute => :test)
        inst.validates?
        inst.has_run?
      end
    end # when using :allow_nil
    
    context "when using :allow_blank" do
      should "skip validation if the validatable object is #blank?" do
        inst = topic.new(OpenStruct.new(:test => ""), :allow_blank => true, :attribute => :test)
        inst.validates?
        inst.has_run?
      end.equals(false)
      
      should "not skip validation if the validatable object is non-#blank?" do
        inst = topic.new(OpenStruct.new(:test => "bzzt"), :allow_blank => true, :attribute => :test)
        inst.validates?
        inst.has_run?
      end
    end # when using :allow_blank
    
  end     # when mixed into a class
end       # skippable validation mixin

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
whyvalidationssuckin96-1.5.5 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.5.4 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.5.3 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.5.2 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.5.1 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.5.0 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.4.0 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.3.1 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.3.0 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.2.3 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.2.2 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.2.1 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.2.0 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.1.0 test/attribute_based_validation_test.rb
whyvalidationssuckin96-1.0.0 test/attribute_based_validation_test.rb