Guest User

Untitled

a guest
Aug 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. Why is this spec failing, when the conditions it's testing pass in development?
  2. def is_destroyable?
  3. if user.encrypted_password.present? || user.authentications.count > 1
  4. true
  5. else
  6. errors.add :base, 'not allowed'
  7. false
  8. end
  9. end
  10.  
  11. describe "Authentication#is_destroyable?" do
  12.  
  13. before(:each) do
  14. # This creates a user with no password and a single authentication
  15. @user = FactoryGirl.create(:user_with_oauth)
  16. @auth = @user.authentications.first
  17. end
  18.  
  19. # This spec passes :)
  20. it "should return false when is users only authentication method" do
  21. @auth.is_destroyable?.should be_false
  22. end
  23.  
  24. # This FAILS - I have no idea why :(
  25. it "should return true when user has multiple authentications" do
  26. @user.authentications.create FactoryGirl.attributes_for(:authentication, :provider => 'twitter')
  27. @auth.is_destroyable?.should be_true
  28. end
  29.  
  30. # This FAILS - I have no idea why :(
  31. it "should return true when user has a password" do
  32. @user.update_attributes :password => 'password'
  33. @auth.is_destroyable?.should be_true
  34. end
  35.  
  36. end
  37.  
  38. Failure/Error: @auth.is_destroyable?.should be_true
  39. expected false to be true
  40.  
  41. FactoryGirl.define do
  42.  
  43. factory :user do
  44. username { FactoryGirl.generate(:username) }
  45. name 'Test User'
  46. email { FactoryGirl.generate(:email) }
  47. password 'password'
  48. end
  49.  
  50. factory :user_with_oauth, :parent => :user do
  51. password nil
  52. authentications [ FactoryGirl.build(:authentication) ]
  53. end
  54.  
  55. factory :authentication do
  56. provider 'facebook'
  57. uid SecureRandom.hex(16)
  58. end
  59.  
  60. end
  61.  
  62. factory :user_with_oauth, :parent => :user do
  63. password nil
  64. authentications { [FactoryGirl.build(:authentication)] }
  65. end
Add Comment
Please, Sign In to add comment