-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
130 - add without_emails and import ujs instead
- Loading branch information
Showing
3 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,48 @@ | |
expect(user.deactivated?).to be_truthy | ||
end | ||
end | ||
|
||
describe '.without_emails' do | ||
let(:user_with_email_field) do | ||
create(:user).tap do |user| | ||
user[:email] = user.email | ||
user.save! | ||
user.emails.destroy_all | ||
end | ||
end | ||
let(:user_with_emails_association) { create(:user) } | ||
|
||
it 'does not return users with email and associated Email record' do | ||
user_with_email_field | ||
user_with_emails_association | ||
expect(User.without_emails).to eq([user_with_email_field]) | ||
end | ||
end | ||
|
||
describe '#update_emails' do | ||
let(:user_with_email_field) do | ||
create(:user, email: '[email protected]').tap do |user| | ||
user[:email] = user.email | ||
user.save! | ||
user.emails.destroy_all | ||
end | ||
end | ||
let(:user_with_emails_association) { create(:user) } | ||
|
||
it 'creates a new Email record for users with email but no associated Email record' do | ||
user_with_email_field | ||
|
||
expect { user_with_email_field.update_emails }.to change(Email, :count).by(1) | ||
expect(user_with_email_field.reload.read_attribute_before_type_cast('email')).to eq('[email protected]') | ||
expect(user_with_email_field.emails.first).to have_attributes( | ||
email: '[email protected]', | ||
primary: true, | ||
) | ||
end | ||
|
||
it 'does not create a new Email record for users with email and associated Email record' do | ||
user_with_emails_association | ||
expect { user_with_emails_association.update_emails }.not_to change(Email, :count) | ||
end | ||
end | ||
end |