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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
1be31e4a
Commit
1be31e4a
authored
Jul 13, 2020
by
manojmj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mark existing Project Bot Users as confirmed
This change marks existing Project Bot Users as confirmed.
parent
8cb0a93a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
0 deletions
+120
-0
changelogs/unreleased/migration-confirm-project-bot-users.yml
...gelogs/unreleased/migration-confirm-project-bot-users.yml
+5
-0
db/post_migrate/20200713071042_confirm_project_bot_users.rb
db/post_migrate/20200713071042_confirm_project_bot_users.rb
+30
-0
db/structure.sql
db/structure.sql
+1
-0
spec/migrations/confirm_project_bot_users_spec.rb
spec/migrations/confirm_project_bot_users_spec.rb
+84
-0
No files found.
changelogs/unreleased/migration-confirm-project-bot-users.yml
0 → 100644
View file @
1be31e4a
---
title
:
Mark existing Project Bot Users as confirmed
merge_request
:
36692
author
:
type
:
fixed
db/post_migrate/20200713071042_confirm_project_bot_users.rb
0 → 100644
View file @
1be31e4a
# frozen_string_literal: true
class
ConfirmProjectBotUsers
<
ActiveRecord
::
Migration
[
6.0
]
DOWNTIME
=
false
disable_ddl_transaction!
class
User
<
ApplicationRecord
self
.
table_name
=
'users'
include
::
EachBatch
USER_TYPE_PROJECT_BOT
=
6
scope
:project_bots
,
->
{
where
(
user_type:
USER_TYPE_PROJECT_BOT
)
}
scope
:unconfirmed
,
->
{
where
(
confirmed_at:
nil
)
}
end
def
up
User
.
reset_column_information
User
.
project_bots
.
unconfirmed
.
each_batch
do
|
relation
|
relation
.
update_all
(
'confirmed_at = created_at'
)
end
end
def
down
# no-op
end
end
db/structure.sql
View file @
1be31e4a
...
...
@@ -23772,5 +23772,6 @@ COPY "schema_migrations" (version) FROM STDIN;
20200710102846
20200710105332
20200710130234
20200713071042
\
.
spec/migrations/confirm_project_bot_users_spec.rb
0 → 100644
View file @
1be31e4a
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20200713071042_confirm_project_bot_users.rb'
)
RSpec
.
describe
ConfirmProjectBotUsers
,
:migration
do
let
(
:users
)
{
table
(
:users
)
}
context
'project bot users that are currently unconfirmed'
do
let!
(
:project_bot_1
)
do
create_user!
(
name:
'bot_1'
,
email:
'bot_1@example.com'
,
created_at:
2
.
days
.
ago
,
user_type:
described_class
::
User
::
USER_TYPE_PROJECT_BOT
)
end
let!
(
:project_bot_2
)
do
create_user!
(
name:
'bot_2'
,
email:
'bot_2@example.com'
,
created_at:
4
.
days
.
ago
,
user_type:
described_class
::
User
::
USER_TYPE_PROJECT_BOT
)
end
it
'updates their `confirmed_at` attribute'
do
expect
{
migrate!
}
.
to
change
{
project_bot_1
.
reload
.
confirmed_at
}
.
and
change
{
project_bot_2
.
reload
.
confirmed_at
}
end
it
'sets `confirmed_at` to be the same as their `created_at` attribute'
do
migrate!
[
project_bot_1
,
project_bot_2
].
each
do
|
bot
|
expect
(
bot
.
reload
.
confirmed_at
).
to
eq
(
bot
.
created_at
)
end
end
end
context
'project bot users that are currently confirmed'
do
let!
(
:confirmed_project_bot
)
do
create_user!
(
name:
'bot_1'
,
email:
'bot_1@example.com'
,
user_type:
described_class
::
User
::
USER_TYPE_PROJECT_BOT
,
confirmed_at:
1
.
day
.
ago
)
end
it
'does not update their `confirmed_at` attribute'
do
expect
{
migrate!
}.
not_to
change
{
confirmed_project_bot
.
reload
.
confirmed_at
}
end
end
context
'human users that are currently unconfirmed'
do
let!
(
:unconfirmed_human
)
do
create_user!
(
name:
'human'
,
email:
'human@example.com'
,
user_type:
nil
)
end
it
'does not update their `confirmed_at` attribute'
do
expect
{
migrate!
}.
not_to
change
{
unconfirmed_human
.
reload
.
confirmed_at
}
end
end
private
def
create_user!
(
name
:,
email
:,
user_type
:,
created_at:
Time
.
now
,
confirmed_at:
nil
)
users
.
create!
(
name:
name
,
email:
email
,
username:
name
,
projects_limit:
0
,
user_type:
user_type
,
confirmed_at:
confirmed_at
)
end
end
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