Sha256: f2d47bd4dfc350cd0236fccec72599bf057de1a39389b64d1d8d596a00338dbe

Contents?: true

Size: 1.62 KB

Versions: 21

Compression:

Stored size: 1.62 KB

Contents

require 'helper'

class TestValidations < Test::Unit::TestCase
  should "validate via ActiveRecord when the validates symbol is supplied" do
    Business.structure do
      website :string, :validates => :presence
    end

    business = Business.create
    assert(business.errors.include?(:website), "Validation was not applied")
  end

  should "validate via ActiveRecord when the full validation hash is supplied" do
    Category.structure do
      summary :string, :validates => { :format => { :with => /Symphony\d/ } }
    end

    bad_category = Category.create
    good_category = Category.create(:summary => "Symphony5")
    assert(bad_category.errors.include?(:summary), "Validation was not applied")
    assert(!good_category.errors.include?(:summary), "Validation options were incorrect")
  end

  should "validate via ActiveRecord when no field name is given" do
    User.structure do
      email :validates => :presence
    end

    user = User.create
    assert(user.errors.include?(:email), "Validation was not applied")
  end
  
  should "validate multiple validations via ActiveRecord when an array is given" do
    Review.structure do
      name "ABCD", :validates => [:presence, {:length => {:maximum => 4}}]
    end    
    
    not_present = Review.create
    too_long = Review.create(:name => "Textthatistoolong")
    correct = Review.create(:name => "ABC")
    
    assert(not_present.errors.include?(:name), "primary validation was not applied")
    assert(too_long.errors.include?(:name), "secondary validation was not applied")
    assert(!correct.errors.include?(:name), "validation for a correct model failed")
    
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
migrant-1.5.0 test/test_validations.rb
migrant-1.4.3 test/test_validations.rb
migrant-1.4.1 test/test_validations.rb
migrant-1.4.0 test/test_validations.rb
migrant-1.3.2 test/test_validations.rb
migrant-1.3.1 test/test_validations.rb
migrant-1.3.0 test/test_validations.rb
migrant-1.2.8 test/test_validations.rb
migrant-1.2.7 test/test_validations.rb
migrant-1.2.5 test/test_validations.rb
migrant-1.2.2 test/test_validations.rb
migrant-1.2.1 test/test_validations.rb
migrant-1.2.0 test/test_validations.rb
migrant-1.1.2 test/test_validations.rb
migrant-1.1.1 test/test_validations.rb
migrant-1.1.0 test/test_validations.rb
migrant-1.0.2 test/test_validations.rb
migrant-1.0.1 test/test_validations.rb
migrant-1.0.0 test/test_validations.rb
migrant-0.2.4 test/test_validations.rb