Created
August 2, 2008 19:47
-
-
Save teamon/3766 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# auto_validate.rb | |
require "dm-types" # not sure of that... | |
if property.type.ancestors.include?(Types::Enum) | |
validates_within property.name, options_with_message({:set => property.type.flag_map.values}, property, :within) | |
end | |
# auto -validate_spec | |
describe 'for Enum properties' do | |
require 'dm-types' # not sure if it is ok to require dm-types here | |
before :all do | |
class ColorBoat | |
include DataMapper::Resource | |
property :id, Integer, :serial => true | |
property :color, Enum[:red, :yellow, :blue] | |
end | |
end | |
before do | |
@boat = ColorBoat.new | |
end | |
it "should accept red color" do | |
@boat.color = :red | |
@boat.should be_valid | |
end | |
it "should not accept green color" do | |
@boat.color = :green | |
@boat.should_not be_valid | |
@boat.errors.on(:color).should_not be_empty | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment