Sha256: f0dfa146eaf9225cddafd5653d0d998803d2fd46080658b4faa1ccaea211de4c

Contents?: true

Size: 1.19 KB

Versions: 24

Compression:

Stored size: 1.19 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../test_helper')

module Functional
  class ValidatesAssociatedTest < Test::Unit::TestCase
    def setup
      @parent = Class.new do
        include Validatable
        attr_accessor :children
        validates_associated :children
      end
      @child = Class.new do
        include Validatable
        attr_accessor :name
        validates_presence_of :name
      end
    end

    test "given invalid child, when validated, then error is in the parent's error collection" do
      instance = @parent.new
      instance.children = [@child.new]
      instance.valid?
      assert_equal "is invalid", instance.errors.on(:children)
    end

    test "given two invalid children, when validated, then both children have errors" do
      instance = @parent.new
      instance.children = [@child.new, @child.new]
      instance.valid?
      instance.children.each do |child|
        assert_not_nil child.errors.on(:name)
      end
    end

    test "given valid child, when validated, the parent is valid" do
      instance = @parent.new
      instance.children = [@child.new]
      instance.children.first.name = 'x'
      assert instance.valid?
    end
  end
end

Version data entries

24 entries across 24 versions & 7 rubygems

Version Path
hashrocket-validatable-1.7.4 test/functional/test_validates_associated.rb
lgustafson-validatable-1.8.7 test/functional/test_validates_associated.rb
lgustafson-validatable-1.8.6 test/functional/test_validates_associated.rb
np422-validatable-1.8.5 test/functional/test_validates_associated.rb
erotte-validatable-1.8.5 test/functional/test_validates_associated.rb
mattmatt-validatable-1.8.4 test/functional/test_validates_associated.rb
mattmatt-validatable-1.8.3 test/functional/test_validates_associated.rb
jnunemaker-validatable-1.8.4 test/functional/test_validates_associated.rb
jnunemaker-validatable-1.8.3 test/functional/test_validates_associated.rb
jnunemaker-validatable-1.8.2 test/functional/test_validates_associated.rb
jnunemaker-validatable-1.1.10 test/functional/test_validates_associated.rb
jnunemaker-validatable-1.1.9 test/functional/test_validates_associated.rb
durran-validatable-2.0.1 test/functional/test_validates_associated.rb
durran-validatable-2.0.0 test/functional/test_validates_associated.rb
durran-validatable-1.8.4 test/functional/test_validates_associated.rb
durran-validatable-1.8.3 test/functional/test_validates_associated.rb
jnunemaker-validatable-1.8.1 test/functional/test_validates_associated.rb
durran-validatable-1.8.2 test/functional/test_validates_associated.rb
durran-validatable-1.8.1 test/functional/test_validates_associated.rb
durran-validatable-1.8.0 test/functional/test_validates_associated.rb