Created
April 3, 2012 07:41
-
-
Save vangberg/2290212 to your computer and use it in GitHub Desktop.
validatorx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "ostruct" | |
require "active_support/deprecation" | |
require "active_model/validator" | |
require "active_model/validations" | |
require "active_model/naming" | |
require "active_model/translation" | |
class Validatorz < OpenStruct | |
include ActiveModel::Validations | |
end | |
module Shared | |
def validates_person | |
validates_presence_of :name | |
end | |
end | |
class Create < Validatorz | |
extend Shared | |
validates_person | |
end | |
require "test/unit" | |
class TestValidators < Test::Unit::TestCase | |
def test_validates_presence_of_name | |
validator = Create.new(name: "foo") | |
assert_equal true, validator.valid? | |
assert_equal 0, validator.errors.messages.length | |
end | |
def test_fails_validates_presence_of_name | |
validator = Create.new | |
assert_equal false, validator.valid? | |
assert_equal 1, validator.errors.messages.length | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment