rosette-core 1.0.1

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 (158) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +26 -0
  3. data/History.txt +3 -0
  4. data/README.md +94 -0
  5. data/Rakefile +18 -0
  6. data/lib/rosette/core.rb +110 -0
  7. data/lib/rosette/core/branch_utils.rb +152 -0
  8. data/lib/rosette/core/commands.rb +139 -0
  9. data/lib/rosette/core/commands/errors.rb +17 -0
  10. data/lib/rosette/core/commands/git/commit_command.rb +65 -0
  11. data/lib/rosette/core/commands/git/diff_base_command.rb +301 -0
  12. data/lib/rosette/core/commands/git/diff_command.rb +188 -0
  13. data/lib/rosette/core/commands/git/diff_entry.rb +44 -0
  14. data/lib/rosette/core/commands/git/fetch_command.rb +27 -0
  15. data/lib/rosette/core/commands/git/repo_snapshot_command.rb +40 -0
  16. data/lib/rosette/core/commands/git/show_command.rb +70 -0
  17. data/lib/rosette/core/commands/git/snapshot_command.rb +50 -0
  18. data/lib/rosette/core/commands/git/status_command.rb +128 -0
  19. data/lib/rosette/core/commands/git/with_non_merge_ref.rb +48 -0
  20. data/lib/rosette/core/commands/git/with_ref.rb +92 -0
  21. data/lib/rosette/core/commands/git/with_refs.rb +92 -0
  22. data/lib/rosette/core/commands/git/with_repo_name.rb +50 -0
  23. data/lib/rosette/core/commands/git/with_snapshots.rb +45 -0
  24. data/lib/rosette/core/commands/queuing/enqueue_commit_command.rb +37 -0
  25. data/lib/rosette/core/commands/queuing/requeue_commit_command.rb +46 -0
  26. data/lib/rosette/core/commands/translations/export_command.rb +257 -0
  27. data/lib/rosette/core/commands/translations/translation_lookup_command.rb +66 -0
  28. data/lib/rosette/core/commands/translations/with_locale.rb +47 -0
  29. data/lib/rosette/core/configurator.rb +160 -0
  30. data/lib/rosette/core/error_reporters/buffered_error_reporter.rb +96 -0
  31. data/lib/rosette/core/error_reporters/error_reporter.rb +31 -0
  32. data/lib/rosette/core/error_reporters/nil_error_reporter.rb +25 -0
  33. data/lib/rosette/core/error_reporters/printing_error_reporter.rb +58 -0
  34. data/lib/rosette/core/error_reporters/raising_error_reporter.rb +27 -0
  35. data/lib/rosette/core/errors.rb +93 -0
  36. data/lib/rosette/core/extractor/commit_log.rb +33 -0
  37. data/lib/rosette/core/extractor/commit_log_status.rb +57 -0
  38. data/lib/rosette/core/extractor/commit_processor.rb +109 -0
  39. data/lib/rosette/core/extractor/extractor.rb +72 -0
  40. data/lib/rosette/core/extractor/extractor_config.rb +74 -0
  41. data/lib/rosette/core/extractor/locale.rb +118 -0
  42. data/lib/rosette/core/extractor/phrase.rb +76 -0
  43. data/lib/rosette/core/extractor/phrase/phrase_index_policy.rb +108 -0
  44. data/lib/rosette/core/extractor/phrase/phrase_to_hash.rb +33 -0
  45. data/lib/rosette/core/extractor/repo_config.rb +339 -0
  46. data/lib/rosette/core/extractor/serializer_config.rb +55 -0
  47. data/lib/rosette/core/extractor/static_extractor.rb +44 -0
  48. data/lib/rosette/core/extractor/translation.rb +44 -0
  49. data/lib/rosette/core/extractor/translation/translation_to_hash.rb +28 -0
  50. data/lib/rosette/core/git/diff_finder.rb +131 -0
  51. data/lib/rosette/core/git/ref.rb +116 -0
  52. data/lib/rosette/core/git/repo.rb +378 -0
  53. data/lib/rosette/core/path_matcher_factory.rb +330 -0
  54. data/lib/rosette/core/resolvers/extractor_id.rb +37 -0
  55. data/lib/rosette/core/resolvers/integration_id.rb +37 -0
  56. data/lib/rosette/core/resolvers/preprocessor_id.rb +38 -0
  57. data/lib/rosette/core/resolvers/resolver.rb +115 -0
  58. data/lib/rosette/core/resolvers/serializer_id.rb +37 -0
  59. data/lib/rosette/core/snapshots/cached_head_snapshot_factory.rb +51 -0
  60. data/lib/rosette/core/snapshots/cached_snapshot_factory.rb +67 -0
  61. data/lib/rosette/core/snapshots/head_snapshot_factory.rb +58 -0
  62. data/lib/rosette/core/snapshots/repo_config_path_filter.rb +83 -0
  63. data/lib/rosette/core/snapshots/snapshot_factory.rb +184 -0
  64. data/lib/rosette/core/string_utils.rb +23 -0
  65. data/lib/rosette/core/translation_status.rb +81 -0
  66. data/lib/rosette/core/validators.rb +18 -0
  67. data/lib/rosette/core/validators/commit_validator.rb +62 -0
  68. data/lib/rosette/core/validators/commits_validator.rb +32 -0
  69. data/lib/rosette/core/validators/encoding_validator.rb +32 -0
  70. data/lib/rosette/core/validators/locale_validator.rb +37 -0
  71. data/lib/rosette/core/validators/repo_validator.rb +33 -0
  72. data/lib/rosette/core/validators/serializer_validator.rb +37 -0
  73. data/lib/rosette/core/validators/validator.rb +31 -0
  74. data/lib/rosette/core/version.rb +8 -0
  75. data/lib/rosette/data_stores.rb +11 -0
  76. data/lib/rosette/data_stores/errors.rb +26 -0
  77. data/lib/rosette/data_stores/phrase_status.rb +59 -0
  78. data/lib/rosette/integrations.rb +12 -0
  79. data/lib/rosette/integrations/errors.rb +15 -0
  80. data/lib/rosette/integrations/integratable.rb +58 -0
  81. data/lib/rosette/integrations/integration.rb +23 -0
  82. data/lib/rosette/preprocessors.rb +11 -0
  83. data/lib/rosette/preprocessors/errors.rb +14 -0
  84. data/lib/rosette/preprocessors/preprocessor.rb +48 -0
  85. data/lib/rosette/queuing.rb +14 -0
  86. data/lib/rosette/queuing/commits.rb +19 -0
  87. data/lib/rosette/queuing/commits/commit_conductor.rb +90 -0
  88. data/lib/rosette/queuing/commits/commit_job.rb +93 -0
  89. data/lib/rosette/queuing/commits/commits_queue_configurator.rb +60 -0
  90. data/lib/rosette/queuing/commits/extract_stage.rb +46 -0
  91. data/lib/rosette/queuing/commits/fetch_stage.rb +51 -0
  92. data/lib/rosette/queuing/commits/finalize_stage.rb +76 -0
  93. data/lib/rosette/queuing/commits/phrase_storage_granularity.rb +20 -0
  94. data/lib/rosette/queuing/commits/push_stage.rb +91 -0
  95. data/lib/rosette/queuing/commits/stage.rb +96 -0
  96. data/lib/rosette/queuing/job.rb +74 -0
  97. data/lib/rosette/queuing/queue.rb +28 -0
  98. data/lib/rosette/queuing/queue_configurator.rb +76 -0
  99. data/lib/rosette/queuing/worker.rb +30 -0
  100. data/lib/rosette/serializers.rb +10 -0
  101. data/lib/rosette/serializers/serializer.rb +98 -0
  102. data/lib/rosette/tms.rb +9 -0
  103. data/lib/rosette/tms/repository.rb +95 -0
  104. data/rosette-core.gemspec +24 -0
  105. data/spec/core/branch_utils_spec.rb +110 -0
  106. data/spec/core/commands/git/commit_command_spec.rb +60 -0
  107. data/spec/core/commands/git/diff_command_spec.rb +263 -0
  108. data/spec/core/commands/git/fetch_command_spec.rb +61 -0
  109. data/spec/core/commands/git/repo_snapshot_command_spec.rb +72 -0
  110. data/spec/core/commands/git/show_command_spec.rb +128 -0
  111. data/spec/core/commands/git/snapshot_command_spec.rb +86 -0
  112. data/spec/core/commands/git/status_command_spec.rb +154 -0
  113. data/spec/core/commands/queuing/enqueue_commit_command_spec.rb +34 -0
  114. data/spec/core/commands/queuing/requeue_commit_command_spec.rb +46 -0
  115. data/spec/core/commands/translations/export_command_spec.rb +113 -0
  116. data/spec/core/commands/translations/translation_lookup_command_spec.rb +58 -0
  117. data/spec/core/configurator_spec.rb +47 -0
  118. data/spec/core/error_reporters/buffered_error_reporter_spec.rb +61 -0
  119. data/spec/core/error_reporters/nil_error_reporter_spec.rb +16 -0
  120. data/spec/core/error_reporters/printing_error_reporter_spec.rb +60 -0
  121. data/spec/core/extractor/commit_log_status_spec.rb +216 -0
  122. data/spec/core/extractor/commit_processor_spec.rb +68 -0
  123. data/spec/core/extractor/extractor_config_spec.rb +47 -0
  124. data/spec/core/extractor/extractor_spec.rb +26 -0
  125. data/spec/core/extractor/locale_spec.rb +92 -0
  126. data/spec/core/extractor/phrase/phrase_index_policy_spec.rb +116 -0
  127. data/spec/core/extractor/phrase/phrase_to_hash_spec.rb +18 -0
  128. data/spec/core/extractor/repo_config_spec.rb +147 -0
  129. data/spec/core/extractor/translation/translation_to_hash_spec.rb +25 -0
  130. data/spec/core/git/diff_finder_spec.rb +74 -0
  131. data/spec/core/git/ref_spec.rb +118 -0
  132. data/spec/core/git/repo_spec.rb +216 -0
  133. data/spec/core/path_matcher_factory_spec.rb +139 -0
  134. data/spec/core/resolvers/extractor_id_spec.rb +47 -0
  135. data/spec/core/resolvers/integration_id_spec.rb +47 -0
  136. data/spec/core/resolvers/preprocessor_id_spec.rb +47 -0
  137. data/spec/core/resolvers/serializer_id_spec.rb +47 -0
  138. data/spec/core/snapshots/snapshot_factory_spec.rb +145 -0
  139. data/spec/core/string_utils_spec.rb +19 -0
  140. data/spec/core/translation_status_spec.rb +91 -0
  141. data/spec/core/validators/commit_validator_spec.rb +40 -0
  142. data/spec/core/validators/encoding_validator_spec.rb +30 -0
  143. data/spec/core/validators/locale_validator_spec.rb +31 -0
  144. data/spec/core/validators/repo_validator_spec.rb +30 -0
  145. data/spec/core/validators/serializer_validator_spec.rb +31 -0
  146. data/spec/integrations/integratable_spec.rb +58 -0
  147. data/spec/queuing/commits/commit_conductor_spec.rb +71 -0
  148. data/spec/queuing/commits/commit_job_spec.rb +87 -0
  149. data/spec/queuing/commits/extract_stage_spec.rb +68 -0
  150. data/spec/queuing/commits/fetch_stage_spec.rb +101 -0
  151. data/spec/queuing/commits/finalize_stage_spec.rb +88 -0
  152. data/spec/queuing/commits/push_stage_spec.rb +145 -0
  153. data/spec/queuing/commits/stage_spec.rb +80 -0
  154. data/spec/queuing/job_spec.rb +33 -0
  155. data/spec/queuing/queue_configurator_spec.rb +44 -0
  156. data/spec/spec_helper.rb +90 -0
  157. data/spec/test_helpers/fake_commit_stage.rb +17 -0
  158. metadata +257 -0
