rosette-core 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +26 -0
- data/History.txt +3 -0
- data/README.md +94 -0
- data/Rakefile +18 -0
- data/lib/rosette/core.rb +110 -0
- data/lib/rosette/core/branch_utils.rb +152 -0
- data/lib/rosette/core/commands.rb +139 -0
- data/lib/rosette/core/commands/errors.rb +17 -0
- data/lib/rosette/core/commands/git/commit_command.rb +65 -0
- data/lib/rosette/core/commands/git/diff_base_command.rb +301 -0
- data/lib/rosette/core/commands/git/diff_command.rb +188 -0
- data/lib/rosette/core/commands/git/diff_entry.rb +44 -0
- data/lib/rosette/core/commands/git/fetch_command.rb +27 -0
- data/lib/rosette/core/commands/git/repo_snapshot_command.rb +40 -0
- data/lib/rosette/core/commands/git/show_command.rb +70 -0
- data/lib/rosette/core/commands/git/snapshot_command.rb +50 -0
- data/lib/rosette/core/commands/git/status_command.rb +128 -0
- data/lib/rosette/core/commands/git/with_non_merge_ref.rb +48 -0
- data/lib/rosette/core/commands/git/with_ref.rb +92 -0
- data/lib/rosette/core/commands/git/with_refs.rb +92 -0
- data/lib/rosette/core/commands/git/with_repo_name.rb +50 -0
- data/lib/rosette/core/commands/git/with_snapshots.rb +45 -0
- data/lib/rosette/core/commands/queuing/enqueue_commit_command.rb +37 -0
- data/lib/rosette/core/commands/queuing/requeue_commit_command.rb +46 -0
- data/lib/rosette/core/commands/translations/export_command.rb +257 -0
- data/lib/rosette/core/commands/translations/translation_lookup_command.rb +66 -0
- data/lib/rosette/core/commands/translations/with_locale.rb +47 -0
- data/lib/rosette/core/configurator.rb +160 -0
- data/lib/rosette/core/error_reporters/buffered_error_reporter.rb +96 -0
- data/lib/rosette/core/error_reporters/error_reporter.rb +31 -0
- data/lib/rosette/core/error_reporters/nil_error_reporter.rb +25 -0
- data/lib/rosette/core/error_reporters/printing_error_reporter.rb +58 -0
- data/lib/rosette/core/error_reporters/raising_error_reporter.rb +27 -0
- data/lib/rosette/core/errors.rb +93 -0
- data/lib/rosette/core/extractor/commit_log.rb +33 -0
- data/lib/rosette/core/extractor/commit_log_status.rb +57 -0
- data/lib/rosette/core/extractor/commit_processor.rb +109 -0
- data/lib/rosette/core/extractor/extractor.rb +72 -0
- data/lib/rosette/core/extractor/extractor_config.rb +74 -0
- data/lib/rosette/core/extractor/locale.rb +118 -0
- data/lib/rosette/core/extractor/phrase.rb +76 -0
- data/lib/rosette/core/extractor/phrase/phrase_index_policy.rb +108 -0
- data/lib/rosette/core/extractor/phrase/phrase_to_hash.rb +33 -0
- data/lib/rosette/core/extractor/repo_config.rb +339 -0
- data/lib/rosette/core/extractor/serializer_config.rb +55 -0
- data/lib/rosette/core/extractor/static_extractor.rb +44 -0
- data/lib/rosette/core/extractor/translation.rb +44 -0
- data/lib/rosette/core/extractor/translation/translation_to_hash.rb +28 -0
- data/lib/rosette/core/git/diff_finder.rb +131 -0
- data/lib/rosette/core/git/ref.rb +116 -0
- data/lib/rosette/core/git/repo.rb +378 -0
- data/lib/rosette/core/path_matcher_factory.rb +330 -0
- data/lib/rosette/core/resolvers/extractor_id.rb +37 -0
- data/lib/rosette/core/resolvers/integration_id.rb +37 -0
- data/lib/rosette/core/resolvers/preprocessor_id.rb +38 -0
- data/lib/rosette/core/resolvers/resolver.rb +115 -0
- data/lib/rosette/core/resolvers/serializer_id.rb +37 -0
- data/lib/rosette/core/snapshots/cached_head_snapshot_factory.rb +51 -0
- data/lib/rosette/core/snapshots/cached_snapshot_factory.rb +67 -0
- data/lib/rosette/core/snapshots/head_snapshot_factory.rb +58 -0
- data/lib/rosette/core/snapshots/repo_config_path_filter.rb +83 -0
- data/lib/rosette/core/snapshots/snapshot_factory.rb +184 -0
- data/lib/rosette/core/string_utils.rb +23 -0
- data/lib/rosette/core/translation_status.rb +81 -0
- data/lib/rosette/core/validators.rb +18 -0
- data/lib/rosette/core/validators/commit_validator.rb +62 -0
- data/lib/rosette/core/validators/commits_validator.rb +32 -0
- data/lib/rosette/core/validators/encoding_validator.rb +32 -0
- data/lib/rosette/core/validators/locale_validator.rb +37 -0
- data/lib/rosette/core/validators/repo_validator.rb +33 -0
- data/lib/rosette/core/validators/serializer_validator.rb +37 -0
- data/lib/rosette/core/validators/validator.rb +31 -0
- data/lib/rosette/core/version.rb +8 -0
- data/lib/rosette/data_stores.rb +11 -0
- data/lib/rosette/data_stores/errors.rb +26 -0
- data/lib/rosette/data_stores/phrase_status.rb +59 -0
- data/lib/rosette/integrations.rb +12 -0
- data/lib/rosette/integrations/errors.rb +15 -0
- data/lib/rosette/integrations/integratable.rb +58 -0
- data/lib/rosette/integrations/integration.rb +23 -0
- data/lib/rosette/preprocessors.rb +11 -0
- data/lib/rosette/preprocessors/errors.rb +14 -0
- data/lib/rosette/preprocessors/preprocessor.rb +48 -0
- data/lib/rosette/queuing.rb +14 -0
- data/lib/rosette/queuing/commits.rb +19 -0
- data/lib/rosette/queuing/commits/commit_conductor.rb +90 -0
- data/lib/rosette/queuing/commits/commit_job.rb +93 -0
- data/lib/rosette/queuing/commits/commits_queue_configurator.rb +60 -0
- data/lib/rosette/queuing/commits/extract_stage.rb +46 -0
- data/lib/rosette/queuing/commits/fetch_stage.rb +51 -0
- data/lib/rosette/queuing/commits/finalize_stage.rb +76 -0
- data/lib/rosette/queuing/commits/phrase_storage_granularity.rb +20 -0
- data/lib/rosette/queuing/commits/push_stage.rb +91 -0
- data/lib/rosette/queuing/commits/stage.rb +96 -0
- data/lib/rosette/queuing/job.rb +74 -0
- data/lib/rosette/queuing/queue.rb +28 -0
- data/lib/rosette/queuing/queue_configurator.rb +76 -0
- data/lib/rosette/queuing/worker.rb +30 -0
- data/lib/rosette/serializers.rb +10 -0
- data/lib/rosette/serializers/serializer.rb +98 -0
- data/lib/rosette/tms.rb +9 -0
- data/lib/rosette/tms/repository.rb +95 -0
- data/rosette-core.gemspec +24 -0
- data/spec/core/branch_utils_spec.rb +110 -0
- data/spec/core/commands/git/commit_command_spec.rb +60 -0
- data/spec/core/commands/git/diff_command_spec.rb +263 -0
- data/spec/core/commands/git/fetch_command_spec.rb +61 -0
- data/spec/core/commands/git/repo_snapshot_command_spec.rb +72 -0
- data/spec/core/commands/git/show_command_spec.rb +128 -0
- data/spec/core/commands/git/snapshot_command_spec.rb +86 -0
- data/spec/core/commands/git/status_command_spec.rb +154 -0
- data/spec/core/commands/queuing/enqueue_commit_command_spec.rb +34 -0
- data/spec/core/commands/queuing/requeue_commit_command_spec.rb +46 -0
- data/spec/core/commands/translations/export_command_spec.rb +113 -0
- data/spec/core/commands/translations/translation_lookup_command_spec.rb +58 -0
- data/spec/core/configurator_spec.rb +47 -0
- data/spec/core/error_reporters/buffered_error_reporter_spec.rb +61 -0
- data/spec/core/error_reporters/nil_error_reporter_spec.rb +16 -0
- data/spec/core/error_reporters/printing_error_reporter_spec.rb +60 -0
- data/spec/core/extractor/commit_log_status_spec.rb +216 -0
- data/spec/core/extractor/commit_processor_spec.rb +68 -0
- data/spec/core/extractor/extractor_config_spec.rb +47 -0
- data/spec/core/extractor/extractor_spec.rb +26 -0
- data/spec/core/extractor/locale_spec.rb +92 -0
- data/spec/core/extractor/phrase/phrase_index_policy_spec.rb +116 -0
- data/spec/core/extractor/phrase/phrase_to_hash_spec.rb +18 -0
- data/spec/core/extractor/repo_config_spec.rb +147 -0
- data/spec/core/extractor/translation/translation_to_hash_spec.rb +25 -0
- data/spec/core/git/diff_finder_spec.rb +74 -0
- data/spec/core/git/ref_spec.rb +118 -0
- data/spec/core/git/repo_spec.rb +216 -0
- data/spec/core/path_matcher_factory_spec.rb +139 -0
- data/spec/core/resolvers/extractor_id_spec.rb +47 -0
- data/spec/core/resolvers/integration_id_spec.rb +47 -0
- data/spec/core/resolvers/preprocessor_id_spec.rb +47 -0
- data/spec/core/resolvers/serializer_id_spec.rb +47 -0
- data/spec/core/snapshots/snapshot_factory_spec.rb +145 -0
- data/spec/core/string_utils_spec.rb +19 -0
- data/spec/core/translation_status_spec.rb +91 -0
- data/spec/core/validators/commit_validator_spec.rb +40 -0
- data/spec/core/validators/encoding_validator_spec.rb +30 -0
- data/spec/core/validators/locale_validator_spec.rb +31 -0
- data/spec/core/validators/repo_validator_spec.rb +30 -0
- data/spec/core/validators/serializer_validator_spec.rb +31 -0
- data/spec/integrations/integratable_spec.rb +58 -0
- data/spec/queuing/commits/commit_conductor_spec.rb +71 -0
- data/spec/queuing/commits/commit_job_spec.rb +87 -0
- data/spec/queuing/commits/extract_stage_spec.rb +68 -0
- data/spec/queuing/commits/fetch_stage_spec.rb +101 -0
- data/spec/queuing/commits/finalize_stage_spec.rb +88 -0
- data/spec/queuing/commits/push_stage_spec.rb +145 -0
- data/spec/queuing/commits/stage_spec.rb +80 -0
- data/spec/queuing/job_spec.rb +33 -0
- data/spec/queuing/queue_configurator_spec.rb +44 -0
- data/spec/spec_helper.rb +90 -0
- data/spec/test_helpers/fake_commit_stage.rb +17 -0
- 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
|