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.
- 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,68 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe CommitProcessor do
|
8
|
+
let(:repo_name) { 'single_commit' }
|
9
|
+
let(:fixture) { load_repo_fixture(repo_name) }
|
10
|
+
let(:error_reporter) { BufferedErrorReporter.new }
|
11
|
+
|
12
|
+
let(:processor) do
|
13
|
+
CommitProcessor.new(fixture.config, error_reporter)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#process_each_phrase' do
|
17
|
+
it 'extracts each phrase in the commit and returns an enum' do
|
18
|
+
fixture.each_commit do |fixture_commit|
|
19
|
+
processor.process_each_phrase(repo_name, fixture_commit.sha).tap do |phrase_enum|
|
20
|
+
expect(phrase_enum).to be_a(Enumerator)
|
21
|
+
|
22
|
+
phrase_enum.to_a.tap do |phrases|
|
23
|
+
expect(phrases.size).to eq(8)
|
24
|
+
phrases.each { |phrase| fixture_commit.remove(phrase) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
expect(fixture_commit).to_not have_more_phrases
|
29
|
+
expect(error_reporter.errors).to be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'reports syntax errors if they occur' do
|
34
|
+
allow_any_instance_of(Rosette::Extractors::Test::TestExtractor).to(
|
35
|
+
receive(:each_function_call)
|
36
|
+
.with(anything)
|
37
|
+
.and_raise(
|
38
|
+
Rosette::Core::SyntaxError.new(
|
39
|
+
'nope', StandardError.new('error'), :txt
|
40
|
+
)
|
41
|
+
)
|
42
|
+
)
|
43
|
+
|
44
|
+
fixture.each_commit do |fixture_commit|
|
45
|
+
processor.process_each_phrase(repo_name, fixture_commit.sha).to_a
|
46
|
+
|
47
|
+
error_reporter.errors.tap do |errors|
|
48
|
+
expect(errors.size).to eq(3)
|
49
|
+
|
50
|
+
errors.each do |error|
|
51
|
+
expect(error[:error].original_exception).to be_a(StandardError)
|
52
|
+
expect(error[:error].message).to eq(
|
53
|
+
"nope (txt): error (txt) in #{error[:error].file} at #{fixture_commit.sha}"
|
54
|
+
)
|
55
|
+
expect(error[:error].language).to eq(:txt)
|
56
|
+
expect(error[:error].commit_id).to eq(fixture_commit.sha)
|
57
|
+
end
|
58
|
+
|
59
|
+
expect(errors.map { |e| e[:error].file }.sort).to eq([
|
60
|
+
'first_file.txt',
|
61
|
+
'folder/second_file.txt',
|
62
|
+
'folder/with_metakeys.txt'
|
63
|
+
].sort)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe ExtractorConfig do
|
8
|
+
let(:extractor_class) { Rosette::Extractors::Test::TestExtractor }
|
9
|
+
let(:extractor_id) { 'test/test' }
|
10
|
+
|
11
|
+
it 'instantiates the extractor given' do
|
12
|
+
ExtractorConfig.new(extractor_id, extractor_class).tap do |config|
|
13
|
+
expect(config.extractor).to be_instance_of(extractor_class)
|
14
|
+
expect(config.extractor_id).to eq(extractor_id)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'sets a default encoding' do
|
19
|
+
ExtractorConfig.new(extractor_id, extractor_class).tap do |config|
|
20
|
+
expect(config.encoding).to eq(Rosette::Core::DEFAULT_ENCODING)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#set_encoding' do
|
25
|
+
let(:config) { ExtractorConfig.new(extractor_id, extractor_class) }
|
26
|
+
|
27
|
+
it 'sets the encoding on the instance' do
|
28
|
+
config.set_encoding(Encoding::UTF_16BE).tap do |config_with_encoding|
|
29
|
+
expect(config_with_encoding).to be(config)
|
30
|
+
expect(config_with_encoding.encoding).to eq(Encoding::UTF_16BE)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#matches?' do
|
36
|
+
let(:config) { ExtractorConfig.new(extractor_id, extractor_class) }
|
37
|
+
|
38
|
+
it 'delegates #matches? to root' do
|
39
|
+
config.set_conditions do |cond|
|
40
|
+
cond.match_regex(/values-(ja|de)/)
|
41
|
+
end
|
42
|
+
|
43
|
+
expect(config.matches?('MyProject/stuff/values-ja')).to be_truthy
|
44
|
+
expect(config.matches?('MyProject/stuff/values-pt')).to be_falsey
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe Extractor do
|
8
|
+
let(:extractor) do
|
9
|
+
Rosette::Extractors::Test::TestExtractor.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#extract_each_from' do
|
13
|
+
it 'extracts each line and line number from the text file and yields the results' do
|
14
|
+
extractor.extract_each_from("foo\nbar").tap do |extract_enum|
|
15
|
+
expect(extract_enum).to be_a(Enumerator)
|
16
|
+
extract_enum.to_a.tap do |phrases|
|
17
|
+
expect(phrases.size).to eq(2)
|
18
|
+
expect(phrases.all? { |phrase| phrase.first.is_a?(Phrase) }).to be(true)
|
19
|
+
expect(phrases.all? { |phrase| phrase.last.is_a?(Fixnum) }).to be(true) # line numbers
|
20
|
+
expect(phrases.first.first.key).to eq('foo')
|
21
|
+
expect(phrases.last.first.key).to eq('bar')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe Locale do
|
8
|
+
let(:locale) { Locale }
|
9
|
+
|
10
|
+
describe 'self.parse' do
|
11
|
+
it 'returns a locale object' do
|
12
|
+
expect(locale.parse('es_MX')).to be_a(Locale)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "raises an error if the locale format isn't recognized" do
|
16
|
+
expect(lambda { locale.parse('es_MX', :foo) }).to(
|
17
|
+
raise_error(ArgumentError)
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Bcp47Locale do
|
24
|
+
let(:locale) { Bcp47Locale }
|
25
|
+
|
26
|
+
describe 'self.parse' do
|
27
|
+
it 'returns a locale object with the correct language and territory' do
|
28
|
+
locale.parse('es_MX').tap do |locale|
|
29
|
+
expect(locale).to be_a(Bcp47Locale)
|
30
|
+
expect(locale.language).to eq('es')
|
31
|
+
expect(locale.territory).to eq('MX')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns a locale object with a blank territory when not specified' do
|
36
|
+
locale.parse('es').tap do |locale|
|
37
|
+
expect(locale).to be_a(Bcp47Locale)
|
38
|
+
expect(locale.language).to eq('es')
|
39
|
+
expect(locale.territory).to be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'raises an error if the locale is invalid' do
|
44
|
+
expect(lambda { locale.parse('es_MXFGOA') }).to(
|
45
|
+
raise_error(InvalidLocaleError)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'self.valid?' do
|
51
|
+
it 'ensures locale contains a 2 to 4 char language code' do
|
52
|
+
expect(locale.valid?('es')).to be_truthy
|
53
|
+
expect(locale.valid?('foobar')).to be_falsy
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'validates the optional 2 to 5 character territory code' do
|
57
|
+
expect(locale.valid?('es_MX')).to be_truthy
|
58
|
+
expect(locale.valid?('es_MXFGOA')).to be_falsy
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'allows both dashes and underscores to be used' do
|
62
|
+
expect(locale.valid?('es_MX')).to be_truthy
|
63
|
+
expect(locale.valid?('es-MX')).to be_truthy
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#code' do
|
68
|
+
it 'includes the language and territory' do
|
69
|
+
loc = locale.new('es', 'MX')
|
70
|
+
expect(loc.code).to eq('es-MX')
|
71
|
+
end
|
72
|
+
|
73
|
+
it "doesn't include the territory if nil" do
|
74
|
+
loc = locale.new('es')
|
75
|
+
expect(loc.code).to eq('es')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#eql?' do
|
80
|
+
it 'equates two locales with the same language and territory' do
|
81
|
+
expect(locale.new('es', 'MX')).to eq(locale.new('es', 'mx'))
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'does not equate two locales with different territories' do
|
85
|
+
expect(locale.new('es', 'MX')).to_not eq(locale.new('es', 'PE'))
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'does not equate two locales with different languages' do
|
89
|
+
expect(locale.new('fr', 'CA')).to_not eq(locale.new('en', 'CA'))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe PhraseIndexPolicy do
|
8
|
+
class PhraseIndexPolicyTester
|
9
|
+
include PhraseIndexPolicy
|
10
|
+
|
11
|
+
attr_reader :key, :meta_key
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@key, @meta_key = nil, nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_key(key)
|
18
|
+
@key = key
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_meta_key(meta_key)
|
22
|
+
@meta_key = meta_key
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:policy) { PhraseIndexPolicyTester }
|
27
|
+
let(:policy_instance) { policy.new }
|
28
|
+
|
29
|
+
describe '#index_key and #index_value' do
|
30
|
+
it 'returns :meta_key if the key is nil' do
|
31
|
+
policy_instance.set_meta_key('meta key')
|
32
|
+
expect(policy_instance.index_key).to eq(:meta_key)
|
33
|
+
expect(policy_instance.index_value).to eq('meta key')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns :key even if the key is emtpy (and the meta key is nil)' do
|
37
|
+
policy_instance.set_key('')
|
38
|
+
expect(policy_instance.index_key).to eq(:key)
|
39
|
+
expect(policy_instance.index_value).to eq('')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns :key if the meta key is nil' do
|
43
|
+
policy_instance.set_key('key')
|
44
|
+
expect(policy_instance.index_key).to eq(:key)
|
45
|
+
expect(policy_instance.index_value).to eq('key')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns :key if the meta key is empty' do
|
49
|
+
policy_instance.set_meta_key('')
|
50
|
+
expect(policy_instance.index_key).to eq(:key)
|
51
|
+
expect(policy_instance.index_value).to eq('')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns :meta_key if both key and meta key are not nil (or empty)' do
|
55
|
+
policy_instance.set_key('key')
|
56
|
+
policy_instance.set_meta_key('meta key')
|
57
|
+
expect(policy_instance.index_key).to eq(:meta_key)
|
58
|
+
expect(policy_instance.index_value).to eq('meta key')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns :key if both key and meta key are empty' do
|
62
|
+
policy_instance.set_key('')
|
63
|
+
policy_instance.set_meta_key('')
|
64
|
+
expect(policy_instance.index_key).to eq(:key)
|
65
|
+
expect(policy_instance.index_value).to eq('')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns :key if both key and meta key are nil' do
|
69
|
+
expect(policy_instance.index_key).to eq(:key)
|
70
|
+
expect(policy_instance.index_value).to eq('')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'converts nils to empty strings' do
|
74
|
+
expect(policy_instance.key).to be_nil
|
75
|
+
expect(policy_instance.index_key).to eq(:key)
|
76
|
+
expect(policy_instance.index_value).to eq('')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'self.index_key and self.index_value' do
|
81
|
+
it 'returns :meta_key if the key is nil' do
|
82
|
+
expect(policy.index_key(nil, 'meta key')).to eq(:meta_key)
|
83
|
+
expect(policy.index_value(nil, 'meta key')).to eq('meta key')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns :key even if the key is emtpy (and the meta key is nil)' do
|
87
|
+
expect(policy.index_key('', nil)).to eq(:key)
|
88
|
+
expect(policy.index_value('', nil)).to eq('')
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns :key if the meta key is nil' do
|
92
|
+
expect(policy.index_key('key', nil)).to eq(:key)
|
93
|
+
expect(policy.index_value('key', nil)).to eq('key')
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns :key if the meta key is empty' do
|
97
|
+
expect(policy.index_key(nil, '')).to eq(:key)
|
98
|
+
expect(policy.index_value(nil, '')).to eq('')
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'returns :meta_key if both key and meta key are not nil (or empty)' do
|
102
|
+
expect(policy.index_key('key', 'meta key')).to eq(:meta_key)
|
103
|
+
expect(policy.index_value('key', 'meta key')).to eq('meta key')
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns :key if both key and meta key are empty' do
|
107
|
+
expect(policy.index_key('', '')).to eq(:key)
|
108
|
+
expect(policy.index_value('', '')).to eq('')
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns :key if both key and meta key are nil (and converts nils to strings)' do
|
112
|
+
expect(policy.index_key(nil, nil)).to eq(:key)
|
113
|
+
expect(policy.index_value(nil, nil)).to eq('')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe PhraseToHash do
|
8
|
+
describe '#to_h' do
|
9
|
+
it 'returns a hash of the appropriate attributes' do
|
10
|
+
TestPhrase.new('key', 'meta key', 'file', 'commit id') do |t|
|
11
|
+
expect(t.to_h).to eq({
|
12
|
+
key: 'key', meta_key: 'meta key',
|
13
|
+
file: 'file', commit_id: 'commit id'
|
14
|
+
})
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Core
|
6
|
+
|
7
|
+
describe RepoConfig do
|
8
|
+
let(:rosette_config) { nil }
|
9
|
+
let(:config) { RepoConfig.new('repo-name', rosette_config) }
|
10
|
+
|
11
|
+
describe '#set_path' do
|
12
|
+
it 'sets the repo path and instantiates a repo object inside the config' do
|
13
|
+
repo = TmpRepo.new
|
14
|
+
config.set_path(repo.working_dir.join('.git').to_s)
|
15
|
+
expect(config.repo).to be_a(Repo)
|
16
|
+
expect(config.repo.path).to eq(repo.working_dir.to_s)
|
17
|
+
expect(config.path).to eq(repo.working_dir.to_s)
|
18
|
+
repo.unlink
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#add_extractor' do
|
23
|
+
it 'creates an extractor config, yields it, and adds it to the list of extractor configs' do
|
24
|
+
expect(config.extractor_configs.size).to eq(0)
|
25
|
+
|
26
|
+
config.add_extractor('test/test') do |extractor_config|
|
27
|
+
expect(extractor_config).to be_a(ExtractorConfig)
|
28
|
+
end
|
29
|
+
|
30
|
+
expect(config.extractor_configs.size).to eq(1)
|
31
|
+
|
32
|
+
config.extractor_configs.first.tap do |config|
|
33
|
+
expect(config.extractor).to be_a(Rosette::Extractors::Test::TestExtractor)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#add_serializer' do
|
39
|
+
it 'creates a serializer config and adds it to the list of serializer configs' do
|
40
|
+
expect(config.serializer_configs.size).to eq(0)
|
41
|
+
config.add_serializer('my_serializer', format: 'test/test')
|
42
|
+
expect(config.serializer_configs.size).to eq(1)
|
43
|
+
|
44
|
+
config.serializer_configs.first.tap do |serializer_config|
|
45
|
+
expect(serializer_config.klass).to eq(Rosette::Serializers::Test::TestSerializer)
|
46
|
+
expect(serializer_config.serializer_id).to eq('test/test')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#add_locale' do
|
52
|
+
it 'parses the locale and adds it to the list of locales' do
|
53
|
+
expect(config.locales.size).to eq(0)
|
54
|
+
config.add_locale('es-MX')
|
55
|
+
expect(config.locales.size).to eq(1)
|
56
|
+
|
57
|
+
config.locales.first.tap do |locale|
|
58
|
+
expect(locale.language).to eq('es')
|
59
|
+
expect(locale.territory).to eq('MX')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#add_locales' do
|
65
|
+
it 'parses all the locales and adds them to the list of locales' do
|
66
|
+
expect(config.locales.size).to eq(0)
|
67
|
+
config.add_locales(['es-MX', 'fr-CA'])
|
68
|
+
expect(config.locales.size).to eq(2)
|
69
|
+
|
70
|
+
config.locales.first.tap do |locale|
|
71
|
+
expect(locale.language).to eq('es')
|
72
|
+
expect(locale.territory).to eq('MX')
|
73
|
+
end
|
74
|
+
|
75
|
+
config.locales.last.tap do |locale|
|
76
|
+
expect(locale.language).to eq('fr')
|
77
|
+
expect(locale.territory).to eq('CA')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#get_extractor_configs' do
|
83
|
+
before(:each) do
|
84
|
+
config.add_extractor('test/test') do |extractor_config|
|
85
|
+
extractor_config.set_conditions do |conditions|
|
86
|
+
conditions.match_file_extension('.js')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns all the extractor configs that match the given file extension' do
|
92
|
+
matching_configs = config.get_extractor_configs('foo/bar/baz.js')
|
93
|
+
expect(matching_configs.size).to eq(1)
|
94
|
+
|
95
|
+
matching_configs.first.tap do |extractor_config|
|
96
|
+
expect(extractor_config.extractor).to(
|
97
|
+
be_a(Rosette::Extractors::Test::TestExtractor)
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'returns nil if no extractor can be found' do
|
103
|
+
expect(config.get_extractor_configs('foo/bar/baz.rb')).to be_empty
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#get_serializer_config' do
|
108
|
+
it 'returns the serializer config that matches the given id' do
|
109
|
+
config.add_serializer('my_serializer', format: 'test/test')
|
110
|
+
expect(config.get_serializer_config('test/test')).to(
|
111
|
+
be(config.serializer_configs.first)
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#get_locale' do
|
117
|
+
it 'returns the locale object for the given code' do
|
118
|
+
config.add_locales(['es-MX', 'fr-CA', 'zh-CN'])
|
119
|
+
config.get_locale('fr-CA').tap do |locale|
|
120
|
+
expect(locale).to be_a(Locale)
|
121
|
+
expect(locale.language).to eq('fr')
|
122
|
+
expect(locale.territory).to eq('CA')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#use_tms' do
|
128
|
+
it 'looks the tms constant up by string' do
|
129
|
+
config.use_tms('test')
|
130
|
+
expect(config.tms).to be_a(Rosette::Tms::TestTms::Repository)
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'accepts a constant instead of a string' do
|
134
|
+
config.use_tms(Rosette::Tms::TestTms)
|
135
|
+
expect(config.tms).to be_a(Rosette::Tms::TestTms::Repository)
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'yields a configuration object' do
|
139
|
+
config.use_tms('test') do |configurator|
|
140
|
+
expect(configurator).to be_a(Rosette::Tms::TestTms::Configurator)
|
141
|
+
configurator.set_test_value('foobar')
|
142
|
+
end
|
143
|
+
|
144
|
+
expect(config.tms.configurator.test_value).to eq('foobar')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|