Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. specification :user do
  2. should_require_presence_of :username
  3. end
  4.  
  5. specification :authenticated_user do
  6. should_satisfy :user_specification
  7. should_require_presence_of :password
  8. should_require_confirmation_of :password
  9. end
  10.  
  11. ActiveRecord::Base.send(:include, ActiveSpec::Satisfies)
  12.  
  13. class User < ActiveRecord::Base
  14. should_satisfy :user_specification
  15. should_satisfy :authenticated_user_specification, :if => :authorised?
  16. end
  17.  
  18. u = User.new
  19. u.satisfies_specs? # returns false
  20. u.username = 'joebloggs'
  21. u.satisfies_specs? # returns true
  22. u.authorised = true
  23. u.satisfies_specs? # returns false
  24. u.password = 'foobar'
  25. u.satisifies_specs? # returns true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement