txgh 6.0.0.beta1 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,11 @@
1
1
  require 'spec_helper'
2
+ require 'base64'
2
3
 
3
4
  include Txgh
4
5
 
5
6
  describe GithubApi do
6
7
  let(:client) { double(:client) }
7
- let(:api) { GithubApi.create_from_client(client) }
8
+ let(:api) { GithubApi.create_from_client(client, repo) }
8
9
  let(:repo) { 'my_org/my_repo' }
9
10
  let(:branch) { 'master' }
10
11
  let(:sha) { 'abc123' }
@@ -12,26 +13,26 @@ describe GithubApi do
12
13
  describe '#tree' do
13
14
  it 'retrieves a git tree using the client' do
14
15
  expect(client).to receive(:tree).with(repo, sha, recursive: 1)
15
- api.tree(repo, sha)
16
+ api.tree(sha)
16
17
  end
17
18
  end
18
19
 
19
20
  describe '#blob' do
20
21
  it 'retrieves a git blob using the client' do
21
22
  expect(client).to receive(:blob).with(repo, sha)
22
- api.blob(repo, sha)
23
+ api.blob(sha)
23
24
  end
24
25
  end
25
26
 
26
27
  describe '#create_ref' do
27
28
  it 'creates the given ref using the client' do
28
29
  expect(client).to receive(:create_ref).with(repo, branch, sha)
29
- api.create_ref(repo, branch, sha)
30
+ api.create_ref(branch, sha)
30
31
  end
31
32
 
32
33
  it 'returns false on client error' do
33
34
  expect(client).to receive(:create_ref).and_raise(StandardError)
34
- expect(api.create_ref(repo, branch, sha)).to eq(false)
35
+ expect(api.create_ref(branch, sha)).to eq(false)
35
36
  end
36
37
  end
37
38
 
@@ -54,7 +55,7 @@ describe GithubApi do
54
55
  .with(repo, path, 'message', old_sha, new_contents, { branch: branch })
55
56
  )
56
57
 
57
- api.update_contents(repo, branch, { path => new_contents }, 'message')
58
+ api.update_contents(branch, { path => new_contents }, 'message')
58
59
  end
59
60
 
60
61
  it "doesn't update the file contents if the file hasn't changed" do
@@ -66,7 +67,7 @@ describe GithubApi do
66
67
 
67
68
  expect(client).to_not receive(:update_contents)
68
69
 
69
- api.update_contents(repo, branch, { path => old_contents }, 'message')
70
+ api.update_contents(branch, { path => old_contents }, 'message')
70
71
  end
71
72
 
72
73
  it "creates the file if it doesn't already exist" do
@@ -80,118 +81,65 @@ describe GithubApi do
80
81
  .with(repo, path, 'message', '0' * 40, new_contents, { branch: branch })
81
82
  )
82
83
 
