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,40 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core
6
+ include Rosette::Core::Validators
7
+
8
+ describe CommitValidator do
9
+ let(:repo_name) { 'double_commit' }
10
+ let(:fixture) { load_repo_fixture(repo_name) }
11
+ let(:validator) { CommitValidator.new }
12
+
13
+ let(:config) do
14
+ Rosette.build_config do |config|
15
+ config.add_repo(repo_name) do |repo_config|
16
+ repo_config.set_path(fixture.working_dir.join('.git').to_s)
17
+ end
18
+ end
19
+ end
20
+
21
+ let(:shas) do
22
+ fixture.git('rev-list --all').split("\n")
23
+ end
24
+
25
+ describe '#valid?' do
26
+ it 'returns true if the commit exists' do
27
+ shas.each do |sha|
28
+ expect(validator.valid?(sha, repo_name, config)).to be_truthy
29
+ end
30
+ end
31
+
32
+ it "returns false if the commit doesn't exist" do
33
+ expect(validator.valid?('123abc', repo_name, config)).to be_falsy
34
+ end
35
+
36
+ it "returns false if the repo can't be found" do
37
+ expect(validator.valid?(shas.first, 'foobar', config)).to be_falsy
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core
6
+ include Rosette::Core::Validators
7
+
8
+ describe EncodingValidator do
9
+ let(:repo_name) { 'double_commit' }
10
+ let(:fixture) { load_repo_fixture(repo_name) }
11
+ let(:validator) { EncodingValidator.new }
12
+
13
+ let(:config) do
14
+ Rosette.build_config do |config|
15
+ config.add_repo(repo_name) do |repo_config|
16
+ repo_config.set_path(fixture.working_dir.join('.git').to_s)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#valid?' do
22
+ it 'returns true if the encoding is valid' do
23
+ expect(validator.valid?('UTF-8', repo_name, config)).to be_truthy
24
+ end
25
+
26
+ it 'returns false if the encoding is not valid' do
27
+ expect(validator.valid?('FOO', repo_name, config)).to be_falsy
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core
6
+ include Rosette::Core::Validators
7
+
8
+ describe LocaleValidator do
9
+ let(:repo_name) { 'double_commit' }
10
+ let(:fixture) { load_repo_fixture(repo_name) }
11
+ let(:validator) { LocaleValidator.new }
12
+
13
+ let(:config) do
14
+ Rosette.build_config do |config|
15
+ config.add_repo(repo_name) do |repo_config|
16
+ repo_config.set_path(fixture.working_dir.join('.git').to_s)
17
+ repo_config.add_locale('es-MX')
18
+ end
19
+ end
20
+ end
21
+
22
+ describe '#valid?' do
23
+ it 'returns true if the locale exists in the list of configured locales' do
24
+ expect(validator.valid?('es-MX', repo_name, config)).to be_truthy
25
+ end
26
+
27
+ it "returns false if the locale doesn't exist in the list of configured locales" do
28
+ expect(validator.valid?('xx', repo_name, config)).to be_falsy
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core
6
+ include Rosette::Core::Validators
7
+
8
+ describe RepoValidator do
9
+ let(:repo_name) { 'double_commit' }
10
+ let(:fixture) { load_repo_fixture(repo_name) }
11
+ let(:validator) { RepoValidator.new }
12
+
13
+ let(:config) do
14
+ Rosette.build_config do |config|
15
+ config.add_repo(repo_name) do |repo_config|
16
+ repo_config.set_path(fixture.working_dir.join('.git').to_s)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#valid?' do
22
+ it 'returns true if the repo exists' do
23
+ expect(validator.valid?(repo_name, repo_name, config)).to be_truthy
24
+ end
25
+
26
+ it "returns false if the repo doesn't exist" do
27
+ expect(validator.valid?('foobar', repo_name, config)).to be_falsy
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Core
6
+ include Rosette::Core::Validators
7
+
8
+ describe SerializerValidator do
9
+ let(:repo_name) { 'double_commit' }
10
+ let(:fixture) { load_repo_fixture(repo_name) }
11
+ let(:validator) { SerializerValidator.new }
12
+
13
+ let(:config) do
14
+ Rosette.build_config do |config|
15
+ config.add_repo(repo_name) do |repo_config|
16
+ repo_config.set_path(fixture.working_dir.join('.git').to_s)
17
+ repo_config.add_serializer('my_serializer', format: 'test/test')
18
+ end
19
+ end
20
+ end
21
+
22
+ describe '#valid?' do
23
+ it 'returns true if the serializer exists' do
24
+ expect(validator.valid?('test/test', repo_name, config)).to be_truthy
25
+ end
26
+
27
+ it "returns false if the serializer doesn't exist" do
28
+ expect(validator.valid?('foo/bar', repo_name, config)).to be_falsy
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Integrations
6
+
7
+ class IntegratableTestClass
8
+ include Integratable
9
+ end
10
+
11
+ describe Integratable do
12
+ let(:instance) { IntegratableTestClass.new }
13
+
14
+ describe '#add_integration' do
15
+ it 'resolves the integration id and adds the integration to the list' do
16
+ instance.add_integration('test/test')
17
+ instance.integrations.first.tap do |integration|
18
+ expect(integration).to be_a(Test::TestIntegration)
19
+ end
20
+ end
21
+
22
+ it 'yields a configurator' do
23
+ instance.add_integration('test/test') do |integration_config|
24
+ expect(integration_config).to be_a(Test::TestIntegration::Configurator)
25
+ integration_config.set_test_property('foobar')
26
+ end
27
+
28
+ instance.integrations.first.tap do |integration|
29
+ expect(integration.configuration.test_property).to eq('foobar')
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#get_integration' do
35
+ it 'returns the integration instance by id' do
36
+ instance.add_integration('test/test')
37
+ instance.get_integration('test/test').tap do |integration|
38
+ expect(integration).to be_a(Test::TestIntegration)
39
+ end
40
+ end
41
+
42
+ it "returns nil if the integration hasn't been configured" do
43
+ expect(instance.get_integration('test/test')).to be_nil
44
+ end
45
+
46
+ it "returns nil if the integration doesn't exist" do
47
+ expect(instance.get_integration('foo/bar')).to be_nil
48
+ end
49
+ end
50
+
51
+ describe '#apply_integrations' do
52
+ it 'iterates over the list of integrations and applies them to the given object' do
53
+ instance.add_integration('test/test')
54
+ expect(instance.integrations.first).to receive(:integrate).with(:integratable)
55
+ instance.apply_integrations(:integratable)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Queuing::Commits
6
+ include Rosette::Queuing
7
+ include Rosette::DataStores
8
+
9
+ describe CommitConductor do
10
+ let(:repo_name) { 'single_commit' }
11
+ let(:commit_id) { fixture.repo.git('rev-parse HEAD').strip }
12
+
13
+ let(:fixture) do
14
+ load_repo_fixture(repo_name) do |config, repo_config|
15
+ config.use_datastore('in-memory')
16
+ config.use_queue('test')
17
+ end
18
+ end
19
+
20
+ let(:rosette_config) { fixture.config }
21
+ let(:logger) { NullLogger.new }
22
+
23
+ let(:conductor) { CommitConductor.new(rosette_config, repo_name, logger) }
24
+
25
+ before(:each) do
26
+ allow(CommitConductor).to receive(:stage_classes).and_return(
27
+ [FakeCommitStage]
28
+ )
29
+ end
30
+
31
+ describe '#enqueue' do
32
+ it 'adds a new commit job to the queue' do
33
+ expect { conductor.enqueue(commit_id) }.to(
34
+ change { TestQueue::Queue.list.size }.from(0).to(1)
35
+ )
36
+
37
+ job = TestQueue::Queue.list.first
38
+ expect(job.repo_name).to eq(repo_name)
39
+ expect(job.commit_id).to eq(commit_id)
40
+ end
41
+ end
42
+
43
+ describe '#advance' do
44
+ let(:commit_log) do
45
+ InMemoryDataStore::CommitLog.create(
46
+ status: PhraseStatus::FETCHED,
47
+ repo_name: repo_name,
48
+ commit_id: commit_id,
49
+ phrase_count: 0,
50
+ commit_datetime: nil,
51
+ branch_name: 'refs/heads/master'
52
+ )
53
+ end
54
+
55
+ it 'finds the correct stage, executes it, and enqueues the next stage' do
56
+ expect { conductor.advance(commit_log) }.to(
57
+ change { TestQueue::Queue.list.size }.from(0).to(1)
58
+ )
59
+
60
+ expect(commit_log.status).to eq('fake_stage_updated_me')
61
+ end
62
+
63
+ it 'does not enqueue a new job if the commit is finished' do
64
+ expect(conductor).to receive(:finished?).and_return(true)
65
+
66
+ expect { conductor.advance(commit_log) }.to_not(
67
+ change { TestQueue::Queue.list.size }.from(0)
68
+ )
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,87 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Queuing::Commits
6
+ include Rosette::Queuing
7
+ include Rosette::DataStores
8
+
9
+ describe CommitJob do
10
+ let(:repo_name) { 'single_commit' }
11
+ let(:commit_id) { fixture.repo.git('rev-parse HEAD').strip }
12
+ let(:status) { PhraseStatus::FETCHED }
13
+
14
+ let(:fixture) do
15
+ load_repo_fixture(repo_name) do |config, repo_config|
16
+ config.use_datastore('in-memory')
17
+ config.use_queue('test')
18
+ end
19
+ end
20
+
21
+ let(:rosette_config) { fixture.config }
22
+ let(:repo_config) { fixture.config.get_repo(repo_name) }
23
+ let(:logger) { NullLogger.new }
24
+
25
+ let(:commit_log) do
26
+ entry = InMemoryDataStore::CommitLog.entries.find do |entry|
27
+ entry.commit_id == commit_id
28
+ entry.repo_name == repo_name
29
+ end
30
+
31
+ entry || InMemoryDataStore::CommitLog.create(
32
+ status: status,
33
+ repo_name: repo_name,
34
+ commit_id: commit_id,
35
+ phrase_count: 0,
36
+ commit_datetime: nil
37
+ )
38
+ end
39
+
40
+ let(:job) do
41
+ CommitJob.new(repo_name, commit_id, status)
42
+ end
43
+
44
+ before(:each) do
45
+ allow(CommitConductor).to receive(:stage_classes).and_return(
46
+ [FakeCommitStage]
47
+ )
48
+ end
49
+
50
+ describe 'from_stage' do
51
+ it 'instantiates a job with information from the stage' do
52
+ stage = FetchStage.new(rosette_config, repo_config, logger, commit_log)
53
+ CommitJob.from_stage(stage).tap do |job|
54
+ expect(job.repo_name).to eq(repo_name)
55
+ expect(job.commit_id).to eq(commit_id)
56
+ expect(job.status).to eq(commit_log.status)
57
+ end
58
+ end
59
+ end
60
+
61
+ describe '#to_args' do
62
+ it 'creates an array of serializable arguments' do
63
+ expect(job.to_args).to eq([repo_name, commit_id, commit_log.status])
64
+ end
65
+ end
66
+
67
+ describe '#work' do
68
+ it 'looks up the commit log and advances it to the next stage' do
69
+ expect { job.work(rosette_config, logger) }.to(
70
+ change { TestQueue::Queue.list.size }
71
+ )
72
+
73
+ expect(commit_log.status).to eq('fake_stage_updated_me')
74
+ end
75
+
76
+ it 'creates a commit log if one does not already exist' do
77
+ InMemoryDataStore::CommitLog.entries.clear
78
+
79
+ expect { job.work(rosette_config, logger) }.to(
80
+ change { InMemoryDataStore::CommitLog.entries.size }.from(0).to(1)
81
+ )
82
+
83
+ entry = InMemoryDataStore::CommitLog.entries.first
84
+ expect(entry.status).to eq('fake_stage_updated_me')
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Queuing::Commits
6
+ include Rosette::DataStores
7
+
8
+ describe FetchStage do
9
+ let(:repo_name) { 'single_commit' }
10
+ let(:commit_id) { fixture.repo.git('rev-parse HEAD').strip }
11
+
12
+ let(:fixture) do
13
+ load_repo_fixture(repo_name) do |config, repo_config|
14
+ config.use_datastore('in-memory')
15
+ end
16
+ end
17
+
18
+ let(:rosette_config) { fixture.config }
19
+ let(:repo_config) { rosette_config.get_repo(repo_name) }
20
+ let(:logger) { NullLogger.new }
21
+
22
+ let(:commit_log) do
23
+ InMemoryDataStore::CommitLog.create(
24
+ status: PhraseStatus::FETCHED,
25
+ repo_name: repo_name,
26
+ commit_id: commit_id,
27
+ phrase_count: 0,
28
+ commit_datetime: nil,
29
+ branch_name: 'refs/heads/master'
30
+ )
31
+ end
32
+
33
+ let(:stage) do
34
+ ExtractStage.new(rosette_config, repo_config, logger, commit_log)
35
+ end
36
+
37
+ describe '#execute!' do
38
+ it 'extracts phrases' do
39
+ stage.execute!
40
+ phrases = InMemoryDataStore::Phrase.entries.map(&:key)
41
+ expect(phrases).to include("I'm a little teapot")
42
+ expect(phrases).to include("Diamonds are a girl's best friend.")
43
+ expect(phrases).to include(' test string 1')
44
+ end
45
+
46
+ it 'updates the commit log status' do
47
+ stage.execute!
48
+ expect(commit_log.status).to eq(PhraseStatus::EXTRACTED)
49
+ end
50
+
51
+ it "updates the status to MISSING if the commit doesn't exist" do
52
+ fixture.repo.git('reset --hard HEAD')
53
+ fixture.repo.create_file('testfile.txt') { |f| f.write('foo') }
54
+ fixture.repo.add_all
55
+ fixture.repo.commit('Test commit')
56
+
57
+ commit_log.commit_id = fixture.repo.git('rev-parse HEAD').strip
58
+
59
+ fixture.repo.git('reset --hard HEAD~1')
60
+ fixture.repo.git('reflog expire --expire=now --all')
61
+ fixture.repo.git('fsck --unreachable')
62
+ fixture.repo.git('prune -v')
63
+
64
+ stage.execute!
65
+ expect(commit_log.status).to eq(PhraseStatus::MISSING)
66
+ end
67
+ end
68
+ end