test/unit/validation_base_test.rb in validatable-1.3.4 vs test/unit/validation_base_test.rb in validatable-1.4.0

- old
+ new

@@ -1,51 +1,62 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper') class ValidationBaseTest < Test::Unit::TestCase expect true do - validation = Validatable::ValidationBase.new :base + validation = Validatable::ValidationBase.new stub, :base validation.should_validate? Object.new end expect true do - validation = Validatable::ValidationBase.new :base, :times => 1 - validation.validate_this_time? + validation = Validatable::ValidationBase.new stub_everything, :base, :times => 1 + validation.validate_this_time?(stub(:times_validated => 0)) end expect true do - validation = Validatable::ValidationBase.new :base - validation.validate_this_time? + validation = Validatable::ValidationBase.new stub, :base + validation.validate_this_time?(nil) end expect true do - validation = Validatable::ValidationBase.new :base, :times => 2 - validation.validate_this_time? - validation.validate_this_time? + validation = Validatable::ValidationBase.new stub_everything, :base, :times => 2 + validation.validate_this_time?(stub(:times_validated => 1)) end + expect "Validatable::ValidationBase:base:key" do + validation = Validatable::ValidationBase.new stub_everything, :base, :times => 1, :key => "key" + validation.key + end + + expect "Validatable::ValidationBase:base:key" do + validation = Validatable::ValidationBase.new stub_everything, :base, :times => 1 + validation.key + end + expect false do - validation = Validatable::ValidationBase.new :base, :times => 1 - validation.validate_this_time? - validation.validate_this_time? + validation = Validatable::ValidationBase.new stub_everything, :base, :times => 1 + validation.validate_this_time?(stub(:times_validated => 1)) end expect 1 do - validation = Validatable::ValidationBase.new :base + validation = Validatable::ValidationBase.new stub_everything, :base validation.level end + expect ArgumentError do + Validatable::ValidationBase.new stub(:validation_keys_include? => true), :base, :times => 1 + end + expect "some message 100" do - validation = Validatable::ValidationBase.new :base, :message => lambda { "some message #{a_method}" } + validation = Validatable::ValidationBase.new stub, :base, :message => lambda { "some message #{a_method}" } validation.message(stub(:a_method=>'100')) end - test "invalid option causes raise" do - assert_raises ArgumentError do - Validatable::ValidationBase.new(:base).must_understand(:foo => 1, :bar => 2) - end + expect ArgumentError do + Validatable::ValidationBase.new(stub, :base).must_understand(:foo => 1, :bar => 2) end expect true do - Validatable::ValidationBase.new(:base).must_understand(:message => nil, :if => nil, :times => nil, :level => nil, :groups => nil) + options = {:message => nil, :if => nil, :times => nil, :level => nil, :groups => nil, :key => nil} + Validatable::ValidationBase.new(stub, :base).must_understand(options) end end \ No newline at end of file