83
- api.update_contents(repo, branch, { path => new_contents }, 'message')
84
- end
85
- end
86
-
87
- describe '#commit' do
88
- let(:path) { 'path/to/translations' }
89
- let(:other_path) { 'other/path/to/translations' }
90
-
91
- before(:each) do
92
- allow(client).to receive(:create_blob).with(repo, :new_content).and_return(:blob_sha)
93
- allow(client).to receive(:ref).with(repo, branch).and_return(object: { sha: :branch_sha })
94
- allow(client).to receive(:commit).with(repo, :branch_sha).and_return(commit: { tree: { sha: :base_tree_sha } })
95
- allow(client).to receive(:create_tree).and_return(sha: :new_tree_sha)
96
- end
97
-
98
- it 'creates a new commit and updates the branch' do
99
- expect(client).to(
100
- receive(:create_commit)
101
- .with(repo, 'message', :new_tree_sha, :branch_sha)
102
- .and_return(sha: :new_commit_sha)
103
- )
104
-
105
- expect(client).to receive(:update_ref).with(repo, branch, :new_commit_sha, false)
106
- api.commit(repo, branch, { path => :new_content }, 'message', true)
107
- end
108
-
109
- it 'updates multiple files at a time' do
110
- allow(client).to receive(:create_blob).with(repo, :other_content).and_return(:blob_sha_2)
111
-
112
- expect(client).to(
113
- receive(:create_commit)
114
- .with(repo, 'message', :new_tree_sha, :branch_sha)
115
- .and_return(sha: :new_commit_sha)
116
- )
117
-
118
- expect(client).to receive(:update_ref).with(repo, branch, :new_commit_sha, false)
119
- content_map = { path => :new_content, other_path => :other_content }
120
- api.commit(repo, branch, content_map, 'message', true)
121
- end
122
-
123
- context 'with an empty commit' do
124
- before(:each) do
125
- allow(client).to(
126
- receive(:compare)
127
- .with(repo, :branch_sha, :new_commit_sha)
128
- .and_return(files: [])
129
- )
130
-
131
- expect(client).to(
132
- receive(:create_commit)
133
- .with(repo, 'message', :new_tree_sha, :branch_sha)
134
- .and_return(sha: :new_commit_sha)
135
- )
136
- end
137
-
138
- it 'does not allow empty commits by default' do
139
- expect(client).to_not receive(:update_ref)
140
- api.commit(repo, branch, { path => :new_content }, 'message')
141
- end
142
- end
143
-
144
- context 'with a non-empty commit' do
145
- before(:each) do
146
- allow(client).to(
147
- receive(:compare)
148
- .with(repo, :branch_sha, :new_commit_sha)
149
- .and_return(files: %w(abc def))
150
- )
151
-
152
- expect(client).to(
153
- receive(:create_commit)
154
- .with(repo, 'message', :new_tree_sha, :branch_sha)
155
- .and_return(sha: :new_commit_sha)
156
- )
157
- end
158
-
159
- it 'updates the ref as expected' do
160
- expect(client).to receive(:update_ref).with(repo, branch, :new_commit_sha, false)
161
- api.commit(repo, branch, { path => :new_content }, 'message')
162
- end
84
+ api.update_contents(branch, { path => new_contents }, 'message')
163
85
  end
164
86
  end
165
87
 
166
88
  describe '#get_commit' do
167
89
  it 'retrieves the given commit using the client' do
168
90
  expect(client).to receive(:commit).with(repo, sha)
169
- api.get_commit(repo, sha)
91
+ api.get_commit(sha)
170
92
  end
171
93
  end
172
94
 
173
95
  describe '#get_ref' do
174
96
  it 'retrieves the given ref (i.e. branch) using the client' do
175
97
  expect(client).to receive(:ref).with(repo, sha)
176
- api.get_ref(repo, sha)
98
+ api.get_ref(sha)
177
99
  end
178
100
  end
179
101
 
180
102
  describe '#download' do
103
+ let(:path) { 'path/to/file.xyz' }
104
+
181
105
  it 'downloads the file from the given branch' do
182
- path = 'path/to/file.xyz'
106
+ expect(client).to(
107
+ receive(:contents)
108
+ .with(repo, path: path, ref: branch)
109
+ .and_return(
110
+ content: 'content', encoding: 'utf-8'
111
+ )
112
+ )
113
+
114
+ expect(api.download(path, branch)).to eq({ content: 'content' })
115
+ end
116
+
117
+ it 'encodes the string using the encoding specified in the response' do
118
+ content = 'ありがと'.encode('UTF-16')
183
119
 
184
- expect(client).to receive(:ref).with(repo, branch).and_return(object: { sha: :branch_sha })
185
- expect(client).to receive(:commit).with(repo, :branch_sha).and_return(commit: { tree: { sha: :base_tree_sha } })
186
- expect(client).to receive(:tree).with(repo, :base_tree_sha, recursive: 1).and_return(
187
- tree: [{ path: path, sha: :blob_sha }]
120
+ expect(client).to(
121
+ receive(:contents)
122
+ .with(repo, path: path, ref: branch)
123
+ .and_return(
124
+ content: content, encoding: 'utf-16'
125
+ )
188
126
  )
189
127
 
190
- expect(client).to receive(:blob).with(repo, :blob_sha).and_return(
191
- { 'content' => :blob, 'encoding' => 'utf-8' }
128
+ result = api.download(path, branch)
129
+ expect(result[:content].encoding).to eq(Encoding::UTF_16)
130
+ expect(result[:content]).to eq(content)
131
+ end
132
+
133
+ it 'automatically decodes base64-encoded content' do
134
+ expect(client).to(
135
+ receive(:contents)
136
+ .with(repo, path: path, ref: branch)
137
+ .and_return(
138
+ content: Base64.encode64('content'), encoding: 'base64'
139
+ )
192
140
  )
193
141
 
194
- expect(api.download(repo, path, branch)).to eq(:blob)
142
+ expect(api.download(path, branch)).to eq({ content: 'content' })
195
143
  end
196
144
  end
197
145
  end
@@ -26,8 +26,7 @@ describe GithubStatus do
26
26
 
27
27
  context 'with all resources at 100%' do
28
28
  it 'reports status as success' do
29
- expect(github_api).to receive(:create_status) do |repo, commit_sha, state, options|
30
- expect(repo).to eq(repo_name)
29
+ expect(github_api).to receive(:create_status) do |commit_sha, state, options|
31
30
  expect(commit_sha).to eq(sha)
32
31
  expect(state).to eq(GithubStatus::State.success)
33
32
  expect(options[:description]).to eq('Translations complete!')
@@ -56,7 +55,7 @@ describe GithubStatus do
56
55
  end
57
56
 
58
57
  it 'reports status as pending' do
59
- expect(github_api).to receive(:create_status) do |repo, commit_sha, state, options|
58
+ expect(github_api).to receive(:create_status) do |commit_sha, state, options|
60
59
  expect(state).to eq(GithubStatus::State.pending)
61
60
  expect(options[:description]).to eq('15/20 translations complete.')
62
61
  end
@@ -46,6 +46,22 @@ describe MergeCalculator do
46
46
  end
47
47
  end
48
48
 
49
+ context 'with an array added in HEAD' do
50
+ let(:diff_point_phrases) do
51
+ [phrase('planet.earth', 'Human')]
52
+ end
53
+
54
+ let(:head_phrases) do
55
+ diff_point_phrases + [
56
+ phrase('villains', %w(Kahn Chang Valeris Shinzon))
57
+ ]
58
+ end
59
+
60
+ it 'includes the added array' do
61
+ expect(merge_result.phrases).to eq(head_phrases)
62
+ end
63
+ end
64
+
49
65
  context 'with phrases removed from HEAD' do
50
66
  let(:diff_point_phrases) do
51
67
  head_phrases + [
@@ -62,6 +78,22 @@ describe MergeCalculator do
62
78
  end
63
79
  end
64
80
 
81
+ context 'with an array removed from HEAD' do
82
+ let(:diff_point_phrases) do
83
+ head_phrases + [
84
+ phrase('villains', %w(Kahn Chang Valeris Shinzon))
85
+ ]
86
+ end
87
+
88
+ let(:head_phrases) do
89
+ [phrase('planet.earth', 'Human')]
90
+ end
91
+
92
+ it 'does not include the removed array' do
93
+ expect(merge_result.phrases).to eq(head_phrases)
94
+ end
95
+ end
96
+
65
97
  context 'with phrases modified in HEAD' do
66
98
  let(:diff_point_phrases) do
67
99
  [phrase('planet.bajor', 'Cardassian')]
@@ -76,6 +108,20 @@ describe MergeCalculator do
76
108
  end
77
109
  end
78
110
 
111
+ context 'with an array modified in HEAD' do
112
+ let(:diff_point_phrases) do
113
+ [phrase('villains', %w(Kahn Chang Valeris))]
114
+ end
115
+
116
+ let(:head_phrases) do
117
+ [phrase('villains', %w(Kahn Chang Valeris Shinzon))]
118
+ end
119
+
120
+ it 'includes the modified phrase' do
121
+ expect(merge_result.phrases).to eq(head_phrases)
122
+ end
123
+ end
124
+
79
125
  context 'with no phrases modified, added, or removed' do
80
126
  let(:diff_point_phrases) do
81
127
  [phrase('planet.bajor', 'Bajoran')]
@@ -32,7 +32,7 @@ describe ResourceCommitter do
32
32
 
33
33
  expect(github_api).to(
34
34
  receive(:update_contents).with(
35
- repo_name, branch, { file_name => :translations }, commit_message
35
+ branch, { file_name => :translations }, commit_message
36
36
  )
37
37
  )
38
38
  end
@@ -11,18 +11,29 @@ describe ResourceContents do
11
11
  )
12
12
  end
13
13
 
14
- let(:raw_contents) do
14
+ let(:default_contents) do
15
15
  outdent(%Q(
16
16
  en:
17
17
  welcome:
18
- message: Hello!
18
+ message: "Hello!"
19
19
  goodbye:
20
- message: Goodbye!
20
+ message: "Goodbye!"
21
+ ))
22
+ end
23
+
24
+ let(:array_contents) do
25
+ outdent(%Q(
26
+ en:
27
+ captains:
28
+ - "Janeway"
29
+ - "Picard"
30
+ - "Sisko"
31
+ - "Kirk"
21
32
  ))
22
33
  end
23
34
 
24
35
  let(:contents) do
25
- ResourceContents.from_string(tx_resource, raw_contents)
36
+ ResourceContents.from_string(tx_resource, default_contents)
26
37
  end
27
38
 
28
39
  describe '#phrases' do
@@ -32,6 +43,13 @@ describe ResourceContents do
32
43
  { 'key' => 'goodbye.message', 'string' => 'Goodbye!' }
33
44
  ])
