Guest User

Untitled

a guest
Feb 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. # auto_validate.rb
  2. require "dm-types" # not sure of that...
  3. if property.type.ancestors.include?(Types::Enum)
  4. validates_within property.name, options_with_message({:set => property.type.flag_map.values}, property, :within)
  5. end
  6.  
  7. # auto -validate_spec
  8. describe 'for Enum properties' do
  9. require 'dm-types' # not sure if it is ok to require dm-types here
  10. before :all do
  11. class ColorBoat
  12. include DataMapper::Resource
  13. property :id, Integer, :serial => true
  14. property :color, Enum[:red, :yellow, :blue]
  15. end
  16. end
  17.  
  18. before do
  19. @boat = ColorBoat.new
  20. end
  21.  
  22. it "should accept red color" do
  23. @boat.color = :red
  24. @boat.should be_valid
  25. end
  26.  
  27. it "should not accept green color" do
  28. @boat.color = :green
  29. @boat.should_not be_valid
  30. @boat.errors.on(:color).should_not be_empty
  31. end
  32.  
  33. end
Add Comment
Please, Sign In to add comment