Sha256: db831c4cc01d4810a09ec8323311d475a4dfa96291453b8638becc7f544e1900

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

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

class ValidatesTrueForTest < Test::Unit::TestCase
  test "when block returns false for attribute value, then valid is false" do
    validation = Validatable::ValidatesTrueFor.new :name, :logic => lambda { false }
    assert_equal false, validation.valid?(stub_everything)
  end
  
  test "when block returns true for attribute value, then valid is false" do
    validation = Validatable::ValidatesTrueFor.new :name, :logic => lambda { true }
    assert_equal true, validation.valid?(stub_everything)
  end
  
  test "when no logic is given, then an error is raised during construction" do
    assert_raises ArgumentError do
      validation = Validatable::ValidatesTrueFor.new :age
    end
  end
  
  expect true do
    options = [:message, :if, :times, :level, :groups, :logic]
    Validatable::ValidatesTrueFor.new(:name, options.to_blank_options_hash).must_understand(options.to_blank_options_hash)
  end
  
  expect true do
    options = [:logic]
    Validatable::ValidatesTrueFor.new(:name, options.to_blank_options_hash).requires(options.to_blank_options_hash)
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
validatable-1.3.2 test/unit/validates_true_for_test.rb
validatable-1.3.0 test/unit/validates_true_for_test.rb
validatable-1.3.4 test/unit/validates_true_for_test.rb