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,54 +1,56 @@
1
1
  require 'test_helper'
2
2
 
3
- class GithubHookTest < ActiveSupport::TestCase
4
- def setup
5
- @stack = stacks(:shipit)
6
- @hook = github_hooks(:shipit_push)
7
- end
3
+ module Shipit
4
+ class GithubHookTest < ActiveSupport::TestCase
5
+ def setup
6
+ @stack = shipit_stacks(:shipit)
7
+ @hook = shipit_github_hooks(:shipit_push)
8
+ end
8
9
 
9
- test "#verify_signature is true if the signature matches" do
10
- assert @hook.verify_signature('sha1=9fb52fecc2b97b7a912aca27685149d2ce571900', 'hello shipit')
11
- end
10
+ test "#verify_signature is true if the signature matches" do
11
+ assert @hook.verify_signature('sha1=9fb52fecc2b97b7a912aca27685149d2ce571900', 'hello shipit')
12
+ end
12
13
 
13
- test "#verify_signature is false if the signature doesn't match" do
14
- refute @hook.verify_signature('sha1=9fb52fecc2b97b7a912aca27685149d2ce571900', 'hello toto')
15
- end
14
+ test "#verify_signature is false if the signature doesn't match" do
15
+ refute @hook.verify_signature('sha1=9fb52fecc2b97b7a912aca27685149d2ce571900', 'hello toto')
16
+ end
16
17
 
17
- test "#setup! create the hook on Github side" do
18
- @hook = github_hooks(:cyclimse_push)
18
+ test "#setup! create the hook on Github side" do
19
+ @hook = shipit_github_hooks(:cyclimse_push)
19
20
 
20
- response = mock(id: 44, rels: {self: mock(href: 'https://api.github.com/somestuff')})
21
- Shipit.github_api.expects(:create_hook).with(
22
- @hook.github_repo_name,
23
- 'web',
24
- includes(:url, :content_type, :secret),
25
- includes(:events, :active),
26
- ).returns(response)
27
- @hook.setup!
28
- @hook.reload
29
- assert_equal 44, @hook.github_id
30
- assert_equal 'https://api.github.com/somestuff', @hook.api_url
31
- end
21
+ response = mock(id: 44, rels: {self: mock(href: 'https://api.github.com/somestuff')})
22
+ Shipit.github_api.expects(:create_hook).with(
23
+ @hook.github_repo_name,
24
+ 'web',
25
+ includes(:url, :content_type, :secret),
26
+ includes(:events, :active),
27
+ ).returns(response)
28
+ @hook.setup!
29
+ @hook.reload
30
+ assert_equal 44, @hook.github_id
31
+ assert_equal 'https://api.github.com/somestuff', @hook.api_url
32
+ end
32
33
 
33
- test "#setup! update the hook it it already exist" do
34
- response = mock(id: 44, rels: {self: mock(href: 'https://api.github.com/somestuff')})
35
- Shipit.github_api.expects(:edit_hook).with(
36
- @hook.github_repo_name,
37
- @hook.github_id,
38
- 'web',
39
- includes(:url, :content_type, :secret),
40
- includes(:events, :active),
41
- ).returns(response)
42
- @hook.setup!
43
- @hook.reload
44
- assert_equal 44, @hook.github_id
45
- assert_equal 'https://api.github.com/somestuff', @hook.api_url
46
- end
34
+ test "#setup! update the hook it it already exist" do
35
+ response = mock(id: 44, rels: {self: mock(href: 'https://api.github.com/somestuff')})
36
+ Shipit.github_api.expects(:edit_hook).with(
37
+ @hook.github_repo_name,
38
+ @hook.github_id,
39
+ 'web',
40
+ includes(:url, :content_type, :secret),
41
+ includes(:events, :active),
42
+ ).returns(response)
43
+ @hook.setup!
44
+ @hook.reload
45
+ assert_equal 44, @hook.github_id
46
+ assert_equal 'https://api.github.com/somestuff', @hook.api_url
47
+ end
47
48
 
48
- test "#destroy starts by removing the hook" do
49
- Shipit.github_api.expects(:remove_hook).with(@hook.github_repo_name, @hook.github_id)
50
- assert_difference -> { GithubHook.count }, -1 do
51
- @hook.destroy!
49
+ test "#destroy starts by removing the hook" do
50
+ Shipit.github_api.expects(:remove_hook).with(@hook.github_repo_name, @hook.github_id)
51
+ assert_difference -> { GithubHook.count }, -1 do
52
+ @hook.destroy!
53
+ end
52
54
  end
53
55
  end
54
56
  end
@@ -1,57 +1,59 @@
1
1
  require 'test_helper'
2
2
 
3
- class HookTest < ActiveSupport::TestCase
4
- setup do
5
- @stack = stacks(:shipit)
6
- @hook = hooks(:shipit_deploys)
7
- end
8
-
9
- test "#url must be valid" do
10
- @hook.url = 'file:/ad"fa/adfa'
11
- refute @hook.valid?
12
- assert_equal ['Url is not a valid URL'], @hook.errors.full_messages
13
- end
3
+ module Shipit
4
+ class HookTest < ActiveSupport::TestCase
5
+ setup do
6
+ @stack = shipit_stacks(:shipit)
7
+ @hook = shipit_hooks(:shipit_deploys)
8
+ end
14
9
 
15
- test "#url must not be localhost" do
16
- @hook.url = 'file:///etc/passwd'
17
- refute @hook.valid?
18
- assert_equal ['Url is not a valid URL'], @hook.errors.full_messages
19
- end
10
+ test "#url must be valid" do
11
+ @hook.url = 'file:/ad"fa/adfa'
12
+ refute @hook.valid?
13
+ assert_equal ['Url is not a valid URL'], @hook.errors.full_messages
14
+ end
20
15
 
21
- test "#events is accessible as an array" do
22
- assert_equal %w(deploy rollback), @hook.events
23
- end
16
+ test "#url must not be localhost" do
17
+ @hook.url = 'file:///etc/passwd'
18
+ refute @hook.valid?
19
+ assert_equal ['Url is not a valid URL'], @hook.errors.full_messages
20
+ end
24
21
 
25
- test "#events can only contain a defined set of values" do
26
- @hook.events = %w(foo)
27
- refute @hook.valid?
28
- assert_equal ["Events is not a strict subset of #{Hook::EVENTS.inspect}"], @hook.errors.full_messages
29
- end
22
+ test "#events is accessible as an array" do
23
+ assert_equal %w(deploy rollback), @hook.events
24
+ end
30
25
 
31
- test ".emit enqueues an EmitEventJob with the proper payload" do
32
- assert_enqueued_with(job: EmitEventJob) do
33
- Hook.emit(:deploy, @stack, foo: 42)
26
+ test "#events can only contain a defined set of values" do
27
+ @hook.events = %w(foo)
28
+ refute @hook.valid?
29
+ assert_equal ["Events is not a strict subset of #{Hook::EVENTS.inspect}"], @hook.errors.full_messages
34
30
  end
35
- end
36
31
 
37
- test ".deliver schedules a delivery for each matching hook" do
38
- assert_difference -> { Delivery.count }, 2 do
39
- Hook.deliver(:deploy, @stack, 'foo' => 42)
32
+ test ".emit enqueues an EmitEventJob with the proper payload" do
33
+ assert_enqueued_with(job: EmitEventJob) do
34
+ Hook.emit(:deploy, @stack, foo: 42)
35
+ end
40
36
  end
41
37
 
42
- delivery = Delivery.last
38
+ test ".deliver schedules a delivery for each matching hook" do
39
+ assert_difference -> { Delivery.count }, 2 do
40
+ Hook.deliver(:deploy, @stack, 'foo' => 42)
41
+ end
43
42
 
44
- assert_equal @hook.url, delivery.url
45
- assert_equal 'application/x-www-form-urlencoded', delivery.content_type
46
- assert_equal 'foo=42', delivery.payload
47
- assert_equal 'scheduled', delivery.status
48
- end
43
+ delivery = Delivery.last
49
44
 
50
- test ".scoped? returns true if the hook has a stack_id" do
51
- @hook.stack_id = nil
52
- refute @hook.scoped?
45
+ assert_equal @hook.url, delivery.url
46
+ assert_equal 'application/x-www-form-urlencoded', delivery.content_type
47
+ assert_equal 'foo=42', delivery.payload
48
+ assert_equal 'scheduled', delivery.status
49
+ end
50
+
51
+ test ".scoped? returns true if the hook has a stack_id" do
52
+ @hook.stack_id = nil
53
+ refute @hook.scoped?
53
54
 
54
- @hook.stack_id = 42
55
- assert @hook.scoped?
55
+ @hook.stack_id = 42
56
+ assert @hook.scoped?
57
+ end
56
58
  end
57
59
  end
@@ -1,12 +1,14 @@
1
1
  require 'test_helper'
2
2
 
3
- class MembershipTest < ActiveSupport::TestCase
4
- setup do
5
- @membership = memberships(:walrus_shopify_developers)
6
- end
3
+ module Shipit
4
+ class MembershipTest < ActiveSupport::TestCase
5
+ setup do
6
+ @membership = shipit_memberships(:walrus_shopify_developers)
7
+ end
7
8
 
8
- test "no duplicates are accepted" do
9
- membership = Membership.new(user: @membership.user, team: @membership.team)
10
- refute membership.valid?
9
+ test "no duplicates are accepted" do
10
+ membership = Membership.new(user: @membership.user, team: @membership.team)
11
+ refute membership.valid?
12
+ end
11
13
  end
12
14
  end
@@ -1,21 +1,23 @@
1
1
  require 'test_helper'
2
2
 
3
- class MissingStatusTest < ActiveSupport::TestCase
4
- setup do
5
- @real_status = statuses(:first_pending)
6
- @status = MissingStatus.new(@real_status, %w(ci/very-important style/very-important-too))
7
- end
3
+ module Shipit
4
+ class MissingStatusTest < ActiveSupport::TestCase
5
+ setup do
6
+ @real_status = shipit_statuses(:first_pending)
7
+ @status = MissingStatus.new(@real_status, %w(ci/very-important style/very-important-too))
8
+ end
8
9
 
9
- test "#state is 'missing'" do
10
- assert_equal 'missing', @status.state
11
- end
10
+ test "#state is 'missing'" do
11
+ assert_equal 'missing', @status.state
12
+ end
12
13
 
13
- test "#description explains the situation" do
14
- message = 'ci/very-important and style/very-important-too are required for deploy but were not sent'
15
- assert_equal message, @status.description
16
- end
14
+ test "#description explains the situation" do
15
+ message = 'ci/very-important and style/very-important-too are required for deploy but were not sent'
16
+ assert_equal message, @status.description
17
+ end
17
18
 
18
- test "#success? is false" do
19
- refute_predicate @status, :success?
19
+ test "#success? is false" do
20
+ refute_predicate @status, :success?
21
+ end
20
22
  end
21
23
  end
@@ -1,18 +1,20 @@
1
1
  require 'test_helper'
2
2
 
3
- class OutputChunkTest < ActiveSupport::TestCase
4
- def setup
5
- @deploy = deploys(:shipit)
6
- @chunks = 3.times.map { OutputChunk.create!(text: 'bla', task: @deploy) }
7
- end
3
+ module Shipit
4
+ class OutputChunkTest < ActiveSupport::TestCase
5
+ def setup
6
+ @deploy = shipit_deploys(:shipit)
7
+ @chunks = 3.times.map { OutputChunk.create!(text: 'bla', task: @deploy) }
8
+ end
8
9
 
9
- test "tail" do
10
- start = @chunks.first
11
- rest = @chunks - [start]
12
- assert_equal rest, @deploy.chunks.tail(start.id)
13
- end
10
+ test "tail" do
11
+ start = @chunks.first
12
+ rest = @chunks - [start]
13
+ assert_equal rest, @deploy.chunks.tail(start.id)
14
+ end
14
15
 
15
- test "tail without start" do
16
- assert_equal @deploy.chunks, @deploy.chunks.tail(nil)
16
+ test "tail without start" do
17
+ assert_equal @deploy.chunks, @deploy.chunks.tail(nil)
18
+ end
17
19
  end
18
20
  end
@@ -1,19 +1,21 @@
1
1
  require 'test_helper'
2
2
 
3
- class RollbackTest < ActiveSupport::TestCase
4
- setup do
5
- @rollback = Rollback.new
6
- end
3
+ module Shipit
4
+ class RollbackTest < ActiveSupport::TestCase
5
+ setup do
6
+ @rollback = Rollback.new
7
+ end
7
8
 
8
- test "#rollback? returns true" do
9
- assert @rollback.rollback?
10
- end
9
+ test "#rollback? returns true" do
10
+ assert @rollback.rollback?
11
+ end
11
12
 
12
- test "#rollbackable? returns false" do
13
- refute @rollback.rollbackable?
14
- end
13
+ test "#rollbackable? returns false" do
14
+ refute @rollback.rollbackable?
15
+ end
15
16
 
16
- test "#supports_rollback? returns false" do
17
- refute @rollback.supports_rollback?
17
+ test "#supports_rollback? returns false" do
18
+ refute @rollback.supports_rollback?
19
+ end
18
20
  end
19
21
  end
@@ -1,354 +1,356 @@
1
1
  require 'test_helper'
2
2
 
3
- class StacksTest < ActiveSupport::TestCase
4
- def setup
5
- @stack = stacks(:shipit)
6
- @expected_base_path = Rails.root.join('data/stacks', @stack.to_param).to_s
7
- GithubHook.any_instance.stubs(:teardown!)
8
- end
3
+ module Shipit
4
+ class StacksTest < ActiveSupport::TestCase
5
+ def setup
6
+ @stack = shipit_stacks(:shipit)
7
+ @expected_base_path = Rails.root.join('data/stacks', @stack.to_param).to_s
8
+ GithubHook.any_instance.stubs(:teardown!)
9
+ end
9
10
 
10
- test "repo_owner, repo_name and environment uniqueness is enforced" do
11
- clone = Stack.new(@stack.attributes.except('id'))
12
- refute clone.save
13
- assert_equal ["has already been taken"], clone.errors[:repo_name]
14
- end
11
+ test "repo_owner, repo_name and environment uniqueness is enforced" do
12
+ clone = Stack.new(@stack.attributes.except('id'))
13
+ refute clone.save
14
+ assert_equal ["has already been taken"], clone.errors[:repo_name]
15
+ end
15
16
 
16
- test "repo_owner, repo_name, and environment can only be ASCII" do
17
- @stack.update(repo_owner: 'héllò', repo_name: 'wørld', environment: 'pródüctïòn')
18
- refute_predicate @stack, :valid?
19
- end
17
+ test "repo_owner, repo_name, and environment can only be ASCII" do
18
+ @stack.update(repo_owner: 'héllò', repo_name: 'wørld', environment: 'pródüctïòn')
19
+ refute_predicate @stack, :valid?
20
+ end
20
21
 
21
- test "repo_owner is automatically downcased" do
22
- @stack.repo_owner = 'George'
23
- assert_equal 'george', @stack.repo_owner
24
- end
22
+ test "repo_owner is automatically downcased" do
23
+ @stack.repo_owner = 'George'
24
+ assert_equal 'george', @stack.repo_owner
25
+ end
25
26
 
26
- test "repo_name is automatically downcased" do
27
- @stack.repo_name = 'Cyclim.se'
28
- assert_equal 'cyclim.se', @stack.repo_name
29
- end
27
+ test "repo_name is automatically downcased" do
28
+ @stack.repo_name = 'Cyclim.se'
29
+ assert_equal 'cyclim.se', @stack.repo_name
30
+ end
30
31
 
31
- test "branch defaults to master" do
32
- @stack.branch = ""
33
- assert @stack.save
34
- assert_equal 'master', @stack.branch
35
- end
32
+ test "branch defaults to master" do
33
+ @stack.branch = ""
34
+ assert @stack.save
35
+ assert_equal 'master', @stack.branch
36
+ end
36
37
 
37
- test "environment defaults to production" do
38
- @stack.environment = ""
39
- assert @stack.save
40
- assert_equal 'production', @stack.environment
41
- end
38
+ test "environment defaults to production" do
39
+ @stack.environment = ""
40
+ assert @stack.save
41
+ assert_equal 'production', @stack.environment
42
+ end
42
43
 
43
- test "environment can contain a `:`" do
44
- @stack.environment = 'foo:bar'
45
- assert @stack.save
46
- assert_equal 'foo:bar', @stack.environment
47
- end
44
+ test "environment can contain a `:`" do
45
+ @stack.environment = 'foo:bar'
46
+ assert @stack.save
47
+ assert_equal 'foo:bar', @stack.environment
48
+ end
48
49
 
49
- test "repo_owner cannot contain a `/`" do
50
- assert @stack.valid?
51
- @stack.repo_owner = 'foo/bar'
52
- refute @stack.valid?
53
- end
50
+ test "repo_owner cannot contain a `/`" do
51
+ assert @stack.valid?
52
+ @stack.repo_owner = 'foo/bar'
53
+ refute @stack.valid?
54
+ end
54
55
 
55
- test "repo_name cannot contain a `/`" do
56
- assert @stack.valid?
57
- @stack.repo_name = 'foo/bar'
58
- refute @stack.valid?
59
- end
56
+ test "repo_name cannot contain a `/`" do
57
+ assert @stack.valid?
58
+ @stack.repo_name = 'foo/bar'
59
+ refute @stack.valid?
60
+ end
60
61
 
61
- test "repo_http_url" do
62
- assert_equal "https://github.com/#{@stack.repo_owner}/#{@stack.repo_name}", @stack.repo_http_url
63
- end
62
+ test "repo_http_url" do
63
+ assert_equal "https://github.com/#{@stack.repo_owner}/#{@stack.repo_name}", @stack.repo_http_url
64
+ end
64
65
 
65
- test "repo_git_url" do
66
- assert_equal "git@github.com:#{@stack.repo_owner}/#{@stack.repo_name}.git", @stack.repo_git_url
67
- end
66
+ test "repo_git_url" do
67
+ assert_equal "git@github.com:#{@stack.repo_owner}/#{@stack.repo_name}.git", @stack.repo_git_url
68
+ end
68
69
 
69
- test "base_path" do
70
- assert_equal @expected_base_path, @stack.base_path.to_s
71
- end
70
+ test "base_path" do
71
+ assert_equal @expected_base_path, @stack.base_path.to_s
72
+ end
72
73
 
73
- test "deploys_path" do
74
- assert_equal File.join(@expected_base_path, "deploys"), @stack.deploys_path.to_s
75
- end
74
+ test "deploys_path" do
75
+ assert_equal File.join(@expected_base_path, "deploys"), @stack.deploys_path.to_s
76
+ end
76
77
 
77
- test "git_path" do
78
- assert_equal File.join(@expected_base_path, "git"), @stack.git_path.to_s
79
- end
78
+ test "git_path" do
79
+ assert_equal File.join(@expected_base_path, "git"), @stack.git_path.to_s
80
+ end
80
81
 
81
- test "#trigger_deploy persist a new deploy" do
82
- last_commit = commits(:third)
83
- deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
84
- assert deploy.persisted?
85
- assert_equal last_commit.id, deploy.until_commit_id
86
- assert_equal deploys(:shipit_complete).until_commit_id, deploy.since_commit_id
87
- end
82
+ test "#trigger_deploy persist a new deploy" do
83
+ last_commit = shipit_commits(:third)
84
+ deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
85
+ assert deploy.persisted?
86
+ assert_equal last_commit.id, deploy.until_commit_id
87
+ assert_equal shipit_deploys(:shipit_complete).until_commit_id, deploy.since_commit_id
88
+ end
88
89
 
89
- test "#trigger_deploy deploy until the commit passed in argument" do
90
- last_commit = commits(:third)
91
- deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
92
- assert_equal last_commit.id, deploy.until_commit_id
93
- end
90
+ test "#trigger_deploy deploy until the commit passed in argument" do
91
+ last_commit = shipit_commits(:third)
92
+ deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
93
+ assert_equal last_commit.id, deploy.until_commit_id
94
+ end
94
95
 
95
- test "#trigger_deploy since_commit is the last completed deploy until_commit if there is a previous deploy" do
96
- last_commit = commits(:fifth)
97
- deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
98
- assert_equal deploys(:shipit_complete).until_commit_id, deploy.since_commit_id
99
- end
96
+ test "#trigger_deploy since_commit is the last completed deploy until_commit if there is a previous deploy" do
97
+ last_commit = shipit_commits(:fifth)
98
+ deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
99
+ assert_equal shipit_deploys(:shipit_complete).until_commit_id, deploy.since_commit_id
100
+ end
100
101
 
101
- test "#trigger_deploy since_commit is the first stack commit if there is no previous deploy" do
102
- @stack.deploys.destroy_all
102
+ test "#trigger_deploy since_commit is the first stack commit if there is no previous deploy" do
103
+ @stack.deploys.destroy_all
103
104
 
104
- last_commit = commits(:third)
105
- deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
106
- assert_equal @stack.commits.first.id, deploy.since_commit_id
107
- end
105
+ last_commit = shipit_commits(:third)
106
+ deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
107
+ assert_equal @stack.commits.first.id, deploy.since_commit_id
108
+ end
108
109
 
109
- test "#trigger_deploy enqueue a deploy job" do
110
- @stack.deploys.destroy_all
111
- Deploy.any_instance.expects(:enqueue).once
110
+ test "#trigger_deploy enqueue a deploy job" do
111
+ @stack.deploys.destroy_all
112
+ Deploy.any_instance.expects(:enqueue).once
112
113
 
113
- last_commit = commits(:third)
114
- deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
115
- assert_instance_of Deploy, deploy
116
- end
114
+ last_commit = shipit_commits(:third)
115
+ deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
116
+ assert_instance_of Deploy, deploy
117
+ end
117
118
 
118
- test "#update_deployed_revision bail out if there is an active deploy" do
119
- assert_no_difference 'Deploy.count' do
120
- @stack.update_deployed_revision(commits(:fifth).sha)
119
+ test "#update_deployed_revision bail out if there is an active deploy" do
120
+ assert_no_difference 'Deploy.count' do
121
+ @stack.update_deployed_revision(shipit_commits(:fifth).sha)
122
+ end
121
123
  end
122
- end
123
124
 
124
- test "#update_deployed_revision bail out if sha is unknown" do
125
- assert_no_difference 'Deploy.count' do
126
- @stack.update_deployed_revision('skldjaslkdjas')
125
+ test "#update_deployed_revision bail out if sha is unknown" do
126
+ assert_no_difference 'Deploy.count' do
127
+ @stack.update_deployed_revision('skldjaslkdjas')
128
+ end
127
129
  end
128
- end
129
130
 
130
- test "#update_deployed_revision create a new completed deploy" do
131
- Deploy.active.update_all(status: 'error')
131
+ test "#update_deployed_revision create a new completed deploy" do
132
+ Deploy.active.update_all(status: 'error')
132
133
 
133
- assert_equal commits(:fourth), @stack.last_deployed_commit
134
- assert_difference 'Deploy.count', 1 do
135
- deploy = @stack.update_deployed_revision(commits(:fifth).sha)
136
- assert_not_nil deploy
137
- assert_equal commits(:fourth), deploy.since_commit
138
- assert_equal commits(:fifth), deploy.until_commit
134
+ assert_equal shipit_commits(:fourth), @stack.last_deployed_commit
135
+ assert_difference 'Deploy.count', 1 do
136
+ deploy = @stack.update_deployed_revision(shipit_commits(:fifth).sha)
137
+ assert_not_nil deploy
138
+ assert_equal shipit_commits(:fourth), deploy.since_commit
139
+ assert_equal shipit_commits(:fifth), deploy.until_commit
140
+ end
141
+ assert_equal shipit_commits(:fifth), @stack.last_deployed_commit
139
142
  end
140
- assert_equal commits(:fifth), @stack.last_deployed_commit
141
- end
142
143
 
143
- test "#update_deployed_revision creates a new completed deploy without previous deploys" do
144
- stack = stacks(:undeployed_stack)
145
- assert_empty stack.deploys_and_rollbacks
146
- assert_difference 'Deploy.count', 1 do
147
- deploy = stack.update_deployed_revision(commits(:undeployed_stack_first).sha)
148
- assert_not_nil deploy
149
- assert_equal commits(:undeployed_stack_first), deploy.since_commit
150
- assert_equal commits(:undeployed_stack_first), deploy.until_commit
144
+ test "#update_deployed_revision creates a new completed deploy without previous deploys" do
145
+ stack = shipit_stacks(:undeployed_stack)
146
+ assert_empty stack.deploys_and_rollbacks
147
+ assert_difference 'Deploy.count', 1 do
148
+ deploy = stack.update_deployed_revision(shipit_commits(:undeployed_stack_first).sha)
149
+ assert_not_nil deploy
150
+ assert_equal shipit_commits(:undeployed_stack_first), deploy.since_commit
151
+ assert_equal shipit_commits(:undeployed_stack_first), deploy.until_commit
152
+ end
153
+ assert_equal shipit_commits(:undeployed_stack_first), stack.last_deployed_commit
151
154
  end
152
- assert_equal commits(:undeployed_stack_first), stack.last_deployed_commit
153
- end
154
155
 
155
- test "#update_deployed_revision works with short shas" do
156
- Deploy.active.update_all(status: 'error')
156
+ test "#update_deployed_revision works with short shas" do
157
+ Deploy.active.update_all(status: 'error')
157
158
 
158
- assert_equal commits(:fourth), @stack.last_deployed_commit
159
- assert_difference 'Deploy.count', 1 do
160
- deploy = @stack.update_deployed_revision(commits(:fifth).sha[0..5])
161
- assert_not_nil deploy
162
- assert_equal commits(:fourth), deploy.since_commit
163
- assert_equal commits(:fifth), deploy.until_commit
159
+ assert_equal shipit_commits(:fourth), @stack.last_deployed_commit
160
+ assert_difference 'Deploy.count', 1 do
161
+ deploy = @stack.update_deployed_revision(shipit_commits(:fifth).sha[0..5])
162
+ assert_not_nil deploy
163
+ assert_equal shipit_commits(:fourth), deploy.since_commit
164
+ assert_equal shipit_commits(:fifth), deploy.until_commit
165
+ end
166
+ assert_equal shipit_commits(:fifth), @stack.last_deployed_commit
164
167
  end
165
- assert_equal commits(:fifth), @stack.last_deployed_commit
166
- end
167
168
 
168
- test "#update_deployed_revision accepts the deploy if the reported revision is consistent" do
169
- Deploy.active.update_all(status: 'error')
169
+ test "#update_deployed_revision accepts the deploy if the reported revision is consistent" do
170
+ Deploy.active.update_all(status: 'error')
170
171
 
171
- Deploy.any_instance.expects(:accept!).once
172
- last_deploy = @stack.deploys_and_rollbacks.completed.last
173
- @stack.update_deployed_revision(last_deploy.until_commit.sha)
174
- end
172
+ Deploy.any_instance.expects(:accept!).once
173
+ last_deploy = @stack.deploys_and_rollbacks.completed.last
174
+ @stack.update_deployed_revision(last_deploy.until_commit.sha)
175
+ end
175
176
 
176
- test "#update_deployed_revision reject the deploy if the reported revision is inconsistent" do
177
- Deploy.active.update_all(status: 'error')
177
+ test "#update_deployed_revision reject the deploy if the reported revision is inconsistent" do
178
+ Deploy.active.update_all(status: 'error')
178
179
 
179
- Deploy.any_instance.expects(:reject!).once
180
- last_deploy = @stack.deploys_and_rollbacks.completed.last
181
- @stack.update_deployed_revision(last_deploy.since_commit.sha)
182
- end
183
-
184
- test "#create queues 2 GithubSetupWebhooksJob" do
185
- assert_enqueued_with(job: SetupGithubHookJob) do
186
- Stack.create!(repo_name: 'rails', repo_owner: 'rails')
180
+ Deploy.any_instance.expects(:reject!).once
181
+ last_deploy = @stack.deploys_and_rollbacks.completed.last
182
+ @stack.update_deployed_revision(last_deploy.since_commit.sha)
187
183
  end
188
- end
189
184
 
190
- test "#create queues a GithubSyncJob" do
191
- assert_enqueued_with(job: GithubSyncJob) do
192
- Stack.create!(repo_name: 'rails', repo_owner: 'rails')
185
+ test "#create queues 2 GithubSetupWebhooksJob" do
186
+ assert_enqueued_with(job: SetupGithubHookJob) do
187
+ Stack.create!(repo_name: 'rails', repo_owner: 'rails')
188
+ end
193
189
  end
194
- end
195
190
 
196
- test "#destroy also destroy associated GithubHooks" do
197
- assert_difference -> { GithubHook.count }, -2 do
198
- stacks(:shipit).destroy
191
+ test "#create queues a GithubSyncJob" do
192
+ assert_enqueued_with(job: GithubSyncJob) do
193
+ Stack.create!(repo_name: 'rails', repo_owner: 'rails')
194
+ end
199
195
  end
200
- end
201
196
 
202
- test "#destroy delete all local files (git mirror and deploy clones)" do
203
- FileUtils.expects(:rm_rf).with(Rails.root.join('data', 'stacks', 'shopify', 'shipit-engine', 'production').to_s)
204
- stacks(:shipit).destroy
205
- end
206
-
207
- test "#deploying? is false if stack has no deploy in either pending or running state" do
208
- @stack.deploys.active.destroy_all
209
- refute @stack.deploying?
210
- end
197
+ test "#destroy also destroy associated GithubHooks" do
198
+ assert_difference -> { GithubHook.count }, -2 do
199
+ shipit_stacks(:shipit).destroy
200
+ end
201
+ end
211
202
 
212
- test "#deploying? is false if stack has no deploy at all" do
213
- @stack.deploys.destroy_all
214
- refute @stack.deploying?
215
- end
203
+ test "#destroy delete all local files (git mirror and deploy clones)" do
204
+ FileUtils.expects(:rm_rf).with(Rails.root.join('data', 'stacks', 'shopify', 'shipit-engine', 'production').to_s)
205
+ shipit_stacks(:shipit).destroy
206
+ end
216
207
 
217
- test "#deploying? is true if stack has a deploy in either pending or running state" do
218
- @stack.trigger_deploy(commits(:third), AnonymousUser.new)
219
- assert @stack.deploying?
220
- end
208
+ test "#deploying? is false if stack has no deploy in either pending or running state" do
209
+ @stack.deploys.active.destroy_all
210
+ refute @stack.deploying?
211
+ end
221
212
 
222
- test "#deploying? is true if a rollback is ongoing" do
223
- deploys(:shipit_complete).trigger_rollback(AnonymousUser.new)
224
- assert @stack.deploying?
225
- end
213
+ test "#deploying? is false if stack has no deploy at all" do
214
+ @stack.deploys.destroy_all
215
+ refute @stack.deploying?
216
+ end
226
217
 
227
- test "#deploying? is memoized" do
228
- assert_queries(1) do
229
- 10.times { @stack.deploying? }
218
+ test "#deploying? is true if stack has a deploy in either pending or running state" do
219
+ @stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new)
220
+ assert @stack.deploying?
230
221
  end
231
- end
232
222
 
233
- test "#deploying? cache is cleared if a deploy change state" do
234
- assert_queries(1) do
235
- 10.times { @stack.deploying? }
223
+ test "#deploying? is true if a rollback is ongoing" do
224
+ shipit_deploys(:shipit_complete).trigger_rollback(AnonymousUser.new)
225
+ assert @stack.deploying?
236
226
  end
237
- @stack.tasks.where(status: 'running').first.error!
238
- assert_queries(1) do
239
- 10.times { @stack.deploying? }
227
+
228
+ test "#deploying? is memoized" do
229
+ assert_queries(1) do
230
+ 10.times { @stack.deploying? }
231
+ end
240
232
  end
241
- end
242
233
 
243
- test "#deployable? returns true if stack is not locked and is not deploying" do
244
- @stack.deploys.destroy_all
245
- assert @stack.deployable?
246
- end
234
+ test "#deploying? cache is cleared if a deploy change state" do
235
+ assert_queries(1) do
236
+ 10.times { @stack.deploying? }
237
+ end
238
+ @stack.tasks.where(status: 'running').first.error!
239
+ assert_queries(1) do
240
+ 10.times { @stack.deploying? }
241
+ end
242
+ end
247
243
 
248
- test "#deployable? returns false if stack is locked" do
249
- @stack.update!(lock_reason: 'Maintenance operation')
250
- refute @stack.deployable?
251
- end
244
+ test "#deployable? returns true if stack is not locked and is not deploying" do
245
+ @stack.deploys.destroy_all
246
+ assert @stack.deployable?
247
+ end
252
248
 
253
- test "#deployable? returns false if stack is deploying" do
254
- @stack.trigger_deploy(commits(:third), AnonymousUser.new)
255
- refute @stack.deployable?
256
- end
249
+ test "#deployable? returns false if stack is locked" do
250
+ @stack.update!(lock_reason: 'Maintenance operation')
251
+ refute @stack.deployable?
252
+ end
257
253
 
258
- test "#monitoring is empty if cached_deploy_spec is blank" do
259
- @stack.cached_deploy_spec = nil
260
- assert_equal [], @stack.monitoring
261
- end
254
+ test "#deployable? returns false if stack is deploying" do
255
+ @stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new)
256
+ refute @stack.deployable?
257
+ end
262
258
 
263
- test "#monitoring returns deploy_spec's content" do
264
- assert_equal [{'image' => 'https://example.com/monitor.png', 'width' => 200, 'height' => 300}], @stack.monitoring
265
- end
259
+ test "#monitoring is empty if cached_deploy_spec is blank" do
260
+ @stack.cached_deploy_spec = nil
261
+ assert_equal [], @stack.monitoring
262
+ end
266
263
 
267
- test "#destroy deletes the related commits" do
268
- assert_difference -> { @stack.commits.count }, -@stack.commits.count do
269
- @stack.destroy
264
+ test "#monitoring returns deploy_spec's content" do
265
+ assert_equal [{'image' => 'https://example.com/monitor.png', 'width' => 200, 'height' => 300}], @stack.monitoring
270
266
  end
271
- end
272
267
 
273
- test "#destroy deletes the related tasks" do
274
- assert_difference -> { @stack.tasks.count }, -@stack.tasks.count do
275
- @stack.destroy
268
+ test "#destroy deletes the related commits" do
269
+ assert_difference -> { @stack.commits.count }, -@stack.commits.count do
270
+ @stack.destroy
271
+ end
276
272
  end
277
- end
278
273
 
279
- test "#destroy deletes the related webhooks" do
280
- assert_difference -> { @stack.github_hooks.count }, -@stack.github_hooks.count do
281
- @stack.destroy
274
+ test "#destroy deletes the related tasks" do
275
+ assert_difference -> { @stack.tasks.count }, -@stack.tasks.count do
276
+ @stack.destroy
277
+ end
282
278
  end
283
- end
284
279
 
285
- test "locking the stack triggers a webhook" do
286
- expect_hook(:lock, @stack, locked: true, stack: @stack)
287
- @stack.update(lock_reason: "Just for fun", lock_author: users(:walrus))
288
- end
280
+ test "#destroy deletes the related webhooks" do
281
+ assert_difference -> { @stack.github_hooks.count }, -@stack.github_hooks.count do
282
+ @stack.destroy
283
+ end
284
+ end
289
285
 
290
- test "unlocking the stack triggers a webhook" do
291
- @stack.update(lock_reason: "Just for fun", lock_author: users(:walrus))
292
- expect_hook(:lock, @stack, locked: false, stack: @stack)
293
- @stack.update(lock_reason: nil)
294
- end
286
+ test "locking the stack triggers a webhook" do
287
+ expect_hook(:lock, @stack, locked: true, stack: @stack)
288
+ @stack.update(lock_reason: "Just for fun", lock_author: shipit_users(:walrus))
289
+ end
295
290
 
296
- test "the git cache lock prevent concurrent access to the git cache" do
297
- @stack.acquire_git_cache_lock do
298
- assert_raises Redis::Lock::LockTimeout do
299
- @stack.acquire_git_cache_lock(timeout: 0.1) {}
300
- end
291
+ test "unlocking the stack triggers a webhook" do
292
+ @stack.update(lock_reason: "Just for fun", lock_author: shipit_users(:walrus))
293
+ expect_hook(:lock, @stack, locked: false, stack: @stack)
294
+ @stack.update(lock_reason: nil)
301
295
  end
302
- end
303
296
 
304
- test "the git cache lock is scoped to the stack" do
305
- called = false
306
- stacks(:cyclimse).acquire_git_cache_lock do
297
+ test "the git cache lock prevent concurrent access to the git cache" do
307
298
  @stack.acquire_git_cache_lock do
308
- called = true
299
+ assert_raises Redis::Lock::LockTimeout do
300
+ @stack.acquire_git_cache_lock(timeout: 0.1) {}
301
+ end
309
302
  end
310
303
  end
311
- assert called
312
- end
313
304
 
314
- test "#clear_git_cache! deletes the stack git directory" do
315
- FileUtils.mkdir_p(@stack.git_path)
316
- path = File.join(@stack.git_path, 'foo')
317
- File.write(path, 'bar')
318
- @stack.clear_git_cache!
319
- refute File.exist?(path)
320
- end
305
+ test "the git cache lock is scoped to the stack" do
306
+ called = false
307
+ shipit_stacks(:cyclimse).acquire_git_cache_lock do
308
+ @stack.acquire_git_cache_lock do
309
+ called = true
310
+ end
311
+ end
312
+ assert called
313
+ end
321
314
 
322
- test "#clear_git_cache! does nothing if the git directory is not present" do
323
- FileUtils.rm_rf(@stack.git_path)
324
- assert_nothing_raised do
315
+ test "#clear_git_cache! deletes the stack git directory" do
316
+ FileUtils.mkdir_p(@stack.git_path)
317
+ path = File.join(@stack.git_path, 'foo')
318
+ File.write(path, 'bar')
325
319
  @stack.clear_git_cache!
320
+ refute File.exist?(path)
326
321
  end
327
- end
328
322
 
329
- test "#filter_visible_statuses removes statuses from hidden contexts" do
330
- stack = stacks(:cyclimse)
331
- stack.stubs(hidden_statuses: ['ci/hidden'])
332
- commit1 = Status.new(state: 'pending', context: 'ci/valid')
333
- commit2 = Status.new(state: 'pending', context: 'ci/valid')
334
- hidden = Status.new(state: 'pending', context: 'ci/hidden')
323
+ test "#clear_git_cache! does nothing if the git directory is not present" do
324
+ FileUtils.rm_rf(@stack.git_path)
325
+ assert_nothing_raised do
326
+ @stack.clear_git_cache!
327
+ end
328
+ end
335
329
 
336
- assert_equal [commit1, commit2], stack.filter_visible_statuses([hidden, commit1, commit2])
337
- end
330
+ test "#filter_visible_statuses removes statuses from hidden contexts" do
331
+ stack = shipit_stacks(:cyclimse)
332
+ stack.stubs(hidden_statuses: ['ci/hidden'])
333
+ commit1 = Status.new(state: 'pending', context: 'ci/valid')
334
+ commit2 = Status.new(state: 'pending', context: 'ci/valid')
335
+ hidden = Status.new(state: 'pending', context: 'ci/hidden')
338
336
 
339
- test "#filter_meaningful_statuses removes statuses from soft-failing contexts" do
340
- stack = stacks(:cyclimse)
341
- stack.stubs(soft_failing_statuses: ['ci/soft-fail'])
342
- commit1 = Status.new(state: 'pending', context: 'ci/valid')
343
- commit2 = Status.new(state: 'pending', context: 'ci/valid')
344
- soft_fail = Status.new(state: 'pending', context: 'ci/soft-fail')
337
+ assert_equal [commit1, commit2], stack.filter_visible_statuses([hidden, commit1, commit2])
338
+ end
345
339
 
346
- assert_equal [commit1, commit2], stack.filter_meaningful_statuses([soft_fail, commit1, commit2])
347
- end
340
+ test "#filter_meaningful_statuses removes statuses from soft-failing contexts" do
341
+ stack = shipit_stacks(:cyclimse)
342
+ stack.stubs(soft_failing_statuses: ['ci/soft-fail'])
343
+ commit1 = Status.new(state: 'pending', context: 'ci/valid')
344
+ commit2 = Status.new(state: 'pending', context: 'ci/valid')
345
+ soft_fail = Status.new(state: 'pending', context: 'ci/soft-fail')
348
346
 
349
- private
347
+ assert_equal [commit1, commit2], stack.filter_meaningful_statuses([soft_fail, commit1, commit2])
348
+ end
349
+
350
+ private
350
351
 
351
- def expect_hook(event, stack, payload)
352
- Hook.expects(:emit).with(event, stack, payload)
352
+ def expect_hook(event, stack, payload)
353
+ Hook.expects(:emit).with(event, stack, payload)
354
+ end
353
355
  end
354
356
  end