shipit-engine 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -2
  3. data/app/assets/images/archive-solid.svg +1 -0
  4. data/app/assets/stylesheets/_pages/_stacks.scss +76 -0
  5. data/app/controllers/shipit/api/stacks_controller.rb +20 -1
  6. data/app/controllers/shipit/api_clients_controller.rb +49 -0
  7. data/app/controllers/shipit/merge_status_controller.rb +8 -4
  8. data/app/controllers/shipit/stacks_controller.rb +58 -9
  9. data/app/controllers/shipit/webhooks_controller.rb +2 -130
  10. data/app/helpers/shipit/stacks_helper.rb +4 -0
  11. data/app/jobs/shipit/background_job/unique.rb +3 -1
  12. data/app/jobs/shipit/continuous_delivery_job.rb +1 -0
  13. data/app/jobs/shipit/destroy_stack_job.rb +2 -2
  14. data/app/models/shipit/commit.rb +21 -9
  15. data/app/models/shipit/commit_deployment.rb +15 -11
  16. data/app/models/shipit/commit_deployment_status.rb +6 -2
  17. data/app/models/shipit/deploy.rb +48 -7
  18. data/app/models/shipit/deploy_stats.rb +57 -0
  19. data/app/models/shipit/repository.rb +38 -0
  20. data/app/models/shipit/stack.rb +41 -34
  21. data/app/models/shipit/task.rb +26 -4
  22. data/app/models/shipit/webhooks.rb +32 -0
  23. data/app/models/shipit/webhooks/handlers/check_suite_handler.rb +19 -0
  24. data/app/models/shipit/webhooks/handlers/handler.rb +40 -0
  25. data/app/models/shipit/webhooks/handlers/membership_handler.rb +45 -0
  26. data/app/models/shipit/webhooks/handlers/push_handler.rb +20 -0
  27. data/app/models/shipit/webhooks/handlers/status_handler.rb +26 -0
  28. data/app/serializers/shipit/stack_serializer.rb +6 -1
  29. data/app/validators/ascii_only_validator.rb +3 -3
  30. data/app/views/layouts/_head.html.erb +0 -0
  31. data/app/views/layouts/shipit.html.erb +4 -2
  32. data/app/views/shipit/api_clients/index.html.erb +36 -0
  33. data/app/views/shipit/api_clients/new.html.erb +33 -0
  34. data/app/views/shipit/api_clients/show.html.erb +35 -0
  35. data/app/views/shipit/merge_status/logged_out.erb +1 -1
  36. data/app/views/shipit/stacks/_header.html.erb +12 -7
  37. data/app/views/shipit/stacks/_links.html.erb +1 -0
  38. data/app/views/shipit/stacks/index.html.erb +7 -2
  39. data/app/views/shipit/stacks/settings.html.erb +19 -0
  40. data/app/views/shipit/stacks/statistics.html.erb +82 -0
  41. data/config/locales/en.yml +14 -2
  42. data/config/routes.rb +4 -0
  43. data/db/migrate/20191209231045_create_shipit_repositories.rb +12 -0
  44. data/db/migrate/20191209231307_add_repository_reference_to_stacks.rb +15 -0
  45. data/db/migrate/20191216162728_backfill_repository_data.rb +22 -0
  46. data/db/migrate/20191216163010_remove_repository_information_from_stacks.rb +20 -0
  47. data/db/migrate/20191219205202_add_archived_since_to_stacks.rb +6 -0
  48. data/db/migrate/20200102175621_optional_task_commits.rb +6 -0
  49. data/db/migrate/20200109132519_add_sha_to_commit_deployments.rb +5 -0
  50. data/lib/shipit/github_app.rb +32 -3
  51. data/lib/shipit/task_commands.rb +10 -2
  52. data/lib/shipit/version.rb +1 -1
  53. data/test/controllers/api/ccmenu_controller_test.rb +1 -1
  54. data/test/controllers/api/stacks_controller_test.rb +14 -6
  55. data/test/controllers/api_clients_controller_test.rb +103 -0
  56. data/test/controllers/merge_status_controller_test.rb +21 -4
  57. data/test/controllers/stacks_controller_test.rb +35 -0
  58. data/test/controllers/webhooks_controller_test.rb +26 -0
  59. data/test/dummy/config/environments/development.rb +22 -4
  60. data/test/dummy/db/schema.rb +17 -6
  61. data/test/dummy/db/seeds.rb +20 -6
  62. data/test/fixtures/shipit/commit_deployment_statuses.yml +4 -4
  63. data/test/fixtures/shipit/commit_deployments.yml +8 -8
  64. data/test/fixtures/shipit/commits.yml +23 -0
  65. data/test/fixtures/shipit/repositories.yml +23 -0
  66. data/test/fixtures/shipit/stacks.yml +100 -16
  67. data/test/fixtures/shipit/tasks.yml +66 -3
  68. data/test/jobs/destroy_stack_job_test.rb +9 -0
  69. data/test/models/commit_deployment_status_test.rb +33 -4
  70. data/test/models/commit_deployment_test.rb +8 -11
  71. data/test/models/commits_test.rb +22 -2
  72. data/test/models/deploy_stats_test.rb +112 -0
  73. data/test/models/deploys_test.rb +55 -17
  74. data/test/models/pull_request_test.rb +1 -1
  75. data/test/models/shipit/repository_test.rb +76 -0
  76. data/test/models/shipit/wehbooks/handlers_test.rb +26 -0
  77. data/test/models/stacks_test.rb +44 -51
  78. data/test/models/undeployed_commits_test.rb +13 -0
  79. data/test/test_helper.rb +3 -1
  80. data/test/unit/deploy_commands_test.rb +9 -0
  81. data/test/unit/github_app_test.rb +136 -0
  82. metadata +161 -128
