txgh-server 3.1.0 → 4.0.0.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/lib/txgh-server.rb +1 -0
  3. data/lib/txgh-server/application.rb +7 -1
  4. data/lib/txgh-server/download_handler.rb +1 -1
  5. data/lib/txgh-server/gitlab_request_auth.rb +13 -0
  6. data/lib/txgh-server/triggers/handler.rb +18 -1
  7. data/lib/txgh-server/triggers/pull_handler.rb +1 -10
  8. data/lib/txgh-server/triggers/push_handler.rb +1 -10
  9. data/lib/txgh-server/version.rb +1 -1
  10. data/lib/txgh-server/webhooks.rb +2 -0
  11. data/lib/txgh-server/webhooks/git.rb +15 -0
  12. data/lib/txgh-server/webhooks/git/blank_attributes.rb +20 -0
  13. data/lib/txgh-server/webhooks/git/delete_attributes.rb +54 -0
  14. data/lib/txgh-server/webhooks/git/delete_handler.rb +45 -0
  15. data/lib/txgh-server/webhooks/git/ping_handler.rb +21 -0
  16. data/lib/txgh-server/webhooks/git/push_attributes.rb +79 -0
  17. data/lib/txgh-server/webhooks/git/push_handler.rb +98 -0
  18. data/lib/txgh-server/webhooks/git/request_handler.rb +76 -0
  19. data/lib/txgh-server/webhooks/git/status_updater.rb +15 -0
  20. data/lib/txgh-server/webhooks/github/blank_attributes.rb +1 -13
  21. data/lib/txgh-server/webhooks/github/delete_attributes.rb +1 -38
  22. data/lib/txgh-server/webhooks/github/delete_handler.rb +1 -38
  23. data/lib/txgh-server/webhooks/github/ping_handler.rb +1 -12
  24. data/lib/txgh-server/webhooks/github/push_attributes.rb +1 -51
  25. data/lib/txgh-server/webhooks/github/push_handler.rb +2 -88
  26. data/lib/txgh-server/webhooks/github/request_handler.rb +2 -47
  27. data/lib/txgh-server/webhooks/github/status_updater.rb +1 -9
  28. data/lib/txgh-server/webhooks/gitlab.rb +14 -0
  29. data/lib/txgh-server/webhooks/gitlab/blank_attributes.rb +8 -0
  30. data/lib/txgh-server/webhooks/gitlab/delete_attributes.rb +17 -0
  31. data/lib/txgh-server/webhooks/gitlab/delete_handler.rb +8 -0
  32. data/lib/txgh-server/webhooks/gitlab/push_attributes.rb +29 -0
  33. data/lib/txgh-server/webhooks/gitlab/push_handler.rb +13 -0
  34. data/lib/txgh-server/webhooks/gitlab/request_handler.rb +59 -0
  35. data/lib/txgh-server/webhooks/gitlab/status_updater.rb +37 -0
  36. data/lib/txgh-server/webhooks/transifex/request_handler.rb +1 -1
  37. data/spec/application_spec.rb +11 -11
  38. data/spec/download_handler_spec.rb +6 -8
  39. data/spec/github_request_auth_spec.rb +6 -8
  40. data/spec/gitlab_request_auth_spec.rb +26 -0
  41. data/spec/helpers/gitlab_payload_builder.rb +132 -0
  42. data/spec/integration/hooks_spec.rb +1 -1
  43. data/spec/tgz_stream_response_spec.rb +2 -4
  44. data/spec/transifex_request_auth_spec.rb +6 -8
  45. data/spec/webhooks/github/delete_attributes_spec.rb +2 -5
  46. data/spec/webhooks/github/delete_handler_spec.rb +4 -7
  47. data/spec/webhooks/github/ping_handler_spec.rb +2 -5
  48. data/spec/webhooks/github/push_attributes_spec.rb +3 -6
  49. data/spec/webhooks/github/push_handler_spec.rb +5 -8
  50. data/spec/webhooks/github/request_handler_spec.rb +8 -10
  51. data/spec/webhooks/github/status_updater_spec.rb +2 -4
  52. data/spec/webhooks/gitlab/delete_attributes_spec.rb +27 -0
  53. data/spec/webhooks/gitlab/delete_handler_spec.rb +34 -0
  54. data/spec/webhooks/gitlab/push_attributes_spec.rb +64 -0
  55. data/spec/webhooks/gitlab/push_handler_spec.rb +99 -0
  56. data/spec/webhooks/gitlab/request_handler_spec.rb +73 -0
  57. data/spec/webhooks/gitlab/status_updater_spec.rb +66 -0
  58. data/spec/webhooks/transifex/hook_handler_spec.rb +2 -5
  59. data/spec/webhooks/transifex/request_handler_spec.rb +3 -5
  60. data/spec/zip_stream_response_spec.rb +2 -4
  61. data/txgh-server.gemspec +1 -2
  62. metadata +35 -10
  63. data/spec/integration/payloads/github_postbody_l10n.json +0 -136
