Skip to content

Commit

Permalink
Merge pull request #38 from toptier/bug/unique-uid
Browse files Browse the repository at this point in the history
Set uid as email if the provider is email
  • Loading branch information
Matías Mansilla authored Mar 3, 2017
2 parents 0268622 + 48b3b05 commit 1ca9b2d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ end

group :test do
gem 'database_cleaner', '~> 1.4.1'
gem 'faker', '~> 1.4.3'
gem 'faker', '~> 1.7.3'
gem 'shoulda-matchers', '~> 3.1.1'
gem 'simplecov', '~> 0.13.0', require: false
gem 'webmock', '~> 2.3.2'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ GEM
factory_girl_rails (4.5.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
faker (1.4.3)
faker (1.7.3)
i18n (~> 0.5)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
Expand Down Expand Up @@ -402,7 +402,7 @@ DEPENDENCIES
devise_token_auth (~> 0.1.39)
draper (~> 3.0.0.pre)
factory_girl_rails (~> 4.5.0)
faker (~> 1.4.3)
faker (~> 1.7.3)
fog-aws (~> 0.12.0)
haml (~> 4.0.6)
inherited_resources!
Expand Down
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class User < ApplicationRecord

validates :email, uniqueness: true

before_validation :init_uid

def full_name
return username unless first_name.present?
"#{first_name} #{last_name}"
Expand All @@ -49,4 +51,10 @@ def self.from_social_provider(provider, user_params)
user.assign_attributes user_params.except('id')
end
end

private

def init_uid
self.uid = email if uid.blank? && provider == 'email'
end
end
6 changes: 3 additions & 3 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryGirl.define do
factory :user do
email { Faker::Internet.email }
password { Faker::Internet.password(8) }
sequence(:username) { |n| "#{n}#{Faker::Internet.user_name}" }
email { Faker::Internet.unique.email }
password { Faker::Internet.password(8) }
username { Faker::Internet.unique.user_name }
end
end

0 comments on commit 1ca9b2d

Please sign in to comment.