Advertisement
Guest User

Untitled

a guest
May 19th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. module UserTest
  2. def self.a_user_without_a_username_should_not_be_saved
  3. user = UserFixtures.user_without_username
  4. user.save
  5. errors = user.errors.messages
  6. return true if errors.to_s =~ /username/ && errors.to_s =~ /be blank/
  7. end
  8.  
  9. def self.a_username_should_contain_at_least_8_characters
  10. user = UserFixtures.username_too_short
  11. user.save
  12. errors = user.errors.messages
  13. return true if errors.to_s =~ /username/ && errors.to_s =~ /6 characters/
  14. end
  15. end
  16.  
  17. module UserFixtures
  18. def self.user_without_username
  19. User.new(email: Faker::Internet.email, password: 'abc123abc123')
  20. end
  21.  
  22. def self.username_too_short
  23. User.new(email: Faker::Internet.email, password: 'abc123abc123', username: 'foo')
  24. end
  25. end
  26.  
  27. def run_user_tests
  28. # To turn on logging again
  29. # old_logger = ActiveRecord::Base.logger
  30. # ActiveRecord::Base.logger = old_logger
  31. ActiveRecord::Base.logger = nil
  32.  
  33. counter = 0
  34.  
  35. # Use Faker for these tests
  36. UserTest.methods(false).each do |method_name|
  37. User.delete_all
  38. unless UserTest.send(method_name) == true
  39. puts "Failed: #{method_name}"
  40. counter += 1
  41. end
  42. end
  43.  
  44. puts "All User tests passed." unless counter > 0
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement