rosette-core 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,72 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core::Commands
6
+
7
+ describe RepoSnapshotCommand do
8
+ let(:repo_name) { 'double_commit' }
9
+
10
+ let(:fixture) do
11
+ load_repo_fixture(repo_name) do |config, repo_config|
12
+ config.use_datastore('in-memory')
13
+ end
14
+ end
15
+
16
+ let(:command) { RepoSnapshotCommand.new(fixture.config) }
17
+
18
+ context 'validation' do
19
+ it 'requires a valid repo name' do
20
+ command.set_ref('HEAD')
21
+ expect(command).to_not be_valid
22
+ end
23
+
24
+ it 'requires a valid ref' do
25
+ command.set_repo_name(repo_name)
26
+ expect(command).to_not be_valid
27
+ end
28
+
29
+ it 'should be valid if given a valid repo name and ref' do
30
+ command.set_repo_name(repo_name)
31
+ command.set_ref('HEAD')
32
+ expect(command).to be_valid
33
+ end
34
+ end
35
+
36
+ context '#execute' do
37
+ let(:commits) do
38
+ fixture.repo.git("log --pretty=format:'%H'").split("\n")
39
+ end
40
+
41
+ before do
42
+ command.set_repo_name(repo_name)
43
+ expect(commits.size).to eq(2)
44
+ end
45
+
46
+ it 'returns a snapshot with one entry per file' do
47
+ expected_snapshot = {
48
+ 'first_file.txt' => commits.last,
49
+ 'second_file.txt' => commits.first
50
+ }
51
+
52
+ actual_snapshot = command
53
+ .set_ref(commits.first)
54
+ .execute
55
+
56
+ expect(actual_snapshot).to eq(expected_snapshot)
57
+ end
58
+
59
+ it 'returns a snapshot that only contains the specified paths' do
60
+ expected_snapshot = {
61
+ 'first_file.txt' => commits.last
62
+ }
63
+
64
+ actual_snapshot = command
65
+ .set_ref(commits.first)
66
+ .set_paths(['first_file.txt'])
67
+ .execute
68
+
69
+ expect(actual_snapshot).to eq(expected_snapshot)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,128 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core::Commands
6
+
7
+ describe ShowCommand do
8
+ let(:repo_name) { 'four_commits' }
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_regex(//)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ let(:command) { ShowCommand.new(fixture.config) }
22
+
23
+ context 'validations' do
24
+ it 'requires a valid repo name' do
25
+ command.set_ref('HEAD')
26
+ expect(command).to_not be_valid
27
+ end
28
+
29
+ it 'requires a ref' do
30
+ command.set_repo_name(repo_name)
31
+ expect(command).to_not be_valid
32
+ end
33
+
34
+ it 'should be valid if the repo name and ref are set' do
35
+ command.set_repo_name(repo_name)
36
+ command.set_ref('HEAD')
37
+ expect(command).to be_valid
38
+ end
39
+ end
40
+
41
+ context '#execute' do
42
+ before do
43
+ fixture.each_commit do |fixture_commit|
44
+ commit(fixture.config, repo_name, fixture_commit.sha)
45
+ end
46
+
47
+ command.set_repo_name(repo_name)
48
+ end
49
+
50
+ context 'when a phrase gets added' do
51
+ let(:new_key) { 'Yo momma wears army boots' }
52
+
53
+ before do
54
+ fixture.repo.create_file('new_file.txt') do |f|
55
+ f.write(new_key)
56
+ end
57
+
58
+ fixture.repo.add_all
59
+ fixture.repo.commit('Adding new_file.txt')
60
+ commit(fixture.config, repo_name, head_ref(fixture.repo))
61
+ end
62
+
63
+ it 'returns a diff that contains the added phrase' do
64
+ show_hash = command.set_ref(head_ref(fixture.repo)).execute
65
+ expect(show_hash[:added].size).to eq(1)
66
+ expect(show_hash[:added].first.phrase.key).to eq(new_key)
67
+ end
68
+ end
69
+
70
+ context 'when phrases get removed' do
71
+ before do
72
+ fixture.repo.git('rm -f file1.txt')
73
+ fixture.repo.git('rm -f file2.txt')
74
+ fixture.add_all
75
+ fixture.repo.commit('Remove file1.txt and file2.txt')
76
+
77
+ commit(fixture.config, repo_name, head_ref(fixture.repo))
78
+ end
79
+
80
+ it 'returns a diff that contains the deleted phrases' do
81
+ show_hash = command.set_ref(head_ref(fixture.repo)).execute
82
+ expect(show_hash[:removed].size).to eq(2)
83
+ expect(show_hash[:removed].map { |entry| entry.phrase.key }.sort).to eq([
84
+ 'bar', 'foo'
85
+ ])
86
+ end
87
+ end
88
+
89
+ context "when the parent hasn't been processed yet" do
90
+ before do
91
+ command.set_ref(head_ref(fixture.repo))
92
+ parent_commit_id = fixture.repo.git('rev-parse HEAD~1').strip
93
+
94
+ Rosette::DataStores::InMemoryDataStore::CommitLog.entries.reject! do |entry|
95
+ entry.commit_id == parent_commit_id
96
+ end
97
+ end
98
+
99
+ it 'raises an error in strict mode' do
100
+ expect { command.execute }.to raise_error(
101
+ Rosette::Core::Commands::Errors::UnprocessedCommitError
102
+ )
103
+ end
104
+
105
+ it 'uses the most recently processed commit in non-strict mode' do
106
+ show_hash = command.set_strict(false).execute
107
+ expect(show_hash[:added].map { |entry| entry.phrase.key}.sort).to eq([
108
+ 'goo'
109
+ ])
110
+ end
111
+ end
112
+ end
113
+
114
+ def head_ref(repo)
115
+ repo.git('rev-parse HEAD').strip
116
+ end
117
+
118
+ def commit(config, repo_name, ref)
119
+ CommitCommand.new(config)
120
+ .set_repo_name(repo_name)
121
+ .set_ref(ref)
122
+ .execute
123
+
124
+ fixture.config.datastore.add_or_update_commit_log(
125
+ repo_name, ref, nil
126
+ )
127
+ end
128
+ end
@@ -0,0 +1,86 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core::Commands
6
+
7
+ describe SnapshotCommand do
8
+ let(:repo_name) { 'double_commit' }
9
+
10
+ let(:fixture) do
11
+ load_repo_fixture(repo_name) do |config, repo_config|
12
+ config.use_datastore('in-memory')
13
+ end
14
+ end
15
+
16
+ let(:command) { SnapshotCommand.new(fixture.config) }
17
+
18
+ context 'validation' do
19
+ it 'requires a valid repo name' do
20
+ command.set_ref('HEAD')
21
+ expect(command).to_not be_valid
22
+ end
23
+
24
+ it 'requires a valid ref' do
25
+ command.set_repo_name(repo_name)
26
+ expect(command).to_not be_valid
27
+ end
28
+
29
+ it 'should be valid if given a valid repo name and ref' do
30
+ command.set_repo_name(repo_name)
31
+ command.set_ref('HEAD')
32
+ expect(command).to be_valid
33
+ end
34
+ end
35
+
36
+ context '#execute' do
37
+ let(:commits) do
38
+ fixture.repo.git("log --pretty=format:'%H'").split("\n")
39
+ end
40
+
41
+ before do
42
+ command.set_repo_name(repo_name)
43
+ expect(commits.size).to eq(2)
44
+
45
+ commits.each do |commit_id|
46
+ commit(fixture.config, repo_name, commit_id)
47
+ end
48
+ end
49
+
50
+ it 'returns a list of the phrases from both files' do
51
+ phrases = command
52
+ .set_ref(commits.first)
53
+ .execute
54
+ .map(&:key)
55
+
56
+ expect(phrases.sort).to eq([
57
+ "I'm a little teapot",
58
+ 'The green albatross flitters in the moonlight',
59
+ 'Chatanooga Choo Choo',
60
+ "Diamonds are a girl's best friend.",
61
+ 'Cash for the merchandise; cash for the fancy goods.',
62
+ "I'm in Spañish."
63
+ ].sort)
64
+ end
65
+
66
+ it 'returns a list of the phrases only at the specified paths' do
67
+ phrases = command
68
+ .set_ref(commits.first)
69
+ .set_paths(['first_file.txt'])
70
+ .execute
71
+ .map(&:key)
72
+
73
+ expect(phrases.sort).to eq([
74
+ "I'm a little teapot",
75
+ 'The green albatross flitters in the moonlight'
76
+ ].sort)
77
+ end
78
+ end
79
+
80
+ def commit(config, repo_name, ref)
81
+ CommitCommand.new(config)
82
+ .set_repo_name(repo_name)
83
+ .set_ref(ref)
84
+ .execute
85
+ end
86
+ end
@@ -0,0 +1,154 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core::Commands
6
+
7
+ describe StatusCommand do
8
+ let(:repo_name) { 'double_commit' }
9
+ let(:locales) { %w(es de-DE ja-JP) }
10
+
11
+ let(:commit_log_locale_model) do
12
+ Rosette::DataStores::InMemoryDataStore::CommitLogLocale
13
+ end
14
+
15
+ let(:commit_log_model) do
16
+ Rosette::DataStores::InMemoryDataStore::CommitLog
17
+ end
18
+
19
+ let(:fixture) do
20
+ load_repo_fixture(repo_name) do |config, repo_config|
21
+ config.use_datastore('in-memory')
22
+ repo_config.add_locales(locales)
23
+ end
24
+ end
25
+
26
+ let(:repo_config) { fixture.config.get_repo(repo_name) }
27
+ let(:command) { StatusCommand.new(fixture.config) }
28
+
29
+ context 'validations' do
30
+ it 'requires a valid repo name' do
31
+ command.set_ref('HEAD')
32
+ expect(command).to_not be_valid
33
+ end
34
+
35
+ it 'requires a ref' do
36
+ command.set_repo_name(repo_name)
37
+ expect(command).to_not be_valid
38
+ end
39
+
40
+ it 'should be valid if the repo name and ref are set' do
41
+ command.set_repo_name(repo_name)
42
+ command.set_ref('HEAD')
43
+ expect(command).to be_valid
44
+ end
45
+ end
46
+
47
+ context '#execute' do
48
+ let(:translated_count) { 6 }
49
+ let(:phrase_count) { 8 }
50
+ let(:status) { Rosette::DataStores::PhraseStatus::NOT_SEEN }
51
+
52
+ before do
53
+ commit(fixture.config, repo_name, head_ref(fixture.repo))
54
+ command.set_ref('HEAD')
55
+ command.set_repo_name(repo_name)
56
+
57
+ repo_config.repo.each_commit do |rev_commit|
58
+ fixture.config.datastore.add_or_update_commit_log(
59
+ repo_name,
60
+ rev_commit.getId.name,
61
+ nil, status,
62
+ phrase_count
63
+ )
64
+
65
+ locales.each do |locale|
66
+ fixture.config.datastore.add_or_update_commit_log_locale(
67
+ rev_commit.getId.name, locale, translated_count
68
+ )
69
+ end
70
+ end
71
+ end
72
+
73
+ it 'returns the translation status for a commit' do
74
+ status_result = command.execute
75
+ expect(status_result[:commit_id]).to eq(head_ref(fixture.repo))
76
+ expect(status_result[:status]).to eq(Rosette::DataStores::PhraseStatus::NOT_SEEN)
77
+ expect(status_result[:phrase_count]).to eq(phrase_count * 2)
78
+
79
+ locales_result = locales.each_with_object({}) do |locale, ret|
80
+ ret[locale] = {
81
+ percent_translated: (translated_count.to_f / phrase_count).round(2),
82
+ translated_count: translated_count * 2
83
+ }
84
+ end
85
+
86
+ expect(status_result[:locales]).to eq(locales_result)
87
+ end
88
+
89
+ it 'fills in translation data for missing locales' do
90
+ index_to_delete = commit_log_locale_model.entries.delete_if do |commit_log|
91
+ commit_log.locale == locales.first
92
+ end
93
+
94
+ status_result = command.execute
95
+ untranslated_locale = status_result[:locales][locales.first]
96
+
97
+ expect(untranslated_locale).to eq({
98
+ percent_translated: 0.0,
99
+ translated_count: 0
100
+ })
101
+ end
102
+
103
+ context 'with FINALIZED commit logs' do
104
+ let(:status) { Rosette::DataStores::PhraseStatus::FINALIZED }
105
+
106
+ it 'returns a FINALIZED status' do
107
+ expect(command.execute[:status]).to eq(
108
+ Rosette::DataStores::PhraseStatus::FINALIZED
109
+ )
110
+ end
111
+ end
112
+
113
+ context 'with one NOT_SEEN commit and one PUSHED commit' do
114
+ before do
115
+ fixture.config.datastore.add_or_update_commit_log(
116
+ repo_name,
117
+ head_ref(fixture.repo),
118
+ nil, Rosette::DataStores::PhraseStatus::PUSHED,
119
+ phrase_count
120
+ )
121
+ end
122
+
123
+ it 'returns a NOT_SEEN status' do
124
+ expect(command.execute[:status]).to eq(
125
+ Rosette::DataStores::PhraseStatus::NOT_SEEN
126
+ )
127
+ end
128
+ end
129
+
130
+ context 'with an unprocessed commit' do
131
+ before do
132
+ commit_log_locale_model.entries.clear
133
+ commit_log_model.entries.clear
134
+ end
135
+
136
+ it 'returns a NOT_FOUND status' do
137
+ expect(command.execute[:status]).to eq(
138
+ Rosette::DataStores::PhraseStatus::NOT_FOUND
139
+ )
140
+ end
141
+ end
142
+ end
143
+
144
+ def head_ref(repo)
145
+ repo.git('rev-parse HEAD').strip
146
+ end
147
+
148
+ def commit(config, repo_name, ref)
149
+ CommitCommand.new(config)
150
+ .set_repo_name(repo_name)
151
+ .set_ref(ref)
152
+ .execute
153
+ end
154
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core::Commands
6
+
7
+ describe EnqueueCommitCommand 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_queue('test')
13
+ end
14
+ end
15
+
16
+ let(:queue) { Rosette::Queuing::TestQueue::Queue }
17
+ let(:commit_id) { fixture.repo.git('rev-parse HEAD').strip }
18
+ let(:rosette_config) { fixture.config }
19
+ let(:command) do
20
+ EnqueueCommitCommand.new(rosette_config)
21
+ .set_repo_name(repo_name)
22
+ .set_commit_id(commit_id)
23
+ end
24
+
25
+ describe '#execute' do
26
+ it 'enqueues the commit' do
27
+ expect { command.execute }.to(
28
+ change { queue.list.size }.from(0).to(1)
29
+ )
30
+
31
+ expect(queue.list.first.commit_id).to eq(commit_id)
32
+ end
33
+ end
34
+ end