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
21a7aed9
Unverified
Commit
21a7aed9
authored
Apr 07, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests to cover trigger schedule
parent
03088552
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
32 deletions
+82
-32
_form.html.haml
app/views/projects/triggers/_form.html.haml
+6
-11
schema.rb
db/schema.rb
+3
-1
trigger_schedules.rb
spec/factories/ci/trigger_schedules.rb
+3
-1
triggers_spec.rb
spec/features/triggers_spec.rb
+47
-8
trigger_schedule_worker_spec.rb
spec/workers/trigger_schedule_worker_spec.rb
+23
-11
No files found.
app/views/projects/triggers/_form.html.haml
View file @
21a7aed9
...
...
@@ -16,24 +16,19 @@
.checkbox
=
schedule_fields
.
label
:active
do
=
schedule_fields
.
check_box
:active
%strong
Schedule trigger
%strong
Schedule trigger
(experimental)
.help-block
If checked, this trigger will be executed periodically according to `
cron`, `cron_timezone` and `ref`
=
link_to
icon
(
'question-circle'
),
help_page_path
(
'
user/project/pipelines/settings'
,
anchor:
'visibility-of-pipelines
'
)
If checked, this trigger will be executed periodically according to `
Cron` and `Timezone`.
=
link_to
icon
(
'question-circle'
),
help_page_path
(
'
ci/triggers'
,
anchor:
'schedule
'
)
.form-group
=
schedule_fields
.
label
:cron
,
"Cron"
,
class:
"label-light"
=
schedule_fields
.
text_field
:cron
,
class:
"form-control"
,
title:
'
Trigger Schedule cr
on is required.'
,
placeholder:
"0 1 * * *"
=
schedule_fields
.
text_field
:cron
,
class:
"form-control"
,
title:
'
Cron specificati
on is required.'
,
placeholder:
"0 1 * * *"
.form-group
=
schedule_fields
.
label
:cron
,
"Timezone"
,
class:
"label-light"
=
schedule_fields
.
text_field
:cron_timezone
,
class:
"form-control"
,
title:
'T
rigger Schedule cron_t
imezone is required.'
,
placeholder:
"UTC"
=
schedule_fields
.
text_field
:cron_timezone
,
class:
"form-control"
,
title:
'Timezone is required.'
,
placeholder:
"UTC"
.form-group
-
schedule_ref
=
@trigger
.
trigger_schedule
.
ref
||
@project
.
default_branch
=
schedule_fields
.
label
:ref
,
"Branch or tag"
,
class:
"label-light"
=
hidden_field_tag
'trigger[trigger_schedule_attributes][ref]'
,
schedule_ref
=
dropdown_tag
(
schedule_ref
,
options:
{
toggle_class:
'js-branch-select wide'
,
filter:
true
,
dropdown_class:
"dropdown-menu-selectable"
,
placeholder:
"Search branches"
,
data:
{
selected:
schedule_ref
,
field_name:
'trigger[trigger_schedule_attributes][ref]'
}
})
=
schedule_fields
.
text_field
:ref
,
class:
"form-control"
,
title:
'Branch or tag is required.'
,
placeholder:
"master"
.help-block
Existing branch name, tag
=
f
.
submit
btn_text
,
class:
"btn btn-save"
...
...
db/schema.rb
View file @
21a7aed9
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017040
6115029
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017040
7122426
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -311,6 +311,8 @@ ActiveRecord::Schema.define(version: 20170406115029) do
t
.
string
"cron"
t
.
string
"cron_timezone"
t
.
datetime
"next_run_at"
t
.
string
"ref"
t
.
boolean
"active"
end
add_index
"ci_trigger_schedules"
,
[
"next_run_at"
],
name:
"index_ci_trigger_schedules_on_next_run_at"
,
using: :btree
...
...
spec/factories/ci/trigger_schedules.rb
View file @
21a7aed9
...
...
@@ -3,9 +3,11 @@ FactoryGirl.define do
trigger
factory: :ci_trigger_for_trigger_schedule
cron
'0 1 * * *'
cron_timezone
Gitlab
::
Ci
::
CronParser
::
VALID_SYNTAX_SAMPLE_TIME_ZONE
ref
'master'
active
true
after
(
:build
)
do
|
trigger_schedule
,
evaluator
|
trigger_schedule
.
update!
(
project:
trigger_schedule
.
trigger
.
project
)
trigger_schedule
.
project
||=
trigger_schedule
.
trigger
.
project
end
trait
:nightly
do
...
...
spec/features/triggers_spec.rb
View file @
21a7aed9
...
...
@@ -77,6 +77,53 @@ feature 'Triggers', feature: true, js: true do
expect
(
page
.
find
(
'.flash-notice'
)).
to
have_content
'Trigger was successfully updated.'
expect
(
page
.
find
(
'.triggers-list'
)).
to
have_content
new_trigger_title
end
context
'scheduled triggers'
do
let!
(
:trigger
)
do
create
(
:ci_trigger
,
owner:
user
,
project:
@project
,
description:
trigger_title
)
end
context
'enabling schedule'
do
before
do
visit
edit_namespace_project_trigger_path
(
@project
.
namespace
,
@project
,
trigger
)
end
scenario
'do fill form with valid data and save'
do
find
(
'#trigger_trigger_schedule_attributes_active'
).
click
fill_in
'trigger_trigger_schedule_attributes_cron'
,
with:
'1 * * * *'
fill_in
'trigger_trigger_schedule_attributes_cron_timezone'
,
with:
'UTC'
fill_in
'trigger_trigger_schedule_attributes_ref'
,
with:
'master'
click_button
'Save trigger'
expect
(
page
.
find
(
'.flash-notice'
)).
to
have_content
'Trigger was successfully updated.'
end
scenario
'do not fill form with valid data and save'
do
find
(
'#trigger_trigger_schedule_attributes_active'
).
click
click_button
'Save trigger'
expect
(
page
).
to
have_content
'The form contains the following errors'
end
end
context
'enabling schedule'
do
before
do
trigger
.
create_trigger_schedule
(
project:
trigger
.
project
,
active:
true
)
visit
edit_namespace_project_trigger_path
(
@project
.
namespace
,
@project
,
trigger
)
end
scenario
'disable and save form'
do
find
(
'#trigger_trigger_schedule_attributes_active'
).
click
click_button
'Save trigger'
expect
(
page
.
find
(
'.flash-notice'
)).
to
have_content
'Trigger was successfully updated.'
visit
edit_namespace_project_trigger_path
(
@project
.
namespace
,
@project
,
trigger
)
checkbox
=
find_field
(
'trigger_trigger_schedule_attributes_active'
)
expect
(
checkbox
).
not_to
be_checked
end
end
end
end
describe
'trigger "Take ownership" workflow'
do
...
...
@@ -125,14 +172,6 @@ feature 'Triggers', feature: true, js: true do
describe
'show triggers workflow'
do
scenario
'contains trigger description placeholder'
do
expect
(
page
.
find
(
'#trigger_description'
)[
'placeholder'
]).
to
eq
'Trigger description'
expect
(
page
.
find
(
'#trigger_trigger_schedule_attributes_cron'
)[
'placeholder'
]).
to
eq
'0 1 * * *'
expect
(
page
.
find
(
'#trigger_trigger_schedule_attributes_cron_timezone'
)[
'placeholder'
]).
to
eq
'UTC'
expect
(
page
.
find
(
'#trigger_ref'
)[
'placeholder'
]).
to
eq
'master'
end
scenario
'show checkbox for registration of scheduled trigger and checked off defaultly'
do
expect
(
page
.
find
(
'#trigger_trigger_schedule_attributes__destroy'
)[
'type'
]).
to
eq
'checkbox'
expect
(
page
.
find
(
'#trigger_trigger_schedule_attributes__destroy'
)[
'value'
]).
to
eq
'0'
end
scenario
'show "legacy" badge for legacy trigger'
do
...
...
spec/workers/trigger_schedule_worker_spec.rb
View file @
21a7aed9
...
...
@@ -8,24 +8,39 @@ describe TriggerScheduleWorker do
end
context
'when there is a scheduled trigger within next_run_at'
do
let
(
:next_run_at
)
{
2
.
days
.
ago
}
let!
(
:trigger_schedule
)
do
create
(
:ci_trigger_schedule
,
:nightly
)
end
before
do
trigger_schedule
=
create
(
:ci_trigger_schedule
,
:nightly
)
time_future
=
Time
.
now
+
10
.
days
allow
(
Time
).
to
receive
(
:now
).
and_return
(
time_future
)
@next_time
=
Gitlab
::
Ci
::
CronParser
.
new
(
trigger_schedule
.
cron
,
trigger_schedule
.
cron_timezone
).
next_time_from
(
time_future
)
trigger_schedule
.
update_column
(
:next_run_at
,
next_run_at
)
end
it
'creates a new trigger request'
do
expect
{
worker
.
perform
}.
to
change
{
Ci
::
TriggerRequest
.
count
}
.
by
(
1
)
expect
{
worker
.
perform
}.
to
change
{
Ci
::
TriggerRequest
.
count
}
end
it
'creates a new pipeline'
do
expect
{
worker
.
perform
}.
to
change
{
Ci
::
Pipeline
.
count
}
.
by
(
1
)
expect
{
worker
.
perform
}.
to
change
{
Ci
::
Pipeline
.
count
}
expect
(
Ci
::
Pipeline
.
last
).
to
be_pending
end
it
'updates next_run_at'
do
expect
{
worker
.
perform
}.
to
change
{
Ci
::
TriggerSchedule
.
last
.
next_run_at
}.
to
(
@next_time
)
worker
.
perform
expect
(
trigger_schedule
.
reload
.
next_run_at
).
not_to
eq
(
next_run_at
)
end
context
'inactive schedule'
do
before
do
trigger_schedule
.
update
(
active:
false
)
end
it
'does not create a new trigger'
do
expect
{
worker
.
perform
}.
not_to
change
{
Ci
::
TriggerRequest
.
count
}
end
end
end
...
...
@@ -42,10 +57,7 @@ describe TriggerScheduleWorker do
end
context
'when next_run_at is nil'
do
before
do
trigger_schedule
=
create
(
:ci_trigger_schedule
,
:nightly
)
trigger_schedule
.
update_attribute
(
:next_run_at
,
nil
)
end
let!
(
:trigger_schedule
)
{
create
(
:ci_trigger_schedule
,
:nightly
,
next_run_at:
nil
)
}
it
'does not create a new pipeline'
do
expect
{
worker
.
perform
}.
not_to
change
{
Ci
::
Pipeline
.
count
}
...
...
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