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,10 +1,12 @@
1
1
  require 'test_helper'
2
2
 
3
- class StatusControllerTest < ActionController::TestCase
4
- test ":version returns Shipit.revision" do
5
- Shipit.expects(:revision).returns('foo')
6
- get :version
7
- assert_response :success
8
- assert_equal 'foo', response.body
3
+ module Shipit
4
+ class StatusControllerTest < ActionController::TestCase
5
+ test ":version returns Shipit.revision" do
6
+ Shipit.expects(:revision).returns('foo')
7
+ get :version
8
+ assert_response :success
9
+ assert_equal 'foo', response.body
10
+ end
9
11
  end
10
12
  end
@@ -1,88 +1,90 @@
1
1
  require 'test_helper'
2
2
 
3
- class TasksControllerTest < ActionController::TestCase
4
- setup do
5
- @stack = stacks(:shipit)
6
- @definition = @stack.find_task_definition('restart')
7
- @task = tasks(:shipit_restart)
8
- @commit = commits(:second)
9
- session[:user_id] = users(:walrus).id
10
- end
3
+ module Shipit
4
+ class TasksControllerTest < ActionController::TestCase
5
+ setup do
6
+ @stack = shipit_stacks(:shipit)
7
+ @definition = @stack.find_task_definition('restart')
8
+ @task = shipit_tasks(:shipit_restart)
9
+ @commit = shipit_commits(:second)
10
+ session[:user_id] = shipit_users(:walrus).id
11
+ end
11
12
 
12
- test "tasks defined in the shipit.yml can be displayed" do
13
- get :new, stack_id: @stack, definition_id: @definition.id
14
- assert_response :ok
15
- end
13
+ test "tasks defined in the shipit.yml can be displayed" do
14
+ get :new, stack_id: @stack, definition_id: @definition.id
15
+ assert_response :ok
16
+ end
16
17
 
17
- test "tasks defined in the shipit.yml can be triggered" do
18
- assert_difference '@stack.tasks.count', 1 do
19
- post :create, stack_id: @stack, definition_id: @definition.id
18
+ test "tasks defined in the shipit.yml can be triggered" do
19
+ assert_difference '@stack.tasks.count', 1 do
20
+ post :create, stack_id: @stack, definition_id: @definition.id
21
+ end
22
+ assert_redirected_to stack_task_path(@stack, Task.last)
20
23
  end
21
- assert_redirected_to stack_task_path(@stack, Task.last)
22
- end
23
24
 
24
- test "triggered tasks can be observed" do
25
- get :show, stack_id: @stack, id: @task.id
26
- assert_response :ok
27
- end
25
+ test "triggered tasks can be observed" do
26
+ get :show, stack_id: @stack, id: @task.id
27
+ assert_response :ok
28
+ end
28
29
 
29
- test ":abort call abort! on the deploy" do
30
- @task = deploys(:shipit_running)
31
- @task.pid = 42
32
- post :abort, stack_id: @stack.to_param, id: @task.id
30
+ test ":abort call abort! on the deploy" do
31
+ @task = shipit_deploys(:shipit_running)
32
+ @task.pid = 42
33
+ post :abort, stack_id: @stack.to_param, id: @task.id
33
34
 
34
- @task.reload
35
- assert_response :success
36
- assert_equal 'aborting', @task.reload.status
37
- assert_equal false, @task.rollback_once_aborted?
38
- end
35
+ @task.reload
36
+ assert_response :success
37
+ assert_equal 'aborting', @task.reload.status
38
+ assert_equal false, @task.rollback_once_aborted?
39
+ end
39
40
 
40
- test ":abort schedule the rollback if `rollback` is present" do
41
- @task = deploys(:shipit_running)
42
- @task.pid = 42
43
- post :abort, stack_id: @stack.to_param, id: @task.id, rollback: 'true'
41
+ test ":abort schedule the rollback if `rollback` is present" do
42
+ @task = shipit_deploys(:shipit_running)
43
+ @task.pid = 42
44
+ post :abort, stack_id: @stack.to_param, id: @task.id, rollback: 'true'
44
45
 
45
- @task.reload
46
- assert_response :success
47
- assert_equal 'aborting', @task.status
48
- assert_equal true, @task.rollback_once_aborted?
49
- end
46
+ @task.reload
47
+ assert_response :success
48
+ assert_equal 'aborting', @task.status
49
+ assert_equal true, @task.rollback_once_aborted?
50
+ end
50
51
 
51
- test ":index list the stack deploys" do
52
- get :index, stack_id: @stack.to_param
53
- assert_response :success
54
- assert_select '.task-list .task', @stack.tasks.count
55
- end
52
+ test ":index list the stack deploys" do
53
+ get :index, stack_id: @stack.to_param
54
+ assert_response :success
55
+ assert_select '.task-list .task', @stack.tasks.count
56
+ end
56
57
 
57
- test ":index paginates with the `since` parameter" do
58
- get :index, stack_id: @stack.to_param, since: @stack.tasks.last.id
59
- assert_response :success
60
- assert_select '.task-list .task', @stack.tasks.count - 1
61
- end
58
+ test ":index paginates with the `since` parameter" do
59
+ get :index, stack_id: @stack.to_param, since: @stack.tasks.last.id
60
+ assert_response :success
61
+ assert_select '.task-list .task', @stack.tasks.count - 1
62
+ end
62
63
 
63
- test ":tail returns the task status, output, and next url" do
64
- @task = deploys(:shipit_running)
65
- last_chunk = @task.chunks.last
64
+ test ":tail returns the task status, output, and next url" do
65
+ @task = shipit_deploys(:shipit_running)
66
+ last_chunk = @task.chunks.last
66
67
 
67
- get :tail, stack_id: @stack.to_param, id: @task.id, last_id: last_chunk.id, format: :json
68
- assert_response :success
69
- assert_json_keys %w(url status output)
70
- assert_json 'status', @task.status
71
- end
68
+ get :tail, stack_id: @stack.to_param, id: @task.id, last_id: last_chunk.id, format: :json
69
+ assert_response :success
70
+ assert_json_keys %w(url status output)
71
+ assert_json 'status', @task.status
72
+ end
72
73
 
73
- test ":tail doesn't returns the next url if the task is finished" do
74
- @task = deploys(:shipit)
74
+ test ":tail doesn't returns the next url if the task is finished" do
75
+ @task = shipit_deploys(:shipit)
75
76
 
76
- get :tail, stack_id: @stack.to_param, id: @task.id, format: :json
77
- assert_response :success
78
- assert_no_json 'url'
79
- end
77
+ get :tail, stack_id: @stack.to_param, id: @task.id, format: :json
78
+ assert_response :success
79
+ assert_no_json 'url'
80
+ end
80
81
 
81
- test ":tail returns the rollback url if the task have been aborted" do
82
- @task = deploys(:shipit_aborted)
82
+ test ":tail returns the rollback url if the task have been aborted" do
83
+ @task = shipit_deploys(:shipit_aborted)
83
84
 
84
- get :tail, stack_id: @stack.to_param, id: @task.id, format: :json
85
- assert_response :success
86
- assert_json_keys %w(status output rollback_url)
85
+ get :tail, stack_id: @stack.to_param, id: @task.id, format: :json
86
+ assert_response :success
87
+ assert_json_keys %w(status output rollback_url)
88
+ end
87
89
  end
88
90
  end
@@ -1,176 +1,178 @@
1
1
  require 'test_helper'
2
2
 
3
- class WebhooksControllerTest < ActionController::TestCase
4
- setup do
5
- @stack = stacks(:shipit)
6
- GithubHook.any_instance.stubs(:verify_signature).returns(true)
7
- end
3
+ module Shipit
4
+ class WebhooksControllerTest < ActionController::TestCase
5
+ setup do
6
+ @stack = shipit_stacks(:shipit)
7
+ GithubHook.any_instance.stubs(:verify_signature).returns(true)
8
+ end
8
9
 
9
- test ":push with the target branch queues a GithubSyncJob" do
10
- request.headers['X-Github-Event'] = 'push'
11
- params = payload(:push_master)
10
+ test ":push with the target branch queues a GithubSyncJob" do
11
+ request.headers['X-Github-Event'] = 'push'
12
+ params = payload(:push_master)
12
13
 
13
- assert_enqueued_with(job: GithubSyncJob, args: [stack_id: @stack.id]) do
14
- post :push, {stack_id: @stack.id}.merge(params)
14
+ assert_enqueued_with(job: GithubSyncJob, args: [stack_id: @stack.id]) do
15
+ post :push, {stack_id: @stack.id}.merge(params)
16
+ end
15
17
  end
16
- end
17
18
 
18
- test ":push with the target branch queues a GitMirrorUpdateJob" do
19
- request.headers['X-Github-Event'] = 'push'
20
- params = payload(:push_master)
19
+ test ":push with the target branch queues a GitMirrorUpdateJob" do
20
+ request.headers['X-Github-Event'] = 'push'
21
+ params = payload(:push_master)
21
22
 
22
- assert_enqueued_with(job: GitMirrorUpdateJob, args: [@stack]) do
23
- post :push, {stack_id: @stack.id}.merge(params)
23
+ assert_enqueued_with(job: GitMirrorUpdateJob, args: [@stack]) do
24
+ post :push, {stack_id: @stack.id}.merge(params)
25
+ end
24
26
  end
25
- end
26
27
 
27
- test ":push does not enqueue a job if not the target branch" do
28
- request.headers['X-Github-Event'] = 'push'
29
- params = payload(:push_not_master)
30
- assert_no_enqueued_jobs do
31
- post :push, {stack_id: @stack.id}.merge(params)
28
+ test ":push does not enqueue a job if not the target branch" do
29
+ request.headers['X-Github-Event'] = 'push'
30
+ params = payload(:push_not_master)
31
+ assert_no_enqueued_jobs do
32
+ post :push, {stack_id: @stack.id}.merge(params)
33
+ end
32
34
  end
33
- end
34
35
 
35
- test ":state create a Status for the specific commit" do
36
- request.headers['X-Github-Event'] = 'status'
36
+ test ":state create a Status for the specific commit" do
37
+ request.headers['X-Github-Event'] = 'status'
38
+
39
+ status_payload = payload(:status_master)
40
+ commit = shipit_commits(:first)
37
41
 
38
- status_payload = payload(:status_master)
39
- commit = commits(:first)
42
+ assert_difference 'commit.statuses.count', 1 do
43
+ post :state, {stack_id: @stack.id}.merge(status_payload)
44
+ end
40
45
 
41
- assert_difference 'commit.statuses.count', 1 do
42
- post :state, {stack_id: @stack.id}.merge(status_payload)
46
+ status = commit.statuses.last
47
+ assert_equal status_payload['target_url'], status.target_url
48
+ assert_equal status_payload['state'], status.state
49
+ assert_equal status_payload['description'], status.description
50
+ assert_equal status_payload['context'], status.context
51
+ assert_equal status_payload['created_at'], status.created_at.iso8601
43
52
  end
44
53
 
45
- status = commit.statuses.last
46
- assert_equal status_payload['target_url'], status.target_url
47
- assert_equal status_payload['state'], status.state
48
- assert_equal status_payload['description'], status.description
49
- assert_equal status_payload['context'], status.context
50
- assert_equal status_payload['created_at'], status.created_at.iso8601
51
- end
54
+ test ":state with a unexisting commit trows ActiveRecord::RecordNotFound" do
55
+ request.headers['X-Github-Event'] = 'status'
56
+ params = {'sha' => 'notarealcommit', 'state' => 'pending', 'branches' => [{'name' => 'master'}]}
57
+ assert_raises ActiveRecord::RecordNotFound do
58
+ post :state, {stack_id: @stack.id}.merge(params)
59
+ end
60
+ end
52
61
 
53
- test ":state with a unexisting commit trows ActiveRecord::RecordNotFound" do
54
- request.headers['X-Github-Event'] = 'status'
55
- params = {'sha' => 'notarealcommit', 'state' => 'pending', 'branches' => [{'name' => 'master'}]}
56
- assert_raises ActiveRecord::RecordNotFound do
62
+ test ":state in an untracked branche bails out" do
63
+ request.headers['X-Github-Event'] = 'status'
64
+ params = {'sha' => 'notarealcommit', 'state' => 'pending', 'branches' => []}
57
65
  post :state, {stack_id: @stack.id}.merge(params)
66
+ assert_response :ok
58
67
  end
59
- end
60
68
 
61
- test ":state in an untracked branche bails out" do
62
- request.headers['X-Github-Event'] = 'status'
63
- params = {'sha' => 'notarealcommit', 'state' => 'pending', 'branches' => []}
64
- post :state, {stack_id: @stack.id}.merge(params)
65
- assert_response :ok
66
- end
69
+ test ":push returns head :ok if request is ping" do
70
+ @request.headers['X-Github-Event'] = 'ping'
67
71
 
68
- test ":push returns head :ok if request is ping" do
69
- @request.headers['X-Github-Event'] = 'ping'
70
-
71
- assert_no_enqueued_jobs do
72
- post :state, stack_id: @stack.id, zen: "Git is beautiful"
73
- assert_response :ok
72
+ assert_no_enqueued_jobs do
73
+ post :state, stack_id: @stack.id, zen: "Git is beautiful"
74
+ assert_response :ok
75
+ end
74
76
  end
75
- end
76
77
 
77
- test ":state returns head :ok if request is ping" do
78
- @request.headers['X-Github-Event'] = 'ping'
78
+ test ":state returns head :ok if request is ping" do
79
+ @request.headers['X-Github-Event'] = 'ping'
79
80
 
80
- assert_no_enqueued_jobs do
81
- post :state, stack_id: @stack.id
82
- assert_response :ok
81
+ assert_no_enqueued_jobs do
82
+ post :state, stack_id: @stack.id
83
+ assert_response :ok
84
+ end
83
85
  end
84
- end
85
86
 
86
- test ":state verifies webhook signature" do
87
- commit = commits(:first)
87
+ test ":state verifies webhook signature" do
88
+ commit = shipit_commits(:first)
88
89
 
89
- params = {"sha" => commit.sha, "state" => "pending", "target_url" => "https://ci.example.com/1000/output"}
90
- signature = 'sha1=4848deb1c9642cd938e8caa578d201ca359a8249'
90
+ params = {"sha" => commit.sha, "state" => "pending", "target_url" => "https://ci.example.com/1000/output"}
91
+ signature = 'sha1=4848deb1c9642cd938e8caa578d201ca359a8249'
91
92
 
92
- @request.headers['X-Github-Event'] = 'push'
93
- @request.headers['X-Hub-Signature'] = signature
93
+ @request.headers['X-Github-Event'] = 'push'
94
+ @request.headers['X-Hub-Signature'] = signature
94
95
 
95
- GithubHook.any_instance.expects(:verify_signature).with(signature, URI.encode_www_form(params)).returns(false)
96
+ GithubHook.any_instance.expects(:verify_signature).with(signature, URI.encode_www_form(params)).returns(false)
96
97
 
97
- post :push, {stack_id: @stack.id}.merge(params)
98
- assert_response :unprocessable_entity
99
- end
98
+ post :push, {stack_id: @stack.id}.merge(params)
99
+ assert_response :unprocessable_entity
100
+ end
100
101
 
101
- test ":push verifies webhook signature" do
102
- params = {"ref" => "refs/heads/master"}
103
- signature = 'sha1=ad1d939e9acd6bdc2415a2dd5951be0f2a796ce0'
102
+ test ":push verifies webhook signature" do
103
+ params = {"ref" => "refs/heads/master"}
104
+ signature = 'sha1=ad1d939e9acd6bdc2415a2dd5951be0f2a796ce0'
104
105
 
105
- @request.headers['X-Github-Event'] = 'push'
106
- @request.headers['X-Hub-Signature'] = signature
106
+ @request.headers['X-Github-Event'] = 'push'
107
+ @request.headers['X-Hub-Signature'] = signature
107
108
 
108
- GithubHook.any_instance.expects(:verify_signature).with(signature, URI.encode_www_form(params)).returns(false)
109
+ GithubHook.any_instance.expects(:verify_signature).with(signature, URI.encode_www_form(params)).returns(false)
109
110
 
110
- post :push, {stack_id: @stack.id}.merge(params)
111
- assert_response :unprocessable_entity
112
- end
111
+ post :push, {stack_id: @stack.id}.merge(params)
112
+ assert_response :unprocessable_entity
113
+ end
113
114
 
114
- test ":membership creates the mentioned team on the fly" do
115
- assert_difference -> { Team.count }, 1 do
116
- post :membership, membership_params.merge(team: {
117
- id: 48,
118
- name: 'Ouiche Cooks',
119
- slug: 'ouiche-cooks',
120
- url: 'https://example.com',
121
- })
122
- assert_response :ok
115
+ test ":membership creates the mentioned team on the fly" do
116
+ assert_difference -> { Team.count }, 1 do
117
+ post :membership, membership_params.merge(team: {
118
+ id: 48,
119
+ name: 'Ouiche Cooks',
120
+ slug: 'ouiche-cooks',
121
+ url: 'https://example.com',
122
+ })
123
+ assert_response :ok
124
+ end
123
125
  end
124
- end
125
126
 
126
- test ":membership creates the mentioned user on the fly" do
127
- Shipit.github_api.expects(:user).with('george').returns(george)
128
- assert_difference -> { User.count }, 1 do
129
- post :membership, membership_params.merge(member: {login: 'george'})
130
- assert_response :ok
127
+ test ":membership creates the mentioned user on the fly" do
128
+ Shipit.github_api.expects(:user).with('george').returns(george)
129
+ assert_difference -> { User.count }, 1 do
130
+ post :membership, membership_params.merge(member: {login: 'george'})
131
+ assert_response :ok
132
+ end
131
133
  end
132
- end
133
134
 
134
- test ":membership can delete an user membership" do
135
- assert_difference -> { Membership.count }, -1 do
136
- post :membership, membership_params.merge(_action: 'removed')
137
- assert_response :ok
135
+ test ":membership can delete an user membership" do
136
+ assert_difference -> { Membership.count }, -1 do
137
+ post :membership, membership_params.merge(_action: 'removed')
138
+ assert_response :ok
139
+ end
138
140
  end
139
- end
140
141
 
141
- test ":membership can append an user membership" do
142
- assert_difference -> { Membership.count }, 1 do
143
- post :membership, membership_params.merge(member: {login: 'bob'})
144
- assert_response :ok
142
+ test ":membership can append an user membership" do
143
+ assert_difference -> { Membership.count }, 1 do
144
+ post :membership, membership_params.merge(member: {login: 'bob'})
145
+ assert_response :ok
146
+ end
145
147
  end
146
- end
147
148
 
148
- test ":membership can append an user twice" do
149
- assert_no_difference -> { Membership.count } do
150
- post :membership, membership_params
151
- assert_response :ok
149
+ test ":membership can append an user twice" do
150
+ assert_no_difference -> { Membership.count } do
151
+ post :membership, membership_params
152
+ assert_response :ok
153
+ end
152
154
  end
153
- end
154
155
 
155
- test ":membership can delete an user twice" do
156
- assert_no_difference -> { Membership.count } do
157
- post :membership, membership_params.merge(_action: 'removed', member: {login: 'bob'})
158
- assert_response :ok
156
+ test ":membership can delete an user twice" do
157
+ assert_no_difference -> { Membership.count } do
158
+ post :membership, membership_params.merge(_action: 'removed', member: {login: 'bob'})
159
+ assert_response :ok
160
+ end
159
161
  end
160
- end
161
162
 
162
- private
163
+ private
163
164
 
164
- def membership_params
165
- {_action: 'added', team: team_params, organization: {login: 'shopify'}, member: {login: 'walrus'}}
166
- end
165
+ def membership_params
166
+ {_action: 'added', team: team_params, organization: {login: 'shopify'}, member: {login: 'walrus'}}
167
+ end
167
168
 
168
- def team_params
169
- {id: teams(:shopify_developers).id, slug: 'developers', name: 'Developers', url: 'http://example.com'}
170
- end
169
+ def team_params
170
+ {id: shipit_teams(:shopify_developers).id, slug: 'developers', name: 'Developers', url: 'http://example.com'}
171
+ end
171
172
 
172
- def george
173
- rels = {self: stub(href: 'https://api.github.com/user/george')}
174
- stub(id: 42, name: 'George Abitbol', login: 'george', email: 'george@cyclim.se', rels: rels)
173
+ def george
174
+ rels = {self: stub(href: 'https://api.github.com/user/george')}
175
+ stub(id: 42, name: 'George Abitbol', login: 'george', email: 'george@cyclim.se', rels: rels)
176
+ end
175
177
  end
176
178
  end