#Error
expected: # got: #
Clases user.rbclass User < ApplicationRecord validates :email, presence: true, email: true validates_presence_of :uid validates_presence_of :provider has_many :tokens
def self.from_omniauth(data)
User.where(provider: data[:provider], uid: data[:uid]).first_or_create do |user|
user.email = data[:info][:email]
end
end
end
FactoryGirl.define do factory :user do email "[email protected]" name "probando" provider "facebook" uid "22222" end end
user_spec.rbrequire 'rails_helper'
RSpec.describe User, type: :model do it { should validate_presence_of(:email) } it { should_not allow_value("uriel@codigofacilito").for(:email) } it { should allow_value("[email protected]").for(:email) } it { should validate_presence_of(:uid) } it { should validate_presence_of(:provider) }
it "should create an user if uid and provider doesn't exists" do expect{ User.from_omniauth({uid: "22222", provider: "facebook", info: {email: "[email protected]"}}) }.to change(User,:count).by(1) end
it "should find an user if uid and provider already exists" do user = FactoryGirl.create(:user) expect{ User.from_omniauth({uid: user.uid, provider: user.provider}) }.to change(User,:count).by(0) end
it "should return the find user if uid and provider already exists" do user = FactoryGirl.create(:user) expect( User.from_omniauth({uid: user.uid, provider: user.provider}) ).to eq(user) end end