rosette-core 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +26 -0
  3. data/History.txt +3 -0
  4. data/README.md +94 -0
  5. data/Rakefile +18 -0
  6. data/lib/rosette/core.rb +110 -0
  7. data/lib/rosette/core/branch_utils.rb +152 -0
  8. data/lib/rosette/core/commands.rb +139 -0
  9. data/lib/rosette/core/commands/errors.rb +17 -0
  10. data/lib/rosette/core/commands/git/commit_command.rb +65 -0
  11. data/lib/rosette/core/commands/git/diff_base_command.rb +301 -0
  12. data/lib/rosette/core/commands/git/diff_command.rb +188 -0
  13. data/lib/rosette/core/commands/git/diff_entry.rb +44 -0
  14. data/lib/rosette/core/commands/git/fetch_command.rb +27 -0
  15. data/lib/rosette/core/commands/git/repo_snapshot_command.rb +40 -0
  16. data/lib/rosette/core/commands/git/show_command.rb +70 -0
  17. data/lib/rosette/core/commands/git/snapshot_command.rb +50 -0
  18. data/lib/rosette/core/commands/git/status_command.rb +128 -0
  19. data/lib/rosette/core/commands/git/with_non_merge_ref.rb +48 -0
  20. data/lib/rosette/core/commands/git/with_ref.rb +92 -0
  21. data/lib/rosette/core/commands/git/with_refs.rb +92 -0
  22. data/lib/rosette/core/commands/git/with_repo_name.rb +50 -0
  23. data/lib/rosette/core/commands/git/with_snapshots.rb +45 -0
  24. data/lib/rosette/core/commands/queuing/enqueue_commit_command.rb +37 -0
  25. data/lib/rosette/core/commands/queuing/requeue_commit_command.rb +46 -0
  26. data/lib/rosette/core/commands/translations/export_command.rb +257 -0
  27. data/lib/rosette/core/commands/translations/translation_lookup_command.rb +66 -0
  28. data/lib/rosette/core/commands/translations/with_locale.rb +47 -0
  29. data/lib/rosette/core/configurator.rb +160 -0
  30. data/lib/rosette/core/error_reporters/buffered_error_reporter.rb +96 -0
  31. data/lib/rosette/core/error_reporters/error_reporter.rb +31 -0
  32. data/lib/rosette/core/error_reporters/nil_error_reporter.rb +25 -0
  33. data/lib/rosette/core/error_reporters/printing_error_reporter.rb +58 -0
  34. data/lib/rosette/core/error_reporters/raising_error_reporter.rb +27 -0
  35. data/lib/rosette/core/errors.rb +93 -0
  36. data/lib/rosette/core/extractor/commit_log.rb +33 -0
  37. data/lib/rosette/core/extractor/commit_log_status.rb +57 -0
  38. data/lib/rosette/core/extractor/commit_processor.rb +109 -0
  39. data/lib/rosette/core/extractor/extractor.rb +72 -0
  40. data/lib/rosette/core/extractor/extractor_config.rb +74 -0
  41. data/lib/rosette/core/extractor/locale.rb +118 -0
  42. data/lib/rosette/core/extractor/phrase.rb +76 -0
  43. data/lib/rosette/core/extractor/phrase/phrase_index_policy.rb +108 -0
  44. data/lib/rosette/core/extractor/phrase/phrase_to_hash.rb +33 -0
  45. data/lib/rosette/core/extractor/repo_config.rb +339 -0
  46. data/lib/rosette/core/extractor/serializer_config.rb +55 -0
  47. data/lib/rosette/core/extractor/static_extractor.rb +44 -0
  48. data/lib/rosette/core/extractor/translation.rb +44 -0
  49. data/lib/rosette/core/extractor/translation/translation_to_hash.rb +28 -0
  50. data/lib/rosette/core/git/diff_finder.rb +131 -0
  51. data/lib/rosette/core/git/ref.rb +116 -0
  52. data/lib/rosette/core/git/repo.rb +378 -0
  53. data/lib/rosette/core/path_matcher_factory.rb +330 -0
  54. data/lib/rosette/core/resolvers/extractor_id.rb +37 -0
  55. data/lib/rosette/core/resolvers/integration_id.rb +37 -0
  56. data/lib/rosette/core/resolvers/preprocessor_id.rb +38 -0
  57. data/lib/rosette/core/resolvers/resolver.rb +115 -0
  58. data/lib/rosette/core/resolvers/serializer_id.rb +37 -0
  59. data/lib/rosette/core/snapshots/cached_head_snapshot_factory.rb +51 -0
  60. data/lib/rosette/core/snapshots/cached_snapshot_factory.rb +67 -0
  61. data/lib/rosette/core/snapshots/head_snapshot_factory.rb +58 -0
  62. data/lib/rosette/core/snapshots/repo_config_path_filter.rb +83 -0
  63. data/lib/rosette/core/snapshots/snapshot_factory.rb +184 -0
  64. data/lib/rosette/core/string_utils.rb +23 -0
  65. data/lib/rosette/core/translation_status.rb +81 -0
  66. data/lib/rosette/core/validators.rb +18 -0
  67. data/lib/rosette/core/validators/commit_validator.rb +62 -0
  68. data/lib/rosette/core/validators/commits_validator.rb +32 -0
  69. data/lib/rosette/core/validators/encoding_validator.rb +32 -0
  70. data/lib/rosette/core/validators/locale_validator.rb +37 -0
  71. data/lib/rosette/core/validators/repo_validator.rb +33 -0
  72. data/lib/rosette/core/validators/serializer_validator.rb +37 -0
  73. data/lib/rosette/core/validators/validator.rb +31 -0
  74. data/lib/rosette/core/version.rb +8 -0
  75. data/lib/rosette/data_stores.rb +11 -0
  76. data/lib/rosette/data_stores/errors.rb +26 -0
  77. data/lib/rosette/data_stores/phrase_status.rb +59 -0
  78. data/lib/rosette/integrations.rb +12 -0
  79. data/lib/rosette/integrations/errors.rb +15 -0
  80. data/lib/rosette/integrations/integratable.rb +58 -0
  81. data/lib/rosette/integrations/integration.rb +23 -0
  82. data/lib/rosette/preprocessors.rb +11 -0
  83. data/lib/rosette/preprocessors/errors.rb +14 -0
  84. data/lib/rosette/preprocessors/preprocessor.rb +48 -0
  85. data/lib/rosette/queuing.rb +14 -0
  86. data/lib/rosette/queuing/commits.rb +19 -0
  87. data/lib/rosette/queuing/commits/commit_conductor.rb +90 -0
  88. data/lib/rosette/queuing/commits/commit_job.rb +93 -0
  89. data/lib/rosette/queuing/commits/commits_queue_configurator.rb +60 -0
  90. data/lib/rosette/queuing/commits/extract_stage.rb +46 -0
  91. data/lib/rosette/queuing/commits/fetch_stage.rb +51 -0
  92. data/lib/rosette/queuing/commits/finalize_stage.rb +76 -0
  93. data/lib/rosette/queuing/commits/phrase_storage_granularity.rb +20 -0
  94. data/lib/rosette/queuing/commits/push_stage.rb +91 -0
  95. data/lib/rosette/queuing/commits/stage.rb +96 -0
  96. data/lib/rosette/queuing/job.rb +74 -0
  97. data/lib/rosette/queuing/queue.rb +28 -0
  98. data/lib/rosette/queuing/queue_configurator.rb +76 -0
  99. data/lib/rosette/queuing/worker.rb +30 -0
  100. data/lib/rosette/serializers.rb +10 -0
  101. data/lib/rosette/serializers/serializer.rb +98 -0
  102. data/lib/rosette/tms.rb +9 -0
  103. data/lib/rosette/tms/repository.rb +95 -0
  104. data/rosette-core.gemspec +24 -0
  105. data/spec/core/branch_utils_spec.rb +110 -0
  106. data/spec/core/commands/git/commit_command_spec.rb +60 -0
  107. data/spec/core/commands/git/diff_command_spec.rb +263 -0
  108. data/spec/core/commands/git/fetch_command_spec.rb +61 -0
  109. data/spec/core/commands/git/repo_snapshot_command_spec.rb +72 -0
  110. data/spec/core/commands/git/show_command_spec.rb +128 -0
  111. data/spec/core/commands/git/snapshot_command_spec.rb +86 -0
  112. data/spec/core/commands/git/status_command_spec.rb +154 -0
  113. data/spec/core/commands/queuing/enqueue_commit_command_spec.rb +34 -0
  114. data/spec/core/commands/queuing/requeue_commit_command_spec.rb +46 -0
  115. data/spec/core/commands/translations/export_command_spec.rb +113 -0
  116. data/spec/core/commands/translations/translation_lookup_command_spec.rb +58 -0
  117. data/spec/core/configurator_spec.rb +47 -0
  118. data/spec/core/error_reporters/buffered_error_reporter_spec.rb +61 -0
  119. data/spec/core/error_reporters/nil_error_reporter_spec.rb +16 -0
  120. data/spec/core/error_reporters/printing_error_reporter_spec.rb +60 -0
  121. data/spec/core/extractor/commit_log_status_spec.rb +216 -0
  122. data/spec/core/extractor/commit_processor_spec.rb +68 -0
  123. data/spec/core/extractor/extractor_config_spec.rb +47 -0
  124. data/spec/core/extractor/extractor_spec.rb +26 -0
  125. data/spec/core/extractor/locale_spec.rb +92 -0
  126. data/spec/core/extractor/phrase/phrase_index_policy_spec.rb +116 -0
  127. data/spec/core/extractor/phrase/phrase_to_hash_spec.rb +18 -0
  128. data/spec/core/extractor/repo_config_spec.rb +147 -0
  129. data/spec/core/extractor/translation/translation_to_hash_spec.rb +25 -0
  130. data/spec/core/git/diff_finder_spec.rb +74 -0
  131. data/spec/core/git/ref_spec.rb +118 -0
  132. data/spec/core/git/repo_spec.rb +216 -0
  133. data/spec/core/path_matcher_factory_spec.rb +139 -0
  134. data/spec/core/resolvers/extractor_id_spec.rb +47 -0
  135. data/spec/core/resolvers/integration_id_spec.rb +47 -0
  136. data/spec/core/resolvers/preprocessor_id_spec.rb +47 -0
  137. data/spec/core/resolvers/serializer_id_spec.rb +47 -0
  138. data/spec/core/snapshots/snapshot_factory_spec.rb +145 -0
  139. data/spec/core/string_utils_spec.rb +19 -0
  140. data/spec/core/translation_status_spec.rb +91 -0
  141. data/spec/core/validators/commit_validator_spec.rb +40 -0
  142. data/spec/core/validators/encoding_validator_spec.rb +30 -0
  143. data/spec/core/validators/locale_validator_spec.rb +31 -0
  144. data/spec/core/validators/repo_validator_spec.rb +30 -0
  145. data/spec/core/validators/serializer_validator_spec.rb +31 -0
  146. data/spec/integrations/integratable_spec.rb +58 -0
  147. data/spec/queuing/commits/commit_conductor_spec.rb +71 -0
  148. data/spec/queuing/commits/commit_job_spec.rb +87 -0
  149. data/spec/queuing/commits/extract_stage_spec.rb +68 -0
  150. data/spec/queuing/commits/fetch_stage_spec.rb +101 -0
  151. data/spec/queuing/commits/finalize_stage_spec.rb +88 -0
  152. data/spec/queuing/commits/push_stage_spec.rb +145 -0
  153. data/spec/queuing/commits/stage_spec.rb +80 -0
  154. data/spec/queuing/job_spec.rb +33 -0
  155. data/spec/queuing/queue_configurator_spec.rb +44 -0
  156. data/spec/spec_helper.rb +90 -0
  157. data/spec/test_helpers/fake_commit_stage.rb +17 -0
  158. metadata +257 -0
