Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 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. @user.username = 'someusername'
  21. @user.should_be_valid
  22. end
  23.  
  24. specify "should be invalid without an email" do
  25. @user.attributes = valid_user_attributes.except(:email)
  26. @user.should_not_be_valid
  27. @user.errors.on(:email).should_equal "is required"
  28. @user.email = 'joe@bloggs.com'
  29. @user.should_be_valid
  30. end
  31.  
  32. spec "should be invalid without a password" do
  33. @user.attributes = valid_user_attributes.except(:password)
  34. @user.should_not_be_valid
  35. @user.password = 'abcdefg'
  36. @user.should_be_valid
  37. end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement