Sha256: 3069b026b9d13207733cb4fcd0ab4a976e297d2d182271fda929e2666e498c1e

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'test_helper'

class ValidationTests < ActiveSupport::TestCase

  # Make sure we can set things independently
  test 'ensure we can set valid_from without valid_until' do

    assert( User.new( valid_from: Date.today ).valid? )

  end

  test 'ensure we can set valid_until without valid_from' do

    assert( User.new( valid_until: Date.today ).valid? )

  end

  # Now check the both
  test 'ensure we can set valid_until and valid_from, as long as they’re chronologically sensible' do

    assert( User.new( valid_from: ( Date.today - 1.day ), valid_until: Date.today ).valid? )

  end

  test 'ensure we can set valid_until and valid_from for the same day' do

    assert( User.new( valid_from: Date.today, valid_until: Date.today ).valid? )

  end

  test 'ensure we cannot set valid_until to a point before valid_until' do

    assert_not( User.new( valid_from: Date.today, valid_until: ( Date.today - 1.day )).valid? )

  end

  # Check messaging while we’re here
  test 'ensure the validation message looks sane' do

    user = User.new( valid_from: Date.today, valid_until: ( Date.today - 1.day ))
    user.validate

    assert_equal( user.errors.messages[:valid_until].first, 'Cannot be before Valid from' )

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
devise_date_restrictable-1.0.0 test/tests/validation_tests.rb