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,13 +1,15 @@
1
1
  require 'test_helper'
2
2
 
3
- class RefreshGithubUserJobTest < ActiveSupport::TestCase
4
- setup do
5
- @user = users(:walrus)
6
- @job = RefreshGithubUserJob.new
7
- end
3
+ module Shipit
4
+ class RefreshGithubUserJobTest < ActiveSupport::TestCase
5
+ setup do
6
+ @user = shipit_users(:walrus)
7
+ @job = RefreshGithubUserJob.new
8
+ end
8
9
 
9
- test "#perform call #refresh_from_github! on the provided user" do
10
- @user.expects(:refresh_from_github!)
11
- @job.perform(@user)
10
+ test "#perform call #refresh_from_github! on the provided user" do
11
+ @user.expects(:refresh_from_github!)
12
+ @job.perform(@user)
13
+ end
12
14
  end
13
15
  end
@@ -1,20 +1,22 @@
1
1
  require 'test_helper'
2
2
 
3
- class RefreshStatusesJobTest < ActiveSupport::TestCase
4
- setup do
5
- @stack = stacks(:shipit)
6
- @job = RefreshStatusesJob.new
7
- end
3
+ module Shipit
4
+ class RefreshStatusesJobTest < ActiveSupport::TestCase
5
+ setup do
6
+ @stack = shipit_stacks(:shipit)
7
+ @job = RefreshStatusesJob.new
8
+ end
8
9
 
9
- test "#perform call #refresh_statuses! on the last 30 commits of the stack" do
10
- Commit.any_instance.expects(:refresh_statuses!).times(@stack.commits.count)
10
+ test "#perform call #refresh_statuses! on the last 30 commits of the stack" do
11
+ Commit.any_instance.expects(:refresh_statuses!).times(@stack.commits.count)
11
12
 
12
- @job.perform(stack_id: @stack.id)
13
- end
13
+ @job.perform(stack_id: @stack.id)
14
+ end
14
15
 
15
- test "if :commit_id param is present only this commit is refreshed" do
16
- Commit.any_instance.expects(:refresh_statuses!).once
16
+ test "if :commit_id param is present only this commit is refreshed" do
17
+ Commit.any_instance.expects(:refresh_statuses!).once
17
18
 
18
- @job.perform(stack_id: @stack.id, commit_id: commits(:first).id)
19
+ @job.perform(stack_id: @stack.id, commit_id: shipit_commits(:first).id)
20
+ end
19
21
  end
20
22
  end
@@ -1,23 +1,26 @@
1
1
  require 'test_helper'
2
2
 
3
- class UniqueJobTest < ActiveSupport::TestCase
4
- test "the lock key contains the job type" do
5
- task = tasks(:shipit_restart)
6
- job_a = ChunkRollupJob.new(task)
7
- job_b = GithubSyncJob.new(task)
3
+ module Shipit
4
+ class UniqueJobTest < ActiveSupport::TestCase
5
+ test "the lock key contains the job type" do
6
+ task = shipit_tasks(:shipit_restart)
7
+ job_a = ChunkRollupJob.new(task)
8
+ job_b = GithubSyncJob.new(task)
8
9
 
9
- called = false
10
- job_a.acquire_lock do
11
- job_b.acquire_lock do
12
- called = true
10
+ called = false
11
+ job_a.acquire_lock do
12
+ job_b.acquire_lock do
13
+ called = true
14
+ end
13
15
  end
16
+ assert called
14
17
  end
15
- assert called
16
- end
17
18
 
18
- test "the lock key is serialized" do
19
- task = tasks(:shipit_restart)
20
- job = ChunkRollupJob.new(task)
21
- assert_equal %(ChunkRollupJob-{"_aj_globalid"=>"gid://shipit/Task/#{task.id}"}), job.lock_key(*job.arguments)
19
+ test "the lock key is serialized" do
20
+ task = shipit_tasks(:shipit_restart)
21
+ job = ChunkRollupJob.new(task)
22
+ key = %(Shipit::ChunkRollupJob-{"_aj_globalid"=>"gid://shipit/Shipit::Task/#{task.id}"})
23
+ assert_equal key, job.lock_key(*job.arguments)
24
+ end
22
25
  end
23
26
  end
@@ -1,27 +1,29 @@
1
1
  require 'test_helper'
2
2
 
3
- class ApiClientTest < ActiveSupport::TestCase
4
- setup do
5
- @client = api_clients(:spy)
6
- end
3
+ module Shipit
4
+ class ApiClientTest < ActiveSupport::TestCase
5
+ setup do
6
+ @client = shipit_api_clients(:spy)
7
+ end
7
8
 
8
- test "#authentication_token is the signed id" do
9
- assert_match(/^\d+--[\da-f]{40}$/, @client.authentication_token)
10
- end
9
+ test "#authentication_token is the signed id" do
10
+ assert_match(/^\d+--[\da-f]{40}$/, @client.authentication_token)
11
+ end
11
12
 
12
- test "#authentication_token casted as integer is the client id" do
13
- assert_equal @client.id, @client.authentication_token.to_i
14
- end
13
+ test "#authentication_token casted as integer is the client id" do
14
+ assert_equal @client.id, @client.authentication_token.to_i
15
+ end
15
16
 
16
- test ".authenticate returns nil if the signature is invalid" do
17
- assert_nil ApiClient.authenticate("#{@client.id}--foobar")
18
- end
17
+ test ".authenticate returns nil if the signature is invalid" do
18
+ assert_nil ApiClient.authenticate("#{@client.id}--foobar")
19
+ end
19
20
 
20
- test ".authenticate returns nil if the api client do not exists" do
21
- assert_nil ApiClient.authenticate(ApiClient.new(id: 42).authentication_token)
22
- end
21
+ test ".authenticate returns nil if the api client do not exists" do
22
+ assert_nil ApiClient.authenticate(ApiClient.new(id: 42).authentication_token)
23
+ end
23
24
 
24
- test ".authenticate returns the matching ApiClient record if the token is valid" do
25
- assert_equal @client, ApiClient.authenticate(@client.authentication_token)
25
+ test ".authenticate returns the matching ApiClient record if the token is valid" do
26
+ assert_equal @client, ApiClient.authenticate(@client.authentication_token)
27
+ end
26
28
  end
27
29
  end
@@ -1,83 +1,85 @@
1
1
  require 'test_helper'
2
2
  require 'tmpdir'
3
3
 
4
- class CommitChecksTest < ActiveSupport::TestCase
5
- setup do
6
- @commit = commits(:fifth)
7
- @checks = @commit.checks
8
- end
4
+ module Shipit
5
+ class CommitChecksTest < ActiveSupport::TestCase
6
+ setup do
7
+ @commit = shipit_commits(:fifth)
8
+ @checks = @commit.checks
9
+ end
9
10
 
10
- test "#schedule schedule the checks if output is missing" do
11
- assert_enqueued_with(job: PerformCommitChecksJob, args: [commit: @commit]) do
12
- @checks.schedule
11
+ test "#schedule schedule the checks if output is missing" do
12
+ assert_enqueued_with(job: PerformCommitChecksJob, args: [commit: @commit]) do
13
+ @checks.schedule
14
+ end
13
15
  end
14
- end
15
16
 
16
- test "#schedule just returns the current output if present" do
17
- schedule_checks
17
+ test "#schedule just returns the current output if present" do
18
+ schedule_checks
18
19
 
19
- assert_no_enqueued_jobs do
20
- @checks.schedule
20
+ assert_no_enqueued_jobs do
21
+ @checks.schedule
22
+ end
21
23
  end
22
- end
23
24
 
24
- test "it is considered finished if the status is `success`, `failed` or `error`" do
25
- @checks.status = 'success'
26
- assert @checks.finished?
25
+ test "it is considered finished if the status is `success`, `failed` or `error`" do
26
+ @checks.status = 'success'
27
+ assert @checks.finished?
27
28
 
28
- @checks.status = 'failed'
29
- assert @checks.finished?
29
+ @checks.status = 'failed'
30
+ assert @checks.finished?
30
31
 
31
- @checks.status = 'error'
32
- assert @checks.finished?
32
+ @checks.status = 'error'
33
+ assert @checks.finished?
33
34
 
34
- @checks.status = 'scheduled'
35
- refute @checks.finished?
35
+ @checks.status = 'scheduled'
36
+ refute @checks.finished?
36
37
 
37
- @checks.status = 'running'
38
- refute @checks.finished?
38
+ @checks.status = 'running'
39
+ refute @checks.finished?
39
40
 
40
- @checks.status = nil
41
- refute @checks.finished?
42
- end
41
+ @checks.status = nil
42
+ refute @checks.finished?
43
+ end
43
44
 
44
- test "#status is `scheduled` when the job is triggered" do
45
- schedule_checks
46
- assert_equal 'scheduled', @checks.status
47
- end
45
+ test "#status is `scheduled` when the job is triggered" do
46
+ schedule_checks
47
+ assert_equal 'scheduled', @checks.status
48
+ end
48
49
 
49
- test "#write append the string in redis" do
50
- CommitChecks.new(@commit).write('foo')
51
- CommitChecks.new(@commit).write('bar')
52
- assert_equal 'foobar', CommitChecks.new(@commit).output
53
- end
50
+ test "#write append the string in redis" do
51
+ CommitChecks.new(@commit).write('foo')
52
+ CommitChecks.new(@commit).write('bar')
53
+ assert_equal 'foobar', CommitChecks.new(@commit).output
54
+ end
54
55
 
55
- test "#output allow to retreive only a slice of the output" do
56
- @checks.write('foobar')
57
- assert_equal 'bar', @checks.output(since: 3)
58
- end
56
+ test "#output allow to retreive only a slice of the output" do
57
+ @checks.write('foobar')
58
+ assert_equal 'bar', @checks.output(since: 3)
59
+ end
59
60
 
60
- test "#run execute the shell commands and update the status and output" do
61
- StackCommands.any_instance.expects(:with_temporary_working_directory).yields(Pathname.new(Dir.tmpdir))
62
- DeploySpec::FileSystem.any_instance.expects(:dependencies_steps).returns(['echo dependencies'])
63
- DeploySpec::FileSystem.any_instance.expects(:review_checks).returns(['echo review'])
64
-
65
- @checks.run
66
- lines = [
67
- '$ echo dependencies',
68
- 'dependencies',
69
- '',
70
- '$ echo review',
71
- 'review',
72
- '',
73
- ]
74
- assert_equal 'success', @checks.status
75
- assert_equal lines, @checks.output.lines.map(&:strip)
76
- end
61
+ test "#run execute the shell commands and update the status and output" do
62
+ StackCommands.any_instance.expects(:with_temporary_working_directory).yields(Pathname.new(Dir.tmpdir))
63
+ DeploySpec::FileSystem.any_instance.expects(:dependencies_steps).returns(['echo dependencies'])
64
+ DeploySpec::FileSystem.any_instance.expects(:review_checks).returns(['echo review'])
65
+
66
+ @checks.run
67
+ lines = [
68
+ '$ echo dependencies',
69
+ 'dependencies',
70
+ '',
71
+ '$ echo review',
72
+ 'review',
73
+ '',
74
+ ]
75
+ assert_equal 'success', @checks.status
76
+ assert_equal lines, @checks.output.lines.map(&:strip)
77
+ end
77
78
 
