Sha256: 413ec2acb5ebb234e2229a9bce31704a4df7fcc396a3a8f3f993e169d1d43747

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

# -*- coding: utf-8 -*-
require "cases/helper"
require 'models/owner'
require 'models/pet'

class LengthValidationTest < ActiveRecord::TestCase
  fixtures :owners
  repair_validations(Owner)

  def test_validates_size_of_association
    repair_validations Owner do
      assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
      o = Owner.new('name' => 'nopets')
      assert !o.save
      assert o.errors[:pets].any?
      o.pets.build('name' => 'apet')
      assert o.valid?
    end
  end

  def test_validates_size_of_association_using_within
    repair_validations Owner do
      assert_nothing_raised { Owner.validates_size_of :pets, :within => 1..2 }
      o = Owner.new('name' => 'nopets')
      assert !o.save
      assert o.errors[:pets].any?

      o.pets.build('name' => 'apet')
      assert o.valid?

      2.times { o.pets.build('name' => 'apet') }
      assert !o.save
      assert o.errors[:pets].any?
    end
  end

  def test_validates_size_of_association_utf8
    repair_validations Owner do
      assert_nothing_raised { Owner.validates_size_of :pets, :minimum => 1 }
      o = Owner.new('name' => 'あいうえおかきくけこ')
      assert !o.save
      assert o.errors[:pets].any?
      o.pets.build('name' => 'あいうえおかきくけこ')
      assert o.valid?
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
ibm_db-3.0.4-x86-mingw32 test/cases/validations/length_validation_test.rb
ibm_db-3.0.4 test/cases/validations/length_validation_test.rb
ibm_db-3.0.3-x86-mingw32 test/cases/validations/length_validation_test.rb
ibm_db-3.0.3 test/cases/validations/length_validation_test.rb
ibm_db-3.0.2-x86-mingw32 test/cases/validations/length_validation_test.rb
ibm_db-3.0.2 test/cases/validations/length_validation_test.rb
activejob-lock-0.0.2 rails/activerecord/test/cases/validations/length_validation_test.rb
ibm_db-3.0.1 test/cases/validations/length_validation_test.rb
ibm_db-3.0.1-x86-mingw32 test/cases/validations/length_validation_test.rb
activejob-lock-0.0.1 rails/activerecord/test/cases/validations/length_validation_test.rb