@@ -96,7 +96,7 @@ describe 'hook integration tests', integration: true do
96
96
  header(
97
97
  GithubRequestAuth::GITHUB_HEADER,
98
98
  GithubRequestAuth.compute_signature(
99
- body, config.github_repo.webhook_secret
99
+ body, config.git_repo.webhook_secret
100
100
  )
101
101
  )
102
102
  end
@@ -3,9 +3,7 @@ require 'spec_helper'
3
3
  require 'stringio'
4
4
  require 'zlib'
5
5
 
6
- include TxghServer
7
-
8
- describe TgzStreamResponse do
6
+ describe TxghServer::TgzStreamResponse do
9
7
  def read_tgz_from(io)
10
8
  contents = {}
11
9
 
@@ -29,7 +27,7 @@ describe TgzStreamResponse do
29
27
  end
30
28
 
31
29
  let(:response) do
32
- TgzStreamResponse.new(attachment, enum)
30
+ described_class.new(attachment, enum)
33
31
  end
34
32
 
35
33
  describe '#write_to' do
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'rack'
3
3
 
4
- include TxghServer
5
-
6
- describe TransifexRequestAuth do
4
+ describe TxghServer::TransifexRequestAuth do
7
5
  let(:secret) { 'abc123' }
8
6
  let(:params) { { param1: 'value1', param2: 'value2', param3: 123 }.to_json }
9
7
  let(:date_str) { Time.now.strftime('%a, %d %b %Y %H:%M:%S GMT') }
@@ -19,31 +17,31 @@ describe TransifexRequestAuth do
19
17
  describe '.authentic_request?' do
20
18
  it 'returns true if the request is signed correctly' do
21
19
  request = Rack::Request.new(
22
- TransifexRequestAuth::RACK_HEADER => valid_signature,
20
+ described_class::RACK_HEADER => valid_signature,
23
21
  'HTTP_DATE' => date_str,
24
22
  'REQUEST_METHOD' => http_verb,
25
23
  'HTTP_X_TX_URL' => url,
26
24
  'rack.input' => StringIO.new(params)
27
25
  )
28
26
 
29
- authentic = TransifexRequestAuth.authentic_request?(request, secret)
27
+ authentic = described_class.authentic_request?(request, secret)
30
28
  expect(authentic).to eq(true)
31
29
  end
32
30
 
33
31
  it 'returns false if the request is not signed correctly' do
34
32
  request = Rack::Request.new(
35
- TransifexRequestAuth::RACK_HEADER => 'incorrect',
33
+ described_class::RACK_HEADER => 'incorrect',
36
34
  'rack.input' => StringIO.new(params)
37
35
  )
38
36
 
39
- authentic = TransifexRequestAuth.authentic_request?(request, secret)
37
+ authentic = described_class.authentic_request?(request, secret)
40
38
  expect(authentic).to eq(false)
41
39
  end
42
40
  end
43
41
 
44
42
  describe '.compute_signature' do
45
43
  it 'calculates the signature and formats it as an http header' do