78
- private
79
+ private
79
80
 
80
- def schedule_checks
81
- CommitChecks.new(@commit).schedule
81
+ def schedule_checks
82
+ CommitChecks.new(@commit).schedule
83
+ end
82
84
  end
83
85
  end
@@ -1,398 +1,401 @@
1
1
  require 'test_helper'
2
2
 
3
- class CommitsTest < ActiveSupport::TestCase
4
- setup do
5
- @stack = stacks(:shipit)
6
- @pr = @stack.commits.new
7
- @pr.message = "Merge pull request #31 from Shopify/improve-polling\n\nSeveral improvements to polling"
8
- @commit = commits(:first)
9
- end
3
+ module Shipit
4
+ class CommitsTest < ActiveSupport::TestCase
5
+ setup do
6
+ @stack = shipit_stacks(:shipit)
7
+ @pr = @stack.commits.new
8
+ @pr.message = "Merge pull request #31 from Shopify/improve-polling\n\nSeveral improvements to polling"
9
+ @commit = shipit_commits(:first)
10
+ end
10
11
 
11
- test "#pull_request? detect pull request based on message format" do
12
- assert @pr.pull_request?
13
- refute @commit.pull_request?
14
- end
12
+ test "#pull_request? detect pull request based on message format" do
13
+ assert @pr.pull_request?
14
+ refute @commit.pull_request?
15
+ end
15
16
 
16
- test "#pull_request? detects pull requests with unusual branch names" do
17
- @pr.message = "Merge pull request #7 from Shopify/bump-to-v1.0.1\n\nBump to v1.0.1"
18
- assert @pr.pull_request?
19
- assert_equal "Bump to v1.0.1", @pr.pull_request_title
20
- end
17
+ test "#pull_request? detects pull requests with unusual branch names" do
18
+ @pr.message = "Merge pull request #7 from Shopify/bump-to-v1.0.1\n\nBump to v1.0.1"
19
+ assert @pr.pull_request?
20
+ assert_equal "Bump to v1.0.1", @pr.pull_request_title
21
+ end
21
22
 
22
- test "#pull_request_id extract the pull request id from the message" do
23
- assert_equal 31, @pr.pull_request_id
24
- assert_nil @commit.pull_request_id
25
- end
23
+ test "#pull_request_id extract the pull request id from the message" do
24
+ assert_equal 31, @pr.pull_request_id
25
+ assert_nil @commit.pull_request_id
26
+ end
26
27
 
27
- test "#pull_request_title extract the pull request title from the message" do
28
- assert_equal 'Several improvements to polling', @pr.pull_request_title
29
- assert_nil @commit.pull_request_title
30
- end
28
+ test "#pull_request_title extract the pull request title from the message" do
29
+ assert_equal 'Several improvements to polling', @pr.pull_request_title
30
+ assert_nil @commit.pull_request_title
31
+ end
31
32
 
32
- test "#pull_request_url build the pull request url from the message" do
33
- assert_equal 'https://github.com/shopify/shipit-engine/pull/31', @pr.pull_request_url
34
- assert_nil @commit.pull_request_url
35
- end
33
+ test "#pull_request_url build the pull request url from the message" do
34
+ assert_equal 'https://github.com/shopify/shipit-engine/pull/31', @pr.pull_request_url
35
+ assert_nil @commit.pull_request_url
36
+ end
36
37
 
37
- test "#newer_than(nil) returns all commits" do
38
- assert_equal @stack.commits.all.to_a, @stack.commits.newer_than(nil).to_a
39
- end
38
+ test "#newer_than(nil) returns all commits" do
39
+ assert_equal @stack.commits.all.to_a, @stack.commits.newer_than(nil).to_a
40
+ end
40
41
 
41
- test "updating to detached broadcasts an update event" do
42
- expect_event(@stack)
43
- @commit.update(detached: true)
44
- end
42
+ test "updating to detached broadcasts an update event" do
43
+ expect_event(@stack)
44
+ @commit.update(detached: true)
45
+ end
45
46
 
46
- test ".detach! detaches commits" do
47
- parent = commits(:fourth)
48
- child = commits(:fifth)
49
- refute child.detached?, "fifth commit should not be detached"
47
+ test ".detach! detaches commits" do
48
+ parent = shipit_commits(:fourth)
49
+ child = shipit_commits(:fifth)
50
+ refute child.detached?, "fifth commit should not be detached"
50
51
 
51
- parent.detach_children!
52
+ parent.detach_children!
52
53
 
53
- assert child.reload.detached?, "children commits must be detached"
54
- end
54
+ assert child.reload.detached?, "children commits must be detached"
55
+ end
55
56
 
56
- test "#destroy broadcasts an update event" do
57
- expect_event(@stack)
58
- @commit.destroy
59
- end
57
+ test "#destroy broadcasts an update event" do
58
+ expect_event(@stack)
59
+ @commit.destroy
60
+ end
60
61
 
61
- test "updating broadcasts an update event" do
62
- expect_event(@stack)
63
- @commit.update_attributes(message: "toto")
64
- end
62
+ test "updating broadcasts an update event" do
63
+ expect_event(@stack)
64
+ @commit.update_attributes(message: "toto")
65
+ end
65
66
 
66
- test "updating state to success triggers new deploy when stack has continuous deployment" do
67
- @stack.reload.update(continuous_deployment: true)
68
- @stack.deploys.destroy_all
67
+ test "updating state to success triggers new deploy when stack has continuous deployment" do
68
+ @stack.reload.update(continuous_deployment: true)
69
+ @stack.deploys.destroy_all
69
70
 
70
- assert_difference "Deploy.count" do
71
- @stack.commits.last.statuses.create!(state: 'success', context: 'ci/travis')
71
+ assert_difference "Deploy.count" do
72
+ @stack.commits.last.statuses.create!(state: 'success', context: 'ci/travis')
73
+ end
72
74
  end
73
- end
74
75
 
75
- test "updating state to success skips deploy when stack has CD but a deploy is in progress" do
76
- @stack.reload.update(continuous_deployment: true)
77
- @stack.trigger_deploy(@commit, @commit.committer)
76
+ test "updating state to success skips deploy when stack has CD but a deploy is in progress" do
77
+ @stack.reload.update(continuous_deployment: true)
78
+ @stack.trigger_deploy(@commit, @commit.committer)
78
79
 
79
- assert_no_difference "Deploy.count" do
80
- @commit.statuses.create!(state: 'success', context: 'ci/travis')
80
+ assert_no_difference "Deploy.count" do
81
+ @commit.statuses.create!(state: 'success', context: 'ci/travis')
82
+ end
81
83
  end
82
- end
83
84
 
84
- test "updating state to success skips deploy when stack has CD but the stack is locked" do
85
- @stack.deploys.destroy_all
86
- @stack.reload.update!(continuous_deployment: true, lock_reason: "Maintenance ongoing")
85
+ test "updating state to success skips deploy when stack has CD but the stack is locked" do
86
+ @stack.deploys.destroy_all
87
+ @stack.reload.update!(continuous_deployment: true, lock_reason: "Maintenance ongoing")
87
88
 
88
- assert_no_difference "Deploy.count" do
89
- @commit.statuses.create!(state: 'success', context: 'ci/travis')
89
+ assert_no_difference "Deploy.count" do
90
+ @commit.statuses.create!(state: 'success', context: 'ci/travis')
91
+ end
90
92
  end
91
- end
92
93
 
93
- test "updating won't trigger a deploy if a newer commit has been deployed" do
94
- @stack.reload.update(continuous_deployment: true)
95
- @stack.deploys.destroy_all
96
-
97
- walrus = users(:walrus)
98
- new_commit = @stack.commits.create!(
99
- sha: '1234',
100
- message: 'bla',
101
- author: walrus,
102
- committer: walrus,
103
- authored_at: Time.now,
104
- committed_at: Time.now,
105
- )
106
-
107
- @stack.deploys.create!(
108
- user_id: walrus.id,
109
- since_commit: @stack.last_deployed_commit,
110
- until_commit: new_commit,
111
- status: 'success',
112
- )
113
-
114
- assert_no_difference "Deploy.count" do
115
- @commit.statuses.create!(state: 'success')
94
+ test "updating won't trigger a deploy if a newer commit has been deployed" do
95
+ @stack.reload.update(continuous_deployment: true)
96
+ @stack.deploys.destroy_all
97
+
98
+ walrus = shipit_users(:walrus)
99
+ new_commit = @stack.commits.create!(
100
+ sha: '1234',
101
+ message: 'bla',
102
+ author: walrus,
103
+ committer: walrus,
104
+ authored_at: Time.now,
105
+ committed_at: Time.now,
106
+ )
107
+
108
+ @stack.deploys.create!(
109
+ user_id: walrus.id,
110
+ since_commit: @stack.last_deployed_commit,
111
+ until_commit: new_commit,
112
+ status: 'success',
113
+ )
114
+
115
+ assert_no_difference "Deploy.count" do
116
+ @commit.statuses.create!(state: 'success')
117
+ end
116
118
  end
117
- end
118
119
 
119
- test "updating won't trigger a deploy if this commit has already been deployed" do
120
- @stack.reload.update!(continuous_deployment: true)
120
+ test "updating won't trigger a deploy if this commit has already been deployed" do
121
+ @stack.reload.update!(continuous_deployment: true)
121
122
 
122
- assert_no_difference "Deploy.count" do
123
- @stack.last_deployed_commit.statuses.create!(state: 'success')
123
+ assert_no_difference "Deploy.count" do
124
+ @stack.last_deployed_commit.statuses.create!(state: 'success')
125
+ end
124
126
  end
125
- end
126
127
 
127
- test "updating without CD skips deploy regardless of state" do
128
- @stack.reload.deploys.destroy_all
128
+ test "updating without CD skips deploy regardless of state" do
129
+ @stack.reload.deploys.destroy_all
129
130
 
130
- assert_no_difference "Deploy.count" do
131
- @commit.statuses.create!(state: 'success')
131
+ assert_no_difference "Deploy.count" do
132
+ @commit.statuses.create!(state: 'success')
133
+ end
132
134
  end
133
- end
134
135
 
135
- test "updating when not success does not schedule CD" do
136
- @stack.reload.update(continuous_deployment: true)
137
- @stack.deploys.destroy_all
136
+ test "updating when not success does not schedule CD" do
137
+ @stack.reload.update(continuous_deployment: true)
138
+ @stack.deploys.destroy_all
138
139
 
139
- assert_no_difference "Deploy.count" do
140
- @commit.statuses.create!(state: 'failure')
140
+ assert_no_difference "Deploy.count" do
141
+ @commit.statuses.create!(state: 'failure')
142
+ end
141
143
  end
142
- end
143
-
144
- test "creating broadcasts an update event" do
145
- expect_event(@stack)
146
- walrus = users(:walrus)
147
- @stack.commits.create(author: walrus,
148
- committer: walrus,
149
- sha: "ab12",
150
- authored_at: DateTime.now,
151
- committed_at: DateTime.now,
152
- message: "more fish!")
153
- end
154
144
 
155
- test "refresh_statuses! pull state from github" do
156
- rels = {target: mock(href: 'http://example.com')}
157
- status = mock(state: 'success', description: nil, context: 'default', rels: rels, created_at: 1.day.ago)
158
- Shipit.github_api.expects(:statuses).with(@stack.github_repo_name, @commit.sha).returns([status])
159
- assert_difference '@commit.statuses.count', 1 do
160
- @commit.refresh_statuses!
145
+ test "creating broadcasts an update event" do
146
+ expect_event(@stack)
147
+ walrus = shipit_users(:walrus)
148
+ @stack.commits.create(author: walrus,
149
+ committer: walrus,
150
+ sha: "ab12",
151
+ authored_at: DateTime.now,
152
+ committed_at: DateTime.now,
153
+ message: "more fish!")
161
154
  end
162
- assert_equal 'success', @commit.statuses.first.state
163
- end
164
155
 
165
- test "#creating a commit update the undeployed_commits_count" do
166
- walrus = users(:walrus)
167
- assert_equal 1, @stack.undeployed_commits_count
168
- @stack.commits.create(author: walrus,
169
- committer: walrus,
170
- sha: "ab12",
171
- authored_at: DateTime.now,
172
- committed_at: DateTime.now,
173
- message: "more fish!")
174
-
175
- @stack.reload
176
- assert_equal 2, @stack.undeployed_commits_count
177
- end
156
+ test "refresh_statuses! pull state from github" do
157
+ rels = {target: mock(href: 'http://example.com')}
158
+ status = mock(state: 'success', description: nil, context: 'default', rels: rels, created_at: 1.day.ago)
159
+ Shipit.github_api.expects(:statuses).with(@stack.github_repo_name, @commit.sha).returns([status])
160
+ assert_difference '@commit.statuses.count', 1 do
161
+ @commit.refresh_statuses!
162
+ end
163
+ assert_equal 'success', @commit.statuses.first.state
164
+ end
178
165
 
179
- test "fetch_stats! pulls additions and deletions from github" do
180
- commit = stub(stats: stub(additions: 4242, deletions: 2424))
181
- Shipit.github_api.expects(:commit).with(@stack.github_repo_name, @commit.sha).returns(commit)
182
- @commit.fetch_stats!
183
- assert_equal 4242, @commit.additions
184
- assert_equal 2424, @commit.deletions
185
- end
166
+ test "#creating a commit update the undeployed_commits_count" do
167
+ walrus = shipit_users(:walrus)
168
+ assert_equal 1, @stack.undeployed_commits_count
169
+ @stack.commits.create(author: walrus,
170
+ committer: walrus,
171
+ sha: "ab12",
172
+ authored_at: DateTime.now,
173
+ committed_at: DateTime.now,
174
+ message: "more fish!")
175
+
176
+ @stack.reload
177
+ assert_equal 2, @stack.undeployed_commits_count
178
+ end
186
179
 
187
- test "fetch_stats! doesn't fail if the commits have no stats" do
188
- commit = stub(stats: nil)
189
- Shipit.github_api.expects(:commit).with(@stack.github_repo_name, @commit.sha).returns(commit)
190
- assert_nothing_raised do
180
+ test "fetch_stats! pulls additions and deletions from github" do
181
+ commit = stub(stats: stub(additions: 4242, deletions: 2424))
182
+ Shipit.github_api.expects(:commit).with(@stack.github_repo_name, @commit.sha).returns(commit)
191
183
  @commit.fetch_stats!
184
+ assert_equal 4242, @commit.additions
185
+ assert_equal 2424, @commit.deletions
192
186
  end
193
- end
194
187
 
195
- test ".by_sha! can match sha prefixes" do
196
- assert_equal @commit, Commit.by_sha!(@commit.sha[0..7])
197
- end
188
+ test "fetch_stats! doesn't fail if the commits have no stats" do
189
+ commit = stub(stats: nil)
190
+ Shipit.github_api.expects(:commit).with(@stack.github_repo_name, @commit.sha).returns(commit)
191
+ assert_nothing_raised do
192
+ @commit.fetch_stats!
193
+ end
194
+ end
198
195
 
199
- test ".by_sha! raises on ambigous sha prefixes" do
200
- assert_raises Commit::AmbiguousRevision do
201
- Commit.by_sha!(@commit.sha[0..3])
196
+ test ".by_sha! can match sha prefixes" do
197
+ assert_equal @commit, Commit.by_sha!(@commit.sha[0..7])
202
198
  end
203
- end
204
199
 
205
- test ".by_sha! raises if the sha prefix matches multiple commits" do
206
- clone = Commit.new(@commit.attributes.except('id'))
207
- clone.sha[8..-1] = 'abc12'
208
- clone.save!
200
+ test ".by_sha! raises on ambigous sha prefixes" do
201
+ assert_raises Commit::AmbiguousRevision do
202
+ Commit.by_sha!(@commit.sha[0..3])
203
+ end
204
+ end
205
+
206
+ test ".by_sha! raises if the sha prefix matches multiple commits" do
207
+ clone = Commit.new(@commit.attributes.except('id'))
208
+ clone.sha[8..-1] = 'abc12'
209
+ clone.save!
209
210
 
210
- assert_raises Commit::AmbiguousRevision do
211
- Commit.by_sha!(@commit.sha[0..7])
211
+ assert_raises Commit::AmbiguousRevision do
212
+ Commit.by_sha!(@commit.sha[0..7])
213
+ end
212
214
  end
213
- end
214
215
 
215
- test "#state is `unknown` by default" do
216
- assert_equal 'unknown', @stack.commits.new.state
217
- end
216
+ test "#state is `unknown` by default" do
217
+ assert_equal 'unknown', @stack.commits.new.state
218
+ end
218
219
 
219
- test "#state is `success` if all most recent the statuses are `success`" do
220
- assert_equal 'success', commits(:third).state
221
- end
220
+ test "#state is `success` if all most recent the statuses are `success`" do
221
+ assert_equal 'success', shipit_commits(:third).state
222
+ end
222
223
 
223
- test "#state is `failure` one of the most recent the statuses is `failure`" do
224
- assert_equal 'failure', commits(:second).state
225
- end
224
+ test "#state is `failure` one of the most recent the statuses is `failure`" do
225
+ assert_equal 'failure', shipit_commits(:second).state
226
+ end
226
227
 
227
- test "#state is `pending` one of the most recent the statuses is `pending` and none is `failure` or `error`" do
228
- assert_equal 'pending', commits(:fourth).state
229
- end
228
+ test "#state is `pending` one of the most recent the statuses is `pending` and none is `failure` or `error`" do
229
+ assert_equal 'pending', shipit_commits(:fourth).state
230
+ end
230
231
 
231
- test "#state doesn't consider statuses that are hidden or allowed to fail" do
232
- assert_equal 'pending', @commit.state
232
+ test "#state doesn't consider statuses that are hidden or allowed to fail" do
233
+ assert_equal 'pending', @commit.state
233
234
 
234
- @commit.statuses.create!(context: 'metrics/coveralls', state: 'failure')
235
- @commit.statuses.create!(context: 'metrics/performance', state: 'failure')
236
- assert_equal 'failure', @commit.reload.state
235
+ @commit.statuses.create!(context: 'metrics/coveralls', state: 'failure')
236
+ @commit.statuses.create!(context: 'metrics/performance', state: 'failure')
237
+ assert_equal 'failure', @commit.reload.state
237
238
 
238
- @commit.stack.update!(cached_deploy_spec: DeploySpec.new('ci' => {
239
- 'hide' => 'metrics/coveralls',
240
- 'allow_failures' => 'metrics/performance',
241
- }))
242
- assert_equal 'pending', @commit.reload.state
243
- end
239
+ @commit.stack.update!(cached_deploy_spec: DeploySpec.new('ci' => {
240
+ 'hide' => 'metrics/coveralls',
241
+ 'allow_failures' => 'metrics/performance',
242
+ }))
243
+ assert_equal 'pending', @commit.reload.state
244
+ end
244
245
 
245
- test "#last_statuses returns the list of the most recent status of each context" do
246
- assert_equal 4, commits(:second).statuses.count
247
- assert_equal 2, commits(:second).last_statuses.count
248
- end
246
+ test "#last_statuses returns the list of the most recent status of each context" do
247
+ assert_equal 4, shipit_commits(:second).statuses.count
248
+ assert_equal 2, shipit_commits(:second).last_statuses.count
249
+ end
249
250
 
250
- test "#last_statuses return [UnknownStatus] if the commit has no statuses" do
251
- commit = commits(:second)
252
- commit.statuses = []
253
- assert_equal UnknownStatus.new(commit), commit.significant_status
254
- end
251
+ test "#last_statuses return [UnknownStatus] if the commit has no statuses" do
252
+ commit = shipit_commits(:second)
253
+ commit.statuses = []
254
+ assert_equal UnknownStatus.new(commit), commit.significant_status
255
+ end
255
256
 
256
- test "#visible_statuses rejects the statuses that are specified in the deploy spec's `ci.hide`" do
257
- commit = commits(:second)
258
- assert_equal 2, commit.visible_statuses.count
259
- commit.stack.update!(cached_deploy_spec: DeploySpec.new('ci' => {'hide' => 'metrics/coveralls'}))
260
- commit.reload
261
- assert_equal 1, commit.visible_statuses.size
262
- end
257
+ test "#visible_statuses rejects the statuses that are specified in the deploy spec's `ci.hide`" do
258
+ commit = shipit_commits(:second)
259
+ assert_equal 2, commit.visible_statuses.count
260
+ commit.stack.update!(cached_deploy_spec: DeploySpec.new('ci' => {'hide' => 'metrics/coveralls'}))
261
+ commit.reload
262
+ assert_equal 1, commit.visible_statuses.size
263
+ end
263
264
 
264
- test "#deployable? is true if commit status is 'success'" do
265
- assert_predicate commits(:cyclimse_first), :deployable?
266
- end
265
+ test "#deployable? is true if commit status is 'success'" do
266
+ assert_predicate shipit_commits(:cyclimse_first), :deployable?
267
+ end
267
268
 
268
- test "#deployable? is true if stack is set to 'ignore_ci'" do
269
- commit = commits(:first)
270
- commit.stack.update!(ignore_ci: true)
271
- assert_predicate commit, :deployable?
272
- end
269
+ test "#deployable? is true if stack is set to 'ignore_ci'" do
270
+ commit = shipit_commits(:first)
271
+ commit.stack.update!(ignore_ci: true)
272
+ assert_predicate commit, :deployable?
273
+ end
273
274
 
274
- test "#deployable? is false if commit has no statuses" do
275
- refute_predicate commits(:fifth), :deployable?
276
- end
275
+ test "#deployable? is false if commit has no statuses" do
276
+ refute_predicate shipit_commits(:fifth), :deployable?
277
+ end
277
278
 
278
- test "#deployable? is false if a required status is missing" do
279
- commit = commits(:cyclimse_first)
280
- commit.stack.stubs(:required_statuses).returns(%w(ci/very-important))
281
- refute_predicate commit, :deployable?
282
- end
279
+ test "#deployable? is false if a required status is missing" do
280
+ commit = shipit_commits(:cyclimse_first)
281
+ commit.stack.stubs(:required_statuses).returns(%w(ci/very-important))
282
+ refute_predicate commit, :deployable?
283
+ end
283
284
 
284
- expected_webhook_transitions = { # we expect deployable_status to fire on these transitions, and not on any others
285
- 'pending' => %w(success failure error),
286
- 'success' => %w(failure error),
287
- 'failure' => %w(success),
288
- 'error' => %w(success),
289
- }
290
- expected_webhook_transitions.each do |initial_state, firing_states|
291
- initial_status_attributes = {state: initial_state, description: 'abc', context: 'ci/travis'}
292
- expected_webhook_transitions.keys.each do |new_state|
293
- should_fire = firing_states.include?(new_state)
294
- test "#add_status #{should_fire ? 'fires' : 'does not fire'} for status from #{initial_state} to #{new_state}" do
295
- commit = commits(:cyclimse_first)
296
- assert commit.stack.hooks.where(events: ['deploy_status']).size >= 1
297
- refute commit.stack.ignore_ci
298
- commit.statuses.destroy_all
299
- commit.reload
300
- commit.statuses.create!(initial_status_attributes.merge(created_at: 10.days.ago.to_s(:db)))
301
- assert_equal initial_state, commit.state
302
-
303
- expected_status_attributes = {state: new_state, description: initial_state, context: 'ci/travis'}
304
- if should_fire
305
- expect_hook_emit(commit, :deployable_status, expected_status_attributes)
306
- else
307
- Hook.expects(:emit).never
285
+ expected_webhook_transitions = { # we expect deployable_status to fire on these transitions, and not on any others
286
+ 'pending' => %w(success failure error),
287
+ 'success' => %w(failure error),
288
+ 'failure' => %w(success),
289
+ 'error' => %w(success),
290
+ }
291
+ expected_webhook_transitions.each do |initial_state, firing_states|
292
+ initial_status_attributes = {state: initial_state, description: 'abc', context: 'ci/travis'}
293
+ expected_webhook_transitions.keys.each do |new_state|
294
+ should_fire = firing_states.include?(new_state)
295
+ action = should_fire ? 'fires' : 'does not fire'
296
+ test "#add_status #{action} for status from #{initial_state} to #{new_state}" do
297
+ commit = shipit_commits(:cyclimse_first)
298
+ assert commit.stack.hooks.where(events: ['deploy_status']).size >= 1
299
+ refute commit.stack.ignore_ci
300
+ commit.statuses.destroy_all
301
+ commit.reload
302
+ commit.statuses.create!(initial_status_attributes.merge(created_at: 10.days.ago.to_s(:db)))
303
+ assert_equal initial_state, commit.state
304
+
305
+ expected_status_attributes = {state: new_state, description: initial_state, context: 'ci/travis'}
306
+ if should_fire
307
+ expect_hook_emit(commit, :deployable_status, expected_status_attributes)
308
+ else
309
+ Hook.expects(:emit).never
310
+ end
311
+ expect_hook_emit(commit, :commit_status, expected_status_attributes)
312
+
313
+ commit.add_status(expected_status_attributes.merge(created_at: 1.day.ago.to_s(:db)))
308
314
  end
309
- expect_hook_emit(commit, :commit_status, expected_status_attributes)
310
-
311
- commit.add_status(expected_status_attributes.merge(created_at: 1.day.ago.to_s(:db)))
312
315
  end
313
316
  end
314
- end
315
317
 
316
- test "#add_status does not fire webhooks for invisible statuses" do
317
- commit = commits(:second)
318
- assert commit.stack.hooks.where(events: ['commit_status']).size >= 1
319
- Hook.expects(:emit).never
320
- commit.add_status(state: 'failure', description: 'Sad', context: 'ci/hidden', created_at: 1.day.ago.to_s(:db))
321
- end
318
+ test "#add_status does not fire webhooks for invisible statuses" do
319
+ commit = shipit_commits(:second)
320
+ assert commit.stack.hooks.where(events: ['commit_status']).size >= 1
321
+ Hook.expects(:emit).never
322
+ commit.add_status(state: 'failure', description: 'Sad', context: 'ci/hidden', created_at: 1.day.ago.to_s(:db))
323
+ end
322
324
 
323
- test "#add_status does not fire webhooks for non-meaningful statuses" do
324
- commit = commits(:second)
325
- assert commit.stack.hooks.where(events: ['commit_status']).size >= 1
326
- Hook.expects(:emit).never
327
- commit.add_status(state: 'failure', description: 'Sad', context: 'ci/ok_to_fail', created_at: 1.day.ago.to_s(:db))
328
- end
325
+ test "#add_status does not fire webhooks for non-meaningful statuses" do
326
+ commit = shipit_commits(:second)
327
+ assert commit.stack.hooks.where(events: ['commit_status']).size >= 1
328
+ Hook.expects(:emit).never
329
+ commit.add_status(state: 'failure', description: 'Sad', context: 'ci/ok_to_fail', created_at: 1.day.ago.to_s(:db))
330
+ end
329
331
 
330
- test "#visible_statuses forward the last_statuses to the stack" do
331
- commit = commits(:second)
332
- stack = commit.stack
333
- stack.expects(:filter_visible_statuses).with(commit.last_statuses)
334
- commit.visible_statuses
335
- end
332
+ test "#visible_statuses forward the last_statuses to the stack" do
333
+ commit = shipit_commits(:second)
334
+ stack = commit.stack
335
+ stack.expects(:filter_visible_statuses).with(commit.last_statuses)
336
+ commit.visible_statuses
337
+ end
336
338
 
337
- test "#meaningful_statuses forward the last_statuses to the stack" do
338
- commit = commits(:second)
339
- stack = commit.stack
340
- stack.expects(:filter_meaningful_statuses).with(commit.last_statuses)
341
- commit.meaningful_statuses
342
- end
339
+ test "#meaningful_statuses forward the last_statuses to the stack" do
340
+ commit = shipit_commits(:second)
341
+ stack = commit.stack
342
+ stack.expects(:filter_meaningful_statuses).with(commit.last_statuses)
343
+ commit.meaningful_statuses
344
+ end
343
345
 
344
- test "#significant_status is UnknownStatus when the commit has no statuses" do
345
- commit = commits(:first)
346
- commit.statuses = []
347
- assert_equal UnknownStatus.new(commit), commit.significant_status
348
- end
346
+ test "#significant_status is UnknownStatus when the commit has no statuses" do
347
+ commit = shipit_commits(:first)
348
+ commit.statuses = []
349
+ assert_equal UnknownStatus.new(commit), commit.significant_status
350
+ end
349
351
 
350
- test "#significant_status hierarchy uses failures and errors, then pending, then successes, then UnknownStatus" do
351
- commit = commits(:first)
352
- pending = commit.statuses.new(state: 'pending', context: 'ci/pending')
353
- failure = commit.statuses.new(state: 'failure', context: 'ci/failure')
354
- error = commit.statuses.new(state: 'error', context: 'ci/error')
355
- success = commit.statuses.new(state: 'success', context: 'ci/success')
352
+ test "#significant_status hierarchy uses failures and errors, then pending, then successes, then UnknownStatus" do
353
+ commit = shipit_commits(:first)
354
+ pending = commit.statuses.new(state: 'pending', context: 'ci/pending')
355
+ failure = commit.statuses.new(state: 'failure', context: 'ci/failure')
356
+ error = commit.statuses.new(state: 'error', context: 'ci/error')
357
+ success = commit.statuses.new(state: 'success', context: 'ci/success')
356
358
 
357
- commit.reload.statuses = [pending, failure, success, error]
358
- assert_includes [error, failure], commit.significant_status
359
+ commit.reload.statuses = [pending, failure, success, error]
360
+ assert_includes [error, failure], commit.significant_status
359
361
 
360
- commit.reload.statuses = [pending, failure, success]
361
- assert_equal failure, commit.significant_status
362
+ commit.reload.statuses = [pending, failure, success]
363
+ assert_equal failure, commit.significant_status
362
364
 
363
- commit.reload.statuses = [pending, error, success]
364
- assert_equal error, commit.significant_status
365
+ commit.reload.statuses = [pending, error, success]
366
+ assert_equal error, commit.significant_status
365
367
 
366
- commit.reload.statuses = [success, pending]
367
- assert_equal pending, commit.significant_status
368
+ commit.reload.statuses = [success, pending]
369
+ assert_equal pending, commit.significant_status
368
370
 
369
- commit.reload.statuses = [success]
370
- assert_equal success, commit.significant_status
371
+ commit.reload.statuses = [success]
372
+ assert_equal success, commit.significant_status
371
373
 
372
- commit.reload.statuses = []
373
- assert_equal UnknownStatus.new(commit), commit.significant_status
374
- end
374
+ commit.reload.statuses = []
375
+ assert_equal UnknownStatus.new(commit), commit.significant_status
376
+ end
375
377
 
376
- test "#significant_status is UnknownStatus when the commit has statuses but none meaningful" do
377
- commit = commits(:first)
378
- commit.stubs(meaningful_statuses: [])
379
- assert_equal UnknownStatus.new(commit), commit.significant_status
380
- end
378
+ test "#significant_status is UnknownStatus when the commit has statuses but none meaningful" do
379
+ commit = shipit_commits(:first)
380
+ commit.stubs(meaningful_statuses: [])
381
+ assert_equal UnknownStatus.new(commit), commit.significant_status
382
+ end
381
383
 
382
- private
384
+ private
383
385
 
384
- def expect_event(stack)
385
- Pubsubstub::RedisPubSub.expects(:publish).at_least_once
386
- Pubsubstub::RedisPubSub.expects(:publish).with do |channel, event|
387
- data = JSON.load(event.data)
388
- channel == "stack.#{stack.id}" && data['url'] == "/#{stack.to_param}"
386
+ def expect_event(stack)
387
+ Pubsubstub::RedisPubSub.expects(:publish).at_least_once
388
+ Pubsubstub::RedisPubSub.expects(:publish).with do |channel, event|
389
+ data = JSON.load(event.data)
390
+ channel == "stack.#{stack.id}" && data['url'] == "/#{stack.to_param}"
391
+ end
389
392
  end
390
- end
391
393
 
392
- def expect_hook_emit(commit, event, status_attributes)
393
- matchers = status_attributes.to_a.map { |pair| responds_with(pair.first, pair.second) }
394
- Hook.expects(:emit).with(event, commit.stack, has_entries(commit: commit, stack: commit.stack,
395
- event => all_of(*matchers),
396
- status: status_attributes[:state]))
394
+ def expect_hook_emit(commit, event, status_attributes)
395
+ matchers = status_attributes.to_a.map { |pair| responds_with(pair.first, pair.second) }
396
+ Hook.expects(:emit).with(event, commit.stack, has_entries(commit: commit, stack: commit.stack,
397
+ event => all_of(*matchers),
398
+ status: status_attributes[:state]))
399
+ end
397
400
  end
398
401
  end