Skip to content

Instantly share code, notes, and snippets.

@ngty
Created January 20, 2009 16:40
Show Gist options
  • Save ngty/49549 to your computer and use it in GitHub Desktop.
Save ngty/49549 to your computer and use it in GitHub Desktop.
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
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