@@ -0,0 +1,110 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core
6
+ include Rosette::DataStores
7
+
8
+ describe BranchUtils do
9
+ let(:repo_name) { 'single_commit' }
10
+
11
+ # note: the fixture will only be used for its datastore, the actual contents
12
+ # of the underlying repository aren't important
13
+ let(:fixture) do
14
+ load_repo_fixture(repo_name) do |config, repo_config|
15
+ config.use_datastore('in-memory')
16
+ repo_config.add_locales(%w(ko-KR ja-JP pt-BR))
17
+ end
18
+ end
19
+
20
+ let(:datastore) { fixture.config.datastore }
21
+ let(:commit_log) { InMemoryDataStore::CommitLog }
22
+ let(:commit_log_locale) { InMemoryDataStore::CommitLogLocale }
23
+
24
+ let(:locale_statuses_hash) do
25
+ {
26
+ 'ko-KR' => { translated_count: 5, percent_translated: 0.5 },
27
+ 'ja-JP' => { translated_count: 9, percent_translated: 0.9 }
28
+ }.freeze
29
+ end
30
+
31
+ before(:each) do
32
+ commit_log.create(
33
+ repo_name: repo_name, phrase_count: 5, commit_id: 'abc123',
34
+ status: PhraseStatus::FETCHED
35
+ )
36
+
37
+ commit_log_locale.create(
38
+ commit_id: 'abc123', locale: 'ko-KR', translated_count: 5
39
+ )
40
+
41
+ commit_log_locale.create(
42
+ commit_id: 'abc123', locale: 'ja-JP', translated_count: 4
43
+ )
44
+
45
+ commit_log.create(
46
+ repo_name: repo_name, phrase_count: 5, commit_id: 'def456',
47
+ status: PhraseStatus::PUSHED
48
+ )
49
+
50
+ commit_log_locale.create(
51
+ commit_id: 'def456', locale: 'ja-JP', translated_count: 5
52
+ )
53
+ end
54
+
55
+ describe 'derive_status_from' do
56
+ it 'returns the lowest-ranked status' do
57
+ status = BranchUtils.derive_status_from(commit_log.entries)
58
+ expect(status).to eq(PhraseStatus::FETCHED)
59
+ end
60
+ end
61
+
62
+ describe 'derive_phrase_count_from' do
63
+ it 'returns a sum of all phrase counts' do
64
+ count = BranchUtils.derive_phrase_count_from(commit_log.entries)
65
+ expect(count).to eq(10)
66
+ end
67
+ end
68
+
69
+ describe 'derive_locale_statuses_from' do
70
+ it 'returns a hash of locale statuses and translation percentages' do
71
+ locale_statuses = BranchUtils.derive_locale_statuses_from(
72
+ commit_log.entries, repo_name, datastore
73
+ )
74
+
75
+ expect(locale_statuses).to eq(locale_statuses_hash)
76
+ end
77
+
78
+ it "doesn't choke when phrase count is zero (possible divide by zero)" do
79
+ commit_log.entries.each do |entry|
80
+ entry.phrase_count = 0
81
+ end
82
+
83
+ locale_statuses = BranchUtils.derive_locale_statuses_from(
84
+ commit_log.entries, repo_name, datastore
85
+ )
86
+
87
+ expect(locale_statuses.keys).to contain_exactly('ko-KR', 'ja-JP')
88
+
89
+ locale_statuses.each do |_, status|
90
+ expect(status[:percent_translated]).to eq(0.0)
91
+ end
92
+ end
93
+ end
94
+
95
+ describe 'fill_in_missing_locales' do
96
+ it 'adds missing locales to the locale statuses hash' do
97
+ locale_statuses = BranchUtils.fill_in_missing_locales(
98
+ fixture.config.get_repo(repo_name).locales, locale_statuses_hash
99
+ )
100
+
101
+ expect(locale_statuses).to eq(
102
+ locale_statuses_hash.merge(
103
+ 'pt-BR' => {
104
+ translated_count: 0, percent_translated: 0.0
105
+ }
106
+ )
107
+ )
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,60 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core::Commands
6
+
7
+ describe CommitCommand do
8
+ let(:klass) { CommitCommand }
9
+ let(:repo_name) { 'single_commit' }
10
+
11
+ let(:fixture) do
12
+ load_repo_fixture(repo_name) do |config, repo_config|
13
+ config.use_datastore('in-memory')
14
+ end
15
+ end
16
+
17
+ let(:command) { CommitCommand.new(fixture.config) }
18
+ let(:phrase_model) { Rosette::DataStores::InMemoryDataStore::Phrase }
19
+
20
+ context 'validation' do
21
+ it 'requires a valid repo name' do
22
+ command.set_ref('HEAD')
23
+ expect(command).to_not be_valid
24
+ end
25
+
26
+ it 'requires a valid ref' do
27
+ command.set_repo_name('foo')
28
+ expect(command).to_not be_valid
29
+ end
30
+
31
+ it 'should be valid if both the repo name and ref are set' do
32
+ command.set_ref('HEAD')
33
+ command.set_repo_name(repo_name)
34
+ expect(command).to be_valid
35
+ end
36
+ end
37
+
38
+ context 'with valid options' do
39
+ before(:each) do
40
+ command.set_ref('HEAD')
41
+ command.set_repo_name(repo_name)
42
+ end
43
+
44
+ describe '#execute' do
45
+ it 'extracts and stores all phrases' do
46
+ command.execute
47
+ expect(phrase_model.entries.map(&:key).sort).to eq([
48
+ "I'm a little teapot",
49
+ 'The green albatross flitters in the moonlight',
50
+ 'Chatanooga Choo Choo',
51
+ "Diamonds are a girl's best friend.",
52
+ 'Cash for the merchandise; cash for the fancy goods.',
53
+ "I'm in Spañish.",
54
+ ' test string 1',
55
+ ' test string 2'
56
+ ].sort)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,263 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core::Commands
6
+
7
+ describe DiffCommand do
8
+ let(:repo_name) { 'single_commit' }
9
+
10
+ let(:fixture) do
11
+ load_repo_fixture(repo_name) do |config, repo_config|
12
+ config.use_datastore('in-memory')
13
+ repo_config.add_extractor('test/test') do |extractor_config|
14
+ extractor_config.set_conditions do |conditions|
15
+ conditions.match_file_extension('.txt')
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ let(:diff_command) { DiffCommand.new(fixture.config) }
22
+
23
+ context 'validation' do
24
+ it 'requires a valid repo name' do
25
+ diff_command.set_head_ref('HEAD')
26
+ diff_command.set_diff_point_ref('HEAD')
27
+ expect(diff_command).to_not be_valid
28
+ end
29
+
30
+ it 'requires a head ref' do
31
+ diff_command.set_repo_name(repo_name)
32
+ diff_command.set_diff_point_ref('HEAD')
33
+ expect(diff_command).to_not be_valid
34
+ end
35
+
36
+ it 'requires a diff point ref' do
37
+ diff_command.set_repo_name(repo_name)
38
+ diff_command.set_head_ref('HEAD')
39
+ expect(diff_command).to_not be_valid
40
+ end
41
+
42
+ it 'should be valid if the repo name, head ref, and diff point ref are set' do
43
+ diff_command.set_repo_name(repo_name)
44
+ diff_command.set_head_ref('HEAD')
45
+ diff_command.set_diff_point_ref('HEAD')
46
+ expect(diff_command).to be_valid
47
+ end
48
+ end
49
+
50
+ context 'with valid options' do
51
+ before(:each) do
52
+ diff_command.set_diff_point_ref(head_ref)
53
+ diff_command.set_repo_name(repo_name)
54
+
55
+ fixture.repo.each_commit_id do |commit_id|
56
+ commit(fixture.config, repo_name, commit_id)
57
+ end
58
+ end
59
+
60
+ describe '#execute' do
61
+ let(:key) { 'Here is a test string' }
62
+
63
+ context 'when a phrase is added to HEAD' do
64
+ before do
65
+ fixture.repo.create_file('test.txt') do |writer|
66
+ writer.write(key)
67
+ end
68
+
69
+ fixture.repo.add_all
70
+ fixture.repo.commit('Commit message')
71
+
72
+ commit(fixture.config, repo_name, head_ref)
73
+ diff_command.set_head_ref(head_ref)
74
+ end
75
+
76
+ it 'returns a diff that contains the added phrase' do
77
+ added_phrases = diff_command.execute[:added]
78
+ expect(added_phrases.size).to eq(1)
79
+ expect(added_phrases.first.phrase.key).to eq(key)
80
+ end
81
+ end
82
+
83
+ context 'when a phrase is removed from HEAD' do
84
+ before(:each) do
85
+ fixture.repo.git('rm -f first_file.txt')
86
+ fixture.add_all
87
+ fixture.repo.commit('Remove file.txt')
88
+
89
+ commit(fixture.config, repo_name, head_ref)
90
+ diff_command.set_head_ref(head_ref)
91
+ end
92
+
93
+ it 'returns a diff that contains the removed phrases' do
94
+ removed_phrases = diff_command.execute[:removed]
95
+ expect(removed_phrases.size).to eq(2)
96
+ expect(removed_phrases.map { |diff_entry| diff_entry.phrase.key }).to eq([
97
+ "I'm a little teapot",
98
+ "The green albatross flitters in the moonlight"
99
+ ])
100
+ end
101
+ end
102
+
103
+ context "when the parent hasn't been processed yet" do
104
+ let(:repo_name) { 'four_commits' }
105
+
106
+ before do
107
+ parent_commit_id = fixture.repo.git('rev-parse HEAD~3').strip
108
+ diff_command.set_head_ref(head_ref)
109
+ diff_command.set_diff_point_ref(parent_commit_id)
110
+
111
+ Rosette::DataStores::InMemoryDataStore::CommitLog.entries.reject! do |entry|
112
+ entry.commit_id == parent_commit_id
113
+ end
114
+ end
115
+
116
+ it 'raises an error in strict mode' do
117
+ expect { diff_command.execute }.to raise_error(
118
+ Rosette::Core::Commands::Errors::UnprocessedCommitError
119
+ )
120
+ end
121
+
122
+ it 'uses the most recently processed commit in non-strict mode' do
123
+ show_hash = diff_command.set_strict(false).execute
124
+ expect(show_hash[:added].map { |entry| entry.phrase.key}.sort).to eq([
125
+ 'bar', 'baz', 'foo', 'goo'
126
+ ])
127
+ end
128
+ end
129
+
130
+ context 'with a file that contains metakeys' do
131
+ let(:file_path) { fixture.working_dir.join('folder/with_metakeys.txt') }
132
+ let(:phrases) { File.read(file_path).split("\n") }
133
+
134
+ context 'when a phrase is modified on HEAD' do
135
+ let(:new_key) { 'Here is a new string' }
136
+
137
+ before do
138
+ first_phrase = phrases.first.split(':')
139
+ @meta_key = first_phrase[0]
140
+ @old_key = first_phrase[1]
141
+ first_phrase[1] = new_key
142
+ phrases[0] = first_phrase.join(':')
143
+
144
+ File.open(file_path, 'w+') do |f|
145
+ f.write(phrases.join("\n"))
146
+ end
147
+
148
+ fixture.repo.add_all
149
+ fixture.repo.commit('Modified a string')
150
+
151
+ commit(fixture.config, repo_name, head_ref)
152
+ diff_command.set_head_ref(head_ref)
153
+ end
154
+
155
+ it 'returns a diff that contains the modified phrase' do
156
+ modified_phrases = diff_command.execute[:modified]
157
+ expect(modified_phrases.size).to eq(1)
158
+ modified_phrase = modified_phrases.first.phrase
159
+ expect(modified_phrases.first.old_phrase.key).to eq(@old_key)
160
+ expect(modified_phrase.meta_key).to eq(@meta_key)
161
+ expect(modified_phrase.key).to eq(new_key)
162
+ end
163
+ end
164
+
165
+ context 'when a phrase is added to HEAD' do
166
+ let(:new_meta_key) { 'cool.metakey' }
167
+ let(:new_key) { 'my new key' }
168
+
169
+ before do
170
+ phrases << new_meta_key + ':' + new_key
171
+ File.open(file_path, 'w+') do |f|
172
+ f.write(phrases.join("\n"))
173
+ end
174
+
175
+ fixture.repo.add_all
176
+ fixture.repo.commit('Added a string')
177
+
178
+ commit(fixture.config, repo_name, head_ref)
179
+ diff_command.set_head_ref(head_ref)
180
+ end
181
+
182
+ it 'returns a diff that contains the added phrase' do
183
+ added_phrases = diff_command.execute[:added]
184
+ expect(added_phrases.size).to eq(1)
185
+ expect(added_phrases.first.phrase.meta_key).to eq(new_meta_key)
186
+ expect(added_phrases.first.phrase.key).to eq(new_key)
187
+ end
188
+ end
189
+
190
+ context 'when a phrase is removed from HEAD' do
191
+ before do
192
+ first_phrase = phrases.shift.split(':')
193
+ @meta_key = first_phrase[0]
194
+ @key = first_phrase[1]
195
+
196
+ File.open(file_path, 'w+') do |f|
197
+ f.write(phrases.join("\n"))
198
+ end
199
+
200
+ fixture.repo.add_all
201
+ fixture.repo.commit('Removed a string')
202
+
203
+ commit(fixture.config, repo_name, head_ref)
204
+ diff_command.set_head_ref(head_ref)
205
+ end
206
+
207
+ it 'returns a diff that contains the removed phrase' do
208
+ removed_phrases = diff_command.execute[:removed]
209
+ expect(removed_phrases.size).to eq(1)
210
+ expect(removed_phrases.first.phrase.meta_key).to eq(@meta_key)
211
+ expect(removed_phrases.first.phrase.key).to eq(@key)
212
+ end
213
+
214
+ end
215
+
216
+ context "when the given head doesn't contain phrase changes" do
217
+ let(:file_path) { fixture.working_dir.join('folder/new_file.txt') }
218
+
219
+ before do
220
+ File.open(file_path, 'w+') do |f|
221
+ f.write('foobarbazboo')
222
+ end
223
+
224
+ fixture.repo.add_all
225
+ fixture.repo.commit('Added a string')
226
+ commit(fixture.config, repo_name, head_ref)
227
+
228
+ # the .foo file extension isn't processed by the text/text extractor
229
+ fixture.repo.create_file('test.foo') do |writer|
230
+ writer.write('foobarbaz')
231
+ end
232
+
233
+ fixture.repo.add_all
234
+ fixture.repo.commit('Commit message')
235
+ commit(fixture.config, repo_name, head_ref)
236
+ diff_command.set_head_ref(head_ref)
237
+ end
238
+
239
+ it 'should show the correct added phrases' do
240
+ diff = diff_command.execute
241
+ expect(diff[:added].size).to eq(1)
242
+ expect(diff[:added].first.phrase.key).to eq('foobarbazboo')
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
248
+
249
+ def head_ref
250
+ fixture.repo.git('rev-parse HEAD').strip
251
+ end
252
+
253
+ def commit(config, repo_name, ref)
254
+ CommitCommand.new(config)
255
+ .set_repo_name(repo_name)
256
+ .set_ref(ref)
257
+ .execute
258
+
259
+ fixture.config.datastore.add_or_update_commit_log(
260
+ repo_name, ref, nil
261
+ )
262
+ end
263
+ end
@@ -0,0 +1,61 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core::Commands
6
+
7
+ describe FetchCommand do
8
+ let(:source_repo) { TmpRepo.new }
9
+ let(:dest_repo) { TmpRepo.new }
10
+ let(:repo_name) { 'my_repo' }
11
+
12
+ let(:configuration) do
13
+ Rosette.build_config do |config|
14
+ config.add_repo(repo_name) do |repo_config|
15
+ repo_config.set_path(dest_repo.working_dir.join('.git').to_s)
16
+ end
17
+ end
18
+ end
19
+
20
+ let(:command) do
21
+ Rosette::Core::Commands::FetchCommand.new(configuration)
22
+ end
23
+
24
+ context 'validation' do
25
+ it 'requires a valid repo name' do
26
+ expect(command).to_not be_valid
27
+ end
28
+
29
+ it 'should be valid if repo name is set' do
30
+ command.set_repo_name(repo_name)
31
+ expect(command).to be_valid
32
+ end
33
+ end
34
+
35
+ context '#execute' do
36
+ before do
37
+ command.set_repo_name(repo_name)
38
+ end
39
+
40
+ it 'fetches new commits from origin' do
41
+ source_repo.create_file('foo.txt') { |f| f.write('foo') }
42
+ source_repo.add_all
43
+ source_repo.commit('Initial commit')
44
+
45
+ source_repo.create_branch('new_branch')
46
+ source_repo.create_file('bar.txt') { |f| f.write('bar') }
47
+ source_repo.add_all
48
+ source_repo.commit('Second commit')
49
+ source_repo.checkout('master')
50
+
51
+ expect(dest_repo.git('branch -a').strip.split("\n")).to be_empty
52
+
53
+ dest_repo.git("remote add origin #{source_repo.working_dir}")
54
+ command.execute
55
+
56
+ expect(dest_repo.git('branch -a').split("\n").map(&:strip)).to(
57
+ eq(['remotes/origin/master', 'remotes/origin/new_branch'])
58
+ )
59
+ end
60
+ end
61
+ end