@@ -0,0 +1,101 @@
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::NOT_SEEN,
25
+ repo_name: repo_name,
26
+ commit_id: commit_id,
27
+ phrase_count: 0,
28
+ commit_datetime: nil,
29
+ branch_name: nil
30
+ )
31
+ end
32
+
33
+ let(:stage) do
34
+ FetchStage.new(rosette_config, repo_config, logger, commit_log)
35
+ end
36
+
37
+ let(:git) { double(:git) }
38
+ let(:git_message_chain) { [:fetch, :setRemote, :setRemoveDeletedRefs] }
39
+
40
+ before(:each) do
41
+ stage.instance_variable_set(:'@git', git)
42
+
43
+ allow(git).to(
44
+ receive_message_chain(git_message_chain).and_return(git)
45
+ )
46
+ end
47
+
48
+ describe '#execute!' do
49
+ it 'runs a git fetch on the repo' do
50
+ expect(git).to receive(:call)
51
+ stage.execute!
52
+ end
53
+
54
+ context 'with a mocked fetch operation' do
55
+ before(:each) do
56
+ allow(git).to receive(:call)
57
+ end
58
+
59
+ it 'updates the commit log status' do
60
+ stage.execute!
61
+ expect(commit_log.status).to eq(PhraseStatus::FETCHED)
62
+ end
63
+
64
+ it 'sets branch_name to the master branch if the commit exists in master' do
65
+ remote_repo = TmpRepo.new
66
+
67
+ # git doesn't allow you to push to the currently checked out branch, so
68
+ # create a new branch to avoid an error
69
+ remote_repo.git('checkout -b new_branch')
70
+ fixture.repo.git("remote add origin #{remote_repo.working_dir}")
71
+ fixture.repo.git('push origin HEAD')
72
+
73
+ stage.execute!
74
+ entry = InMemoryDataStore::CommitLog.entries.first
75
+ expect(entry.branch_name).to eq('refs/remotes/origin/master')
76
+
77
+ remote_repo.unlink
78
+ end
79
+
80
+ it 'sets branch_name to the first remote ref when creating a new commit log' do
81
+ fixture.repo.git('checkout -b my_branch')
82
+ fixture.repo.create_file('test.txt') do |writer|
83
+ writer.write('test test test')
84
+ end
85
+
86
+ fixture.repo.add_all
87
+ fixture.repo.commit('Commit message')
88
+
89
+ remote_repo = TmpRepo.new
90
+ fixture.repo.git("remote add origin #{remote_repo.working_dir}")
91
+ fixture.repo.git('push origin HEAD')
92
+
93
+ stage.execute!
94
+ entry = InMemoryDataStore::CommitLog.entries.first
95
+ expect(entry.branch_name).to eq('refs/remotes/origin/my_branch')
96
+
97
+ remote_repo.unlink
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,88 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Queuing::Commits
6
+ include Rosette::DataStores
7
+ include Rosette::Core
8
+
9
+ describe FinalizeStage 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
+ repo_config.use_tms('test')
17
+ repo_config.add_locales(%w(pt-BR ja-JP))
18
+ end
19
+ end
20
+
21
+ let(:rosette_config) { fixture.config }
22
+ let(:repo_config) { rosette_config.get_repo(repo_name) }
23
+ let(:logger) { NullLogger.new }
24
+
25
+ let(:commit_log) do
26
+ InMemoryDataStore::CommitLog.create(
27
+ status: PhraseStatus::PUSHED,
28
+ repo_name: repo_name,
29
+ commit_id: commit_id,
30
+ phrase_count: 10,
31
+ commit_datetime: nil,
32
+ branch_name: 'refs/heads/master'
33
+ )
34
+ end
35
+
36
+ let(:stage) do
37
+ FinalizeStage.new(rosette_config, repo_config, logger, commit_log)
38
+ end
39
+
40
+ describe '#execute!' do
41
+ before(:each) do
42
+ allow(repo_config.tms).to receive(:status).and_return(
43
+ TranslationStatus.new(commit_log.phrase_count).tap do |status|
44
+ repo_config.locales.each do |locale|
45
+ status.add_locale_count(locale.code, locale_count)
46
+ end
47
+ end
48
+ )
49
+ end
50
+
51
+ context 'with a not fully translated status' do
52
+ let(:locale_count) { commit_log.phrase_count - 1 }
53
+
54
+ it "creates commit log locale entries and doesn't update the status" do
55
+ expect(repo_config.tms).to_not receive(:finalize)
56
+ stage.execute!
57
+ expect(commit_log.status).to eq(PhraseStatus::PUSHED)
58
+ entries = InMemoryDataStore::CommitLogLocale.map(&:translated_count)
59
+ entries.each { |e| expect(e).to eq(commit_log.phrase_count - 1) }
60
+ end
61
+ end
62
+
63
+ context 'with a fully translated status' do
64
+ let(:locale_count) { commit_log.phrase_count }
65
+
66
+ it 'calls finalize on the tms, updates the status, and creates entries' do
67
+ expect(repo_config.tms).to receive(:finalize)
68
+ stage.execute!
69
+ expect(commit_log.status).to eq(PhraseStatus::FINALIZED)
70
+ entries = InMemoryDataStore::CommitLogLocale.map(&:translated_count)
71
+ entries.each { |e| expect(e).to eq(commit_log.phrase_count) }
72
+ end
73
+ end
74
+ end
75
+
76
+ describe '#to_job' do
77
+ it 'adds a delay to the job if the status is still PUSHED' do
78
+ job = stage.to_job
79
+ expect(job.delay).to be > 0
80
+ end
81
+
82
+ it 'does not add a delay if the job is FINALIZED' do
83
+ stage.commit_log.status = PhraseStatus::FINALIZED
84
+ job = stage.to_job
85
+ expect(job.delay).to eq(0)
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,145 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Queuing::Commits
6
+ include Rosette::DataStores
7
+
8
+ describe PushStage do
9
+ let(:repo_name) { 'single_commit' }
10
+
11
+ let(:fixture) do
12
+ load_repo_fixture(repo_name) do |config, repo_config|
13
+ repo_config.use_tms('test')
14
+ config.use_datastore('in-memory')
15
+ config.use_queue('test') do |queue_config|
16
+ queue_config.enable_queue('commits')
17
+ end
18
+ end
19
+ end
20
+
21
+ let(:rosette_config) { fixture.config }
22
+ let(:repo_config) { rosette_config.get_repo(repo_name) }
23
+ let(:logger) { NullLogger.new }
24
+
25
+ describe '#execute!' do
26
+ context 'with a single commit' do
27
+ let(:commit_log) do
28
+ InMemoryDataStore::CommitLog.create(
29
+ status: PhraseStatus::FETCHED,
30
+ repo_name: repo_name,
31
+ commit_id: commit_id,
32
+ phrase_count: 0,
33
+ commit_datetime: nil,
34
+ branch_name: 'refs/heads/master'
35
+ )
36
+ end
37
+
38
+ let(:stage) do
39
+ PushStage.new(rosette_config, repo_config, logger, commit_log)
40
+ end
41
+
42
+ let(:commit_id) { fixture.repo.git('rev-parse HEAD').strip }
43
+
44
+ before(:each) do
45
+ args = [rosette_config, repo_config, logger, commit_log]
46
+ ExtractStage.new(*args).execute!
47
+ end
48
+
49
+ it 'updates the status to FINALIZED when no phrases are found' do
50
+ expect(stage).to receive(:phrases).and_return([])
51
+ stage.execute!
52
+ expect(commit_log.status).to eq(PhraseStatus::FINALIZED)
53
+ end
54
+
55
+ it 'stores the phrases in the repository' do
56
+ stage.execute!
57
+ phrases = repo_config.tms.stored_phrases[commit_id].map(&:key)
58
+ expect(phrases).to include('The green albatross flitters in the moonlight')
59
+ expect(phrases).to include('Chatanooga Choo Choo')
60
+ expect(phrases).to include(' test string 1')
61
+ end
62
+
63
+ it 'updates the commit log status' do
64
+ stage.execute!
65
+ expect(commit_log.status).to eq(PhraseStatus::PUSHED)
66
+ end
67
+
68
+ it "updates the status to MISSING if one of the objects doesn't exist" do
69
+ fixture.repo.git('reset --hard HEAD')
70
+ fixture.repo.create_file('testfile.txt') { |f| f.write('foo') }
71
+ fixture.repo.add_all
72
+ fixture.repo.commit('Test commit')
73
+
74
+ commit_log.commit_id = fixture.repo.git('rev-parse HEAD').strip
75
+
76
+ fixture.repo.git('reset --hard HEAD~1')
77
+ fixture.repo.git('reflog expire --expire=now --all')
78
+ fixture.repo.git('fsck --unreachable')
79
+ fixture.repo.git('prune -v')
80
+
81
+ stage.execute!
82
+ expect(commit_log.status).to eq(PhraseStatus::MISSING)
83
+ end
84
+ end
85
+ end
86
+
87
+ context 'with a git branch' do
88
+ before(:each) do
89
+ fixture.repo.create_branch('my_branch')
90
+
91
+ fixture.repo.create_file('testfile.txt') { |f| f.write('first') }
92
+ fixture.repo.add_all
93
+ fixture.repo.commit('Test commit')
94
+
95
+ fixture.repo.create_file('anothertestfile.txt') { |f| f.write('second') }
96
+ fixture.repo.add_all
97
+ fixture.repo.commit('Another test commit')
98
+
99
+ fixture.repo.each_commit_id do |commit_id|
100
+ commit_log = InMemoryDataStore::CommitLog.create(
101
+ status: PhraseStatus::FETCHED,
102
+ repo_name: repo_name,
103
+ commit_id: commit_id,
104
+ phrase_count: 0,
105
+ commit_datetime: nil,
106
+ branch_name: 'refs/heads/my_branch'
107
+ )
108
+
109
+ args = [rosette_config, repo_config, logger, commit_log]
110
+ ExtractStage.new(*args).execute!
111
+ end
112
+ end
113
+
114
+ context 'with phrase storage granularity set to BRANCH' do
115
+ before(:each) do
116
+ queue = rosette_config.queue.configurator.get_queue_config('commits')
117
+ queue.set_phrase_storage_granularity(PhraseStorageGranularity::BRANCH)
118
+ end
119
+
120
+ let(:commit_log) do
121
+ InMemoryDataStore::CommitLog.entries.first
122
+ end
123
+
124
+ let(:stage) do
125
+ PushStage.new(rosette_config, repo_config, logger, commit_log)
126
+ end
127
+
128
+ describe '#execute' do
129
+ it 'pushes all the phrases in the branch' do
130
+ stage.execute!
131
+ phrases = repo_config.tms.stored_phrases[commit_log.commit_id]
132
+ keys = phrases.map(&:key)
133
+ expect(keys).to eq(%w(second first))
134
+ end
135
+
136
+ it 'pushes by commit if the branch name is null' do
137
+ commit_log.branch_name = nil
138
+ stage.execute!
139
+ phrases = repo_config.tms.stored_phrases[commit_log.commit_id]
140
+ expect(phrases.map(&:key)).to eq(%w(second))
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,80 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Queuing::Commits
6
+ include Rosette::DataStores
7
+
8
+ describe Stage do
9
+ let(:stage_class) { Class.new(Stage) }
10
+ let(:repo_name) { 'single_commit' }
11
+ let(:commit_id) { '123abc' }
12
+
13
+ let(:fixture) do
14
+ load_repo_fixture(repo_name) do |config, repo_config|
15
+ config.use_datastore('in-memory')
16
+ end
17
+ end
18
+
19
+ let(:rosette_config) { fixture.config }
20
+ let(:repo_config) { rosette_config.get_repo(repo_name) }
21
+ let(:logger) { NullLogger.new }
22
+
23
+ let(:pushed_commit_log) do
24
+ InMemoryDataStore::CommitLog.create(
25
+ status: PhraseStatus::PUSHED, repo_name: repo_name, commit_id: commit_id
26
+ )
27
+ end
28
+
29
+ let(:extracted_commit_log) do
30
+ InMemoryDataStore::CommitLog.create(
31
+ status: PhraseStatus::EXTRACTED, repo_name: repo_name, commit_id: commit_id
32
+ )
33
+ end
34
+
35
+ before(:each) do
36
+ stage_class.accepts(PhraseStatus::EXTRACTED)
37
+ end
38
+
39
+ describe '.accepts?' do
40
+ it 'returns true if the stage accepts the given commit log' do
41
+ expect(stage_class.accepts?(extracted_commit_log)).to be_truthy
42
+ end
43
+
44
+ it 'returns false if the stage does not accept the given commit log' do
45
+ expect(stage_class.accepts?(pushed_commit_log)).to be_falsy
46
+ end
47
+ end
48
+
49
+ describe '.for_commit_log' do
50
+ it "returns nil if the commit log isn't accepted" do
51
+ result = stage_class.for_commit_log(
52
+ pushed_commit_log, rosette_config, logger
53
+ )
54
+
55
+ expect(result).to be_nil
56
+ end
57
+
58
+ it 'wraps the commit log in a stage instance' do
59
+ result = stage_class.for_commit_log(
60
+ extracted_commit_log, rosette_config, logger
61
+ )
62
+
63
+ expect(result).to be_a(stage_class)
64
+ expect(result.rosette_config).to eq(rosette_config)
65
+ expect(result.repo_config).to_not be_nil
66
+ expect(result.logger).to eq(logger)
67
+ expect(result.commit_log).to eq(extracted_commit_log)
68
+ end
69
+ end
70
+
71
+ describe '#to_job' do
72
+ let(:stage) do
73
+ stage_class.new(rosette_config, repo_config, logger, extracted_commit_log)
74
+ end
75
+
76
+ it 'converts the stage to a job' do
77
+ expect(stage.to_job).to be_a(CommitJob)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ include Rosette::Queuing
6
+
7
+ describe Job do
8
+ let(:job_class) { Class.new(Job) }
9
+
10
+ describe '.queue_name' do
11
+ it 'returns the default queue name' do
12
+ expect(job_class.queue_name).to eq('default')
13
+ end
14
+
15
+ it 'returns a custom queue name' do
16
+ job_class.set_queue_name('foobar')
17
+ expect(job_class.queue_name).to eq('foobar')
18
+ end
19
+ end
20
+
21
+ describe '#set_delay' do
22
+ let(:job) { job_class.new }
23
+
24
+ it 'checks the delay is set to zero by default' do
25
+ expect(job.delay).to eq(0)
26
+ end
27
+
28
+ it 'sets the delay' do
29
+ job.set_delay(10)
30
+ expect(job.delay).to eq(10)
31
+ end
32
+ end
33
+ end