Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why is this spec failing, when the conditions it's testing pass in development?
- def is_destroyable?
- if user.encrypted_password.present? || user.authentications.count > 1
- true
- else
- errors.add :base, 'not allowed'
- false
- end
- end
- describe "Authentication#is_destroyable?" do
- before(:each) do
- # This creates a user with no password and a single authentication
- @user = FactoryGirl.create(:user_with_oauth)
- @auth = @user.authentications.first
- end
- # This spec passes :)
- it "should return false when is users only authentication method" do
- @auth.is_destroyable?.should be_false
- end
- # This FAILS - I have no idea why :(
- it "should return true when user has multiple authentications" do
- @user.authentications.create FactoryGirl.attributes_for(:authentication, :provider => 'twitter')
- @auth.is_destroyable?.should be_true
- end
- # This FAILS - I have no idea why :(
- it "should return true when user has a password" do
- @user.update_attributes :password => 'password'
- @auth.is_destroyable?.should be_true
- end
- end
- Failure/Error: @auth.is_destroyable?.should be_true
- expected false to be true
- FactoryGirl.define do
- factory :user do
- username { FactoryGirl.generate(:username) }
- name 'Test User'
- email { FactoryGirl.generate(:email) }
- password 'password'
- end
- factory :user_with_oauth, :parent => :user do
- password nil
- authentications [ FactoryGirl.build(:authentication) ]
- end
- factory :authentication do
- provider 'facebook'
- uid SecureRandom.hex(16)
- end
- end
- factory :user_with_oauth, :parent => :user do
- password nil
- authentications { [FactoryGirl.build(:authentication)] }
- end
Add Comment
Please, Sign In to add comment