@@ -96,6 +96,14 @@ module Shipit
96
96
  assert_equal shipit_users(:walrus), commit.author
97
97
  end
98
98
 
99
+ test "#message= truncates the message" do
100
+ skip unless Shipit::Commit.columns_hash['message'].limit
101
+ limit = Shipit::Commit.columns_hash['message'].limit
102
+
103
+ @commit.update!(message: 'a' * limit * 2)
104
+ assert_equal limit, @commit.message.size
105
+ end
106
+
99
107
  test "#pull_request? detect pull request based on message format" do
100
108
  assert @pr.pull_request?
101
109
  refute @commit.pull_request?
@@ -190,12 +198,14 @@ module Shipit
190
198
  committed_at: Time.now,
191
199
  )
192
200
 
193
- @stack.deploys.create!(
201
+ deploy = @stack.deploys.build(
194
202
  user_id: walrus.id,
195
203
  since_commit: @stack.commits.first,
196
204
  until_commit: new_commit,
197
205
  status: 'success',
198
206
  )
207
+ deploy.stubs(:pull_request_head_for_commit).returns(nil)
208
+ deploy.save!
199
209
 
200
210
  assert_no_difference "Deploy.count" do
201
211
  @commit.statuses.create!(stack_id: @stack.id, state: 'success')
@@ -248,7 +258,7 @@ module Shipit
248
258
  target_url: 'http://example.com',
249
259
  created_at: 1.day.ago,
250
260
  )
251
- Shipit.github.api.expects(:statuses).with(@stack.github_repo_name, @commit.sha).returns([status])
261
+ Shipit.github.api.expects(:statuses).with(@stack.github_repo_name, @commit.sha, per_page: 100).returns([status])
252
262
  assert_difference '@commit.statuses.count', 1 do
253
263
  @commit.refresh_statuses!
254
264
  end
@@ -773,6 +783,16 @@ module Shipit
773
783
  assert_equal commit.deploy_requested_at, commit.created_at
774
784
  end
