shipit-engine 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/shipit/api/cacheable.rb +13 -0
- data/app/controllers/concerns/shipit/api/paginable.rb +37 -0
- data/app/controllers/concerns/shipit/api/rendering.rb +25 -0
- data/app/controllers/concerns/{api/paginable.rb → shipit/pagination.rb} +5 -13
- data/app/controllers/shipit/api/base_controller.rb +68 -0
- data/app/controllers/shipit/api/deploys_controller.rb +17 -0
- data/app/controllers/shipit/api/hooks_controller.rb +53 -0
- data/app/controllers/shipit/api/locks_controller.rb +32 -0
- data/app/controllers/shipit/api/outputs_controller.rb +17 -0
- data/app/controllers/shipit/api/stacks_controller.rb +21 -0
- data/app/controllers/shipit/api/tasks_controller.rb +20 -0
- data/app/controllers/shipit/commit_checks_controller.rb +26 -0
- data/app/controllers/shipit/deploys_controller.rb +47 -0
- data/app/controllers/shipit/github_authentication_controller.rb +27 -0
- data/app/controllers/shipit/rollbacks_controller.rb +26 -0
- data/app/controllers/shipit/shipit_controller.rb +62 -0
- data/app/controllers/shipit/stacks_controller.rb +81 -0
- data/app/controllers/shipit/status_controller.rb +7 -0
- data/app/controllers/shipit/tasks_controller.rb +48 -0
- data/app/controllers/shipit/webhooks_controller.rb +101 -0
- data/app/helpers/shipit/chunks_helper.rb +8 -0
- data/app/helpers/shipit/deploys_helper.rb +28 -0
- data/app/helpers/shipit/github_url_helper.rb +48 -0
- data/app/helpers/shipit/shipit_helper.rb +64 -0
- data/app/helpers/shipit/stacks_helper.rb +78 -0
- data/app/helpers/shipit/tasks_helper.rb +11 -0
- data/app/jobs/shipit/background_job.rb +24 -0
- data/app/jobs/shipit/background_job/unique.rb +28 -0
- data/app/jobs/shipit/cache_deploy_spec_job.rb +12 -0
- data/app/jobs/shipit/chunk_rollup_job.rb +21 -0
- data/app/jobs/shipit/clear_git_cache_job.rb +9 -0
- data/app/jobs/shipit/deliver_hook_job.rb +9 -0
- data/app/jobs/shipit/destroy_stack_job.rb +9 -0
- data/app/jobs/shipit/emit_event_job.rb +10 -0
- data/app/jobs/shipit/fetch_commit_stats_job.rb +9 -0
- data/app/jobs/shipit/fetch_deployed_revision_job.rb +23 -0
- data/app/jobs/shipit/git_mirror_update_job.rb +12 -0
- data/app/jobs/shipit/github_sync_job.rb +55 -0
- data/app/jobs/shipit/perform_commit_checks_job.rb +7 -0
- data/app/jobs/shipit/perform_task_job.rb +57 -0
- data/app/jobs/shipit/refresh_github_user_job.rb +9 -0
- data/app/jobs/shipit/refresh_statuses_job.rb +14 -0
- data/app/jobs/shipit/setup_github_hook_job.rb +11 -0
- data/app/models/shipit/anonymous_user.rb +43 -0
- data/app/models/shipit/api_client.rb +44 -0
- data/app/models/shipit/commit.rb +209 -0
- data/app/models/shipit/commit_checks.rb +90 -0
- data/app/models/shipit/delivery.rb +47 -0
- data/app/models/shipit/deploy.rb +153 -0
- data/app/models/shipit/deploy_spec.rb +150 -0
- data/app/models/shipit/deploy_spec/bundler_discovery.rb +61 -0
- data/app/models/shipit/deploy_spec/capistrano_discovery.rb +29 -0
- data/app/models/shipit/deploy_spec/file_system.rb +64 -0
- data/app/models/shipit/deploy_spec/pypi_discovery.rb +34 -0
- data/app/models/shipit/deploy_spec/rubygems_discovery.rb +34 -0
- data/app/models/shipit/github_hook.rb +148 -0
- data/app/models/shipit/hook.rb +86 -0
- data/app/models/shipit/membership.rb +8 -0
- data/app/models/shipit/missing_status.rb +21 -0
- data/app/models/shipit/output_chunk.rb +11 -0
- data/app/models/shipit/rollback.rb +31 -0
- data/app/models/shipit/stack.rb +308 -0
- data/app/models/shipit/status.rb +44 -0
- data/app/models/shipit/status_group.rb +35 -0
- data/app/models/shipit/task.rb +201 -0
- data/app/models/shipit/task_definition.rb +38 -0
- data/app/models/shipit/team.rb +69 -0
- data/app/models/shipit/unknown_status.rb +43 -0
- data/app/models/shipit/user.rb +83 -0
- data/app/models/shipit/variable_definition.rb +21 -0
- data/app/serializers/concerns/shipit/conditional_attributes.rb +22 -0
- data/app/serializers/shipit/anonymous_user_serializer.rb +4 -0
- data/app/serializers/shipit/commit_serializer.rb +8 -0
- data/app/serializers/shipit/deploy_serializer.rb +15 -0
- data/app/serializers/shipit/hook_serializer.rb +12 -0
- data/app/serializers/shipit/rollback_serializer.rb +7 -0
- data/app/serializers/shipit/short_commit_serializer.rb +9 -0
- data/app/serializers/shipit/stack_serializer.rb +33 -0
- data/app/serializers/shipit/tail_task_serializer.rb +39 -0
- data/app/serializers/shipit/task_serializer.rb +30 -0
- data/app/serializers/shipit/user_serializer.rb +5 -0
- data/app/views/{commits → shipit/commits}/_commit.html.erb +1 -1
- data/app/views/{commits → shipit/commits}/_commit_author.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_checklist.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_checks.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_concurrent_deploy_warning.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_deploy.html.erb +1 -1
- data/app/views/{deploys → shipit/deploys}/_monitoring.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_summary.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/new.html.erb +3 -3
- data/app/views/{deploys → shipit/deploys}/rollback.html.erb +2 -2
- data/app/views/{deploys → shipit/deploys}/show.html.erb +1 -1
- data/app/views/{github_authentication → shipit/github_authentication}/failed.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/_header.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/index.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/new.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/settings.html.erb +1 -1
- data/app/views/{stacks → shipit/stacks}/show.html.erb +2 -2
- data/app/views/{statuses → shipit/statuses}/_group.html.erb +1 -1
- data/app/views/{statuses → shipit/statuses}/_status.html.erb +0 -0
- data/app/views/{tasks → shipit/tasks}/_task.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/_task_output.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/index.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/new.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/show.html.erb +1 -1
- data/db/migrate/20160104151742_increase_tasks_type_size_back.rb +5 -0
- data/db/migrate/20160104151833_convert_sti_columns.rb +10 -0
- data/lib/shipit.rb +11 -10
- data/lib/shipit/command.rb +171 -0
- data/lib/shipit/commands.rb +25 -0
- data/lib/shipit/deploy_commands.rb +21 -0
- data/lib/shipit/engine.rb +3 -0
- data/lib/shipit/rollback_commands.rb +7 -0
- data/lib/shipit/stack_commands.rb +60 -0
- data/lib/shipit/task_commands.rb +68 -0
- data/lib/shipit/version.rb +1 -1
- data/lib/tasks/cron.rake +3 -3
- data/test/controllers/api/base_controller_test.rb +18 -14
- data/test/controllers/api/deploys_controller_test.rb +56 -52
- data/test/controllers/api/hooks_controller_test.rb +62 -58
- data/test/controllers/api/locks_controller_test.rb +38 -34
- data/test/controllers/api/outputs_controller_test.rb +15 -11
- data/test/controllers/api/stacks_controller_test.rb +56 -52
- data/test/controllers/api/tasks_controller_test.rb +30 -26
- data/test/controllers/commit_checks_controller_test.rb +29 -27
- data/test/controllers/deploys_controller_test.rb +68 -66
- data/test/controllers/github_authentication_controller_test.rb +9 -7
- data/test/controllers/rollbacks_controller_test.rb +43 -41
- data/test/controllers/stacks_controller_test.rb +131 -128
- data/test/controllers/status_controller_test.rb +8 -6
- data/test/controllers/tasks_controller_test.rb +70 -68
- data/test/controllers/webhooks_controller_test.rb +127 -125
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +2 -2
- data/test/dummy/db/seeds.rb +133 -131
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/fixtures/{api_clients.yml → shipit/api_clients.yml} +0 -0
- data/test/fixtures/{commits.yml → shipit/commits.yml} +0 -0
- data/test/fixtures/{deliveries.yml → shipit/deliveries.yml} +0 -0
- data/test/fixtures/{github_hooks.yml → shipit/github_hooks.yml} +4 -4
- data/test/fixtures/{hooks.yml → shipit/hooks.yml} +0 -0
- data/test/fixtures/{memberships.yml → shipit/memberships.yml} +0 -0
- data/test/fixtures/{output_chunks.yml → shipit/output_chunks.yml} +0 -0
- data/test/fixtures/{stacks.yml → shipit/stacks.yml} +0 -0
- data/test/fixtures/{statuses.yml → shipit/statuses.yml} +0 -0
- data/test/fixtures/{tasks.yml → shipit/tasks.yml} +8 -8
- data/test/fixtures/{teams.yml → shipit/teams.yml} +0 -0
- data/test/fixtures/{users.yml → shipit/users.yml} +0 -0
- data/test/helpers/api_helper.rb +1 -1
- data/test/helpers/fixture_aliases_helper.rb +4 -4
- data/test/jobs/cache_deploy_spec_job_test.rb +15 -13
- data/test/jobs/chunk_rollup_job_test.rb +30 -28
- data/test/jobs/deliver_hook_job_test.rb +11 -9
- data/test/jobs/destroy_stack_job_test.rb +11 -9
- data/test/jobs/emit_event_job_test.rb +10 -8
- data/test/jobs/fetch_commit_stats_job_test.rb +10 -8
- data/test/jobs/fetch_deployed_revision_job_test.rb +24 -22
- data/test/jobs/github_sync_job_test.rb +51 -49
- data/test/jobs/perform_task_job_test.rb +78 -76
- data/test/jobs/refresh_github_user_job_test.rb +10 -8
- data/test/jobs/refresh_status_job_test.rb +14 -12
- data/test/jobs/unique_job_test.rb +18 -15
- data/test/models/api_client_test.rb +20 -18
- data/test/models/commit_checks_test.rb +63 -61
- data/test/models/commits_test.rb +317 -314
- data/test/models/delivery_test.rb +29 -27
- data/test/models/deploys_test.rb +289 -287
- data/test/models/github_hook_test.rb +45 -43
- data/test/models/hook_test.rb +44 -42
- data/test/models/membership_test.rb +9 -7
- data/test/models/missing_status_test.rb +16 -14
- data/test/models/output_chunk_test.rb +14 -12
- data/test/models/rollbacks_test.rb +14 -12
- data/test/models/stacks_test.rb +272 -270
- data/test/models/status_group_test.rb +18 -16
- data/test/models/status_test.rb +42 -40
- data/test/models/task_definitions_test.rb +27 -25
- data/test/models/team_test.rb +39 -37
- data/test/models/users_test.rb +61 -59
- data/test/unit/command_test.rb +43 -41
- data/test/unit/commands_test.rb +8 -6
- data/test/unit/csv_serializer_test.rb +28 -26
- data/test/unit/deploy_commands_test.rb +179 -176
- data/test/unit/deploy_spec_test.rb +237 -235
- data/test/unit/github_url_helper_test.rb +19 -17
- data/test/unit/shipit_test.rb +44 -42
- metadata +139 -137
- data/app/controllers/api/base_controller.rb +0 -66
- data/app/controllers/api/deploys_controller.rb +0 -15
- data/app/controllers/api/hooks_controller.rb +0 -51
- data/app/controllers/api/locks_controller.rb +0 -30
- data/app/controllers/api/outputs_controller.rb +0 -15
- data/app/controllers/api/stacks_controller.rb +0 -19
- data/app/controllers/api/tasks_controller.rb +0 -18
- data/app/controllers/commit_checks_controller.rb +0 -24
- data/app/controllers/concerns/api/cacheable.rb +0 -11
- data/app/controllers/concerns/api/rendering.rb +0 -23
- data/app/controllers/concerns/pagination.rb +0 -25
- data/app/controllers/deploys_controller.rb +0 -45
- data/app/controllers/github_authentication_controller.rb +0 -25
- data/app/controllers/rollbacks_controller.rb +0 -24
- data/app/controllers/shipit_controller.rb +0 -54
- data/app/controllers/stacks_controller.rb +0 -79
- data/app/controllers/status_controller.rb +0 -5
- data/app/controllers/tasks_controller.rb +0 -46
- data/app/controllers/webhooks_controller.rb +0 -99
- data/app/helpers/chunks_helper.rb +0 -6
- data/app/helpers/deploys_helper.rb +0 -26
- data/app/helpers/github_url_helper.rb +0 -46
- data/app/helpers/shipit_helper.rb +0 -62
- data/app/helpers/stacks_helper.rb +0 -76
- data/app/helpers/tasks_helper.rb +0 -9
- data/app/jobs/background_job.rb +0 -22
- data/app/jobs/background_job/unique.rb +0 -26
- data/app/jobs/cache_deploy_spec_job.rb +0 -10
- data/app/jobs/chunk_rollup_job.rb +0 -19
- data/app/jobs/clear_git_cache_job.rb +0 -7
- data/app/jobs/deliver_hook_job.rb +0 -7
- data/app/jobs/destroy_stack_job.rb +0 -7
- data/app/jobs/emit_event_job.rb +0 -8
- data/app/jobs/fetch_commit_stats_job.rb +0 -7
- data/app/jobs/fetch_deployed_revision_job.rb +0 -21
- data/app/jobs/git_mirror_update_job.rb +0 -10
- data/app/jobs/github_sync_job.rb +0 -53
- data/app/jobs/perform_commit_checks_job.rb +0 -5
- data/app/jobs/perform_task_job.rb +0 -55
- data/app/jobs/refresh_github_user_job.rb +0 -7
- data/app/jobs/refresh_statuses_job.rb +0 -12
- data/app/jobs/setup_github_hook_job.rb +0 -9
- data/app/models/anonymous_user.rb +0 -41
- data/app/models/api_client.rb +0 -42
- data/app/models/commit.rb +0 -207
- data/app/models/commit_checks.rb +0 -88
- data/app/models/delivery.rb +0 -45
- data/app/models/deploy.rb +0 -151
- data/app/models/deploy_spec.rb +0 -148
- data/app/models/deploy_spec/bundler_discovery.rb +0 -59
- data/app/models/deploy_spec/capistrano_discovery.rb +0 -27
- data/app/models/deploy_spec/file_system.rb +0 -62
- data/app/models/deploy_spec/pypi_discovery.rb +0 -32
- data/app/models/deploy_spec/rubygems_discovery.rb +0 -32
- data/app/models/github_hook.rb +0 -144
- data/app/models/hook.rb +0 -84
- data/app/models/membership.rb +0 -6
- data/app/models/missing_status.rb +0 -18
- data/app/models/output_chunk.rb +0 -9
- data/app/models/rollback.rb +0 -29
- data/app/models/stack.rb +0 -306
- data/app/models/status.rb +0 -42
- data/app/models/status_group.rb +0 -33
- data/app/models/task.rb +0 -197
- data/app/models/task_definition.rb +0 -36
- data/app/models/team.rb +0 -67
- data/app/models/unknown_status.rb +0 -41
- data/app/models/user.rb +0 -81
- data/app/models/variable_definition.rb +0 -19
- data/app/serializers/anonymous_user_serializer.rb +0 -2
- data/app/serializers/commit_serializer.rb +0 -6
- data/app/serializers/concerns/conditional_attributes.rb +0 -20
- data/app/serializers/deploy_serializer.rb +0 -13
- data/app/serializers/hook_serializer.rb +0 -10
- data/app/serializers/rollback_serializer.rb +0 -5
- data/app/serializers/short_commit_serializer.rb +0 -7
- data/app/serializers/stack_serializer.rb +0 -31
- data/app/serializers/tail_task_serializer.rb +0 -37
- data/app/serializers/task_serializer.rb +0 -28
- data/app/serializers/user_serializer.rb +0 -3
- data/lib/command.rb +0 -169
- data/lib/commands.rb +0 -23
- data/lib/deploy_commands.rb +0 -19
- data/lib/rollback_commands.rb +0 -5
- data/lib/stack_commands.rb +0 -58
- data/lib/task_commands.rb +0 -66
@@ -1,90 +1,92 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module Shipit
|
4
|
+
class DeploysControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
Deploy.where(status: %w(running pending)).update_all(status: 'success')
|
7
|
+
@stack = shipit_stacks(:shipit)
|
8
|
+
@deploy = shipit_deploys(:shipit)
|
9
|
+
@commit = shipit_commits(:second)
|
10
|
+
session[:user_id] = shipit_users(:walrus).id
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
test ":show is success" do
|
14
|
+
get :show, stack_id: @stack.to_param, id: @deploy.id
|
15
|
+
assert_response :success
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
test ":new is success" do
|
19
|
+
get :new, stack_id: @stack.to_param, sha: @commit.sha
|
20
|
+
assert_response :success
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
test ":new shows a warning if a deploy is already running" do
|
24
|
+
shipit_deploys(:shipit_running).update_column(:status, 'running')
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
get :new, stack_id: @stack.to_param, sha: @commit.sha
|
27
|
+
assert_response :success
|
28
|
+
assert_select '.warning.concurrent-deploy h2' do |elements|
|
29
|
+
assert_equal 'Lando Walrussian is already deploying!', elements.first.text
|
30
|
+
end
|
31
|
+
assert_select '#new_deploy #force', 1
|
29
32
|
end
|
30
|
-
assert_select '#new_deploy #force', 1
|
31
|
-
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
test ":create persists a new deploy" do
|
35
|
+
assert_difference '@stack.deploys.count', 1 do
|
36
|
+
post :create, stack_id: @stack.to_param, deploy: {until_commit_id: @commit.id}
|
37
|
+
end
|
36
38
|
end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
test ":create can receive an :env hash" do
|
41
|
+
env = {'SAFETY_DISABLED' => '1'}
|
42
|
+
post :create, stack_id: @stack.to_param, deploy: {until_commit_id: @commit.id, env: env}
|
43
|
+
new_deploy = Deploy.last
|
44
|
+
assert_equal env, new_deploy.env
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
test ":create ignore :env keys not declared in the deploy spec" do
|
48
|
+
post :create, stack_id: @stack.to_param, deploy: {until_commit_id: @commit.id, env: {'H4X0R' => '1'}}
|
49
|
+
new_deploy = Deploy.last
|
50
|
+
assert_equal({}, new_deploy.env)
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
test ":create with `force` option ignore the active deploys" do
|
54
|
+
shipit_deploys(:shipit_running).update_column(:status, 'running')
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
assert_difference '@stack.deploys.count', 1 do
|
57
|
+
post :create, stack_id: @stack.to_param, deploy: {until_commit_id: @commit.id}, force: true
|
58
|
+
end
|
57
59
|
end
|
58
|
-
end
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
test ":create redirect back to :new with a warning if there is an active deploy" do
|
62
|
+
shipit_deploys(:shipit_running).update_column(:status, 'running')
|
62
63
|
|
63
|
-
|
64
|
-
|
64
|
+
assert_no_difference '@stack.deploys.count' do
|
65
|
+
post :create, stack_id: @stack.to_param, deploy: {until_commit_id: @commit.id}
|
66
|
+
end
|
67
|
+
assert_redirected_to new_stack_deploy_path(@stack, sha: @commit.sha)
|
65
68
|
end
|
66
|
-
assert_redirected_to new_stack_deploy_path(@stack, sha: @commit.sha)
|
67
|
-
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
test ":create redirects to the new deploy" do
|
71
|
+
post :create, stack_id: @stack.to_param, deploy: {until_commit_id: @commit.id}
|
72
|
+
new_deploy = Deploy.last
|
73
|
+
assert_redirected_to stack_deploy_path(@stack, new_deploy)
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
test ":rollback is success" do
|
77
|
+
get :rollback, stack_id: @stack.to_param, id: @deploy.id
|
78
|
+
assert_response :success
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
81
|
+
test ":rollback shows a warning if a deploy is already running" do
|
82
|
+
shipit_deploys(:shipit_running).update_column(:status, 'running')
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
get :rollback, stack_id: @stack.to_param, id: @deploy.id
|
85
|
+
assert_response :success
|
86
|
+
assert_select '.warning.concurrent-deploy h2' do |elements|
|
87
|
+
assert_equal 'Lando Walrussian is already deploying!', elements.first.text
|
88
|
+
end
|
89
|
+
assert_select '#new_rollback #force', 1
|
87
90
|
end
|
88
|
-
assert_select '#new_rollback #force', 1
|
89
91
|
end
|
90
92
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Shipit
|
4
|
+
class GithubAuthenticationControllerTest < ActionController::TestCase
|
5
|
+
test ":callback can sign in to github" do
|
6
|
+
@request.env['omniauth.auth'] = {info: {nickname: 'shipit'}}
|
7
|
+
github_user = mock('Sawyer User')
|
8
|
+
Shipit.github_api.stubs(:user).returns(github_user)
|
9
|
+
User.expects(:find_or_create_from_github).with(github_user).returns(stub(id: 44))
|
9
10
|
|
10
|
-
|
11
|
+
get :callback
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
@@ -1,55 +1,57 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
test ":create persists a new rollback" do
|
12
|
-
assert_difference '@stack.rollbacks.count', 1 do
|
13
|
-
post :create, stack_id: @stack.to_param, rollback: {parent_id: @deploy.id}
|
3
|
+
module Shipit
|
4
|
+
class RollbacksControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
Deploy.where(status: %w(running pending)).update_all(status: 'success')
|
7
|
+
@stack = shipit_stacks(:shipit)
|
8
|
+
@deploy = shipit_deploys(:shipit)
|
9
|
+
session[:user_id] = shipit_users(:walrus).id
|
14
10
|
end
|
15
|
-
end
|
16
11
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
12
|
+
test ":create persists a new rollback" do
|
13
|
+
assert_difference '@stack.rollbacks.count', 1 do
|
14
|
+
post :create, stack_id: @stack.to_param, rollback: {parent_id: @deploy.id}
|
15
|
+
end
|
16
|
+
end
|
23
17
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
test ":create can receive an :env hash" do
|
19
|
+
env = {'SAFETY_DISABLED' => '1'}
|
20
|
+
post :create, stack_id: @stack.to_param, rollback: {parent_id: @deploy.id, env: env}
|
21
|
+
new_rollback = Rollback.last
|
22
|
+
assert_equal env, new_rollback.env
|
23
|
+
end
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
test ":create ignore :env keys not declared in the deploy spec" do
|
26
|
+
post :create, stack_id: @stack.to_param, rollback: {parent_id: @deploy.id, env: {'H4X0R' => '1'}}
|
27
|
+
new_rollback = Rollback.last
|
28
|
+
assert_equal({}, new_rollback.env)
|
29
|
+
end
|
34
30
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
test ":create redirects to the new deploy" do
|
32
|
+
post :create, stack_id: @stack.to_param, rollback: {parent_id: @deploy.id}
|
33
|
+
assert_redirected_to stack_deploy_path(@stack, Rollback.last)
|
34
|
+
end
|
39
35
|
|
40
|
-
|
41
|
-
deploys(:shipit_running).update_column(:status, 'running')
|
42
|
-
assert_no_difference '@stack.deploys.count' do
|
36
|
+
test ":create locks deploys" do
|
43
37
|
post :create, stack_id: @stack.to_param, rollback: {parent_id: @deploy.id}
|
38
|
+
assert @stack.reload.locked?
|
39
|
+
end
|
40
|
+
|
41
|
+
test ":create redirects back to the :new page if there is an active deploy" do
|
42
|
+
shipit_deploys(:shipit_running).update_column(:status, 'running')
|
43
|
+
assert_no_difference '@stack.deploys.count' do
|
44
|
+
post :create, stack_id: @stack.to_param, rollback: {parent_id: @deploy.id}
|
45
|
+
end
|
46
|
+
assert_redirected_to rollback_stack_deploy_path(@stack, @deploy)
|
44
47
|
end
|
45
|
-
assert_redirected_to rollback_stack_deploy_path(@stack, @deploy)
|
46
|
-
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
test ":create with `force` option ignore the active deploys" do
|
50
|
+
shipit_deploys(:shipit_running).update_column(:status, 'running')
|
51
|
+
assert_difference '@stack.deploys.count', 1 do
|
52
|
+
post :create, stack_id: @stack.to_param, rollback: {parent_id: @deploy.id}, force: true
|
53
|
+
end
|
54
|
+
assert_redirected_to stack_deploy_path(@stack, Rollback.last)
|
52
55
|
end
|
53
|
-
assert_redirected_to stack_deploy_path(@stack, Rollback.last)
|
54
56
|
end
|
55
57
|
end
|
@@ -1,164 +1,167 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class StacksControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
@routes = Shipit::Engine.routes
|
7
|
+
@stack = shipit_stacks(:shipit)
|
8
|
+
session[:user_id] = shipit_users(:walrus).id
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
test "validates that Shipit.github_oauth_id is present" do
|
12
|
+
Shipit.stubs(github_oauth_credentials: {'secret' => 'abc'})
|
13
|
+
get :index
|
14
|
+
assert_template 'missing_settings'
|
15
|
+
assert_select "#github_oauth_id .missing"
|
16
|
+
assert_select ".missing", count: 1
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
test "validates that Shipit.github_oauth_secret is present" do
|
20
|
+
Shipit.stubs(github_oauth_credentials: {'id' => 'abc'})
|
21
|
+
get :index
|
22
|
+
assert_template 'missing_settings'
|
23
|
+
assert_select "#github_oauth_secret .missing"
|
24
|
+
assert_select ".missing", count: 1
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
test "validates that Shipit.github_api_credentials is present" do
|
28
|
+
Shipit.stubs(github_api_credentials: {})
|
29
|
+
get :index
|
30
|
+
assert_template 'missing_settings'
|
31
|
+
assert_select "#github_api .missing"
|
32
|
+
assert_select ".missing", count: 1
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
test "validates that Shipit.redis_url is present" do
|
36
|
+
Shipit.stubs(redis_url: nil)
|
37
|
+
get :index
|
38
|
+
assert_template 'missing_settings'
|
39
|
+
assert_select "#redis_url .missing"
|
40
|
+
assert_select ".missing", count: 1
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
test "validates that Shipit.host is present" do
|
44
|
+
Shipit.stubs(host: nil)
|
45
|
+
get :index
|
46
|
+
assert_template 'missing_settings'
|
47
|
+
assert_select "#host .missing"
|
48
|
+
assert_select ".missing", count: 1
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
test "GitHub authentication is mandatory" do
|
52
|
+
session[:user_id] = nil
|
53
|
+
get :index
|
54
|
+
assert_redirected_to '/github/auth/github?origin=http%3A%2F%2Ftest.host%2F'
|
55
|
+
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
test "current_user must be a member of Shipit.github_team" do
|
58
|
+
Shipit.stubs(:github_team).returns(shipit_teams(:cyclimse_cooks))
|
59
|
+
get :index
|
60
|
+
assert_response :forbidden
|
61
|
+
assert_equal 'You must be a member of cyclimse/cooks to access this application.', response.body
|
62
|
+
end
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
test "#show is success" do
|
65
|
+
get :show, id: @stack.to_param
|
66
|
+
assert_response :ok
|
67
|
+
end
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
test "#show handles locked stacks without a lock_author" do
|
70
|
+
@stack.update!(lock_reason: "I am a lock with no author")
|
71
|
+
get :show, id: @stack.to_param
|
72
|
+
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
test "#show auto-links URLs in lock reason" do
|
75
|
+
@stack.update!(lock_reason: 'http://google.com')
|
76
|
+
get :show, id: @stack.to_param
|
77
|
+
assert_response :ok
|
78
|
+
assert_select 'a[href="http://google.com"]'
|
79
|
+
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
test "#create creates a Stack, queues a job to setup webhooks and redirects to it" do
|
82
|
+
params = {}
|
83
|
+
params[:stack] = {
|
84
|
+
repo_name: "rails",
|
85
|
+
repo_owner: "rails",
|
86
|
+
environment: "staging",
|
87
|
+
branch: "staging",
|
88
|
+
}
|
89
|
+
|
90
|
+
assert_difference "Stack.count" do
|
91
|
+
post :create, params
|
92
|
+
end
|
87
93
|
|
88
|
-
|
89
|
-
post :create, params
|
94
|
+
assert_redirected_to stack_path(Stack.last)
|
90
95
|
end
|
91
96
|
|
92
|
-
|
93
|
-
|
97
|
+
test "#create when not valid renders new" do
|
98
|
+
assert_no_difference "Stack.count" do
|
99
|
+
post :create, stack: {repo_owner: 'some', repo_name: 'owner/path'}
|
100
|
+
end
|
94
101
|
|
95
|
-
|
96
|
-
assert_no_difference "Stack.count" do
|
97
|
-
post :create, stack: {repo_owner: 'some', repo_name: 'owner/path'}
|
102
|
+
assert_template :new
|
98
103
|
end
|
99
104
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
delete :destroy, id: @stack.to_param
|
105
|
+
test "#destroy enqueues a DestroyStackJob" do
|
106
|
+
assert_enqueued_with(job: DestroyStackJob, args: [@stack]) do
|
107
|
+
delete :destroy, id: @stack.to_param
|
108
|
+
end
|
109
|
+
assert_redirected_to stacks_path
|
106
110
|
end
|
107
|
-
assert_redirected_to stacks_path
|
108
|
-
end
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
112
|
+
test "#settings is success" do
|
113
|
+
get :settings, id: @stack.to_param
|
114
|
+
assert_response :success
|
115
|
+
end
|
114
116
|
|
115
|
-
|
116
|
-
|
117
|
+
test "#update allows to lock the stack" do
|
118
|
+
refute @stack.locked?
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
120
|
+
patch :update, id: @stack.to_param, stack: {lock_reason: 'Went out to eat some chips!'}
|
121
|
+
@stack.reload
|
122
|
+
assert @stack.locked?
|
123
|
+
assert_equal shipit_users(:walrus), @stack.lock_author
|
124
|
+
end
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
126
|
+
test "#update allows to unlock the stack" do
|
127
|
+
@stack.update!(lock_reason: 'Went out to eat some chips!')
|
128
|
+
assert @stack.locked?
|
127
129
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
130
|
+
patch :update, id: @stack.to_param, stack: {lock_reason: ''}
|
131
|
+
@stack.reload
|
132
|
+
refute @stack.locked?
|
133
|
+
assert_instance_of AnonymousUser, @stack.lock_author
|
134
|
+
end
|
133
135
|
|
134
|
-
|
135
|
-
|
136
|
+
test "#refresh queues a RefreshStatusesJob and a GithubSyncJob" do
|
137
|
+
request.env['HTTP_REFERER'] = stack_settings_path(@stack)
|
136
138
|
|
137
|
-
|
138
|
-
|
139
|
-
|
139
|
+
assert_enqueued_with(job: RefreshStatusesJob, args: [stack_id: @stack.id]) do
|
140
|
+
assert_enqueued_with(job: GithubSyncJob, args: [stack_id: @stack.id]) do
|
141
|
+
post :refresh, id: @stack.to_param
|
142
|
+
end
|
140
143
|
end
|
141
|
-
end
|
142
144
|
|
143
|
-
|
144
|
-
|
145
|
+
assert_redirected_to stack_settings_path(@stack)
|
146
|
+
end
|
145
147
|
|
146
|
-
|
147
|
-
|
148
|
-
|
148
|
+
test "#sync_webhooks queues #{Stack::REQUIRED_HOOKS.count} SetupGithubHookJob" do
|
149
|
+
assert_enqueued_jobs(Stack::REQUIRED_HOOKS.count) do
|
150
|
+
post :sync_webhooks, id: @stack.to_param
|
151
|
+
end
|
152
|
+
assert_redirected_to stack_settings_path(@stack)
|
149
153
|
end
|
150
|
-
assert_redirected_to stack_settings_path(@stack)
|
151
|
-
end
|
152
154
|
|
153
|
-
|
154
|
-
|
155
|
-
|
155
|
+
test "#clear_git_cache queues a ClearGitCacheJob" do
|
156
|
+
assert_enqueued_with(job: ClearGitCacheJob, args: [@stack]) do
|
157
|
+
post :clear_git_cache, id: @stack.to_param
|
158
|
+
end
|
159
|
+
assert_redirected_to stack_settings_path(@stack)
|
156
160
|
end
|
157
|
-
assert_redirected_to stack_settings_path(@stack)
|
158
|
-
end
|
159
161
|
|
160
|
-
|
161
|
-
|
162
|
-
|
162
|
+
test "#update redirects to return_to parameter" do
|
163
|
+
patch :update, id: @stack.to_param, stack: {ignore_ci: false}, return_to: stack_path(@stack)
|
164
|
+
assert_redirected_to stack_path(@stack)
|
165
|
+
end
|
163
166
|
end
|
164
167
|
end
|