Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
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
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
4 deletions
+50
-4
app/models/user.rb
app/models/user.rb
+5
-2
app/services/emails/create_service.rb
app/services/emails/create_service.rb
+2
-2
spec/models/user_spec.rb
spec/models/user_spec.rb
+38
-0
spec/services/emails/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
...
@@ -526,8 +526,11 @@ class User < ActiveRecord::Base
def
update_emails_with_primary_email
def
update_emails_with_primary_email
primary_email_record
=
emails
.
find_by
(
email:
email
)
primary_email_record
=
emails
.
find_by
(
email:
email
)
if
primary_email_record
if
primary_email_record
Emails
::
DestroyService
.
new
(
self
,
email:
email
).
execute
Emails
::
DestroyService
.
new
(
self
).
execute
(
primary_email_record
)
Emails
::
CreateService
.
new
(
self
,
email:
email_was
).
execute
# 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
end
end
...
...
app/services/emails/create_service.rb
View file @
85d2bf77
module
Emails
module
Emails
class
CreateService
<
::
Emails
::
BaseService
class
CreateService
<
::
Emails
::
BaseService
def
execute
def
execute
(
options
=
{})
@user
.
emails
.
create
(
email:
@email
)
@user
.
emails
.
create
(
{
email:
@email
}.
merge
(
options
)
)
end
end
end
end
end
end
spec/models/user_spec.rb
View file @
85d2bf77
...
@@ -379,6 +379,44 @@ describe User do
...
@@ -379,6 +379,44 @@ describe User do
user
.
update_attributes!
(
email:
'shawnee.ritchie@denesik.com'
)
user
.
update_attributes!
(
email:
'shawnee.ritchie@denesik.com'
)
end
end
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
end
describe
'#update_tracked_fields!'
,
:clean_gitlab_redis_shared_state
do
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
...
@@ -12,6 +12,11 @@ describe Emails::CreateService do
expect
(
Email
.
where
(
opts
)).
not_to
be_empty
expect
(
Email
.
where
(
opts
)).
not_to
be_empty
end
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
it
'has the right user association'
do
service
.
execute
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