BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
85d2bf77
Commit
85d2bf77
authored
Sep 13, 2017
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
when a primary email is replaced and added to the secondary emails list,
make sure it stays confirmed
parent
b2d53791
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
4 deletions
+50
-4
user.rb
app/models/user.rb
+5
-2
create_service.rb
app/services/emails/create_service.rb
+2
-2
user_spec.rb
spec/models/user_spec.rb
+38
-0
create_service_spec.rb
spec/services/emails/create_service_spec.rb
+5
-0
No files found.
app/models/user.rb
View file @
85d2bf77
...
...
@@ -526,8 +526,11 @@ class User < ActiveRecord::Base
def
update_emails_with_primary_email
primary_email_record
=
emails
.
find_by
(
email:
email
)
if
primary_email_record
Emails
::
DestroyService
.
new
(
self
,
email:
email
).
execute
Emails
::
CreateService
.
new
(
self
,
email:
email_was
).
execute
Emails
::
DestroyService
.
new
(
self
).
execute
(
primary_email_record
)
# the original primary email was confirmed, and we want that to carry over. We don't
# have access to the original confirmation values at this point, so just set confirmed_at
Emails
::
CreateService
.
new
(
self
,
email:
email_was
).
execute
(
confirmed_at:
confirmed_at_was
)
end
end
...
...
app/services/emails/create_service.rb
View file @
85d2bf77
module
Emails
class
CreateService
<
::
Emails
::
BaseService
def
execute
@user
.
emails
.
create
(
email:
@email
)
def
execute
(
options
=
{})
@user
.
emails
.
create
(
{
email:
@email
}.
merge
(
options
)
)
end
end
end
spec/models/user_spec.rb
View file @
85d2bf77
...
...
@@ -379,6 +379,44 @@ describe User do
user
.
update_attributes!
(
email:
'shawnee.ritchie@denesik.com'
)
end
end
describe
'#update_emails_with_primary_email'
do
before
do
@user
=
create
(
:user
,
email:
'primary@example.com'
).
tap
do
|
user
|
user
.
skip_reconfirmation!
end
@secondary
=
create
:email
,
email:
'secondary@example.com'
,
user:
@user
@user
.
reload
end
it
'gets called when email updated'
do
expect
(
@user
).
to
receive
(
:update_emails_with_primary_email
)
@user
.
update_attributes!
(
email:
'new_primary@example.com'
)
end
it
'does not add old primary to secondary emails'
do
@user
.
update_attributes!
(
email:
'new_primary@example.com'
)
@user
.
reload
expect
(
@user
.
emails
.
count
).
to
eq
1
expect
(
@user
.
emails
.
first
.
email
).
to
eq
@secondary
.
email
end
it
'adds old primary to secondary emails if secondary is becoming a primary'
do
@user
.
update_attributes!
(
email:
@secondary
.
email
)
@user
.
reload
expect
(
@user
.
emails
.
count
).
to
eq
1
expect
(
@user
.
emails
.
first
.
email
).
to
eq
'primary@example.com'
end
it
'transfers old confirmation values into new secondary'
do
org_user
=
@user
@user
.
update_attributes!
(
email:
@secondary
.
email
)
@user
.
reload
expect
(
@user
.
emails
.
count
).
to
eq
1
expect
(
@user
.
emails
.
first
.
confirmed_at
).
not_to
eq
nil
end
end
end
describe
'#update_tracked_fields!'
,
:clean_gitlab_redis_shared_state
do
...
...
spec/services/emails/create_service_spec.rb
View file @
85d2bf77
...
...
@@ -12,6 +12,11 @@ describe Emails::CreateService do
expect
(
Email
.
where
(
opts
)).
not_to
be_empty
end
it
'creates an email with additional attributes'
do
expect
{
service
.
execute
(
confirmation_token:
'abc'
)
}.
to
change
{
Email
.
count
}.
by
(
1
)
expect
(
Email
.
where
(
opts
).
first
.
confirmation_token
).
to
eq
'abc'
end
it
'has the right user association'
do
service
.
execute
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment