diff --git a/app/models/user.rb b/app/models/user.rb index 77863712..dab25525 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -30,7 +30,7 @@ class User < ApplicationRecord validates :provider, presence: true validates :image, format: { with: /\.(png|jpg)\Z/i }, allow_blank: true validates :email, length: { maximum: 256 }, allow_blank: true, - uniqueness: { case_sensitive: false }, + uniqueness: { case_sensitive: false, scope: :provider }, format: { with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i } validates :password, length: { minimum: 6 }, confirmation: true, if: :greenlight_account?, on: :create diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 93703ace..e5891e6d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -29,7 +29,7 @@ describe User, type: :model do it { should validate_presence_of(:provider) } - it { should validate_uniqueness_of(:email).case_insensitive } + it { should validate_uniqueness_of(:email).scoped_to(:provider).case_insensitive } it { should validate_length_of(:email).is_at_most(256) } it { should allow_value("", nil).for(:email) } it { should allow_value("valid@email.com").for(:email) }