Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
Add Comment
Please, Sign In to add comment