46
- value = TransifexRequestAuth.compute_signature(
44
+ value = described_class.compute_signature(
47
45
  http_verb: http_verb,
48
46
  date_str: date_str,
49
47
  url: url,
@@ -1,10 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'helpers/github_payload_builder'
3
3
 
4
- include TxghServer
5
- include TxghServer::Webhooks::Github
6
-
7
- describe DeleteAttributes do
4
+ describe TxghServer::Webhooks::Github::DeleteAttributes do
8
5
  let(:repo_name) { 'my_repo' }
9
6
  let(:ref) { 'heads/my_ref' }
10
7
 
@@ -13,7 +10,7 @@ describe DeleteAttributes do
13
10
  end
14
11
 
15
12
  describe '#from_webhook_payload' do
16
- let(:attributes) { DeleteAttributes.from_webhook_payload(payload.to_h) }
13
+ let(:attributes) { TxghServer::Webhooks::Github::DeleteAttributes.from_webhook_payload(payload.to_h) }
17
14
 
18
15
  it 'pulls out repo name' do
19
16
  expect(attributes.repo_name).to eq(repo_name)
@@ -2,22 +2,19 @@ require 'spec_helper'
2
2
  require 'helpers/github_payload_builder'
3
3
  require 'helpers/standard_txgh_setup'
4
4
 
5
- include TxghServer
6
- include TxghServer::Webhooks::Github
7
-
8
- describe DeleteHandler do
5
+ describe TxghServer::Webhooks::Github::DeleteHandler do
9
6
  include StandardTxghSetup
10
7
 
11
8
  let(:handler) do
12
- DeleteHandler.new(transifex_project, github_repo, logger, attributes)
9
+ TxghServer::Webhooks::Github::DeleteHandler.new(transifex_project, github_repo, logger, attributes)
13
10
  end
14
11
 
15
12
  let(:attributes) do
16
- DeleteAttributes.from_webhook_payload(payload.to_h)
13
+ TxghServer::Webhooks::Github::DeleteAttributes.from_webhook_payload(payload.to_h)
17
14
  end
18
15
 
19
16
  let(:payload) do
20
- GithubPayloadBuilder.delete_payload(repo_name, ref)
17
+ GithubPayloadBuilder.delete_payload(github_repo_name, ref)
21
18
  end
22
19
 
23
20
  it 'deletes resources' do
@@ -1,12 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require 'helpers/nil_logger'
3
3
 
4
- include TxghServer
5
- include TxghServer::Webhooks::Github
6
-
7
- describe PingHandler do
4
+ describe TxghServer::Webhooks::Github::PingHandler do
8
5
  let(:handler) do
9
- PingHandler.new(NilLogger.new)
6
+ TxghServer::Webhooks::Github::PingHandler.new(NilLogger.new)
10
7
  end
11
8
 
12
9
  it 'responds with a 200 success' do
@@ -1,10 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'helpers/github_payload_builder'
3
3
 
4
- include TxghServer
5
- include TxghServer::Webhooks::Github
6
-
7
- describe PushAttributes do
4
+ describe TxghServer::Webhooks::Github::PushAttributes do
8
5
  let(:repo_name) { 'my_repo' }
9
6
  let(:ref) { 'heads/my_ref' }
10
7
  let(:added) { ['added_file.txt'] }
@@ -15,7 +12,7 @@ describe PushAttributes do
15
12
  end
16
13
 
17
14
  describe '#from_webhook_payload' do
18
- let(:attributes) { PushAttributes.from_webhook_payload(payload.to_h) }
15
+ let(:attributes) { TxghServer::Webhooks::Github::PushAttributes.from_webhook_payload(payload.to_h) }
19
16
 
20
17
  it "when no head commit, uses the pusher's name instead" do
21
18
  payload.merge!(pusher: { name: 'Fu Barro', email: 'fu@barro.com' })
@@ -29,7 +26,7 @@ describe PushAttributes do
29
26
  end
30
27
 
31
28
  describe '#from_webhook_payload' do
32
- let(:attributes) { PushAttributes.from_webhook_payload(payload.to_h) }
29
+ let(:attributes) { TxghServer::Webhooks::Github::PushAttributes.from_webhook_payload(payload.to_h) }
33
30
 
34
31
  it 'pulls out repo name' do
35
32
  expect(attributes.repo_name).to eq(repo_name)
@@ -2,22 +2,19 @@ require 'spec_helper'
2
2
  require 'helpers/github_payload_builder'
3
3
  require 'helpers/standard_txgh_setup'
4
4
 
5
- include TxghServer
6
- include TxghServer::Webhooks::Github
7
-
8
- describe PushHandler do
5
+ describe TxghServer::Webhooks::Github::PushHandler do
9
6
  include StandardTxghSetup
10
7
 
11
8
  let(:handler) do
12
- PushHandler.new(transifex_project, github_repo, logger, attributes)
9
+ TxghServer::Webhooks::Github::PushHandler.new(transifex_project, github_repo, logger, attributes)
13
10
  end
14
11
 
15
12
  let(:attributes) do
16
- PushAttributes.from_webhook_payload(payload.to_h)
13
+ TxghServer::Webhooks::Github::PushAttributes.from_webhook_payload(payload.to_h)
17
14
  end
18
15
 
19
16
  let(:payload) do
20
- GithubPayloadBuilder.push_payload(repo_name, ref)
17
+ GithubPayloadBuilder.push_payload(github_repo_name, ref)
21
18
  end
22
19
 
23
20
  let(:modified_files) do
@@ -87,7 +84,7 @@ describe PushHandler do
87
84
  let(:after) { '0' * 40 }
88
85
 
89
86
  let(:payload) do
90
- GithubPayloadBuilder.push_payload(repo_name, ref, before, after)
87
+ GithubPayloadBuilder.push_payload(github_repo_name, ref, before, after)
91
88
  end
92
89
 
93
90
  it "doesn't upload anything" do
@@ -4,9 +4,7 @@ require 'helpers/nil_logger'
4
4
  require 'helpers/standard_txgh_setup'
5
5
  require 'helpers/test_request'
6
6
 
7
- include TxghServer::Webhooks
8
-
9
- describe Github::RequestHandler do
7
+ describe TxghServer::Webhooks::Github::RequestHandler do
10
8
  include StandardTxghSetup
11
9
 
12
10
  let(:logger) { NilLogger.new }
@@ -19,10 +17,10 @@ describe Github::RequestHandler do
19
17
  describe '#handle_request' do
20
18
  context 'push event' do
21
19
  let(:event) { 'push' }
22
- let(:payload) { GithubPayloadBuilder.push_payload(repo_name, ref).tap { |p| p.add_commit } }
20
+ let(:payload) { GithubPayloadBuilder.push_payload(github_repo_name, ref).tap { |p| p.add_commit } }
23
21
 
24
22
  it 'does not execute if unauthorized' do
25
- expect_any_instance_of(Github::PushHandler).to_not receive(:execute)
23
+ expect_any_instance_of(TxghServer::Webhooks::Github::PushHandler).to_not receive(:execute)
26
24
  response = handler.handle_request
27
25
  expect(response.status).to eq(401)
28
26
  end
@@ -33,7 +31,7 @@ describe Github::RequestHandler do
33
31
  end
34
32
 
35
33
  it 'handles the request with the push handler' do
36
- expect_any_instance_of(Github::PushHandler).to receive(:execute).and_return(:response)
34
+ expect_any_instance_of(TxghServer::Webhooks::Github::PushHandler).to receive(:execute).and_return(:response)
37
35
  expect(handler.handle_request).to eq(:response)
38
36
  end
39
37
  end
@@ -41,10 +39,10 @@ describe Github::RequestHandler do
41
39
 
42
40
  context 'delete event' do
43
41
  let(:event) { 'delete' }
44
- let(:payload) { GithubPayloadBuilder.delete_payload(repo_name, ref) }
42
+ let(:payload) { GithubPayloadBuilder.delete_payload(github_repo_name, ref) }
45
43
 
46
44
  it 'does not execute if unauthorized' do
47
- expect_any_instance_of(Github::DeleteHandler).to_not receive(:execute)
45
+ expect_any_instance_of(TxghServer::Webhooks::Github::DeleteHandler).to_not receive(:execute)
48
46
  response = handler.handle_request
49
47
  expect(response.status).to eq(401)
50
48
  end
@@ -55,7 +53,7 @@ describe Github::RequestHandler do
55
53
  end
56
54
 
57
55
  it 'handles the request with the delete handler' do
58
- expect_any_instance_of(Github::DeleteHandler).to receive(:execute).and_return(:response)
56
+ expect_any_instance_of(TxghServer::Webhooks::Github::DeleteHandler).to receive(:execute).and_return(:response)
59
57
  expect(handler.handle_request).to eq(:response)
60
58
  end
61
59
  end
@@ -63,7 +61,7 @@ describe Github::RequestHandler do
63
61
 
64
62
  context 'unrecognized event' do
65
63
  let(:event) { 'foo' }
66
- let(:payload) { { repository: { full_name: repo_name } } }
64
+ let(:payload) { { repository: { full_name: github_repo_name } } }
67
65
 
68
66
  it 'responds with a 400' do
69
67
  allow(handler).to receive(:authentic_request?).and_return(true)
@@ -1,12 +1,10 @@
1
1
  require 'spec_helper'
2
2
  require 'helpers/standard_txgh_setup'
3
3
 
4
- include TxghServer::Webhooks::Github
5
-
6
- describe StatusUpdater do
4
+ describe TxghServer::Webhooks::Github::StatusUpdater do
7
5
  include StandardTxghSetup
8
6
 
9
- let(:updater) { StatusUpdater.new(transifex_project, github_repo, ref) }
7
+ let(:updater) { TxghServer::Webhooks::Github::StatusUpdater.new(transifex_project, github_repo, ref) }
10
8
 
11
9
  describe '#report_error_and_update_status' do
12
10
  let(:description) { 'An error done occurred, fool' }
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'helpers/gitlab_payload_builder'
3
+
4
+ describe TxghServer::Webhooks::Gitlab::DeleteAttributes do
5
+ let(:repo_name) { 'my_repo' }
6
+ let(:ref) { 'heads/my_ref' }
7
+
8
+ let(:payload) do
9
+ GitlabPayloadBuilder.delete_payload(repo_name, ref)
10
+ end
11
+
12
+ describe '#from_webhook_payload' do
13
+ let(:attributes) { TxghServer::Webhooks::Gitlab::DeleteAttributes.from_webhook_payload(payload.to_h) }
14
+
15
+ it 'pulls out repo name' do
16
+ expect(attributes.repo_name).to eq(repo_name)
17
+ end
18
+
19
+ it 'pulls out ref' do
20
+ expect(attributes.ref).to eq("refs/#{ref}")
21
+ end
22
+
23
+ it 'pulls out ref type' do
24
+ expect(attributes.ref_type).to eq('branch')
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'helpers/gitlab_payload_builder'
3
+ require 'helpers/standard_txgh_setup'
4
+
5
+ describe TxghServer::Webhooks::Gitlab::DeleteHandler do
6
+ include StandardTxghSetup
7
+
8
+ let(:handler) do
9
+ TxghServer::Webhooks::Gitlab::DeleteHandler.new(transifex_project, gitlab_repo, logger, attributes)
10
+ end
11
+
12
+ let(:attributes) do
13
+ TxghServer::Webhooks::Gitlab::DeleteAttributes.from_webhook_payload(payload.to_h)
14
+ end
15
+
16
+ let(:payload) do
17
+ GitlabPayloadBuilder.delete_payload(gitlab_repo_name, ref)
18
+ end
19
+
20
+ it 'deletes resources' do
21
+ expect_any_instance_of(Txgh::ResourceDeleter).to receive(:delete_resources)
22
+ response = handler.execute
23
+ expect(response.status).to eq(200)
24
+ expect(response.body).to eq(true)
25
+ end
26
+
27
+ it 'does not delete resources if auto resource deletions are disabled' do
28
+ project_config['auto_delete_resources'] = 'false'
29
+ expect(transifex_api).to_not receive(:delete)
30
+ response = handler.execute
31
+ expect(response.status).to eq(200)
32
+ expect(response.body).to eq(true)
33
+ end
34
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'helpers/gitlab_payload_builder'
3
+
4
+ describe TxghServer::Webhooks::Gitlab::PushAttributes do
5
+ let(:repo_name) { 'my_repo' }
6
+ let(:ref) { 'heads/my_ref' }
7
+ let(:added) { ['added_file.txt'] }
8
+ let(:modified) { ['modified_file.txt'] }
9
+
10
+ let(:payload) do
11
+ GitlabPayloadBuilder.push_payload(repo_name, ref)
12
+ end
13
+
14
+ describe '#from_webhook_payload' do
15
+ let(:attributes) { TxghServer::Webhooks::Gitlab::PushAttributes.from_webhook_payload(payload.to_h) }
16
+
17
+ it "when no head commit, uses the pusher's name instead" do
18
+ payload.merge!(user_name: 'Fu Barro')
19
+ expect(attributes.author).to eq('Fu Barro')
20
+ end
21
+ end
22
+
23
+ context 'with a commit added to the payload' do
24
+ before(:each) do
25
+ payload.add_commit(added: added, modified: modified)
26
+ end
27
+
28
+ describe '#from_webhook_payload' do
29
+ let(:attributes) { TxghServer::Webhooks::Gitlab::PushAttributes.from_webhook_payload(payload.to_h) }
30
+
31
+ it 'pulls out repo name' do
32
+ expect(attributes.repo_name).to eq(repo_name)
33
+ end
34
+
35
+ it 'pulls out ref' do
36
+ expect(attributes.ref).to eq("refs/#{ref}")
37
+ end
38
+
39
+ it 'pulls out before sha' do
40
+ expect(attributes.before).to eq(payload.to_h['before'])
41
+ end
42
+
43
+ it 'pulls out after sha' do
44
+ expect(attributes.after).to eq(payload.to_h['after'])
45
+ end
46
+
47
+ it 'pulls out added files' do
48
+ expect(attributes.added_files.to_a).to eq(added)
49
+ end
50
+
51
+ it 'pulls out modified files' do
52
+ expect(attributes.modified_files.to_a).to eq(modified)
53
+ end
54
+
55
+ it 'combines all files into one handy array' do
56
+ expect(attributes.files.sort).to eq((added + modified).sort)
57
+ end
58
+
59
+ it 'pulls out the author' do
60
+ expect(attributes.author).to eq('testuser')
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+ require 'helpers/gitlab_payload_builder'
3
+ require 'helpers/standard_txgh_setup'
4
+
5
+ describe TxghServer::Webhooks::Gitlab::PushHandler do
6
+ include StandardTxghSetup
7
+
8
+ let(:handler) do
9
+ TxghServer::Webhooks::Gitlab::PushHandler.new(transifex_project, gitlab_repo, logger, attributes)
10
+ end
11
+
12
+ let(:attributes) do
13
+ TxghServer::Webhooks::Gitlab::PushAttributes.from_webhook_payload(payload.to_h)
14
+ end
15
+
16
+ let(:payload) do
17
+ GitlabPayloadBuilder.push_payload(gitlab_repo_name, ref)
18
+ end
19
+
20
+ let(:modified_files) do
21
+ file_sha = 'def456'
22
+ tx_config.resources.map do |resource|
23
+ { path: resource.source_file, sha: file_sha.next! }
24
+ end
25
+ end
26
+
27
+ let(:updater) { double(:updater) }
28
+
29
+ before(:each) do
30
+ payload.add_commit(
31
+ modified: modified_files.map { |f| f[:path] }
32
+ )
33
+
34
+ allow(Txgh::ResourceUpdater).to receive(:new).and_return(updater)
35
+ end
36
+
37
+ it 'correctly uploads modified resources to transifex' do
38
+ tx_config.resources.each do |resource|
39
+ expect(updater).to(
40
+ receive(:update_resource) do |resource, categories|
41
+ expect(resource.project_slug).to eq(project_name)
42
+ expect(resource.resource_slug).to eq(resource_slug)
43
+ expect(categories).to eq('author' => 'testuser')
44
+ end
45
+ )
46
+ end
47
+
48
+ expect(Txgh::GitlabStatus).to(
49
+ receive(:update).with(transifex_project, gitlab_repo, ref)
50
+ )
51
+
52
+ response = handler.execute
53
+ expect(response.status).to eq(200)
54
+ expect(response.body).to eq(true)
55
+ end
56
+
57
+ context 'with an error' do
58
+ let(:description) { 'An error done occurred, fool' }
59
+ let(:target_url) { 'http://you-goofed.com' }
60
+
61
+ let(:status_params) do
62
+ { description: description, target_url: target_url }
63
+ end
64
+
65
+ let(:error_params) { { foo: 'bar' } }
66
+
67
+ before(:each) do
68
+ Txgh.events.subscribe(Txgh::Events::ERROR_CHANNEL) { error_params }
69
+ Txgh.events.subscribe('gitlab.status.error') { status_params }
70
+ end
71
+
72
+ it 'reports errors and updates the gitlab status' do
73
+ expect(Txgh::GitlabStatus).to(
74
+ receive(:error).with(transifex_project, gitlab_repo, ref, status_params)
75
+ )
76
+
77
+ expect(handler).to receive(:should_process?).and_raise(StandardError)
78
+ handler.execute
79
+ end
80
+ end
81
+
82
+ context 'with a deleted branch' do
83
+ let(:before) { nil }
84
+ let(:after) { '0' * 40 }
85
+
86
+ let(:payload) do
87
+ GitlabPayloadBuilder.push_payload(gitlab_repo_name, ref, before, after)
88
+ end
89
+
90
+ it "doesn't upload anything" do
91
+ expect(updater).to_not receive(:update_resource)
92
+ expect(gitlab_api).to_not receive(:create_ref)
93
+
94
+ response = handler.execute
95
+ expect(response.status).to eq(200)
96
+ expect(response.body).to eq(true)
97
+ end
98
+ end
99
+ end