Sha256: be168a87d72c10ed8e613e44ebc1dd0929ef7c39344184c4c7378cf394090e0f

Contents?: true

Size: 1.87 KB

Versions: 6

Compression:

Stored size: 1.87 KB

Contents

require 'teststrap'

context "validates date" do

  should "add a validation macro" do
    WhyValidationsSuckIn96::ValidationBuilder.instance_methods
  end.includes('validates_as_date')

  context "with some default options" do
    setup do
      WhyValidationsSuckIn96::ValidatesDate.new(Object.new, :attribute => :start_date)
    end

    should "have a message accessor with a default message" do
      topic.message
    end.equals("does not match the given date format or is not a valid date")
  end # with some default options

  context "validating an object" do

    should "fail if given attribute does not match the regular expression" do
      validation = WhyValidationsSuckIn96::ValidatesDate.new(OpenStruct.new(:start_date => "13-22-1969"), :attribute => :start_date)
      validation.validates?
    end.equals(false)

    should "fail if given attribute is not a valid date" do
      validation = WhyValidationsSuckIn96::ValidatesDate.new(OpenStruct.new(:start_date => "02-31-1969"), :attribute => :start_date)
      validation.validates?
    end.equals(false)

    should "pass if given attribute matches the regular expression" do
      validation = WhyValidationsSuckIn96::ValidatesDate.new(OpenStruct.new(:start_date => "4-20-1969"), :attribute => :start_date)
      validation.validates?
    end

    should "have an accessor for the parsed date string" do
      validation = WhyValidationsSuckIn96::ValidatesDate.new(OpenStruct.new(:start_date => "4-20-1969"), :attribute => :start_date)
      validation.validates?
      validation.date
    end.equals(Date.civil(1969, 4, 20))

    should "#date returns nil if validation does not pass" do
      validation = WhyValidationsSuckIn96::ValidatesDate.new(OpenStruct.new(:start_date => "34-393"), :attribute => :start_date)
      validation.validates?
      validation.date
    end.not!
  end   # validating an object
end     # validates format

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
whyvalidationssuckin96-1.6.1 test/macros/validates_date_test.rb
whyvalidationssuckin96-1.6.0 test/macros/validates_date_test.rb
whyvalidationssuckin96-1.5.5 test/macros/validates_date_test.rb
whyvalidationssuckin96-1.5.4 test/macros/validates_date_test.rb
whyvalidationssuckin96-1.5.3 test/macros/validates_date_test.rb
whyvalidationssuckin96-1.5.2 test/macros/validates_date_test.rb