Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. module UserSpecHelper
  2. def valid_user_attributes
  3. { :email => 'joe@bloggs.com',
  4. :username => 'joebloggs',
  5. :password => 'abcdefg' }
  6. end
  7. end
  8.  
  9. context "A user (in general)" do
  10. include UserSpecHelper
  11.  
  12. def setup
  13. @user = User.new
  14. end
  15.  
  16. specify "should be invalid without a username" do
  17. @user.attributes = valid_user_attributes.except(:username)
  18. @user.should_not_be_valid
  19. @user.errors.on(:username).should_equal "is required"
  20. end
  21.  
  22. specify "should be invalid without an email" do
  23. @user.attributes = valid_user_attributes.except(:email)
  24. @user.should_not_be_valid
  25. @user.errors.on(:email).should_equal "is required"
  26. end
  27.  
  28. specify "should be invalid without a password" do
  29. @user.attributes = valid_user_attributes.except(:password)
  30. @user.should_not_be_valid
  31. end
  32.  
  33. specify "should be valid with a full set of valid attributes" do
  34. @user.attributes = valid_user_attributes
  35. @user.should_be_valid
  36. end
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement