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.
Files changed (274) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/shipit/api/cacheable.rb +13 -0
  3. data/app/controllers/concerns/shipit/api/paginable.rb +37 -0
  4. data/app/controllers/concerns/shipit/api/rendering.rb +25 -0
  5. data/app/controllers/concerns/{api/paginable.rb → shipit/pagination.rb} +5 -13
  6. data/app/controllers/shipit/api/base_controller.rb +68 -0
  7. data/app/controllers/shipit/api/deploys_controller.rb +17 -0
  8. data/app/controllers/shipit/api/hooks_controller.rb +53 -0
  9. data/app/controllers/shipit/api/locks_controller.rb +32 -0
  10. data/app/controllers/shipit/api/outputs_controller.rb +17 -0
  11. data/app/controllers/shipit/api/stacks_controller.rb +21 -0
  12. data/app/controllers/shipit/api/tasks_controller.rb +20 -0
  13. data/app/controllers/shipit/commit_checks_controller.rb +26 -0
  14. data/app/controllers/shipit/deploys_controller.rb +47 -0
  15. data/app/controllers/shipit/github_authentication_controller.rb +27 -0
  16. data/app/controllers/shipit/rollbacks_controller.rb +26 -0
  17. data/app/controllers/shipit/shipit_controller.rb +62 -0
  18. data/app/controllers/shipit/stacks_controller.rb +81 -0
  19. data/app/controllers/shipit/status_controller.rb +7 -0
  20. data/app/controllers/shipit/tasks_controller.rb +48 -0
  21. data/app/controllers/shipit/webhooks_controller.rb +101 -0
  22. data/app/helpers/shipit/chunks_helper.rb +8 -0
  23. data/app/helpers/shipit/deploys_helper.rb +28 -0
  24. data/app/helpers/shipit/github_url_helper.rb +48 -0
  25. data/app/helpers/shipit/shipit_helper.rb +64 -0
  26. data/app/helpers/shipit/stacks_helper.rb +78 -0
  27. data/app/helpers/shipit/tasks_helper.rb +11 -0
  28. data/app/jobs/shipit/background_job.rb +24 -0
  29. data/app/jobs/shipit/background_job/unique.rb +28 -0
  30. data/app/jobs/shipit/cache_deploy_spec_job.rb +12 -0
  31. data/app/jobs/shipit/chunk_rollup_job.rb +21 -0
  32. data/app/jobs/shipit/clear_git_cache_job.rb +9 -0
  33. data/app/jobs/shipit/deliver_hook_job.rb +9 -0
  34. data/app/jobs/shipit/destroy_stack_job.rb +9 -0
  35. data/app/jobs/shipit/emit_event_job.rb +10 -0
  36. data/app/jobs/shipit/fetch_commit_stats_job.rb +9 -0
  37. data/app/jobs/shipit/fetch_deployed_revision_job.rb +23 -0
  38. data/app/jobs/shipit/git_mirror_update_job.rb +12 -0
  39. data/app/jobs/shipit/github_sync_job.rb +55 -0
  40. data/app/jobs/shipit/perform_commit_checks_job.rb +7 -0
  41. data/app/jobs/shipit/perform_task_job.rb +57 -0
  42. data/app/jobs/shipit/refresh_github_user_job.rb +9 -0
  43. data/app/jobs/shipit/refresh_statuses_job.rb +14 -0
  44. data/app/jobs/shipit/setup_github_hook_job.rb +11 -0
  45. data/app/models/shipit/anonymous_user.rb +43 -0
  46. data/app/models/shipit/api_client.rb +44 -0
  47. data/app/models/shipit/commit.rb +209 -0
  48. data/app/models/shipit/commit_checks.rb +90 -0
  49. data/app/models/shipit/delivery.rb +47 -0
  50. data/app/models/shipit/deploy.rb +153 -0
  51. data/app/models/shipit/deploy_spec.rb +150 -0
  52. data/app/models/shipit/deploy_spec/bundler_discovery.rb +61 -0
  53. data/app/models/shipit/deploy_spec/capistrano_discovery.rb +29 -0
  54. data/app/models/shipit/deploy_spec/file_system.rb +64 -0
  55. data/app/models/shipit/deploy_spec/pypi_discovery.rb +34 -0
  56. data/app/models/shipit/deploy_spec/rubygems_discovery.rb +34 -0
  57. data/app/models/shipit/github_hook.rb +148 -0
  58. data/app/models/shipit/hook.rb +86 -0
  59. data/app/models/shipit/membership.rb +8 -0
  60. data/app/models/shipit/missing_status.rb +21 -0
  61. data/app/models/shipit/output_chunk.rb +11 -0
  62. data/app/models/shipit/rollback.rb +31 -0
  63. data/app/models/shipit/stack.rb +308 -0
  64. data/app/models/shipit/status.rb +44 -0
  65. data/app/models/shipit/status_group.rb +35 -0
  66. data/app/models/shipit/task.rb +201 -0
  67. data/app/models/shipit/task_definition.rb +38 -0
  68. data/app/models/shipit/team.rb +69 -0
  69. data/app/models/shipit/unknown_status.rb +43 -0
  70. data/app/models/shipit/user.rb +83 -0
  71. data/app/models/shipit/variable_definition.rb +21 -0
  72. data/app/serializers/concerns/shipit/conditional_attributes.rb +22 -0
  73. data/app/serializers/shipit/anonymous_user_serializer.rb +4 -0
  74. data/app/serializers/shipit/commit_serializer.rb +8 -0
  75. data/app/serializers/shipit/deploy_serializer.rb +15 -0
  76. data/app/serializers/shipit/hook_serializer.rb +12 -0
  77. data/app/serializers/shipit/rollback_serializer.rb +7 -0
  78. data/app/serializers/shipit/short_commit_serializer.rb +9 -0
  79. data/app/serializers/shipit/stack_serializer.rb +33 -0
  80. data/app/serializers/shipit/tail_task_serializer.rb +39 -0
  81. data/app/serializers/shipit/task_serializer.rb +30 -0
  82. data/app/serializers/shipit/user_serializer.rb +5 -0
  83. data/app/views/{commits → shipit/commits}/_commit.html.erb +1 -1
  84. data/app/views/{commits → shipit/commits}/_commit_author.html.erb +0 -0
  85. data/app/views/{deploys → shipit/deploys}/_checklist.html.erb +0 -0
  86. data/app/views/{deploys → shipit/deploys}/_checks.html.erb +0 -0
  87. data/app/views/{deploys → shipit/deploys}/_concurrent_deploy_warning.html.erb +0 -0
  88. data/app/views/{deploys → shipit/deploys}/_deploy.html.erb +1 -1
  89. data/app/views/{deploys → shipit/deploys}/_monitoring.html.erb +0 -0
  90. data/app/views/{deploys → shipit/deploys}/_summary.html.erb +0 -0
  91. data/app/views/{deploys → shipit/deploys}/new.html.erb +3 -3
  92. data/app/views/{deploys → shipit/deploys}/rollback.html.erb +2 -2
  93. data/app/views/{deploys → shipit/deploys}/show.html.erb +1 -1
  94. data/app/views/{github_authentication → shipit/github_authentication}/failed.html.erb +0 -0
  95. data/app/views/{stacks → shipit/stacks}/_header.html.erb +0 -0
  96. data/app/views/{stacks → shipit/stacks}/index.html.erb +0 -0
  97. data/app/views/{stacks → shipit/stacks}/new.html.erb +0 -0
  98. data/app/views/{stacks → shipit/stacks}/settings.html.erb +1 -1
  99. data/app/views/{stacks → shipit/stacks}/show.html.erb +2 -2
  100. data/app/views/{statuses → shipit/statuses}/_group.html.erb +1 -1
  101. data/app/views/{statuses → shipit/statuses}/_status.html.erb +0 -0
  102. data/app/views/{tasks → shipit/tasks}/_task.html.erb +1 -1
  103. data/app/views/{tasks → shipit/tasks}/_task_output.html.erb +1 -1
  104. data/app/views/{tasks → shipit/tasks}/index.html.erb +1 -1
  105. data/app/views/{tasks → shipit/tasks}/new.html.erb +1 -1
  106. data/app/views/{tasks → shipit/tasks}/show.html.erb +1 -1
  107. data/db/migrate/20160104151742_increase_tasks_type_size_back.rb +5 -0
  108. data/db/migrate/20160104151833_convert_sti_columns.rb +10 -0
  109. data/lib/shipit.rb +11 -10
  110. data/lib/shipit/command.rb +171 -0
  111. data/lib/shipit/commands.rb +25 -0
  112. data/lib/shipit/deploy_commands.rb +21 -0
  113. data/lib/shipit/engine.rb +3 -0
  114. data/lib/shipit/rollback_commands.rb +7 -0
  115. data/lib/shipit/stack_commands.rb +60 -0
  116. data/lib/shipit/task_commands.rb +68 -0
  117. data/lib/shipit/version.rb +1 -1
  118. data/lib/tasks/cron.rake +3 -3
  119. data/test/controllers/api/base_controller_test.rb +18 -14
  120. data/test/controllers/api/deploys_controller_test.rb +56 -52
  121. data/test/controllers/api/hooks_controller_test.rb +62 -58
  122. data/test/controllers/api/locks_controller_test.rb +38 -34
  123. data/test/controllers/api/outputs_controller_test.rb +15 -11
  124. data/test/controllers/api/stacks_controller_test.rb +56 -52
  125. data/test/controllers/api/tasks_controller_test.rb +30 -26
  126. data/test/controllers/commit_checks_controller_test.rb +29 -27
  127. data/test/controllers/deploys_controller_test.rb +68 -66
  128. data/test/controllers/github_authentication_controller_test.rb +9 -7
  129. data/test/controllers/rollbacks_controller_test.rb +43 -41
  130. data/test/controllers/stacks_controller_test.rb +131 -128
  131. data/test/controllers/status_controller_test.rb +8 -6
  132. data/test/controllers/tasks_controller_test.rb +70 -68
  133. data/test/controllers/webhooks_controller_test.rb +127 -125
  134. data/test/dummy/db/development.sqlite3 +0 -0
  135. data/test/dummy/db/schema.rb +2 -2
  136. data/test/dummy/db/seeds.rb +133 -131
  137. data/test/dummy/db/test.sqlite3 +0 -0
  138. data/test/fixtures/{api_clients.yml → shipit/api_clients.yml} +0 -0
  139. data/test/fixtures/{commits.yml → shipit/commits.yml} +0 -0
  140. data/test/fixtures/{deliveries.yml → shipit/deliveries.yml} +0 -0
  141. data/test/fixtures/{github_hooks.yml → shipit/github_hooks.yml} +4 -4
  142. data/test/fixtures/{hooks.yml → shipit/hooks.yml} +0 -0
  143. data/test/fixtures/{memberships.yml → shipit/memberships.yml} +0 -0
  144. data/test/fixtures/{output_chunks.yml → shipit/output_chunks.yml} +0 -0
  145. data/test/fixtures/{stacks.yml → shipit/stacks.yml} +0 -0
  146. data/test/fixtures/{statuses.yml → shipit/statuses.yml} +0 -0
  147. data/test/fixtures/{tasks.yml → shipit/tasks.yml} +8 -8
  148. data/test/fixtures/{teams.yml → shipit/teams.yml} +0 -0
  149. data/test/fixtures/{users.yml → shipit/users.yml} +0 -0
  150. data/test/helpers/api_helper.rb +1 -1
  151. data/test/helpers/fixture_aliases_helper.rb +4 -4
  152. data/test/jobs/cache_deploy_spec_job_test.rb +15 -13
  153. data/test/jobs/chunk_rollup_job_test.rb +30 -28
  154. data/test/jobs/deliver_hook_job_test.rb +11 -9
  155. data/test/jobs/destroy_stack_job_test.rb +11 -9
  156. data/test/jobs/emit_event_job_test.rb +10 -8
  157. data/test/jobs/fetch_commit_stats_job_test.rb +10 -8
  158. data/test/jobs/fetch_deployed_revision_job_test.rb +24 -22
  159. data/test/jobs/github_sync_job_test.rb +51 -49
  160. data/test/jobs/perform_task_job_test.rb +78 -76
  161. data/test/jobs/refresh_github_user_job_test.rb +10 -8
  162. data/test/jobs/refresh_status_job_test.rb +14 -12
  163. data/test/jobs/unique_job_test.rb +18 -15
  164. data/test/models/api_client_test.rb +20 -18
  165. data/test/models/commit_checks_test.rb +63 -61
  166. data/test/models/commits_test.rb +317 -314
  167. data/test/models/delivery_test.rb +29 -27
  168. data/test/models/deploys_test.rb +289 -287
  169. data/test/models/github_hook_test.rb +45 -43
  170. data/test/models/hook_test.rb +44 -42
  171. data/test/models/membership_test.rb +9 -7
  172. data/test/models/missing_status_test.rb +16 -14
  173. data/test/models/output_chunk_test.rb +14 -12
  174. data/test/models/rollbacks_test.rb +14 -12
  175. data/test/models/stacks_test.rb +272 -270
  176. data/test/models/status_group_test.rb +18 -16
  177. data/test/models/status_test.rb +42 -40
  178. data/test/models/task_definitions_test.rb +27 -25
  179. data/test/models/team_test.rb +39 -37
  180. data/test/models/users_test.rb +61 -59
  181. data/test/unit/command_test.rb +43 -41
  182. data/test/unit/commands_test.rb +8 -6
  183. data/test/unit/csv_serializer_test.rb +28 -26
  184. data/test/unit/deploy_commands_test.rb +179 -176
  185. data/test/unit/deploy_spec_test.rb +237 -235
  186. data/test/unit/github_url_helper_test.rb +19 -17
  187. data/test/unit/shipit_test.rb +44 -42
  188. metadata +139 -137
  189. data/app/controllers/api/base_controller.rb +0 -66
  190. data/app/controllers/api/deploys_controller.rb +0 -15
  191. data/app/controllers/api/hooks_controller.rb +0 -51
  192. data/app/controllers/api/locks_controller.rb +0 -30
  193. data/app/controllers/api/outputs_controller.rb +0 -15
  194. data/app/controllers/api/stacks_controller.rb +0 -19
  195. data/app/controllers/api/tasks_controller.rb +0 -18
  196. data/app/controllers/commit_checks_controller.rb +0 -24
  197. data/app/controllers/concerns/api/cacheable.rb +0 -11
  198. data/app/controllers/concerns/api/rendering.rb +0 -23
  199. data/app/controllers/concerns/pagination.rb +0 -25
  200. data/app/controllers/deploys_controller.rb +0 -45
  201. data/app/controllers/github_authentication_controller.rb +0 -25
  202. data/app/controllers/rollbacks_controller.rb +0 -24
  203. data/app/controllers/shipit_controller.rb +0 -54
  204. data/app/controllers/stacks_controller.rb +0 -79
  205. data/app/controllers/status_controller.rb +0 -5
  206. data/app/controllers/tasks_controller.rb +0 -46
  207. data/app/controllers/webhooks_controller.rb +0 -99
  208. data/app/helpers/chunks_helper.rb +0 -6
  209. data/app/helpers/deploys_helper.rb +0 -26
  210. data/app/helpers/github_url_helper.rb +0 -46
  211. data/app/helpers/shipit_helper.rb +0 -62
  212. data/app/helpers/stacks_helper.rb +0 -76
  213. data/app/helpers/tasks_helper.rb +0 -9
  214. data/app/jobs/background_job.rb +0 -22
  215. data/app/jobs/background_job/unique.rb +0 -26
  216. data/app/jobs/cache_deploy_spec_job.rb +0 -10
  217. data/app/jobs/chunk_rollup_job.rb +0 -19
  218. data/app/jobs/clear_git_cache_job.rb +0 -7
  219. data/app/jobs/deliver_hook_job.rb +0 -7
  220. data/app/jobs/destroy_stack_job.rb +0 -7
  221. data/app/jobs/emit_event_job.rb +0 -8
  222. data/app/jobs/fetch_commit_stats_job.rb +0 -7
  223. data/app/jobs/fetch_deployed_revision_job.rb +0 -21
  224. data/app/jobs/git_mirror_update_job.rb +0 -10
  225. data/app/jobs/github_sync_job.rb +0 -53
  226. data/app/jobs/perform_commit_checks_job.rb +0 -5
  227. data/app/jobs/perform_task_job.rb +0 -55
  228. data/app/jobs/refresh_github_user_job.rb +0 -7
  229. data/app/jobs/refresh_statuses_job.rb +0 -12
  230. data/app/jobs/setup_github_hook_job.rb +0 -9
  231. data/app/models/anonymous_user.rb +0 -41
  232. data/app/models/api_client.rb +0 -42
  233. data/app/models/commit.rb +0 -207
  234. data/app/models/commit_checks.rb +0 -88
  235. data/app/models/delivery.rb +0 -45
  236. data/app/models/deploy.rb +0 -151
  237. data/app/models/deploy_spec.rb +0 -148
  238. data/app/models/deploy_spec/bundler_discovery.rb +0 -59
  239. data/app/models/deploy_spec/capistrano_discovery.rb +0 -27
  240. data/app/models/deploy_spec/file_system.rb +0 -62
  241. data/app/models/deploy_spec/pypi_discovery.rb +0 -32
  242. data/app/models/deploy_spec/rubygems_discovery.rb +0 -32
  243. data/app/models/github_hook.rb +0 -144
  244. data/app/models/hook.rb +0 -84
  245. data/app/models/membership.rb +0 -6
  246. data/app/models/missing_status.rb +0 -18
  247. data/app/models/output_chunk.rb +0 -9
  248. data/app/models/rollback.rb +0 -29
  249. data/app/models/stack.rb +0 -306
  250. data/app/models/status.rb +0 -42
  251. data/app/models/status_group.rb +0 -33
  252. data/app/models/task.rb +0 -197
  253. data/app/models/task_definition.rb +0 -36
  254. data/app/models/team.rb +0 -67
  255. data/app/models/unknown_status.rb +0 -41
  256. data/app/models/user.rb +0 -81
  257. data/app/models/variable_definition.rb +0 -19
  258. data/app/serializers/anonymous_user_serializer.rb +0 -2
  259. data/app/serializers/commit_serializer.rb +0 -6
  260. data/app/serializers/concerns/conditional_attributes.rb +0 -20
  261. data/app/serializers/deploy_serializer.rb +0 -13
  262. data/app/serializers/hook_serializer.rb +0 -10
  263. data/app/serializers/rollback_serializer.rb +0 -5
  264. data/app/serializers/short_commit_serializer.rb +0 -7
  265. data/app/serializers/stack_serializer.rb +0 -31
  266. data/app/serializers/tail_task_serializer.rb +0 -37
  267. data/app/serializers/task_serializer.rb +0 -28
  268. data/app/serializers/user_serializer.rb +0 -3
  269. data/lib/command.rb +0 -169
  270. data/lib/commands.rb +0 -23
  271. data/lib/deploy_commands.rb +0 -19
  272. data/lib/rollback_commands.rb +0 -5
  273. data/lib/stack_commands.rb +0 -58
  274. data/lib/task_commands.rb +0 -66
@@ -1,37 +1,39 @@
1
1
  require 'test_helper'
2
2
 
3
- class DeliveryTest < ActiveSupport::TestCase
4
- setup do
5
- @hook = hooks(:shipit_deploys)
6
- @delivery = deliveries(:scheduled_shipit_deploy)
7
- end
3
+ module Shipit
4
+ class DeliveryTest < ActiveSupport::TestCase
5
+ setup do
6
+ @hook = shipit_hooks(:shipit_deploys)
7
+ @delivery = shipit_deliveries(:scheduled_shipit_deploy)
8
+ end
8
9
 
9
- test "#schedule! enqueue a DeliverHookJob and update the status to `scheduled`" do
10
- delivery = @hook.deliveries.create!(
11
- event: 'deploy',
12
- url: 'http://example.com',
13
- content_type: 'application/json',
14
- payload: '{}',
15
- )
16
- assert_equal 'pending', delivery.status
10
+ test "#schedule! enqueue a DeliverHookJob and update the status to `scheduled`" do
11
+ delivery = @hook.deliveries.create!(
12
+ event: 'deploy',
13
+ url: 'http://example.com',
14
+ content_type: 'application/json',
15
+ payload: '{}',
16
+ )
17
+ assert_equal 'pending', delivery.status
17
18
 
18
- assert_enqueued_with(job: DeliverHookJob, args: [delivery]) do
19
- delivery.schedule!
19
+ assert_enqueued_with(job: DeliverHookJob, args: [delivery]) do
20
+ delivery.schedule!
21
+ end
22
+ assert_equal 'scheduled', delivery.status
20
23
  end
21
- assert_equal 'scheduled', delivery.status
22
- end
23
24
 
24
- test "#send! post the payload and update the status to `sent`" do
25
- headers = {'content-type' => 'text/plain', 'content-length' => '2'}
26
- FakeWeb.register_uri(:post, @delivery.url, headers.merge(body: 'OK'))
25
+ test "#send! post the payload and update the status to `sent`" do
26
+ headers = {'content-type' => 'text/plain', 'content-length' => '2'}
27
+ FakeWeb.register_uri(:post, @delivery.url, headers.merge(body: 'OK'))
27
28
 
28
- assert_equal 'scheduled', @delivery.status
29
- @delivery.send!
29
+ assert_equal 'scheduled', @delivery.status
30
+ @delivery.send!
30
31
 
31
- assert_equal 'sent', @delivery.status
32
- assert_not_nil @delivery.delivered_at
33
- assert_equal 200, @delivery.response_code
34
- assert_equal headers, @delivery.response_headers
35
- assert_equal 'OK', @delivery.response_body
32
+ assert_equal 'sent', @delivery.status
33
+ assert_not_nil @delivery.delivered_at
34
+ assert_equal 200, @delivery.response_code
35
+ assert_equal headers, @delivery.response_headers
36
+ assert_equal 'OK', @delivery.response_body
37
+ end
36
38
  end
37
39
  end
@@ -1,392 +1,394 @@
1
1
  require 'test_helper'
2
2
 
3
- class DeploysTest < ActiveSupport::TestCase
4
- def setup
5
- @deploy = deploys(:shipit)
6
- @deploy.pid = 42
7
- @stack = stacks(:shipit)
8
- @user = users(:walrus)
9
- end
3
+ module Shipit
4
+ class DeploysTest < ActiveSupport::TestCase
5
+ def setup
6
+ @deploy = shipit_deploys(:shipit)
7
+ @deploy.pid = 42
8
+ @stack = shipit_stacks(:shipit)
9
+ @user = shipit_users(:walrus)
10
+ end
10
11
 
11
- test "#rollback? returns false" do
12
- refute @deploy.rollback?
13
- end
12
+ test "#rollback? returns false" do
13
+ refute @deploy.rollback?
14
+ end
14
15
 
15
- test "enqueue" do
16
- assert_enqueued_with(job: PerformTaskJob, args: [@deploy]) do
17
- @deploy.enqueue
16
+ test "enqueue" do
17
+ assert_enqueued_with(job: PerformTaskJob, args: [@deploy]) do
18
+ @deploy.enqueue
19
+ end
18
20
  end
19
- end
20
21
 
21
- test "enqueue when not persisted" do
22
- assert_raise(RuntimeError) { Deploy.new.enqueue }
23
- end
22
+ test "enqueue when not persisted" do
23
+ assert_raise(RuntimeError) { Deploy.new.enqueue }
24
+ end
24
25
 
25
- test "working_directory" do
26
- assert_equal File.join(@deploy.stack.deploys_path, @deploy.id.to_s), @deploy.working_directory
27
- end
26
+ test "working_directory" do
27
+ assert_equal File.join(@deploy.stack.deploys_path, @deploy.id.to_s), @deploy.working_directory
28
+ end
28
29
 
29
- test "#since_commit_id returns the database value if present" do
30
- @deploy.since_commit_id = 1
31
- assert_equal 1, @deploy.since_commit_id
32
- end
30
+ test "#since_commit_id returns the database value if present" do
31
+ @deploy.since_commit_id = 1
32
+ assert_equal 1, @deploy.since_commit_id
33
+ end
33
34
 
34
- test "#since_commit_id returns nil if stack_id isn't set" do
35
- deploy = Deploy.new
36
- assert_nil deploy.since_commit_id
37
- end
35
+ test "#since_commit_id returns nil if stack_id isn't set" do
36
+ deploy = Deploy.new
37
+ assert_nil deploy.since_commit_id
38
+ end
38
39
 
39
- test "#since_commit_id returns a default value if stack_id is set" do
40
- stack = stacks(:shipit)
41
- deploy = stack.deploys.new
42
- last = stack.deploys.success.last.until_commit_id
43
- assert_equal last, deploy.since_commit_id
44
- end
40
+ test "#since_commit_id returns a default value if stack_id is set" do
41
+ stack = shipit_stacks(:shipit)
42
+ deploy = stack.deploys.new
43
+ last = stack.deploys.success.last.until_commit_id
44
+ assert_equal last, deploy.since_commit_id
45
+ end
45
46
 
46
- test "#commits returns empty array if stack isn't set" do
47
- @deploy.expects(:stack).returns(nil)
48
- assert_equal [], @deploy.commits
49
- end
47
+ test "#commits returns empty array if stack isn't set" do
48
+ @deploy.expects(:stack).returns(nil)
49
+ assert_equal [], @deploy.commits
50
+ end
50
51
 
51
- test "additions and deletions are denormalized on before create" do
52
- stack = stacks(:shipit)
53
- first = commits(:first)
54
- third = commits(:third)
52
+ test "additions and deletions are denormalized on before create" do
53
+ stack = shipit_stacks(:shipit)
54
+ first = shipit_commits(:first)
55
+ third = shipit_commits(:third)
55
56
 
56
- deploy = stack.deploys.create!(
57
- since_commit: first,
58
- until_commit: third,
59
- )
57
+ deploy = stack.deploys.create!(
58
+ since_commit: first,
59
+ until_commit: third,
60
+ )
60
61
 
61
- assert_equal 13, deploy.additions
62
- assert_equal 65, deploy.deletions
63
- end
62
+ assert_equal 13, deploy.additions
63
+ assert_equal 65, deploy.deletions
64
+ end
64
65
 
65
- test "#commits returns the commits in the id range" do
66
- stack = stacks(:shipit)
67
- first = commits(:first)
68
- last = commits(:third)
66
+ test "#commits returns the commits in the id range" do
67
+ stack = shipit_stacks(:shipit)
68
+ first = shipit_commits(:first)
69
+ last = shipit_commits(:third)
69
70
 
70
- deploy = stack.deploys.new(
71
- since_commit: first,
72
- until_commit: last,
73
- )
71
+ deploy = stack.deploys.new(
72
+ since_commit: first,
73
+ until_commit: last,
74
+ )
74
75
 
75
- commits = deploy.commits
76
+ commits = deploy.commits
76
77
 
77
- assert_not_empty commits
78
- assert_equal last.id, commits.map(&:id).max
79
- assert_not_equal first.id, commits.map(&:id).min
80
- end
78
+ assert_not_empty commits
79
+ assert_equal last.id, commits.map(&:id).max
80
+ assert_not_equal first.id, commits.map(&:id).min
81
+ end
81
82
 
82
- test "#commits returns commits from newer to older" do
83
- stack = stacks(:shipit)
84
- first = commits(:first)
85
- last = commits(:fourth)
83
+ test "#commits returns commits from newer to older" do
84
+ stack = shipit_stacks(:shipit)
85
+ first = shipit_commits(:first)
86
+ last = shipit_commits(:fourth)
86
87
 
87
- deploy = stack.deploys.new(
88
- since_commit: first,
89
- until_commit: last,
90
- )
88
+ deploy = stack.deploys.new(
89
+ since_commit: first,
90
+ until_commit: last,
91
+ )
91
92
 
92
- assert_equal [4, 3, 2], deploy.commits.pluck(:id)
93
- end
93
+ assert_equal [4, 3, 2], deploy.commits.pluck(:id)
94
+ end
94
95
 
95
- test "transitioning to success causes an event to be broadcasted" do
96
- deploy = deploys(:shipit_pending)
96
+ test "transitioning to success causes an event to be broadcasted" do
97
+ deploy = shipit_deploys(:shipit_pending)
97
98
 
98
- expect_hook(:deploy, deploy.stack, status: 'success', deploy: deploy, stack: deploy.stack)
99
- expect_event(deploy)
100
- deploy.status = 'running'
101
- deploy.complete!
102
- end
99
+ expect_hook(:deploy, deploy.stack, status: 'success', deploy: deploy, stack: deploy.stack)
100
+ expect_event(deploy)
101
+ deploy.status = 'running'
102
+ deploy.complete!
103
+ end
103
104
 
104
- test "transitioning to failed causes an event to be broadcasted" do
105
- deploy = deploys(:shipit_pending)
105
+ test "transitioning to failed causes an event to be broadcasted" do
106
+ deploy = shipit_deploys(:shipit_pending)
106
107
 
107
- expect_hook(:deploy, deploy.stack, status: 'failed', deploy: deploy, stack: deploy.stack)
108
- expect_event(deploy)
109
- deploy.status = 'running'
110
- deploy.failure!
111
- end
108
+ expect_hook(:deploy, deploy.stack, status: 'failed', deploy: deploy, stack: deploy.stack)
109
+ expect_event(deploy)
110
+ deploy.status = 'running'
111
+ deploy.failure!
112
+ end
112
113
 
113
- test "transitioning to error causes an event to be broadcasted" do
114
- deploy = deploys(:shipit_pending)
114
+ test "transitioning to error causes an event to be broadcasted" do
115
+ deploy = shipit_deploys(:shipit_pending)
115
116
 
116
- expect_hook(:deploy, deploy.stack, status: 'error', deploy: deploy, stack: deploy.stack)
117
- expect_event(deploy)
118
- deploy.status = 'running'
119
- deploy.error!
120
- end
117
+ expect_hook(:deploy, deploy.stack, status: 'error', deploy: deploy, stack: deploy.stack)
118
+ expect_event(deploy)
119
+ deploy.status = 'running'
120
+ deploy.error!
121
+ end
121
122
 
122
- test "transitioning to running causes an event to be broadcasted" do
123
- deploy = deploys(:shipit_pending)
123
+ test "transitioning to running causes an event to be broadcasted" do
124
+ deploy = shipit_deploys(:shipit_pending)
124
125
 
125
- expect_hook(:deploy, deploy.stack, status: 'running', deploy: deploy, stack: deploy.stack)
126
- expect_event(deploy)
127
- deploy.status = 'pending'
128
- deploy.run!
129
- end
126
+ expect_hook(:deploy, deploy.stack, status: 'running', deploy: deploy, stack: deploy.stack)
127
+ expect_event(deploy)
128
+ deploy.status = 'pending'
129
+ deploy.run!
130
+ end
130
131
 
131
- test "creating a deploy causes an event to be broadcasted" do
132
- shipit = stacks(:shipit)
133
- deploy = shipit.deploys.build(
134
- since_commit: shipit.commits.first,
135
- until_commit: shipit.commits.last,
136
- )
132
+ test "creating a deploy causes an event to be broadcasted" do
133
+ shipit = shipit_stacks(:shipit)
134
+ deploy = shipit.deploys.build(
135
+ since_commit: shipit.commits.first,
136
+ until_commit: shipit.commits.last,
137
+ )
137
138
 
138
- expect_event(deploy)
139
- deploy.save!
140
- end
139
+ expect_event(deploy)
140
+ deploy.save!
141
+ end
141
142
 
142
- test "transitioning to success triggers next deploy when stack uses CD" do
143
- commits(:fifth).statuses.create!(state: 'success')
143
+ test "transitioning to success triggers next deploy when stack uses CD" do
144
+ shipit_commits(:fifth).statuses.create!(state: 'success')
144
145
 
145
- deploy = deploys(:shipit_running)
146
- deploy.stack.update(continuous_deployment: true)
146
+ deploy = shipit_deploys(:shipit_running)
147
+ deploy.stack.update(continuous_deployment: true)
147
148
 
148
- assert_difference "Deploy.count" do
149
- deploy.complete!
149
+ assert_difference "Deploy.count" do
150
+ deploy.complete!
151
+ end
150
152
  end
151
- end
152
153
 
153
- test "transitioning to success skips CD deploy when stack doesn't use it" do
154
- commits(:fifth).statuses.create!(state: 'success')
154
+ test "transitioning to success skips CD deploy when stack doesn't use it" do
155
+ shipit_commits(:fifth).statuses.create!(state: 'success')
155
156
 
156
- deploy = deploys(:shipit_running)
157
+ deploy = shipit_deploys(:shipit_running)
157
158
 
158
- assert_no_difference "Deploy.count" do
159
- deploy.complete!
159
+ assert_no_difference "Deploy.count" do
160
+ deploy.complete!
161
+ end
160
162
  end
161
- end
162
163
 
163
- test "transitioning to success skips CD when no successful commits after until_commit" do
164
- deploy = deploys(:shipit_running)
165
- deploy.stack.update(continuous_deployment: true)
164
+ test "transitioning to success skips CD when no successful commits after until_commit" do
165
+ deploy = shipit_deploys(:shipit_running)
166
+ deploy.stack.update(continuous_deployment: true)
166
167
 
167
- assert_no_difference "Deploy.count" do
168
- deploy.complete!
168
+ assert_no_difference "Deploy.count" do
169
+ deploy.complete!
170
+ end
169
171
  end
170
- end
171
172
 
172
- test "transitioning to success schedule a fetch of the deployed revision" do
173
- @deploy = deploys(:shipit_running)
174
- assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
175
- @deploy.complete!
173
+ test "transitioning to success schedule a fetch of the deployed revision" do
174
+ @deploy = shipit_deploys(:shipit_running)
175
+ assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
176
+ @deploy.complete!
177
+ end
176
178
  end
177
- end
178
179
 
179
- test "transitioning to failure schedule a fetch of the deployed revision" do
180
- @deploy = deploys(:shipit_running)
181
- assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
182
- @deploy.failure!
180
+ test "transitioning to failure schedule a fetch of the deployed revision" do
181
+ @deploy = shipit_deploys(:shipit_running)
182
+ assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
183
+ @deploy.failure!
184
+ end
183
185
  end
184
- end
185
186
 
186
- test "transitioning to error schedule a fetch of the deployed revision" do
187
- @deploy = deploys(:shipit_running)
188
- assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
189
- @deploy.error!
187
+ test "transitioning to error schedule a fetch of the deployed revision" do
188
+ @deploy = shipit_deploys(:shipit_running)
189
+ assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
190
+ @deploy.error!
191
+ end
190
192
  end
191
- end
192
193
 
193
- test "transitioning to aborted schedule a rollback if required" do
194
- @deploy = deploys(:shipit_running)
195
- @deploy.pid = 42
196
- @deploy.abort!(rollback_once_aborted: true)
194
+ test "transitioning to aborted schedule a rollback if required" do
195
+ @deploy = shipit_deploys(:shipit_running)
196
+ @deploy.pid = 42
197
+ @deploy.abort!(rollback_once_aborted: true)
197
198
 
198
- assert_difference -> { @stack.rollbacks.count }, 1 do
199
- assert_enqueued_with(job: PerformTaskJob) do
200
- @deploy.aborted!
199
+ assert_difference -> { @stack.rollbacks.count }, 1 do
200
+ assert_enqueued_with(job: PerformTaskJob) do
201
+ @deploy.aborted!
202
+ end
201
203
  end
202
204
  end
203
- end
204
205
 
205
- test "#build_rollback returns an unsaved record" do
206
- assert @deploy.build_rollback.new_record?
207
- end
208
-
209
- test "#build_rollback returns a rollback" do
210
- assert @deploy.build_rollback.rollback?
211
- end
206
+ test "#build_rollback returns an unsaved record" do
207
+ assert @deploy.build_rollback.new_record?
208
+ end
212
209
 
213
- test "#build_rollback set the id of the rollbacked deploy" do
214
- rollback = @deploy.build_rollback
215
- assert_equal @deploy.id, rollback.parent_id
216
- end
210
+ test "#build_rollback returns a rollback" do
211
+ assert @deploy.build_rollback.rollback?
212
+ end
217
213
 
218
- test "#build_rollback set the last_deployed_commit as the rollback since_commit" do
219
- rollback = @deploy.build_rollback
220
- assert_equal @stack.last_deployed_commit, rollback.since_commit
221
- end
214
+ test "#build_rollback set the id of the rollbacked deploy" do
215
+ rollback = @deploy.build_rollback
216
+ assert_equal @deploy.id, rollback.parent_id
217
+ end
222
218
 
223
- test "#trigger_rollback rolls the stack back to this deploy" do
224
- assert_equal commits(:fourth), @stack.last_deployed_commit
225
- rollback = @deploy.trigger_rollback
226
- rollback.run!
227
- rollback.complete!
228
- assert_equal commits(:second), @stack.last_deployed_commit
229
- end
219
+ test "#build_rollback set the last_deployed_commit as the rollback since_commit" do
220
+ rollback = @deploy.build_rollback
221
+ assert_equal @stack.last_deployed_commit, rollback.since_commit
222
+ end
230
223
 
231
- test "#trigger_revert rolls the stack back to before this deploy" do
232
- assert_equal commits(:fourth), @stack.last_deployed_commit
233
- rollback = @deploy.trigger_revert
234
- rollback.run!
235
- rollback.complete!
236
- assert_equal commits(:first), @stack.last_deployed_commit
237
- end
224
+ test "#trigger_rollback rolls the stack back to this deploy" do
225
+ assert_equal shipit_commits(:fourth), @stack.last_deployed_commit
226
+ rollback = @deploy.trigger_rollback
227
+ rollback.run!
228
+ rollback.complete!
229
+ assert_equal shipit_commits(:second), @stack.last_deployed_commit
230
+ end
238
231
 
239
- test "#trigger_rollback creates a new Rollback" do
240
- assert_difference -> { Rollback.count }, 1 do
241
- @deploy.trigger_rollback(@user)
232
+ test "#trigger_revert rolls the stack back to before this deploy" do
233
+ assert_equal shipit_commits(:fourth), @stack.last_deployed_commit
234
+ rollback = @deploy.trigger_revert
235
+ rollback.run!
236
+ rollback.complete!
237
+ assert_equal shipit_commits(:first), @stack.last_deployed_commit
242
238
  end
243
- end
244
239
 
245
- test "#trigger_rollback schedule the task" do
246
- Hook.expects(:emit).at_least_once
247
- assert_enqueued_with(job: PerformTaskJob) do
248
- @deploy.trigger_rollback(@user)
240
+ test "#trigger_rollback creates a new Rollback" do
241
+ assert_difference -> { Rollback.count }, 1 do
242
+ @deploy.trigger_rollback(@user)
243
+ end
249
244
  end
250
- end
251
245
 
252
- test "#trigger_rollback locks the stack" do
253
- refute @stack.locked?
254
- @deploy.trigger_rollback(@user)
255
- assert @stack.reload.locked?
256
- assert_equal @user, @stack.lock_author
257
- end
246
+ test "#trigger_rollback schedule the task" do
247
+ Hook.expects(:emit).at_least_once
248
+ assert_enqueued_with(job: PerformTaskJob) do
249
+ @deploy.trigger_rollback(@user)
250
+ end
251
+ end
258
252
 
259
- test "pid is persisted" do
260
- clone = Deploy.find(@deploy.id)
261
- assert_equal 42, clone.pid
262
- end
253
+ test "#trigger_rollback locks the stack" do
254
+ refute @stack.locked?
255
+ @deploy.trigger_rollback(@user)
256
+ assert @stack.reload.locked?
257
+ assert_equal @user, @stack.lock_author
258
+ end
263
259
 
264
- test "abort! transition to `aborting`" do
265
- @deploy.abort!
266
- assert_equal 'aborting', @deploy.status
267
- end
260
+ test "pid is persisted" do
261
+ clone = Deploy.find(@deploy.id)
262
+ assert_equal 42, clone.pid
263
+ end
268
264
 
269
- test "abort! schedule the rollback if `rollback_once_aborted` is true" do
270
- @deploy.abort!(rollback_once_aborted: true)
271
- assert @deploy.reload.rollback_once_aborted?
272
- end
265
+ test "abort! transition to `aborting`" do
266
+ @deploy.abort!
267
+ assert_equal 'aborting', @deploy.status
268
+ end
273
269
 
274
- test "abort! sends a SIGTERM to the recorded PID" do
275
- Process.expects(:kill).with('TERM', @deploy.pid)
276
- @deploy.abort!
277
- end
270
+ test "abort! schedule the rollback if `rollback_once_aborted` is true" do
271
+ @deploy.abort!(rollback_once_aborted: true)
272
+ assert @deploy.reload.rollback_once_aborted?
273
+ end
278
274
 
279
- test "abort! still succeeds if the process is already dead" do
280
- Process.expects(:kill).with('TERM', @deploy.pid).raises(Errno::ESRCH)
281
- assert_nothing_raised do
275
+ test "abort! sends a SIGTERM to the recorded PID" do
276
+ Process.expects(:kill).with('TERM', @deploy.pid)
282
277
  @deploy.abort!
283
278
  end
284
- end
285
279
 
286
- test "abort! transition to `aborted` if the process is already dead" do
287
- @deploy = deploys(:shipit_running)
288
- @deploy.pid = 42
280
+ test "abort! still succeeds if the process is already dead" do
281
+ Process.expects(:kill).with('TERM', @deploy.pid).raises(Errno::ESRCH)
282
+ assert_nothing_raised do
283
+ @deploy.abort!
284
+ end
285
+ end
289
286
 
290
- @deploy.abort!
291
- assert_equal 'aborting', @deploy.status
287
+ test "abort! transition to `aborted` if the process is already dead" do
288
+ @deploy = shipit_deploys(:shipit_running)
289
+ @deploy.pid = 42
292
290
 
293
- Process.expects(:kill).with('TERM', @deploy.pid).raises(Errno::ESRCH)
294
- @deploy.abort!
295
- assert_equal 'aborted', @deploy.status
296
- end
291
+ @deploy.abort!
292
+ assert_equal 'aborting', @deploy.status
297
293
 
298
- test "abort! bails out if the PID is nil" do
299
- Process.expects(:kill).never
300
- @deploy.pid = nil
301
- assert_nothing_raised do
294
+ Process.expects(:kill).with('TERM', @deploy.pid).raises(Errno::ESRCH)
302
295
  @deploy.abort!
296
+ assert_equal 'aborted', @deploy.status
303
297
  end
304
- end
305
298
 
306
- test "destroy deletes the related output chunks" do
307
- assert_difference -> { @deploy.chunks.count }, -@deploy.chunks.count do
308
- @deploy.destroy
299
+ test "abort! bails out if the PID is nil" do
300
+ Process.expects(:kill).never
301
+ @deploy.pid = nil
302
+ assert_nothing_raised do
303
+ @deploy.abort!
304
+ end
309
305
  end
310
- end
311
306
 
312
- test "#chunk_output joins all chunk test if logs not rolled up" do
313
- assert_equal @deploy.chunks.count, @deploy.chunks.count
314
- assert_equal @deploy.chunks.pluck(:text).join, @deploy.chunk_output
315
- refute @deploy.rolled_up
316
- end
307
+ test "destroy deletes the related output chunks" do
308
+ assert_difference -> { @deploy.chunks.count }, -@deploy.chunks.count do
309
+ @deploy.destroy
310
+ end
311
+ end
317
312
 
318
- test "#chunk_output returns logs from records if rolled up" do
319
- expected_output = @deploy.chunks.pluck(:text).join
320
- @deploy.rollup_chunks
313
+ test "#chunk_output joins all chunk test if logs not rolled up" do
314
+ assert_equal @deploy.chunks.count, @deploy.chunks.count
315
+ assert_equal @deploy.chunks.pluck(:text).join, @deploy.chunk_output
316
+ refute @deploy.rolled_up
317
+ end
318
+
319
+ test "#chunk_output returns logs from records if rolled up" do
320
+ expected_output = @deploy.chunks.pluck(:text).join
321
+ @deploy.rollup_chunks
321
322
 
322
- assert_no_queries do
323
- assert_equal expected_output, @deploy.chunk_output
324
- assert @deploy.rolled_up
323
+ assert_no_queries do
324
+ assert_equal expected_output, @deploy.chunk_output
325
+ assert @deploy.rolled_up
326
+ end
325
327
  end
326
- end
327
328
 
328
- test "#accept! bails out if the deploy is successful already" do
329
- assert_predicate @deploy, :success?
329
+ test "#accept! bails out if the deploy is successful already" do
330
+ assert_predicate @deploy, :success?
331
+
332
+ Deploy::CONFIRMATIONS_REQUIRED.times do
333
+ @deploy.accept!
334
+ assert_predicate @deploy, :success?
335
+ end
336
+ end
337
+
338
+ test "#accept! first transition to flapping then ultimately to success if the deploy was failed" do
339
+ @deploy = shipit_deploys(:shipit2)
340
+ assert_predicate @deploy, :failed?
341
+
342
+ (Deploy::CONFIRMATIONS_REQUIRED - 1).times do
343
+ @deploy.accept!
344
+ assert_predicate @deploy, :flapping?
345
+ end
330
346
 
331
- Deploy::CONFIRMATIONS_REQUIRED.times do
332
347
  @deploy.accept!
333
348
  assert_predicate @deploy, :success?
334
349
  end
335
- end
336
350
 
337
- test "#accept! first transition to flapping then ultimately to success if the deploy was failed" do
338
- @deploy = deploys(:shipit2)
339
- assert_predicate @deploy, :failed?
351
+ test "#reject! bails out if the deploy is failed already" do
352
+ @deploy = shipit_deploys(:shipit2)
353
+ assert_predicate @deploy, :failed?
340
354
 
341
- (Deploy::CONFIRMATIONS_REQUIRED - 1).times do
342
- @deploy.accept!
343
- assert_predicate @deploy, :flapping?
355
+ Deploy::CONFIRMATIONS_REQUIRED.times do
356
+ @deploy.reject!
357
+ assert_predicate @deploy, :failed?
358
+ end
344
359
  end
345
360
 
346
- @deploy.accept!
347
- assert_predicate @deploy, :success?
348
- end
361
+ test "#reject! first transition to flapping then ultimately to failed if the deploy was successful" do
362
+ assert_predicate @deploy, :success?
349
363
 
350
- test "#reject! bails out if the deploy is failed already" do
351
- @deploy = deploys(:shipit2)
352
- assert_predicate @deploy, :failed?
364
+ (Deploy::CONFIRMATIONS_REQUIRED - 1).times do
365
+ @deploy.reject!
366
+ assert_predicate @deploy, :flapping?
367
+ end
353
368
 
354
- Deploy::CONFIRMATIONS_REQUIRED.times do
355
369
  @deploy.reject!
356
370
  assert_predicate @deploy, :failed?
357
371
  end
358
- end
359
-
360
- test "#reject! first transition to flapping then ultimately to failed if the deploy was successful" do
361
- assert_predicate @deploy, :success?
362
372
 
363
- (Deploy::CONFIRMATIONS_REQUIRED - 1).times do
364
- @deploy.reject!
373
+ test "entering flapping state triggers webhooks" do
374
+ assert_enqueued_with job: EmitEventJob do
375
+ @deploy.reject!
376
+ end
365
377
  assert_predicate @deploy, :flapping?
366
378
  end
367
379
 
368
- @deploy.reject!
369
- assert_predicate @deploy, :failed?
370
- end
380
+ private
371
381
 
372
- test "entering flapping state triggers webhooks" do
373
- assert_enqueued_with job: EmitEventJob do
374
- @deploy.reject!
382
+ def expect_event(deploy)
383
+ Pubsubstub::RedisPubSub.expects(:publish).at_least_once
384
+ Pubsubstub::RedisPubSub.expects(:publish).with do |channel, event|
385
+ data = JSON.load(event.data)
386
+ channel == "stack.#{deploy.stack.id}" && data['url'] == "/#{deploy.stack.to_param}"
387
+ end
375
388
  end
376
- assert_predicate @deploy, :flapping?
377
- end
378
389
 
379
- private
380
-
381
- def expect_event(deploy)
382
- Pubsubstub::RedisPubSub.expects(:publish).at_least_once
383
- Pubsubstub::RedisPubSub.expects(:publish).with do |channel, event|
384
- data = JSON.load(event.data)
385
- channel == "stack.#{deploy.stack.id}" && data['url'] == "/#{deploy.stack.to_param}"
390
+ def expect_hook(event, stack, payload)
391
+ Hook.expects(:emit).with(event, stack, payload)
386
392
  end
387
393
  end
388
-
389
- def expect_hook(event, stack, payload)
390
- Hook.expects(:emit).with(event, stack, payload)
391
- end
392
394
  end