Created
January 20, 2009 16:40
-
-
Save ngty/49549 to your computer and use it in GitHub Desktop.
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
module DmSkinnySpec::Validations | |
module Common | |
class ExpectationArgs | |
attr_reader :attribute, :context | |
def initialize( attribute, options ) | |
@attribute = attribute | |
@context = options.delete(:when) || :default | |
@message = options.delete(:message) | |
end | |
protected | |
def default_message( type, *values ) | |
DataMapper::Validate::ValidationErrors::default_error_message( type, attribute, *values ) | |
end | |
def suggested_message | |
@message | |
end | |
end | |
end |
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
module DmSkinnySpec::Validations::ItShouldValidatePresent | |
class ExpectationArgs < DmSkinnySpec::Validations::Common::ExpectationArgs | |
def initialize( attribute, options ) | |
@type = options.delete(:type) || :String | |
super | |
end | |
def message | |
suggested_message || | |
case @type | |
when :Boolean ; default_message(:nil) | |
else ; default_message(:blank) | |
end | |
end | |
def bad_values | |
@values ||= | |
case @type | |
when :String ; [ nil, '' ] | |
else ; [ nil ] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment