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,11 +1,13 @@
1
1
  require 'test_helper'
2
2
 
3
- class CommandsTest < ActiveSupport::TestCase
4
- def setup
5
- @commands = Commands.new
6
- end
3
+ module Shipit
4
+ class CommandsTest < ActiveSupport::TestCase
5
+ def setup
6
+ @commands = Commands.new
7
+ end
7
8
 
8
- test 'SHIPIT gets added to the environment variables' do
9
- assert_equal '1', @commands.env['SHIPIT']
9
+ test 'SHIPIT gets added to the environment variables' do
10
+ assert_equal '1', @commands.env['SHIPIT']
11
+ end
10
12
  end
11
13
  end
@@ -1,36 +1,38 @@
1
1
  require 'test_helper'
2
2
 
3
- class CSVSerializerTest < ActiveSupport::TestCase
4
- test "blank values are dumped as nil" do
5
- assert_dumped nil, ''
6
- assert_dumped nil, ' '
7
- assert_dumped nil, nil
8
- assert_dumped nil, []
9
- end
3
+ module Shipit
4
+ class CSVSerializerTest < ActiveSupport::TestCase
5
+ test "blank values are dumped as nil" do
6
+ assert_dumped nil, ''
7
+ assert_dumped nil, ' '
8
+ assert_dumped nil, nil
9
+ assert_dumped nil, []
10
+ end
10
11
 
11
- test "blank values are loaded as an empty array" do
12
- assert_loaded [], ''
13
- assert_loaded [], ' '
14
- assert_loaded [], nil
15
- end
12
+ test "blank values are loaded as an empty array" do
13
+ assert_loaded [], ''
14
+ assert_loaded [], ' '
15
+ assert_loaded [], nil
16
+ end
16
17
 
17
- test "load split the words by comma" do
18
- assert_loaded %w(foo bar), 'foo,bar'
19
- end
18
+ test "load split the words by comma" do
19
+ assert_loaded %w(foo bar), 'foo,bar'
20
+ end
20
21
 
21
- test "dump join the words with a comma" do
22
- assert_dumped 'foo,bar', %w(foo bar)
23
- end
22
+ test "dump join the words with a comma" do
23
+ assert_dumped 'foo,bar', %w(foo bar)
24
+ end
24
25
 
25
- private
26
+ private
26
27
 
27
- def assert_dumped(expected, object)
28
- message = "Expected CSVSerializer.dump(#{object.inspect}) to eq #{expected.inspect}"
29
- assert_equal(expected, Shipit::CSVSerializer.dump(object), message)
30
- end
28
+ def assert_dumped(expected, object)
29
+ message = "Expected CSVSerializer.dump(#{object.inspect}) to eq #{expected.inspect}"
30
+ assert_equal(expected, Shipit::CSVSerializer.dump(object), message)
31
+ end
31
32
 
32
- def assert_loaded(expected, payload)
33
- message = "Expected CSVSerializer.load(#{payload.inspect}) to eq #{expected.inspect}"
34
- assert_equal(expected, Shipit::CSVSerializer.load(payload), message)
33
+ def assert_loaded(expected, payload)
34
+ message = "Expected CSVSerializer.load(#{payload.inspect}) to eq #{expected.inspect}"
35
+ assert_equal(expected, Shipit::CSVSerializer.load(payload), message)
36
+ end
35
37
  end
36
38
  end
@@ -1,180 +1,183 @@
1
1
  require 'test_helper'
2
2
 
3
- class DeployCommandsTest < ActiveSupport::TestCase
4
- def setup
5
- @stack = stacks(:shipit)
6
- @deploy = deploys(:shipit_pending)
7
- @commands = DeployCommands.new(@deploy)
8
- @deploy_spec = stub(
9
- dependencies_steps!: ['bundle install --some-args'],
10
- deploy_steps!: ['bundle exec cap $ENVIRONMENT deploy'],
11
- rollback_steps!: ['bundle exec cap $ENVIRONMENT deploy:rollback'],
12
- machine_env: {'GLOBAL' => '1'},
13
- directory: nil,
14
- )
15
- @commands.stubs(:deploy_spec).returns(@deploy_spec)
16
-
17
- StackCommands.stubs(git_version: Gem::Version.new('1.8.4.3'))
18
- end
19
-
20
- test "#fetch calls git fetch if repository cache already exist" do
21
- Dir.expects(:exist?).with(@stack.git_path).returns(true)
22
- command = @commands.fetch
23
- assert_equal %w(git fetch origin --tags master), command.args
24
- end
25
-
26
- test "#fetch calls git fetch in git_path directory if repository cache already exist" do
27
- Dir.expects(:exist?).with(@stack.git_path).returns(true)
28
- command = @commands.fetch
29
- assert_equal @stack.git_path, command.chdir
30
- end
31
-
32
- test "#fetch calls git clone if repository cache do not exist" do
33
- Dir.expects(:exist?).with(@stack.git_path).returns(false)
34
- command = @commands.fetch
35
- expected = %W(git clone --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
36
- assert_equal expected, command.args
37
- end
38
-
39
- test "#fetch does not use --single-branch if git is outdated" do
40
- Dir.expects(:exist?).with(@stack.git_path).returns(false)
41
- StackCommands.stubs(git_version: Gem::Version.new('1.7.2.30'))
42
- command = @commands.fetch
43
- expected = %W(git clone --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
44
- assert_equal expected, command.args
45
- end
46
-
47
- test "#fetch calls git fetch in base_path directory if repository cache do not exist" do
48
- Dir.expects(:exist?).with(@stack.git_path).returns(false)
49
- command = @commands.fetch
50
- assert_equal @stack.deploys_path, command.chdir
51
- end
52
-
53
- test "#fetch merges Shipit.env in ENVIRONMENT" do
54
- Shipit.stubs(:env).returns("SPECIFIC_CONFIG" => 5)
55
- command = @commands.fetch
56
- assert_equal 5, command.env["SPECIFIC_CONFIG"]
57
- end
58
-
59
- test "#clone clones the repository cache into the working directory" do
60
- command = @commands.clone
61
- assert_equal ['git', 'clone', '--local', @stack.git_path, @deploy.working_directory], command.args
62
- end
63
-
64
- test "#clone clones the repository cache from the deploys_path" do
65
- command = @commands.clone
66
- assert_equal @stack.deploys_path, command.chdir
67
- end
68
-
69
- test "#checkout checks out the deployed commit" do
70
- command = @commands.checkout(@deploy.until_commit)
71
- assert_equal ['git', 'checkout', @deploy.until_commit.sha], command.args
72
- end
73
-
74
- test "#checkout checks out the deployed commit from the working directory" do
75
- command = @commands.checkout(@deploy.until_commit)
76
- assert_equal @deploy.working_directory, command.chdir
77
- end
78
-
79
- test "#perform calls cap $environment deploy" do
80
- commands = @commands.perform
81
- assert_equal 1, commands.length
82
- command = commands.first
83
- assert_equal ['bundle exec cap $ENVIRONMENT deploy'], command.args
84
- end
85
-
86
- test "#perform calls cap $environment deploy:rollback for a rollback of a capistrano stack" do
87
- @rollback = @deploy.build_rollback
88
- @rollback.save!
89
- @commands = Commands.for(@rollback)
90
- @commands.stubs(:deploy_spec).returns(@deploy_spec)
91
-
92
- steps = @commands.perform
93
- assert_equal 1, steps.length
94
- step = steps.first
95
- assert_equal ['bundle exec cap $ENVIRONMENT deploy:rollback'], step.args
96
- end
97
-
98
- test "#perform calls cap $environment deploy from the working_directory" do
99
- commands = @commands.perform
100
- assert_equal 1, commands.length
101
- command = commands.first
102
- assert_equal @deploy.working_directory, command.chdir
103
- end
104
-
105
- test "the working_directory can be overriten in the spec" do
106
- @deploy_spec.stubs(:directory).returns('my_directory')
107
- commands = @commands.perform
108
- assert_equal 1, commands.length
109
- command = commands.first
110
- assert_equal File.join(@deploy.working_directory, 'my_directory'), command.chdir
111
- end
112
-
113
- test "#perform calls cap $environment deploy with the SHA in the environment" do
114
- commands = @commands.perform
115
- assert_equal 1, commands.length
116
- command = commands.first
117
- assert_equal @deploy.until_commit.sha, command.env['SHA']
118
- end
119
-
120
- test "#perform calls cap $environment deploy with the SHIPIT_LINK in the environment" do
121
- commands = @commands.perform
122
- assert_equal 1, commands.length
123
- command = commands.first
124
- assert_equal "http://shipit.com/shopify/shipit-engine/production/deploys/#{@deploy.id}", command.env['SHIPIT_LINK']
125
- end
126
-
127
- test "#perform calls cap $environment deploy with the LAST_DEPLOYED_SHA in the environment" do
128
- commands = @commands.perform
129
- assert_equal 1, commands.length
130
- command = commands.first
131
- assert_equal @deploy.stack.last_deployed_commit.sha, command.env['LAST_DEPLOYED_SHA']
132
- end
133
-
134
- test "#perform transliterates the user name" do
135
- @deploy.user = User.new(login: 'Sirupsen', name: "Simon Hørup Eskildsen")
136
- commands = @commands.perform
137
- assert_equal 1, commands.length
138
- command = commands.first
139
- assert_equal "Sirupsen (Simon Horup Eskildsen) via Shipit", command.env['USER']
140
- end
141
-
142
- test "#perform calls cap $environment deploy with the ENVIRONMENT in the environment" do
143
- commands = @commands.perform
144
- assert_equal 1, commands.length
145
- command = commands.first
146
- assert_equal @stack.environment, command.env['ENVIRONMENT']
147
- end
148
-
149
- test "#perform merges Shipit.env in ENVIRONMENT" do
150
- Shipit.stubs(:env).returns("SPECIFIC_CONFIG" => 5)
151
- assert_equal 5, @commands.env["SPECIFIC_CONFIG"]
152
- end
153
-
154
- test "#perform merges shipit.yml machine_env in ENVIRONMENT" do
155
- assert_equal '1', @commands.env['GLOBAL']
156
- end
157
-
158
- test "#install_dependencies calls bundle install" do
159
- commands = @commands.install_dependencies
160
- assert_equal 1, commands.length
161
- assert_equal ['bundle install --some-args'], commands.first.args
162
- end
163
-
164
- test "#install_dependencies merges Shipit.env in ENVIRONMENT" do
165
- Shipit.stubs(:env).returns("SPECIFIC_CONFIG" => 5)
166
- command = @commands.install_dependencies.first
167
- assert_equal 5, command.env["SPECIFIC_CONFIG"]
168
- end
169
-
170
- test "#install_dependencies merges machine_env in ENVIRONMENT" do
171
- command = @commands.install_dependencies.first
172
- assert_equal '1', command.env['GLOBAL']
173
- end
174
-
175
- test "the deploy's `env` is merged in ENVIRONMENT" do
176
- @deploy.env = {'FOO' => 'BAR'}
177
- command = @commands.install_dependencies.first
178
- assert_equal 'BAR', command.env['FOO']
3
+ module Shipit
4
+ class DeployCommandsTest < ActiveSupport::TestCase
5
+ def setup
6
+ @stack = shipit_stacks(:shipit)
7
+ @deploy = shipit_deploys(:shipit_pending)
8
+ @commands = DeployCommands.new(@deploy)
9
+ @deploy_spec = stub(
10
+ dependencies_steps!: ['bundle install --some-args'],
11
+ deploy_steps!: ['bundle exec cap $ENVIRONMENT deploy'],
12
+ rollback_steps!: ['bundle exec cap $ENVIRONMENT deploy:rollback'],
13
+ machine_env: {'GLOBAL' => '1'},
14
+ directory: nil,
15
+ )
16
+ @commands.stubs(:deploy_spec).returns(@deploy_spec)
17
+
18
+ StackCommands.stubs(git_version: Gem::Version.new('1.8.4.3'))
19
+ end
20
+
21
+ test "#fetch calls git fetch if repository cache already exist" do
22
+ Dir.expects(:exist?).with(@stack.git_path).returns(true)
23
+ command = @commands.fetch
24
+ assert_equal %w(git fetch origin --tags master), command.args
25
+ end
26
+
27
+ test "#fetch calls git fetch in git_path directory if repository cache already exist" do
28
+ Dir.expects(:exist?).with(@stack.git_path).returns(true)
29
+ command = @commands.fetch
30
+ assert_equal @stack.git_path, command.chdir
31
+ end
32
+
33
+ test "#fetch calls git clone if repository cache do not exist" do
34
+ Dir.expects(:exist?).with(@stack.git_path).returns(false)
35
+ command = @commands.fetch
36
+ expected = %W(git clone --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
37
+ assert_equal expected, command.args
38
+ end
39
+
40
+ test "#fetch does not use --single-branch if git is outdated" do
41
+ Dir.expects(:exist?).with(@stack.git_path).returns(false)
42
+ StackCommands.stubs(git_version: Gem::Version.new('1.7.2.30'))
43
+ command = @commands.fetch
44
+ expected = %W(git clone --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
45
+ assert_equal expected, command.args
46
+ end
47
+
48
+ test "#fetch calls git fetch in base_path directory if repository cache do not exist" do
49
+ Dir.expects(:exist?).with(@stack.git_path).returns(false)
50
+ command = @commands.fetch
51
+ assert_equal @stack.deploys_path, command.chdir
52
+ end
53
+
54
+ test "#fetch merges Shipit.env in ENVIRONMENT" do
55
+ Shipit.stubs(:env).returns("SPECIFIC_CONFIG" => 5)
56
+ command = @commands.fetch
57
+ assert_equal 5, command.env["SPECIFIC_CONFIG"]
58
+ end
59
+
60
+ test "#clone clones the repository cache into the working directory" do
61
+ command = @commands.clone
62
+ assert_equal ['git', 'clone', '--local', @stack.git_path, @deploy.working_directory], command.args
63
+ end
64
+
65
+ test "#clone clones the repository cache from the deploys_path" do
66
+ command = @commands.clone
67
+ assert_equal @stack.deploys_path, command.chdir
68
+ end
69
+
70
+ test "#checkout checks out the deployed commit" do
71
+ command = @commands.checkout(@deploy.until_commit)
72
+ assert_equal ['git', 'checkout', @deploy.until_commit.sha], command.args
73
+ end
74
+
75
+ test "#checkout checks out the deployed commit from the working directory" do
76
+ command = @commands.checkout(@deploy.until_commit)
77
+ assert_equal @deploy.working_directory, command.chdir
78
+ end
79
+
80
+ test "#perform calls cap $environment deploy" do
81
+ commands = @commands.perform
82
+ assert_equal 1, commands.length
83
+ command = commands.first
84
+ assert_equal ['bundle exec cap $ENVIRONMENT deploy'], command.args
85
+ end
86
+
87
+ test "#perform calls cap $environment deploy:rollback for a rollback of a capistrano stack" do
88
+ @rollback = @deploy.build_rollback
89
+ @rollback.save!
90
+ @commands = Commands.for(@rollback)
91
+ @commands.stubs(:deploy_spec).returns(@deploy_spec)
92
+
93
+ steps = @commands.perform
94
+ assert_equal 1, steps.length
95
+ step = steps.first
96
+ assert_equal ['bundle exec cap $ENVIRONMENT deploy:rollback'], step.args
97
+ end
98
+
99
+ test "#perform calls cap $environment deploy from the working_directory" do
100
+ commands = @commands.perform
101
+ assert_equal 1, commands.length
102
+ command = commands.first
103
+ assert_equal @deploy.working_directory, command.chdir
104
+ end
105
+
106
+ test "the working_directory can be overriten in the spec" do
107
+ @deploy_spec.stubs(:directory).returns('my_directory')
108
+ commands = @commands.perform
109
+ assert_equal 1, commands.length
110
+ command = commands.first
111
+ assert_equal File.join(@deploy.working_directory, 'my_directory'), command.chdir
112
+ end
113
+
114
+ test "#perform calls cap $environment deploy with the SHA in the environment" do
115
+ commands = @commands.perform
116
+ assert_equal 1, commands.length
117
+ command = commands.first
118
+ assert_equal @deploy.until_commit.sha, command.env['SHA']
119
+ end
120
+
121
+ test "#perform calls cap $environment deploy with the SHIPIT_LINK in the environment" do
122
+ commands = @commands.perform
123
+ assert_equal 1, commands.length
124
+ command = commands.first
125
+ url = "http://shipit.com/shopify/shipit-engine/production/deploys/#{@deploy.id}"
126
+ assert_equal url, command.env['SHIPIT_LINK']
127
+ end
128
+
129
+ test "#perform calls cap $environment deploy with the LAST_DEPLOYED_SHA in the environment" do
130
+ commands = @commands.perform
131
+ assert_equal 1, commands.length
132
+ command = commands.first
133
+ assert_equal @deploy.stack.last_deployed_commit.sha, command.env['LAST_DEPLOYED_SHA']
134
+ end
135
+
136
+ test "#perform transliterates the user name" do
137
+ @deploy.user = User.new(login: 'Sirupsen', name: "Simon Hørup Eskildsen")
138
+ commands = @commands.perform
139
+ assert_equal 1, commands.length
140
+ command = commands.first
141
+ assert_equal "Sirupsen (Simon Horup Eskildsen) via Shipit", command.env['USER']
142
+ end
143
+
144
+ test "#perform calls cap $environment deploy with the ENVIRONMENT in the environment" do
145
+ commands = @commands.perform
146
+ assert_equal 1, commands.length
147
+ command = commands.first
148
+ assert_equal @stack.environment, command.env['ENVIRONMENT']
149
+ end
150
+
151
+ test "#perform merges Shipit.env in ENVIRONMENT" do
152
+ Shipit.stubs(:env).returns("SPECIFIC_CONFIG" => 5)
153
+ assert_equal 5, @commands.env["SPECIFIC_CONFIG"]
154
+ end
155
+
156
+ test "#perform merges shipit.yml machine_env in ENVIRONMENT" do
157
+ assert_equal '1', @commands.env['GLOBAL']
158
+ end
159
+
160
+ test "#install_dependencies calls bundle install" do
161
+ commands = @commands.install_dependencies
162
+ assert_equal 1, commands.length
163
+ assert_equal ['bundle install --some-args'], commands.first.args
164
+ end
165
+
166
+ test "#install_dependencies merges Shipit.env in ENVIRONMENT" do
167
+ Shipit.stubs(:env).returns("SPECIFIC_CONFIG" => 5)
168
+ command = @commands.install_dependencies.first
169
+ assert_equal 5, command.env["SPECIFIC_CONFIG"]
170
+ end
171
+
172
+ test "#install_dependencies merges machine_env in ENVIRONMENT" do
173
+ command = @commands.install_dependencies.first
174
+ assert_equal '1', command.env['GLOBAL']
175
+ end
176
+
177
+ test "the deploy's `env` is merged in ENVIRONMENT" do
178
+ @deploy.env = {'FOO' => 'BAR'}
179
+ command = @commands.install_dependencies.first
180
+ assert_equal 'BAR', command.env['FOO']
181
+ end
179
182
  end
180
183
  end
@@ -1,288 +1,290 @@
1
1
  require 'test_helper'
2
2
 
3
- class DeploySpecTest < ActiveSupport::TestCase
4
- setup do
5
- @spec = DeploySpec::FileSystem.new('/tmp/', 'env')
6
- @spec.stubs(:load_config).returns({})
7
- end
3
+ module Shipit
4
+ class DeploySpecTest < ActiveSupport::TestCase
5
+ setup do
6
+ @spec = DeploySpec::FileSystem.new('/tmp/', 'env')
7
+ @spec.stubs(:load_config).returns({})
8
+ end
8
9
 
9
- test '#supports_fetch_deployed_revision? returns false by default' do
10
- refute @spec.supports_fetch_deployed_revision?
11
- end
10
+ test '#supports_fetch_deployed_revision? returns false by default' do
11
+ refute @spec.supports_fetch_deployed_revision?
12
+ end
12
13
 
13
- test '#supports_fetch_deployed_revision? returns true if steps are defined' do
14
- @spec.stubs(:load_config).returns('fetch' => ['curl --silent https://example.com/status/version'])
15
- assert @spec.supports_fetch_deployed_revision?
16
- end
14
+ test '#supports_fetch_deployed_revision? returns true if steps are defined' do
15
+ @spec.stubs(:load_config).returns('fetch' => ['curl --silent https://example.com/status/version'])
16
+ assert @spec.supports_fetch_deployed_revision?
17
+ end
17
18
 
18
- test '#supports_rollback? returns false by default' do
19
- refute @spec.supports_rollback?
20
- end
19
+ test '#supports_rollback? returns false by default' do
20
+ refute @spec.supports_rollback?
21
+ end
21
22
 
22
- test '#supports_rollback? returns true if steps are defined' do
23
- @spec.stubs(:load_config).returns('rollback' => {'override' => ['rm -rf /usr /lib/nvidia-current/xorg/xorg']})
24
- assert @spec.supports_rollback?
25
- end
23
+ test '#supports_rollback? returns true if steps are defined' do
24
+ @spec.stubs(:load_config).returns('rollback' => {'override' => ['rm -rf /usr /lib/nvidia-current/xorg/xorg']})
25
+ assert @spec.supports_rollback?
26
+ end
26
27
 
27
- test '#supports_rollback? returns true if stack is detected as capistrano' do
28
- @spec.expects(:capistrano?).returns(true)
29
- assert @spec.supports_rollback?
30
- end
28
+ test '#supports_rollback? returns true if stack is detected as capistrano' do
29
+ @spec.expects(:capistrano?).returns(true)
30
+ assert @spec.supports_rollback?
31
+ end
31
32
 
32
- test '#dependencies_steps returns `dependencies.override` if present' do
33
- @spec.stubs(:load_config).returns('dependencies' => {'override' => %w(foo bar baz)})
34
- assert_equal %w(foo bar baz), @spec.dependencies_steps
35
- end
33
+ test '#dependencies_steps returns `dependencies.override` if present' do
34
+ @spec.stubs(:load_config).returns('dependencies' => {'override' => %w(foo bar baz)})
35
+ assert_equal %w(foo bar baz), @spec.dependencies_steps
36
+ end
36
37
 
37
- test '#dependencies_steps returns `bundle install` if a `Gemfile` is present' do
38
- @spec.expects(:bundler?).returns(true)
39
- @spec.expects(:bundle_install).returns(:bundle_install)
40
- assert_equal :bundle_install, @spec.dependencies_steps
41
- end
38
+ test '#dependencies_steps returns `bundle install` if a `Gemfile` is present' do
39
+ @spec.expects(:bundler?).returns(true)
40
+ @spec.expects(:bundle_install).returns(:bundle_install)
41
+ assert_equal :bundle_install, @spec.dependencies_steps
42
+ end
42
43
 
43
- test '#fetch_deployed_revision_steps! is unknown by default' do
44
- assert_raises DeploySpec::Error do
45
- @spec.fetch_deployed_revision_steps!
44
+ test '#fetch_deployed_revision_steps! is unknown by default' do
45
+ assert_raises DeploySpec::Error do
46
+ @spec.fetch_deployed_revision_steps!
47
+ end
46
48
  end
47
- end
48
49
 
49
- test '#fetch_deployed_revision_steps use `fetch` is present' do
50
- @spec.stubs(:load_config).returns('fetch' => ['echo l33t'])
51
- assert_equal ['echo l33t'], @spec.fetch_deployed_revision_steps
52
- end
50
+ test '#fetch_deployed_revision_steps use `fetch` is present' do
51
+ @spec.stubs(:load_config).returns('fetch' => ['echo l33t'])
52
+ assert_equal ['echo l33t'], @spec.fetch_deployed_revision_steps
53
+ end
53
54
 
54
- test '#bundle_install return a sane default bundle install command' do
55
- @spec.stubs(:gemfile_lock_exists?).returns(true)
56
- command = %(
57
- bundle check --path=#{DeploySpec.bundle_path} ||
58
- bundle install
59
- --frozen
60
- --path=#{DeploySpec.bundle_path}
61
- --retry=2
62
- --without=default:production:development:test:staging:benchmark:debug
63
- ).gsub(/\s+/, ' ').strip
64
- assert_equal command, @spec.bundle_install.last
65
- end
55
+ test '#bundle_install return a sane default bundle install command' do
56
+ @spec.stubs(:gemfile_lock_exists?).returns(true)
57
+ command = %(
58
+ bundle check --path=#{DeploySpec.bundle_path} ||
59
+ bundle install
60
+ --frozen
61
+ --path=#{DeploySpec.bundle_path}
62
+ --retry=2
63
+ --without=default:production:development:test:staging:benchmark:debug
64
+ ).gsub(/\s+/, ' ').strip
65
+ assert_equal command, @spec.bundle_install.last
66
+ end
66
67
 
67
- test '#bundle_install use `dependencies.bundler.without` if present to build the --without argument' do
68
- @spec.stubs(:gemfile_lock_exists?).returns(true)
69
- @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'without' => %w(some custom groups)}})
70
- command = %(
71
- bundle check --path=#{DeploySpec.bundle_path} ||
72
- bundle install
73
- --frozen
74
- --path=#{DeploySpec.bundle_path}
75
- --retry=2
76
- --without=some:custom:groups
77
- ).gsub(/\s+/, ' ').strip
78
- assert_equal command, @spec.bundle_install.last
79
- end
68
+ test '#bundle_install use `dependencies.bundler.without` if present to build the --without argument' do
69
+ @spec.stubs(:gemfile_lock_exists?).returns(true)
70
+ @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'without' => %w(some custom groups)}})
71
+ command = %(
72
+ bundle check --path=#{DeploySpec.bundle_path} ||
73
+ bundle install
74
+ --frozen
75
+ --path=#{DeploySpec.bundle_path}
76
+ --retry=2
77
+ --without=some:custom:groups
78
+ ).gsub(/\s+/, ' ').strip
79
+ assert_equal command, @spec.bundle_install.last
80
+ end
80
81
 
81
- test '#bundle_install has --frozen option if Gemfile.lock is present' do
82
- @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'without' => %w(some custom groups)}})
83
- @spec.stubs(:gemfile_lock_exists?).returns(true)
84
- assert @spec.bundle_install.last.include?('--frozen')
85
- end
82
+ test '#bundle_install has --frozen option if Gemfile.lock is present' do
83
+ @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'without' => %w(some custom groups)}})
84
+ @spec.stubs(:gemfile_lock_exists?).returns(true)
85
+ assert @spec.bundle_install.last.include?('--frozen')
86
+ end
86
87
 
87
- test '#bundle_install does not have --frozen option if Gemfile.lock is not present' do
88
- @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'without' => %w(some custom groups)}})
89
- @spec.stubs(:gemfile_lock_exists?).returns(false)
90
- refute @spec.bundle_install.last.include?('--frozen')
91
- end
88
+ test '#bundle_install does not have --frozen option if Gemfile.lock is not present' do
89
+ @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'without' => %w(some custom groups)}})
90
+ @spec.stubs(:gemfile_lock_exists?).returns(false)
91
+ refute @spec.bundle_install.last.include?('--frozen')
92
+ end
92
93
 
93
- test '#bundle_install does not have --frozen if overridden in shipit.yml' do
94
- @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'frozen' => false}})
95
- @spec.stubs(:gemfile_lock_exists?).returns(true)
96
- refute @spec.bundle_install.last.include?('--frozen')
97
- end
94
+ test '#bundle_install does not have --frozen if overridden in shipit.yml' do
95
+ @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'frozen' => false}})
96
+ @spec.stubs(:gemfile_lock_exists?).returns(true)
97
+ refute @spec.bundle_install.last.include?('--frozen')
98
+ end
98
99
 
99
- test '#deploy_steps returns `deploy.override` if present' do
100
- @spec.stubs(:load_config).returns('deploy' => {'override' => %w(foo bar baz)})
101
- assert_equal %w(foo bar baz), @spec.deploy_steps
102
- end
100
+ test '#deploy_steps returns `deploy.override` if present' do
101
+ @spec.stubs(:load_config).returns('deploy' => {'override' => %w(foo bar baz)})
102
+ assert_equal %w(foo bar baz), @spec.deploy_steps
103
+ end
103
104
 
104
- test '#deploy_steps returns `cap $ENVIRONMENT deploy` if a `Capfile` is present' do
105
- @spec.expects(:bundler?).returns(true)
106
- @spec.expects(:capistrano?).returns(true)
107
- assert_equal ['bundle exec cap $ENVIRONMENT deploy'], @spec.deploy_steps
108
- end
105
+ test '#deploy_steps returns `cap $ENVIRONMENT deploy` if a `Capfile` is present' do
106
+ @spec.expects(:bundler?).returns(true)
107
+ @spec.expects(:capistrano?).returns(true)
108
+ assert_equal ['bundle exec cap $ENVIRONMENT deploy'], @spec.deploy_steps
109
+ end
109
110
 
110
- test '#deploy_steps raise a DeploySpec::Error! if it dont know how to deploy the app' do
111
- @spec.expects(:capistrano?).returns(false)
112
- assert_raise DeploySpec::Error do
113
- @spec.deploy_steps!
111
+ test '#deploy_steps raise a DeploySpec::Error! if it dont know how to deploy the app' do
112
+ @spec.expects(:capistrano?).returns(false)
113
+ assert_raise DeploySpec::Error do
114
+ @spec.deploy_steps!
115
+ end
114
116
  end
115
- end
116
117
 
117
- test '#rollback_steps returns `rollback.override` if present' do
118
- @spec.stubs(:load_config).returns('rollback' => {'override' => %w(foo bar baz)})
119
- assert_equal %w(foo bar baz), @spec.rollback_steps
120
- end
118
+ test '#rollback_steps returns `rollback.override` if present' do
119
+ @spec.stubs(:load_config).returns('rollback' => {'override' => %w(foo bar baz)})
120
+ assert_equal %w(foo bar baz), @spec.rollback_steps
121
+ end
121
122
 
122
- test '#rollback_steps returns `cap $ENVIRONMENT deploy:rollback` if a `Capfile` is present' do
123
- @spec.expects(:bundler?).returns(true)
124
- @spec.expects(:capistrano?).returns(true)
125
- assert_equal ['bundle exec cap $ENVIRONMENT deploy:rollback'], @spec.rollback_steps
126
- end
123
+ test '#rollback_steps returns `cap $ENVIRONMENT deploy:rollback` if a `Capfile` is present' do
124
+ @spec.expects(:bundler?).returns(true)
125
+ @spec.expects(:capistrano?).returns(true)
126
+ assert_equal ['bundle exec cap $ENVIRONMENT deploy:rollback'], @spec.rollback_steps
127
+ end
127
128
 
128
- test '#machine_env return an environment hash' do
129
- @spec.stubs(:load_config).returns('machine' => {'environment' => {'GLOBAL' => '1'}})
130
- assert_equal({'GLOBAL' => '1'}, @spec.machine_env)
131
- end
129
+ test '#machine_env return an environment hash' do
130
+ @spec.stubs(:load_config).returns('machine' => {'environment' => {'GLOBAL' => '1'}})
131
+ assert_equal({'GLOBAL' => '1'}, @spec.machine_env)
132
+ end
132
133
 
133
- test '#load_config can grab the env-specific shipit.yml file' do
134
- config = {}
135
- config.expects(:exist?).returns(true)
136
- config.expects(:read).returns({'dependencies' => {'override' => %w(foo bar baz)}}.to_yaml)
137
- spec = DeploySpec::FileSystem.new('.', 'staging')
138
- spec.expects(:file).with('shipit.staging.yml').returns(config)
139
- assert_equal %w(foo bar baz), spec.dependencies_steps
140
- end
134
+ test '#load_config can grab the env-specific shipit.yml file' do
135
+ config = {}
136
+ config.expects(:exist?).returns(true)
137
+ config.expects(:read).returns({'dependencies' => {'override' => %w(foo bar baz)}}.to_yaml)
138
+ spec = DeploySpec::FileSystem.new('.', 'staging')
139
+ spec.expects(:file).with('shipit.staging.yml').returns(config)
140
+ assert_equal %w(foo bar baz), spec.dependencies_steps
141
+ end
141
142
 
142
- test '#load_config grabs the global shipit.yml file if there is no env-specific file' do
143
- not_config = {}
144
- not_config.expects(:exist?).returns(false)
143
+ test '#load_config grabs the global shipit.yml file if there is no env-specific file' do
144
+ not_config = {}
145
+ not_config.expects(:exist?).returns(false)
145
146
 
146
- config = {}
147
- config.expects(:exist?).returns(true)
148
- config.expects(:read).returns({'dependencies' => {'override' => %w(foo bar baz)}}.to_yaml)
147
+ config = {}
148
+ config.expects(:exist?).returns(true)
149
+ config.expects(:read).returns({'dependencies' => {'override' => %w(foo bar baz)}}.to_yaml)
149
150
 
150
- spec = DeploySpec::FileSystem.new('.', 'staging')
151
- spec.expects(:file).with('shipit.staging.yml').returns(not_config)
152
- spec.expects(:file).with('shipit.yml').returns(config)
153
- assert_equal %w(foo bar baz), spec.dependencies_steps
154
- end
151
+ spec = DeploySpec::FileSystem.new('.', 'staging')
152
+ spec.expects(:file).with('shipit.staging.yml').returns(not_config)
153
+ spec.expects(:file).with('shipit.yml').returns(config)
154
+ assert_equal %w(foo bar baz), spec.dependencies_steps
155
+ end
155
156
 
156
- test '#gemspec gives the path of the repo gemspec if present' do
157
- spec = DeploySpec::FileSystem.new('foobar/', 'production')
158
- Dir.expects(:[]).with('foobar/*.gemspec').returns(['foobar/foobar.gemspec'])
159
- assert_equal 'foobar/foobar.gemspec', spec.gemspec
160
- end
157
+ test '#gemspec gives the path of the repo gemspec if present' do
158
+ spec = DeploySpec::FileSystem.new('foobar/', 'production')
159
+ Dir.expects(:[]).with('foobar/*.gemspec').returns(['foobar/foobar.gemspec'])
160
+ assert_equal 'foobar/foobar.gemspec', spec.gemspec
161
+ end
161
162
 
162
- test '#gem? is true if a gemspec is present' do
163
- @spec.expects(:gemspec).returns('something')
164
- assert @spec.gem?
165
- end
163
+ test '#gem? is true if a gemspec is present' do
164
+ @spec.expects(:gemspec).returns('something')
165
+ assert @spec.gem?
166
+ end
166
167
 
167
- test '#gem? is false if there is no gemspec' do
168
- @spec.expects(:gemspec).returns(nil)
169
- refute @spec.gem?
170
- end
168
+ test '#gem? is false if there is no gemspec' do
169
+ @spec.expects(:gemspec).returns(nil)
170
+ refute @spec.gem?
171
+ end
171
172
 
172
- test '#publish_gem first check if version tag have been created, and then invoke bundler release task' do
173
- @spec.stubs(:gemspec).returns('/tmp/shipit.gemspec')
174
- refute @spec.capistrano?
175
- assert_equal ['assert-gem-version-tag /tmp/shipit.gemspec', 'bundle exec rake release'], @spec.deploy_steps
176
- end
173
+ test '#publish_gem first check if version tag have been created, and then invoke bundler release task' do
174
+ @spec.stubs(:gemspec).returns('/tmp/shipit.gemspec')
175
+ refute @spec.capistrano?
176
+ assert_equal ['assert-gem-version-tag /tmp/shipit.gemspec', 'bundle exec rake release'], @spec.deploy_steps
177
+ end
177
178
 
178
- test '#setup_dot_py gives the path of the repo setup.py if present' do
179
- spec = DeploySpec::FileSystem.new('foobar/', 'production')
180
- assert_equal Pathname.new('foobar/setup.py'), spec.setup_dot_py
181
- end
179
+ test '#setup_dot_py gives the path of the repo setup.py if present' do
180
+ spec = DeploySpec::FileSystem.new('foobar/', 'production')
181
+ assert_equal Pathname.new('foobar/setup.py'), spec.setup_dot_py
182
+ end
182
183
 
183
- test '#egg? is true if a setup.py is present' do
184
- @spec.expects(:setup_dot_py).returns(Shipit::Engine.root.join('Gemfile'))
185
- assert @spec.egg?
186
- end
184
+ test '#egg? is true if a setup.py is present' do
185
+ @spec.expects(:setup_dot_py).returns(Shipit::Engine.root.join('Gemfile'))
186
+ assert @spec.egg?
187
+ end
187
188
 
188
- test '#egg? is false if there is no setup.py' do
189
- @spec.expects(:setup_dot_py).returns(Shipit::Engine.root.join("tmp-#{SecureRandom.hex}"))
190
- refute @spec.egg?
191
- end
189
+ test '#egg? is false if there is no setup.py' do
190
+ @spec.expects(:setup_dot_py).returns(Shipit::Engine.root.join("tmp-#{SecureRandom.hex}"))
191
+ refute @spec.egg?
192
+ end
192
193
 
193
- test '#publish_egg first check if version tag have been created and then invoke setup.py upload' do
194
- file = Pathname.new('/tmp/fake_setup.py')
195
- file.write('foo')
196
- @spec.stubs(:setup_dot_py).returns(file)
197
- steps = ['assert-egg-version-tag /tmp/fake_setup.py', 'python setup.py register sdist upload']
198
- assert_equal steps, @spec.deploy_steps
199
- end
194
+ test '#publish_egg first check if version tag have been created and then invoke setup.py upload' do
195
+ file = Pathname.new('/tmp/fake_setup.py')
196
+ file.write('foo')
197
+ @spec.stubs(:setup_dot_py).returns(file)
198
+ steps = ['assert-egg-version-tag /tmp/fake_setup.py', 'python setup.py register sdist upload']
199
+ assert_equal steps, @spec.deploy_steps
200
+ end
200
201
 
201
- test '#cacheable returns a DeploySpec instance that can be serialized' do
202
- assert_instance_of DeploySpec::FileSystem, @spec
203
- assert_instance_of DeploySpec, @spec.cacheable
204
- config = {
205
- 'ci' => {'hide' => [], 'allow_failures' => [], 'require' => []},
206
- 'machine' => {'environment' => {}, 'directory' => nil},
207
- 'review' => {'checklist' => [], 'monitoring' => [], 'checks' => []},
208
- 'dependencies' => {'override' => []},
209
- 'plugins' => {},
210
- 'deploy' => {'override' => nil, 'variables' => []},
211
- 'rollback' => {'override' => nil},
212
- 'fetch' => nil,
213
- 'tasks' => {},
214
- }
215
- assert_equal config, @spec.cacheable.config
216
- end
202
+ test '#cacheable returns a DeploySpec instance that can be serialized' do
203
+ assert_instance_of DeploySpec::FileSystem, @spec
204
+ assert_instance_of DeploySpec, @spec.cacheable
205
+ config = {
206
+ 'ci' => {'hide' => [], 'allow_failures' => [], 'require' => []},
207
+ 'machine' => {'environment' => {}, 'directory' => nil},
208
+ 'review' => {'checklist' => [], 'monitoring' => [], 'checks' => []},
209
+ 'dependencies' => {'override' => []},
210
+ 'plugins' => {},
211
+ 'deploy' => {'override' => nil, 'variables' => []},
212
+ 'rollback' => {'override' => nil},
213
+ 'fetch' => nil,
214
+ 'tasks' => {},
215
+ }
216
+ assert_equal config, @spec.cacheable.config
217
+ end
217
218
 
218
- test "#deploy_variables returns an empty array by default" do
219
- assert_equal [], @spec.deploy_variables
220
- end
219
+ test "#deploy_variables returns an empty array by default" do
220
+ assert_equal [], @spec.deploy_variables
221
+ end
221
222
 
222
- test "#deploy_variables returns an array of VariableDefinition instances" do
223
- @spec.stubs(:load_config).returns('deploy' => {'variables' => [{
224
- 'name' => 'SAFETY_DISABLED',
225
- 'title' => 'Set to 1 to do dangerous things',
226
- 'default' => 0,
227
- }]})
223
+ test "#deploy_variables returns an array of VariableDefinition instances" do
224
+ @spec.stubs(:load_config).returns('deploy' => {'variables' => [{
225
+ 'name' => 'SAFETY_DISABLED',
226
+ 'title' => 'Set to 1 to do dangerous things',
227
+ 'default' => 0,
228
+ }]})
228
229
 
229
- assert_equal 1, @spec.deploy_variables.size
230
- variable_definition = @spec.deploy_variables.first
231
- assert_equal 'SAFETY_DISABLED', variable_definition.name
232
- end
230
+ assert_equal 1, @spec.deploy_variables.size
231
+ variable_definition = @spec.deploy_variables.first
232
+ assert_equal 'SAFETY_DISABLED', variable_definition.name
233
+ end
233
234
 
234
- test "task definitions prepend bundle exec if necessary" do
235
- @spec.expects(:load_config).returns('tasks' => {'restart' => {'steps' => %w(foo)}})
236
- @spec.expects(:bundler?).returns(true).at_least_once
237
- definition = @spec.find_task_definition('restart')
235
+ test "task definitions prepend bundle exec if necessary" do
236
+ @spec.expects(:load_config).returns('tasks' => {'restart' => {'steps' => %w(foo)}})
237
+ @spec.expects(:bundler?).returns(true).at_least_once
238
+ definition = @spec.find_task_definition('restart')
238
239
 
239
- assert_equal ['bundle exec foo'], definition.steps
240
- end
240
+ assert_equal ['bundle exec foo'], definition.steps
241
+ end
241
242
 
242
- test "task definitions prepend bundle exec before serialization" do
243
- @spec.expects(:load_config).returns('tasks' => {'restart' => {'steps' => %w(foo)}})
244
- @spec.expects(:bundler?).returns(true).at_least_once
243
+ test "task definitions prepend bundle exec before serialization" do
244
+ @spec.expects(:load_config).returns('tasks' => {'restart' => {'steps' => %w(foo)}})
245
+ @spec.expects(:bundler?).returns(true).at_least_once
245
246
 
246
- cached_spec = DeploySpec.load(DeploySpec.dump(@spec))
247
- definition = cached_spec.find_task_definition('restart')
248
- assert_equal ['bundle exec foo'], definition.steps
249
- end
247
+ cached_spec = DeploySpec.load(DeploySpec.dump(@spec))
248
+ definition = cached_spec.find_task_definition('restart')
249
+ assert_equal ['bundle exec foo'], definition.steps
250
+ end
250
251
 
251
- test "#review_checklist returns an array" do
252
- @spec.expects(:load_config).returns('review' => {'checklist' => %w(foo bar)})
253
- assert_equal %w(foo bar), @spec.review_checklist
254
- end
252
+ test "#review_checklist returns an array" do
253
+ @spec.expects(:load_config).returns('review' => {'checklist' => %w(foo bar)})
254
+ assert_equal %w(foo bar), @spec.review_checklist
255
+ end
255
256
 
256
- test "#review_checklist returns an empty array if the section is missing" do
257
- assert_equal [], @spec.review_checklist
258
- end
257
+ test "#review_checklist returns an empty array if the section is missing" do
258
+ assert_equal [], @spec.review_checklist
259
+ end
259
260
 
260
- test "#review_monitoring returns an array of hashes" do
261
- @spec.expects(:load_config).returns('review' => {'monitoring' => [
262
- {'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400},
263
- {'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400},
264
- ]})
265
- assert_equal [
266
- {'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400},
267
- {'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400},
268
- ], @spec.review_monitoring
269
- end
261
+ test "#review_monitoring returns an array of hashes" do
262
+ @spec.expects(:load_config).returns('review' => {'monitoring' => [
263
+ {'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400},
264
+ {'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400},
265
+ ]})
266
+ assert_equal [
267
+ {'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400},
268
+ {'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400},
269
+ ], @spec.review_monitoring
270
+ end
270
271
 
271
- test "#review_monitoring returns an empty array if the section is missing" do
272
- assert_equal [], @spec.review_monitoring
273
- end
272
+ test "#review_monitoring returns an empty array if the section is missing" do
273
+ assert_equal [], @spec.review_monitoring
274
+ end
274
275
 
275
- test "#hidden_statuses is empty by default" do
276
- assert_equal [], @spec.hidden_statuses
277
- end
276
+ test "#hidden_statuses is empty by default" do
277
+ assert_equal [], @spec.hidden_statuses
278
+ end
278
279
 
279
- test "#hidden_statuses is an array even if the value is a string" do
280
- @spec.expects(:load_config).returns('ci' => {'hide' => 'ci/circleci'})
281
- assert_equal %w(ci/circleci), @spec.hidden_statuses
282
- end
280
+ test "#hidden_statuses is an array even if the value is a string" do
281
+ @spec.expects(:load_config).returns('ci' => {'hide' => 'ci/circleci'})
282
+ assert_equal %w(ci/circleci), @spec.hidden_statuses
283
+ end
283
284
 
284
- test "#hidden_statuses is an array even if the value is present" do
285
- @spec.expects(:load_config).returns('ci' => {'hide' => %w(ci/circleci ci/jenkins)})
286
- assert_equal %w(ci/circleci ci/jenkins), @spec.hidden_statuses
285
+ test "#hidden_statuses is an array even if the value is present" do
286
+ @spec.expects(:load_config).returns('ci' => {'hide' => %w(ci/circleci ci/jenkins)})
287
+ assert_equal %w(ci/circleci ci/jenkins), @spec.hidden_statuses
288
+ end
287
289
  end
288
290
  end