775
785
 
786
+ test "#recently_pushed?" do
787
+ freeze_time do
788
+ commit = Commit.new(message: "abcd", created_at: Time.now.utc)
789
+ assert_predicate commit, :recently_pushed?
790
+
791
+ commit = Commit.new(message: "abcd", created_at: 10.minutes.ago)
792
+ refute_predicate commit, :recently_pushed?
793
+ end
794
+ end
795
+
776
796
  private
777
797
 
778
798
  def expect_event(stack)
@@ -0,0 +1,112 @@
1
+ require 'test_helper'
2
+
3
+ module Shipit
4
+ class DeployStatsTest < ActiveSupport::TestCase
5
+ def setup
6
+ @stack = shipit_stacks(:shipit_stats)
7
+ @stats = Shipit::DeployStats.new(@stack.deploys.not_active)
8
+ @old_deploys = @stack.deploys.not_active.where(created_at: 62.minutes.ago..32.minutes.ago)
9
+ @new_deploys = @stack.deploys.not_active.where("created_at > ?", 32.minutes.ago)
10
+ end
11
+
12
+ test "#average_duration is accurate" do
13
+ assert_equal 225.0, @stats.average_duration
14
+ end
15
+
16
+ test "#median_duration is accurate" do
17
+ assert_equal 210.0, @stats.median_duration
18
+ end
19
+
20
+ test "#max_duration is accurate" do
21
+ assert_equal 360.0, @stats.max_duration
22
+ end
23
+
24
+ test "#min_duration is accurate" do
25
+ assert_equal 120.0, @stats.min_duration
26
+ end
27
+
28
+ test "#success_rate is accurate" do
29
+ assert_equal 75.0, @stats.success_rate
30
+ end
31
+
32
+ test "#average_duration handles empty deploy data" do
33
+ stats = Shipit::DeployStats.new([])
34
+ assert_nil stats.average_duration
35
+ end
36
+
37
+ test "#median_duration handles empty deploy data" do
38
+ stats = Shipit::DeployStats.new([])
39
+ assert_nil stats.median_duration
40
+ end
41
+
42
+ test "#max_duration handles empty deploy data" do
43
+ stats = Shipit::DeployStats.new([])
44
+ assert_nil stats.max_duration
45
+ end
46
+
47
+ test "#min_duration handles empty deploy data" do
48
+ stats = Shipit::DeployStats.new([])
49
+ assert_nil stats.min_duration
50
+ end
51
+
52
+ test "#success_rate handles empty deploy data" do
53
+ stats = Shipit::DeployStats.new([])
54
+ assert_nil stats.success_rate
55
+ end
56
+
57
+ test "#compare count handles empty compare count" do
58
+ comparison = Shipit::DeployStats.new([])
59
+ results = @stats.compare(comparison)
60
+ assert_equal 400, results[:count]
61
+ end
62
+
63
+ test "#compare average and median handles empty array" do
64
+ comparison = Shipit::DeployStats.new([])
65
+ results = @stats.compare(comparison)
66
+ assert_nil results[:average_duration]
67
+ assert_nil results[:median_duration]
68
+ end
69
+
70
+ test "#compare average is accurate when negative" do
71
+ new_data = Shipit::DeployStats.new(@new_deploys)
72
+ old_data = Shipit::DeployStats.new(@old_deploys)
73
+ results = new_data.compare(old_data)
74
+ assert_equal(-53.84615384615385, results[:average_duration])
75
+ end
76
+
77
+ test "#compare median is accurate when negative" do
78
+ new_data = Shipit::DeployStats.new(@new_deploys)
79
+ old_data = Shipit::DeployStats.new(@old_deploys)
80
+ results = new_data.compare(old_data)
81
+ assert_equal(-50, results[:median_duration])
82
+ end
83
+
84
+ test "#compare count is accurate when negative" do
85
+ new_data = Shipit::DeployStats.new(@new_deploys)
86
+ old_data = Shipit::DeployStats.new(@old_deploys)
87
+ results = new_data.compare(old_data)
88
+ assert_equal(-66.66666666666666, results[:count])
89
+ end
90
+
91
+ test "#compare average is accurate" do
92
+ old_data = Shipit::DeployStats.new(@new_deploys)
93
+ new_data = Shipit::DeployStats.new(@old_deploys)
94
+ results = new_data.compare(old_data)
95
+ assert_equal(116.66666666666667, results[:average_duration])
96
+ end
97
+
98
+ test "#compare median is accurate" do
99
+ old_data = Shipit::DeployStats.new(@new_deploys)
100
+ new_data = Shipit::DeployStats.new(@old_deploys)
101
+ results = new_data.compare(old_data)
102
+ assert_equal(100, results[:median_duration])
103
+ end
104
+
105
+ test "#compare count is accurate" do
106
+ old_data = Shipit::DeployStats.new(@new_deploys)
107
+ new_data = Shipit::DeployStats.new(@old_deploys)
108
+ results = new_data.compare(old_data)
109
+ assert_equal(200, results[:count])
110
+ end
111
+ end
112
+ end
@@ -199,6 +199,7 @@ module Shipit
199
199
  since_commit: shipit.commits.first,
200
200
  until_commit: shipit.commits.last,
201
201
  )
202
+ deploy.stubs(:pull_request_head_for_commit).returns(nil)
202
203
 
203
204
  expect_event(deploy)
204
205
  deploy.save!
@@ -300,18 +301,6 @@ module Shipit
300
301
  end
301
302
  end
302
303
 
303
- test "creating a deploy creates one CommitDeployment per commit" do
304
- shipit = shipit_stacks(:shipit)
305
- deploy = shipit.deploys.build(
306
- since_commit: shipit.commits.first,
307
- until_commit: shipit.commits.last,
308
- )
309
-
310
- assert_difference -> { CommitDeployment.count }, deploy.commits.size do
311
- deploy.save!
312
- end
313
- end
314
-
315
304
  test "#build_rollback returns an unsaved record" do
316
305
  assert @deploy.build_rollback.new_record?
317
306
  end
@@ -338,10 +327,9 @@ module Shipit
338
327
  assert_equal shipit_commits(:second), @stack.last_deployed_commit
339
328
  end
340
329
 
341
- def create_test_stack
330
+ def create_test_stack(repository: Shipit::Repository.find_or_create_by!(owner: "shopify-test", name: "shipit-engine-test"))
342
331
  Shipit::Stack.create(
343
- repo_owner: "shopify-test",
344
- repo_name: "shipit-engine-test",
332
+ repository: repository,
345
333
  environment: 'production',
346
334
  branch: "master",
347
335
  merge_queue_enabled: true,
@@ -552,8 +540,7 @@ module Shipit
552
540
  user_id = @user.id
553
541
  test_stack = create_test_stack
554
542
  test_stack.save
555
- other_stack = create_test_stack
556
- other_stack.repo_name += "_other"
543
+ other_stack = create_test_stack(repository: Shipit::Repository.create!(owner: "_", name: "_some-other-repository"))
557
544
  other_stack.save
558
545
  other_stack.reload
559
546
  stack_id = test_stack.id
@@ -860,6 +847,57 @@ module Shipit
860
847
  end
861
848
  end
862
849
 
850
+ test "succeeding a deploy creates CommitDeploymentStatuses" do
851
+ @deploy = shipit_deploys(:shipit_running)
852
+ refute_empty @deploy.commit_deployments
853
+
854
+ assert_difference -> { CommitDeploymentStatus.count }, @deploy.commit_deployments.size do
855
+ @deploy.report_complete!
856
+ end
857
+
858
+ assert_equal 'success', CommitDeploymentStatus.last.status
859
+ end
860
+
861
+ test "creates one CommitDeployment and status per commit, and one more for the batch head" do
862
+ template_task = shipit_tasks(:shipit_pending)
863
+ deploy = template_task.stack.deploys.build(
864
+ since_commit: template_task.since_commit,
865
+ until_commit: template_task.until_commit,
866
+ )
867
+
868
+ pull_request_response = stub(head: stub(sha: '6dcb09b5b57875f334f61aebed695e2e4193db5e'))
869
+ Shipit.github.api.expects(:pull_request).with('shopify/shipit-engine', 7).returns(pull_request_response)
870
+
871
+ expected_delta = deploy.commits.select(&:pull_request?).size + 1
872
+ assert_difference -> { CommitDeployment.count }, expected_delta do
873
+ assert_difference -> { CommitDeploymentStatus.count }, expected_delta do
874
+ deploy.save!
875
+ end
876
+ end
877
+
878
+ refute_nil CommitDeployment.find_by(sha: '6dcb09b5b57875f334f61aebed695e2e4193db5e')
879
+ refute_nil CommitDeployment.find_by(sha: deploy.until_commit.sha)
880
+ end
881
+
882
+ test "#create_commit_deployments handles API errors when loading pull request details" do
883
+ template_task = shipit_tasks(:shipit_pending)
884
+ deploy = template_task.stack.deploys.build(
885
+ since_commit: template_task.since_commit,
886
+ until_commit: template_task.until_commit,
887
+ )
888
+
889
+ Shipit.github.api.expects(:pull_request).with('shopify/shipit-engine', 7).raises(Octokit::NotFound)
890
+
891
+ expected_delta = 1 # Only the batch head
892
+ assert_difference -> { CommitDeployment.count }, expected_delta do
893
+ assert_difference -> { CommitDeploymentStatus.count }, expected_delta do
894
+ deploy.save!
895
+ end
896
+ end
897
+
898
+ refute_nil CommitDeployment.find_by(sha: deploy.until_commit.sha)
899
+ end
900
+
863
901
  private
864
902
 
865
903
  def expect_event(deploy)
@@ -116,7 +116,7 @@ module Shipit
116
116
  )