34
45
  end
46
+
47
+ it 'preserves arrays' do
48
+ rsrc_contents = ResourceContents.from_string(tx_resource, array_contents)
49
+ expect(rsrc_contents.phrases).to eq([
50
+ { 'key' => 'captains', 'string' => %w(Janeway Picard Sisko Kirk) }
51
+ ])
52
+ end
35
53
  end
36
54
 
37
55
  describe '#add' do
@@ -47,13 +65,14 @@ describe ResourceContents do
47
65
  it 'serializes the phrases to the given stream' do
48
66
  stream = StringIO.new
49
67
  contents.write_to(stream)
50
- expect(stream.string).to eq(outdent(%Q(
51
- en:
52
- welcome:
53
- message: "Hello!"
54
- goodbye:
55
- message: "Goodbye!"
56
- )))
68
+ expect(stream.string).to eq(default_contents)
69
+ end
70
+
71
+ it 'serializes arrays correctly' do
72
+ stream = StringIO.new
73
+ rsrc_contents = ResourceContents.from_string(tx_resource, array_contents)
74
+ rsrc_contents.write_to(stream)
75
+ expect(stream.string).to eq(array_contents)
57
76
  end
58
77
 
59
78
  it 'includes phrases that were added after the fact' do
@@ -97,8 +97,8 @@ describe ResourceDownloader do
97
97
  let(:ref) { 'heads/mybranch' }
98
98
 
99
99
  before(:each) do
100
- allow(github_api).to receive(:download) do |repo_name, file, branch|
101
- source_for(branch)
100
+ allow(github_api).to receive(:download) do |file, branch|
101
+ { content: source_for(branch) }
102
102
  end
103
103
  end
104
104
 
@@ -15,10 +15,6 @@ describe ResourceUpdater do
15
15
  let(:resource) { tx_config.resource(resource_slug, ref) }
16
16
  let(:commit_sha) { '8765309' }
17
17
 
18
- let(:modified_files) do
19
- [{ 'path' => resource.source_file, 'sha' => 'def456' }]
20
- end
21
-
22
18
  let(:translations) do
23
19
  YAML.load("|
24
20
  en:
@@ -28,26 +24,14 @@ describe ResourceUpdater do
28
24
  ")
29
25
  end
30
26
 
31
- before(:each) do
32
- tree_sha = 'abc123'
33
-
34
- allow(github_api).to(
35
- receive(:get_commit).with(repo_name, commit_sha) do
36
- { 'commit' => { 'tree' => { 'sha' => tree_sha } } }
37
- end
38
- )
39
-
40
- allow(github_api).to(
41
- receive(:tree).with(repo_name, tree_sha) do
42
- { 'tree' => modified_files }
43
- end
44
- )
27
+ let(:modified_files) do
28
+ [{ path: resource.source_file, content: translations, sha: commit_sha }]
29
+ end
45
30
 
31
+ before(:each) do
46
32
  modified_files.each do |file|
47
33
  allow(github_api).to(
48
- receive(:blob).with(repo_name, file['sha']) do
49
- { 'content' => translations, 'encoding' => 'utf-8' }
50
- end
34
+ receive(:download).with(file[:path]).and_return(file)
51
35
  )
52
36
  end
53
37
  end
@@ -56,19 +40,19 @@ describe ResourceUpdater do
56
40
  modified_files.each do |file|
57
41
  expect(transifex_api).to(
58
42
  receive(:create_or_update) do |resource, content|
59
- expect(resource.source_file).to eq(file['path'])
43
+ expect(resource.source_file).to eq(file[:path])
60
44
  expect(content).to eq(translations)
61
45
  end
62
46
  )
63
47
  end
64
48
 
65
- updater.update_resource(resource, commit_sha)
49
+ updater.update_resource(resource)
66
50
  end
67
51
 
68
52
  it 'fires the transifex.resource.updated event' do
69
53
  allow(transifex_api).to receive(:create_or_update)
70
54
 
71
- expect { updater.update_resource(resource, commit_sha) }.to(
55
+ expect { updater.update_resource(resource) }.to(
72
56
  change { Txgh.events.published.size }.by(1)
73
57
  )
74
58
 
@@ -92,14 +76,14 @@ describe ResourceUpdater do
92
76
  modified_files.each do |file|
93
77
  expect(transifex_api).to(
94
78
  receive(:create) do |resource, content, categories|
95
- expect(resource.source_file).to eq(file['path'])
79
+ expect(resource.source_file).to eq(file[:path])
96
80
  expect(content).to eq(translations)
97
81
  expect(categories).to include("branch:#{ref}")
98
82
  end
99
83
  )
100
84
  end
101
85
 
102
- updater.update_resource(resource, commit_sha)
86
+ updater.update_resource(resource)
103
87
  end
104
88
 
105
89
  it 'adds categories when passed in' do
@@ -113,7 +97,7 @@ describe ResourceUpdater do
113
97
  )
114
98
  end
115
99
 
116
- updater.update_resource(resource, commit_sha, { 'foo' => 'bar' })
100
+ updater.update_resource(resource, { 'foo' => 'bar' })
117
101
  end
118
102
  end
119
103
 
@@ -134,7 +118,7 @@ describe ResourceUpdater do
134
118
  it 'uploads a diff instead of the whole resource' do
135
119
  expect(github_api).to(
136
120
  receive(:download)
137
- .with(repo_name, 'en.yml', diff_point)
121
+ .with('en.yml', diff_point)
138
122
  .and_return(YAML.load("|
139
123
  en:
140
124
  welcome: Hello
@@ -151,7 +135,7 @@ describe ResourceUpdater do
151
135
  receive(:upload_by_branch).with(resource, diff, anything)
152
136
  )
153
137
 
154
- updater.update_resource(resource, commit_sha)
138
+ updater.update_resource(resource)
155
139
  end
156
140
 
157
141
  context 'when asked to upload the diff point' do
@@ -162,7 +146,7 @@ describe ResourceUpdater do
162
146
  receive(:upload_by_branch).with(resource, translations, anything)
163
147
  )
164
148
 
165
- updater.update_resource(resource, commit_sha)
149
+ updater.update_resource(resource)
166
150
  end
167
151
  end
168
152
  end
@@ -10,12 +10,6 @@ describe TxResource do
10
10
  )
11
11
  end
12
12
 
13
- describe '#L10N_resource_slug' do
14
- it 'appends L10N to the resource slug' do
15
- expect(resource.L10N_resource_slug).to eq("L10Nresource_slug")
16
- end
17
- end
18
-
19
13
  describe '#lang_map' do
20
14
  it 'converts the given language if a mapping exists for it' do
21
15
  expect(resource.lang_map('ko-KR')).to eq('ko')
data/txgh.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.platform = Gem::Platform::RUBY
14
14
  s.has_rdoc = true
15
15
 
16
- s.add_dependency 'abroad', '~> 4.0'
16
+ s.add_dependency 'abroad', '~> 4.1'
17
17
  s.add_dependency 'faraday', '~> 0.9'
18
18
  s.add_dependency 'faraday_middleware', '~> 0.10'
19
19
  s.add_dependency 'json', '~> 1.8'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: txgh
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.beta1
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Jackowski
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-01 00:00:00.000000000 Z
12
+ date: 2016-09-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abroad
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '4.0'
20
+ version: '4.1'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '4.0'
27
+ version: '4.1'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -104,8 +104,6 @@ extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
106
  - LICENSE
107
- - README.md
108
- - lib/ext/zipline/output_stream.rb
109
107
  - lib/txgh.rb
110
108
  - lib/txgh/category_support.rb
111
109
  - lib/txgh/config.rb
@@ -188,12 +186,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
186
  version: '0'
189
187
  required_rubygems_version: !ruby/object:Gem::Requirement
190
188
  requirements:
191
- - - ">"
189
+ - - ">="
192
190
  - !ruby/object:Gem::Version
193
- version: 1.3.1
191
+ version: '0'
194
192
  requirements: []
195
193
  rubyforge_project:
196
- rubygems_version: 2.2.3
194
+ rubygems_version: 2.6.6
197
195
  signing_key:
198
196
  specification_version: 4
199
197
  summary: A library for syncing translation resources between Github and Transifex.