Skip to content

Instantly share code, notes, and snippets.

@vangberg
Created April 3, 2012 07:41
Show Gist options
  • Save vangberg/2290212 to your computer and use it in GitHub Desktop.
Save vangberg/2290212 to your computer and use it in GitHub Desktop.
validatorx
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