117
117
  end
118
118
 
119
- Shipit.github.api.expects(:statuses).with(@stack.github_repo_name, head_sha).returns([stub(
119
+ Shipit.github.api.expects(:statuses).with(@stack.github_repo_name, head_sha, per_page: 100).returns([stub(
120
120
  state: 'success',
121
121
  description: nil,
122
122
  context: 'default',
@@ -0,0 +1,76 @@
1
+ require 'test_helper'
2
+
3
+ module Shipit
4
+ class RepositoryTest < ActiveSupport::TestCase
5
+ setup do
6
+ @repository = shipit_repositories(:shipit)
7
+ end
8
+
9
+ test "owner, and name uniqueness is enforced" do
10
+ clone = Repository.new(@repository.attributes.except('id'))
11
+ refute clone.save
12
+ assert_equal ["cannot be used more than once"], clone.errors[:name]
13
+ end
14
+
15
+ test "owner, name, and environment can only be ASCII" do
16
+ @repository.update(owner: 'héllò', name: 'wørld')
17
+ refute_predicate @repository, :valid?
18
+ end
19
+
20
+ test "owner and name are case insensitive" do
21
+ assert_no_difference -> { Repository.count } do
22
+ error = assert_raises ActiveRecord::RecordInvalid do
23
+ Repository.create!(
24
+ owner: @repository.owner.upcase,
25
+ name: @repository.name.upcase,
26
+ )
27
+ end
28
+ assert_equal 'Validation failed: Name cannot be used more than once', error.message
29
+ end
30
+
31
+ new_repository = Repository.create!(owner: 'FOO', name: 'BAR')
32
+ assert_equal new_repository, Repository.find_by(owner: 'foo', name: 'bar')
33
+ end
34
+
35
+ test "owner is automatically downcased" do
36
+ @repository.owner = 'George'
37
+ assert_equal 'george', @repository.owner
38
+ end
39
+
40
+ test "name is automatically downcased" do
41
+ @repository.name = 'Cyclim.se'
42
+ assert_equal 'cyclim.se', @repository.name
43
+ end
44
+
45
+ test "owner cannot contain a `/`" do
46
+ assert @repository.valid?
47
+ @repository.owner = 'foo/bar'
48
+ refute @repository.valid?
49
+ end
50
+
51
+ test "name cannot contain a `/`" do
52
+ assert @repository.valid?
53
+ @repository.name = 'foo/bar'
54
+ refute @repository.valid?
55
+ end
56
+
57
+ test "http_url" do
58
+ assert_equal "https://github.com/#{@repository.owner}/#{@repository.name}", @repository.http_url
59
+ end
60
+
61
+ test "git_url" do
62
+ assert_equal "https://github.com/#{@repository.owner}/#{@repository.name}.git", @repository.git_url
63
+ end
64
+
65
+ test "from_github_repo_name" do
66
+ owner = "repository-owner"
67
+ name = "repository-name"
68
+ github_repo_name = [owner, name].join("/")
69
+ expected_repository = Repository.create(owner: owner, name: name)
70
+
71
+ found_repository = Repository.from_github_repo_name(github_repo_name)
72
+
73
+ assert_equal(expected_repository, found_repository)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ module Shipit
4
+ module Webhooks
5
+ class HandlersTest < ActiveSupport::TestCase
6
+ test 'custom handlers do not replace default shipit handlers' do
7
+ event = 'push'
8
+ mock_handler = mock
9
+ Shipit::Webhooks.register_handler(event, mock_handler)
10
+
11
+ assert_includes Shipit::Webhooks.for_event(event), mock_handler
12
+ assert_includes Shipit::Webhooks.for_event(event), Shipit::Webhooks::Handlers::PushHandler
13
+
14
+ Shipit::Webhooks.reset_handlers!
15
+ end
16
+
17
+ test "unknown events have no handlers" do
18
+ event = '_'
19
+
20
+ handlers = Shipit::Webhooks.for_event(event)
21
+
22
+ assert_equal [], handlers
23
+ end
24
+ end
25
+ end
26
+ end
@@ -9,43 +9,6 @@ module Shipit
9
9
  GithubHook.any_instance.stubs(:teardown!)
10
10
  end
11
11
 
12
- test "repo_owner, repo_name and environment uniqueness is enforced" do
13
- clone = Stack.new(@stack.attributes.except('id'))
14
- refute clone.save
15
- assert_equal ["cannot be used more than once with this environment"], clone.errors[:repo_name]
16
- end
17
-
18
- test "repo_owner, repo_name, and environment can only be ASCII" do
19
- @stack.update(repo_owner: 'héllò', repo_name: 'wørld', environment: 'pródüctïòn')
20
- refute_predicate @stack, :valid?
21
- end
22
-
23
- test "repo_owner and repo_name are case insensitive" do
24
- assert_no_difference -> { Stack.count } do
25
- error = assert_raises ActiveRecord::RecordInvalid do
26
- Stack.create!(
27
- repo_owner: @stack.repo_owner.upcase,
28
- repo_name: @stack.repo_name.upcase,
29
- environment: @stack.environment,
30
- )
31
- end
32
- assert_equal 'Validation failed: Repo name cannot be used more than once with this environment', error.message
33
- end
34
-
35
- new_stack = Stack.create!(repo_owner: 'FOO', repo_name: 'BAR')
36
- assert_equal new_stack, Stack.find_by(repo_owner: 'foo', repo_name: 'bar')
37
- end
38
-
39
- test "repo_owner is automatically downcased" do
40
- @stack.repo_owner = 'George'
41
- assert_equal 'george', @stack.repo_owner
42
- end
43
-
44
- test "repo_name is automatically downcased" do
45
- @stack.repo_name = 'Cyclim.se'
46
- assert_equal 'cyclim.se', @stack.repo_name
47
- end
48
-
49
12
  test "branch defaults to master" do
50
13
  @stack.branch = ""
51
14
  assert @stack.save
@@ -64,18 +27,6 @@ module Shipit
64
27
  assert_equal 'foo:bar', @stack.environment
65
28
  end
66
29
 
67
- test "repo_owner cannot contain a `/`" do
68
- assert @stack.valid?
69
- @stack.repo_owner = 'foo/bar'
70
- refute @stack.valid?
71
- end
72
-
73
- test "repo_name cannot contain a `/`" do
74
- assert @stack.valid?
75
- @stack.repo_name = 'foo/bar'
76
- refute @stack.valid?
77
- end
78
-
79
30
  test "repo_http_url" do
80
31
  assert_equal "https://github.com/#{@stack.repo_owner}/#{@stack.repo_name}", @stack.repo_http_url
81
32
  end
@@ -104,6 +55,30 @@ module Shipit
104
55
  assert_equal shipit_deploys(:shipit_complete).until_commit_id, deploy.since_commit_id
105
56
  end
106
57
 
58
+ test "#trigger_deploy emits a hook" do
59
+ original_receivers = Shipit.internal_hook_receivers
60
+
61
+ FakeReceiver = Module.new do
62
+ mattr_accessor :hooks
63
+ self.hooks = []
64
+
65
+ def self.deliver(event, stack, payload)
66
+ hooks << [event, stack, payload]
67
+ end
68
+ end
69
+ Shipit.internal_hook_receivers = [FakeReceiver]
70
+
71
+ last_commit = shipit_commits(:third)
72
+ deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
73
+ assert_includes FakeReceiver.hooks, [
74
+ :deploy,
75
+ @stack,
76
+ {deploy: deploy, status: "pending", stack: @stack},
77
+ ]
78
+ ensure
79
+ Shipit.internal_hook_receivers = original_receivers
80
+ end
81
+
107
82
  test "#trigger_deploy deploy until the commit passed in argument" do
108
83
  last_commit = shipit_commits(:third)
109
84
  deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
@@ -225,7 +200,7 @@ module Shipit
225
200
 
226
201
  test "#create queues a GithubSyncJob" do
227
202
  assert_enqueued_with(job: GithubSyncJob) do
228
- Stack.create!(repo_name: 'rails', repo_owner: 'rails')
203
+ Stack.create!(repository: shipit_repositories(:rails))
229
204
  end
230
205
  end
231
206
 
@@ -273,7 +248,10 @@ module Shipit
273
248
  end
274
249
 
275
250
  test ".run_deploy_in_foreground triggers a deploy" do
276
- stack = Stack.create!(repo_owner: 'foo', repo_name: 'bar', environment: 'production')
251
+ stack = Stack.create!(
252
+ repository: Repository.new(owner: "foo", name: "bar"),
253
+ environment: 'production',
254
+ )
277
255
  commit = shipit_commits(:first)
278
256
  stack.commits << commit
279
257
 
@@ -870,6 +848,21 @@ module Shipit
870
848
  )
871
849
  end
872
850
 
851
+ test "#trigger_continuous_delivery sets delay if commit was pushed recently" do
852
+ freeze_time do
853
+ @stack.tasks.delete_all
854
+
855
+ commit = @stack.next_commit_to_deploy
856
+ commit.touch(:created_at)
857
+
858
+ assert_no_enqueued_jobs(only: Shipit::PerformTaskJob) do
859
+ assert_no_difference -> { Deploy.count } do
860
+ @stack.trigger_continuous_delivery
861
+ end
862
+ end
863
+ end
864
+ end
865
+
873
866
  private
874
867
 
875
868
  def generate_revert_commit(stack:, reverted_commit:, author: reverted_commit.author)