lokalise_rails 1.0.1 → 1.1.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +10 -3
- data/lib/generators/templates/lokalise_rails_config.rb +6 -0
- data/lib/lokalise_rails.rb +11 -1
- data/lib/lokalise_rails/railtie.rb +0 -2
- data/lib/lokalise_rails/task_definition/base.rb +14 -1
- data/lib/lokalise_rails/task_definition/exporter.rb +1 -1
- data/lib/lokalise_rails/task_definition/importer.rb +1 -1
- data/lib/lokalise_rails/version.rb +1 -1
- data/lokalise_rails.gemspec +0 -1
- data/spec/dummy/config/lokalise_rails.rb +2 -0
- data/spec/lib/lokalise_rails/task_definition/base_spec.rb +85 -0
- data/spec/lib/lokalise_rails/{exporter_spec.rb → task_definition/exporter_spec.rb} +28 -10
- data/spec/lib/lokalise_rails/{importer_spec.rb → task_definition/importer_spec.rb} +7 -6
- data/spec/lib/lokalise_rails_spec.rb +21 -8
- data/spec/lib/tasks/import_task_spec.rb +15 -9
- data/spec/spec_helper.rb +0 -3
- data/spec/support/spec_addons.rb +4 -2
- metadata +8 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 951a2d142a56078d2d9509fa36c13f87f7069b8f2defa9bd158a90a67aba2b9a
|
4
|
+
data.tar.gz: ac2360ad608a4251c9061454c0fea986f868facb90567a5bcd94ae01d33bd8e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f41072fa0c0e138fc3f6a838b672c50e0f3af799e151b0cbc2b66aa1792446c6cdde4a1426ed1a5243871c48cc55bc9e12439ecc7eb00be090629ad0a77bd4c
|
7
|
+
data.tar.gz: ae1acd8d95ce227c8c16a362d2fb0d0bc371a986e5108043a7d9f3037bf292e1da2a48efa4c84720e7a4f1f1e66c13e757ba59ababe1ab081d77960516340803
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails and allows to exchange translation files easily. It relies on [ruby-lokalise-api](https://lokalise.github.io/ruby-lokalise-api) to send APIv2 requests.
|
8
8
|
|
9
|
+
*If you would like to know how this gem was built, check out the ["How to create a Ruby gem" series at Lokalise blog](https://lokalise.com/blog/create-a-ruby-gem-basics/).*
|
10
|
+
|
9
11
|
## Getting started
|
10
12
|
|
11
13
|
### Requirements
|
@@ -71,13 +73,16 @@ require "#{Rails.root}/config/lokalise_rails.rb"
|
|
71
73
|
|
72
74
|
# Import the files:
|
73
75
|
result = LokaliseRails::TaskDefinition::Importer.import!
|
74
|
-
|
76
|
+
```
|
77
|
+
`result` contains a boolean value with the result of the operation
|
75
78
|
|
79
|
+
```ruby
|
76
80
|
# Export the files:
|
77
81
|
processes = LokaliseRails::TaskDefinition::Exporter.export!
|
78
|
-
# `processes` contains a list of queued background processes
|
79
82
|
```
|
80
83
|
|
84
|
+
`processes` contains a list of [queued background processes](https://lokalise.github.io/ruby-lokalise-api/api/queued-processes).
|
85
|
+
|
81
86
|
## Configuration
|
82
87
|
|
83
88
|
Options are specified in the `config/lokalise_rails.rb` file.
|
@@ -88,6 +93,8 @@ Options are specified in the `config/lokalise_rails.rb` file.
|
|
88
93
|
* `project_id` (`string`, required) - Lokalise project ID. You must have import/export permissions in the specified project.
|
89
94
|
* `locales_path` (`string`) - path to the directory with your translation files. Defaults to `"#{Rails.root}/config/locales"`.
|
90
95
|
* `file_ext_regexp` (`regexp`) - regular expression applied to file extensions to determine which files should be imported and exported. Defaults to `/\.ya?ml\z/i` (YAML files).
|
96
|
+
* `branch` (`string`) - Lokalise project branch to use. Defaults to `"master"`.
|
97
|
+
* `timeouts` (`hash`) - set [request timeouts for the Lokalise API client](https://lokalise.github.io/ruby-lokalise-api/additional_info/customization#setting-timeouts). By default, requests have no timeouts: `{open_timeout: nil, timeout: nil}`. Both values are in seconds.
|
91
98
|
|
92
99
|
### Import settings
|
93
100
|
|
@@ -134,4 +141,4 @@ c.skip_file_export = ->(file) { f.split[1].to_s.include?('fr') }
|
|
134
141
|
|
135
142
|
## License
|
136
143
|
|
137
|
-
Copyright (c) [Lokalise team](http://lokalise.com), [Ilya Bodrov](http://bodrovis.tech)
|
144
|
+
Copyright (c) [Lokalise team](http://lokalise.com), [Ilya Bodrov](http://bodrovis.tech). License type is [MIT](https://github.com/bodrovis/lokalise_rails/blob/master/LICENSE).
|
@@ -10,6 +10,12 @@ LokaliseRails.config do |c|
|
|
10
10
|
# Provide a custom path to the directory with your translation files:
|
11
11
|
# c.locales_path = "#{Rails.root}/config/locales"
|
12
12
|
|
13
|
+
# Provide a Lokalise project branch to use:
|
14
|
+
# c.branch = 'master'
|
15
|
+
|
16
|
+
# Provide request timeouts for the Lokalise API client:
|
17
|
+
# c.timeouts = {open_timeout: nil, timeout: nil}
|
18
|
+
|
13
19
|
# Import options have the following defaults:
|
14
20
|
# c.import_opts = {
|
15
21
|
# format: 'yaml',
|
data/lib/lokalise_rails.rb
CHANGED
@@ -8,7 +8,7 @@ module LokaliseRails
|
|
8
8
|
class << self
|
9
9
|
attr_accessor :api_token, :project_id
|
10
10
|
attr_writer :import_opts, :import_safe_mode, :export_opts, :locales_path,
|
11
|
-
:file_ext_regexp, :skip_file_export
|
11
|
+
:file_ext_regexp, :skip_file_export, :branch, :timeouts
|
12
12
|
|
13
13
|
# Main interface to provide configuration options for rake tasks
|
14
14
|
def config
|
@@ -20,6 +20,16 @@ module LokaliseRails
|
|
20
20
|
@locales_path || "#{Rails.root}/config/locales"
|
21
21
|
end
|
22
22
|
|
23
|
+
# Project branch to use
|
24
|
+
def branch
|
25
|
+
@branch || 'master'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Set request timeouts for the Lokalise API client
|
29
|
+
def timeouts
|
30
|
+
@timeouts || {}
|
31
|
+
end
|
32
|
+
|
23
33
|
# Regular expression used to select translation files with proper extensions
|
24
34
|
def file_ext_regexp
|
25
35
|
@file_ext_regexp || /\.ya?ml\z/i
|
@@ -13,7 +13,13 @@ module LokaliseRails
|
|
13
13
|
#
|
14
14
|
# @return [Lokalise::Client]
|
15
15
|
def api_client
|
16
|
-
@api_client ||= ::Lokalise.client LokaliseRails.api_token
|
16
|
+
@api_client ||= ::Lokalise.client LokaliseRails.api_token, LokaliseRails.timeouts
|
17
|
+
end
|
18
|
+
|
19
|
+
# Resets API client
|
20
|
+
def reset_api_client!
|
21
|
+
Lokalise.reset_client!
|
22
|
+
@api_client = nil
|
17
23
|
end
|
18
24
|
|
19
25
|
# Checks task options
|
@@ -44,6 +50,13 @@ module LokaliseRails
|
|
44
50
|
def subdir_and_filename_for(entry)
|
45
51
|
Pathname.new(entry).split
|
46
52
|
end
|
53
|
+
|
54
|
+
# Returns Lokalise project ID and branch, semicolumn separated
|
55
|
+
#
|
56
|
+
# @return [String]
|
57
|
+
def project_id_with_branch
|
58
|
+
"#{LokaliseRails.project_id}:#{LokaliseRails.branch}"
|
59
|
+
end
|
47
60
|
end
|
48
61
|
end
|
49
62
|
end
|
@@ -20,7 +20,7 @@ module LokaliseRails
|
|
20
20
|
queued_processes = []
|
21
21
|
each_file do |full_path, relative_path|
|
22
22
|
queued_processes << api_client.upload_file(
|
23
|
-
|
23
|
+
project_id_with_branch, opts(full_path, relative_path)
|
24
24
|
)
|
25
25
|
rescue StandardError => e
|
26
26
|
$stdout.puts "Error while trying to upload #{full_path}: #{e.inspect}"
|
@@ -37,7 +37,7 @@ module LokaliseRails
|
|
37
37
|
def download_files
|
38
38
|
opts = LokaliseRails.import_opts
|
39
39
|
|
40
|
-
api_client.download_files
|
40
|
+
api_client.download_files project_id_with_branch, opts
|
41
41
|
rescue StandardError => e
|
42
42
|
$stdout.puts "There was an error when trying to download files: #{e.inspect}"
|
43
43
|
end
|
data/lokalise_rails.gemspec
CHANGED
@@ -35,7 +35,6 @@ Gem::Specification.new do |spec|
|
|
35
35
|
end
|
36
36
|
spec.add_development_dependency 'rake', '~> 13.0'
|
37
37
|
spec.add_development_dependency 'rspec', '~> 3.6'
|
38
|
-
spec.add_development_dependency 'rspec-rails', '~> 4.0'
|
39
38
|
spec.add_development_dependency 'rubocop', '~> 0.60'
|
40
39
|
spec.add_development_dependency 'rubocop-performance', '~> 1.5'
|
41
40
|
spec.add_development_dependency 'rubocop-rspec', '~> 1.37'
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe LokaliseRails::TaskDefinition::Base do
|
4
|
+
specify '.reset_client!' do
|
5
|
+
expect(described_class.api_client).to be_an_instance_of(Lokalise::Client)
|
6
|
+
described_class.reset_api_client!
|
7
|
+
current_client = described_class.instance_variable_get '@api_client'
|
8
|
+
expect(current_client).to be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
specify '.project_id_with_branch!' do
|
12
|
+
result = described_class.send :project_id_with_branch
|
13
|
+
expect(result).to be_an_instance_of(String)
|
14
|
+
expect(result).to include(':master')
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.subdir_and_filename_for' do
|
18
|
+
it 'works properly for longer paths' do
|
19
|
+
path = 'my_path/is/here/file.yml'
|
20
|
+
result = described_class.send(:subdir_and_filename_for, path)
|
21
|
+
expect(result.length).to eq(2)
|
22
|
+
expect(result[0]).to be_an_instance_of(Pathname)
|
23
|
+
expect(result[0].to_s).to eq('my_path/is/here')
|
24
|
+
expect(result[1].to_s).to eq('file.yml')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'works properly for shorter paths' do
|
28
|
+
path = 'file.yml'
|
29
|
+
result = described_class.send(:subdir_and_filename_for, path)
|
30
|
+
expect(result.length).to eq(2)
|
31
|
+
expect(result[1]).to be_an_instance_of(Pathname)
|
32
|
+
expect(result[0].to_s).to eq('.')
|
33
|
+
expect(result[1].to_s).to eq('file.yml')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.opt_errors' do
|
38
|
+
it 'returns an error when the API key is not set' do
|
39
|
+
allow(LokaliseRails).to receive(:api_token).and_return(nil)
|
40
|
+
errors = described_class.opt_errors
|
41
|
+
|
42
|
+
expect(LokaliseRails).to have_received(:api_token)
|
43
|
+
expect(errors.length).to eq(1)
|
44
|
+
expect(errors.first).to include('API token is not set')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns an error when the project_id is not set' do
|
48
|
+
allow(LokaliseRails).to receive(:project_id).and_return(nil)
|
49
|
+
errors = described_class.opt_errors
|
50
|
+
|
51
|
+
expect(LokaliseRails).to have_received(:project_id)
|
52
|
+
expect(errors.length).to eq(1)
|
53
|
+
expect(errors.first).to include('Project ID is not set')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '.proper_ext?' do
|
58
|
+
it 'works properly with path represented as a string' do
|
59
|
+
path = 'my_path/here/file.yml'
|
60
|
+
expect(described_class.send(:proper_ext?, path)).to be true
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'works properly with path represented as a pathname' do
|
64
|
+
path = Pathname.new 'my_path/here/file.json'
|
65
|
+
expect(described_class.send(:proper_ext?, path)).to be false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '.api_client' do
|
70
|
+
before(:all) { described_class.reset_api_client! }
|
71
|
+
|
72
|
+
after(:all) { described_class.reset_api_client! }
|
73
|
+
|
74
|
+
it 'is possible to set timeouts' do
|
75
|
+
allow(LokaliseRails).to receive(:timeouts).and_return({
|
76
|
+
open_timeout: 100,
|
77
|
+
timeout: 500
|
78
|
+
})
|
79
|
+
|
80
|
+
expect(described_class.api_client).to be_an_instance_of(Lokalise::Client)
|
81
|
+
expect(described_class.api_client.open_timeout).to eq(100)
|
82
|
+
expect(described_class.api_client.timeout).to eq(500)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -19,7 +19,7 @@ describe LokaliseRails::TaskDefinition::Exporter do
|
|
19
19
|
describe '.export!' do
|
20
20
|
it 'sends a proper API request' do
|
21
21
|
allow_project_id
|
22
|
-
|
22
|
+
|
23
23
|
process = VCR.use_cassette('upload_files') do
|
24
24
|
described_class.export!
|
25
25
|
end.first
|
@@ -28,16 +28,31 @@ describe LokaliseRails::TaskDefinition::Exporter do
|
|
28
28
|
expect(process.status).to eq('queued')
|
29
29
|
end
|
30
30
|
|
31
|
+
it 'sends a proper API request when a different branch is provided' do
|
32
|
+
allow_project_id
|
33
|
+
allow(LokaliseRails).to receive(:branch).and_return('develop')
|
34
|
+
|
35
|
+
process = VCR.use_cassette('upload_files_branch') do
|
36
|
+
described_class.export!
|
37
|
+
end.first
|
38
|
+
|
39
|
+
expect(LokaliseRails).to have_received(:branch)
|
40
|
+
expect(process.project_id).to eq(LokaliseRails.project_id)
|
41
|
+
expect(process.status).to eq('queued')
|
42
|
+
end
|
43
|
+
|
31
44
|
it 'halts when the API key is not set' do
|
32
|
-
|
33
|
-
|
45
|
+
allow(LokaliseRails).to receive(:api_token).and_return(nil)
|
46
|
+
|
34
47
|
expect(-> { described_class.export! }).to output(/API token is not set/).to_stdout
|
48
|
+
expect(LokaliseRails).to have_received(:api_token)
|
35
49
|
end
|
36
50
|
|
37
51
|
it 'halts when the project_id is not set' do
|
38
|
-
|
39
|
-
|
52
|
+
allow(LokaliseRails).to receive(:project_id).and_return(nil)
|
53
|
+
|
40
54
|
expect(-> { described_class.export! }).to output(/Project ID is not set/).to_stdout
|
55
|
+
expect(LokaliseRails).to have_received(:project_id)
|
41
56
|
end
|
42
57
|
end
|
43
58
|
|
@@ -62,13 +77,14 @@ describe LokaliseRails::TaskDefinition::Exporter do
|
|
62
77
|
end
|
63
78
|
|
64
79
|
it 'allows to redefine options' do
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
80
|
+
allow(LokaliseRails).to receive(:export_opts).and_return({
|
81
|
+
detect_icu_plurals: true,
|
82
|
+
convert_placeholders: true
|
83
|
+
})
|
69
84
|
|
70
85
|
resulting_opts = described_class.opts(path, relative_name)
|
71
86
|
|
87
|
+
expect(LokaliseRails).to have_received(:export_opts)
|
72
88
|
expect(resulting_opts[:data]).to eq(base64content)
|
73
89
|
expect(resulting_opts[:filename]).to eq(relative_name)
|
74
90
|
expect(resulting_opts[:lang_iso]).to eq('en')
|
@@ -133,7 +149,7 @@ describe LokaliseRails::TaskDefinition::Exporter do
|
|
133
149
|
end
|
134
150
|
|
135
151
|
it 'does not yield files that have to be skipped' do
|
136
|
-
|
152
|
+
allow(LokaliseRails).to receive(:skip_file_export).twice.and_return(
|
137
153
|
->(f) { f.split[1].to_s.include?('ru') }
|
138
154
|
)
|
139
155
|
expect { |b| described_class.each_file(&b) }.to yield_successive_args(
|
@@ -142,6 +158,8 @@ describe LokaliseRails::TaskDefinition::Exporter do
|
|
142
158
|
Pathname.new(relative_name)
|
143
159
|
]
|
144
160
|
)
|
161
|
+
|
162
|
+
expect(LokaliseRails).to have_received(:skip_file_export).twice
|
145
163
|
end
|
146
164
|
end
|
147
165
|
end
|
@@ -12,19 +12,18 @@ describe LokaliseRails::TaskDefinition::Importer do
|
|
12
12
|
|
13
13
|
describe '.download_files' do
|
14
14
|
it 'returns a proper download URL' do
|
15
|
-
|
15
|
+
allow(LokaliseRails).to receive(:project_id).and_return('189934715f57a162257d74.88352370')
|
16
16
|
response = VCR.use_cassette('download_files') do
|
17
17
|
described_class.download_files
|
18
18
|
end
|
19
19
|
|
20
|
+
expect(LokaliseRails).to have_received(:project_id)
|
20
21
|
expect(response['project_id']).to eq('189934715f57a162257d74.88352370')
|
21
22
|
expect(response['bundle_url']).to include('s3-eu-west-1.amazonaws.com')
|
22
23
|
end
|
23
24
|
|
24
25
|
it 'rescues from errors during file download' do
|
25
|
-
allow_project_id
|
26
|
-
allow(LokaliseRails).to receive(:api_token).and_return('incorrect')
|
27
|
-
|
26
|
+
allow_project_id 'invalid'
|
28
27
|
VCR.use_cassette('download_files_error') do
|
29
28
|
expect(-> { described_class.download_files }).
|
30
29
|
to output(/Lokalise::Error::BadRequest/).to_stdout
|
@@ -34,14 +33,16 @@ describe LokaliseRails::TaskDefinition::Importer do
|
|
34
33
|
|
35
34
|
describe '.import!' do
|
36
35
|
it 'halts when the API key is not set' do
|
37
|
-
|
36
|
+
allow(LokaliseRails).to receive(:api_token).and_return(nil)
|
38
37
|
expect(-> { described_class.import! }).to output(/API token is not set/).to_stdout
|
38
|
+
expect(LokaliseRails).to have_received(:api_token)
|
39
39
|
expect(count_translations).to eq(0)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'halts when the project_id is not set' do
|
43
|
-
|
43
|
+
allow(LokaliseRails).to receive(:project_id).and_return(nil)
|
44
44
|
expect(-> { described_class.import! }).to output(/Project ID is not set/).to_stdout
|
45
|
+
expect(LokaliseRails).to have_received(:project_id)
|
45
46
|
expect(count_translations).to eq(0)
|
46
47
|
end
|
47
48
|
end
|
@@ -15,17 +15,17 @@ describe LokaliseRails do
|
|
15
15
|
let(:fake_class) { class_double('LokaliseRails') }
|
16
16
|
|
17
17
|
it 'is possible to set project_id' do
|
18
|
-
|
18
|
+
allow(fake_class).to receive(:project_id=).with('123.abc')
|
19
19
|
fake_class.project_id = '123.abc'
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'is possible to set file_ext_regexp' do
|
23
|
-
|
23
|
+
allow(fake_class).to receive(:file_ext_regexp=).with(Regexp.new('.*'))
|
24
24
|
fake_class.file_ext_regexp = Regexp.new('.*')
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'is possible to set import_opts' do
|
28
|
-
|
28
|
+
allow(fake_class).to receive(:import_opts=).with(duck_type(:each))
|
29
29
|
fake_class.import_opts = {
|
30
30
|
format: 'json',
|
31
31
|
indentation: '8sp'
|
@@ -33,31 +33,44 @@ describe LokaliseRails do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'is possible to set export_opts' do
|
36
|
-
|
36
|
+
allow(fake_class).to receive(:export_opts=).with(duck_type(:each))
|
37
37
|
fake_class.export_opts = {
|
38
38
|
convert_placeholders: true,
|
39
39
|
detect_icu_plurals: true
|
40
40
|
}
|
41
41
|
end
|
42
42
|
|
43
|
+
it 'is possible to set branch' do
|
44
|
+
allow(fake_class).to receive(:branch=).with('custom')
|
45
|
+
fake_class.branch = 'custom'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'is possible to set timeouts' do
|
49
|
+
allow(fake_class).to receive(:timeouts=).with(duck_type(:each))
|
50
|
+
fake_class.timeouts = {
|
51
|
+
open_timeout: 100,
|
52
|
+
timeout: 500
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
43
56
|
it 'is possible to set import_safe_mode' do
|
44
|
-
|
57
|
+
allow(fake_class).to receive(:import_safe_mode=).with(true)
|
45
58
|
fake_class.import_safe_mode = true
|
46
59
|
end
|
47
60
|
|
48
61
|
it 'is possible to set api_token' do
|
49
|
-
|
62
|
+
allow(fake_class).to receive(:api_token=).with('abc')
|
50
63
|
fake_class.api_token = 'abc'
|
51
64
|
end
|
52
65
|
|
53
66
|
it 'is possible to override locales_path' do
|
54
|
-
|
67
|
+
allow(fake_class).to receive(:locales_path=).with('/demo/path')
|
55
68
|
fake_class.locales_path = '/demo/path'
|
56
69
|
end
|
57
70
|
|
58
71
|
it 'is possible to set skip_file_export' do
|
59
72
|
cond = ->(f) { f.nil? }
|
60
|
-
|
73
|
+
allow(fake_class).to receive(:skip_file_export=).with(cond)
|
61
74
|
fake_class.skip_file_export = cond
|
62
75
|
end
|
63
76
|
end
|
@@ -18,7 +18,7 @@ RSpec.describe LokaliseRails do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'import rake task is callable' do
|
21
|
-
|
21
|
+
allow(LokaliseRails::TaskDefinition::Importer).to receive(
|
22
22
|
:download_files
|
23
23
|
).and_return(
|
24
24
|
{
|
@@ -30,14 +30,14 @@ RSpec.describe LokaliseRails do
|
|
30
30
|
expect(import_executor).to output(/complete!/).to_stdout
|
31
31
|
|
32
32
|
expect(count_translations).to eq(4)
|
33
|
-
|
33
|
+
expect(LokaliseRails::TaskDefinition::Importer).to have_received(:download_files)
|
34
34
|
expect_file_exist loc_path, 'en/nested/main_en.yml'
|
35
35
|
expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
|
36
36
|
expect_file_exist loc_path, 'ru/main_ru.yml'
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'import rake task downloads ZIP archive properly' do
|
40
|
-
|
40
|
+
allow(LokaliseRails::TaskDefinition::Importer).to receive(
|
41
41
|
:download_files
|
42
42
|
).and_return(
|
43
43
|
{
|
@@ -48,8 +48,8 @@ RSpec.describe LokaliseRails do
|
|
48
48
|
|
49
49
|
expect(import_executor).to output(/complete!/).to_stdout
|
50
50
|
|
51
|
+
expect(LokaliseRails::TaskDefinition::Importer).to have_received(:download_files)
|
51
52
|
expect(count_translations).to eq(4)
|
52
|
-
|
53
53
|
expect_file_exist loc_path, 'en/nested/main_en.yml'
|
54
54
|
expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
|
55
55
|
expect_file_exist loc_path, 'ru/main_ru.yml'
|
@@ -73,7 +73,7 @@ RSpec.describe LokaliseRails do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'import proceeds when the user agrees' do
|
76
|
-
|
76
|
+
allow(LokaliseRails::TaskDefinition::Importer).to receive(
|
77
77
|
:download_files
|
78
78
|
).and_return(
|
79
79
|
{
|
@@ -81,21 +81,27 @@ RSpec.describe LokaliseRails do
|
|
81
81
|
'bundle_url' => local_trans
|
82
82
|
}
|
83
83
|
)
|
84
|
-
|
84
|
+
|
85
|
+
allow($stdin).to receive(:gets).and_return('Y')
|
85
86
|
expect(import_executor).to output(/is not empty/).to_stdout
|
86
87
|
|
87
88
|
expect(count_translations).to eq(5)
|
88
|
-
|
89
|
+
expect($stdin).to have_received(:gets)
|
90
|
+
expect(LokaliseRails::TaskDefinition::Importer).to have_received(:download_files)
|
89
91
|
expect_file_exist loc_path, 'en/nested/main_en.yml'
|
90
92
|
expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml'
|
91
93
|
expect_file_exist loc_path, 'ru/main_ru.yml'
|
92
94
|
end
|
93
95
|
|
94
96
|
it 'import halts when a user chooses not to proceed' do
|
95
|
-
|
96
|
-
|
97
|
+
allow(LokaliseRails::TaskDefinition::Importer).to receive(
|
98
|
+
:download_files
|
99
|
+
).at_most(0).times
|
100
|
+
allow($stdin).to receive(:gets).and_return('N')
|
97
101
|
expect(import_executor).to output(/is not empty/).to_stdout
|
98
102
|
|
103
|
+
expect(LokaliseRails::TaskDefinition::Importer).not_to have_received(:download_files)
|
104
|
+
expect($stdin).to have_received(:gets)
|
99
105
|
expect(count_translations).to eq(1)
|
100
106
|
end
|
101
107
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -22,11 +22,8 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
|
|
22
22
|
ENV['RAILS_ENV'] = 'test'
|
23
23
|
|
24
24
|
require_relative '../spec/dummy/config/environment'
|
25
|
-
# ActiveRecord::Migrator.migrations_paths = [File.expand_path('../spec/dummy/db/migrate', __dir__)]
|
26
25
|
ENV['RAILS_ROOT'] ||= "#{File.dirname(__FILE__)}../../../spec/dummy"
|
27
26
|
|
28
|
-
require 'rspec/rails'
|
29
|
-
|
30
27
|
RSpec.configure do |config|
|
31
28
|
config.include FileManager
|
32
29
|
config.include RakeUtils
|
data/spec/support/spec_addons.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SpecAddons
|
2
|
-
def allow_project_id
|
4
|
+
def allow_project_id(value = '189934715f57a162257d74.88352370')
|
3
5
|
allow(LokaliseRails).to receive(:project_id).
|
4
|
-
|
6
|
+
and_return(value)
|
5
7
|
end
|
6
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lokalise_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Bodrov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-lokalise-api
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.6'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rspec-rails
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '4.0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '4.0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: rubocop
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -242,8 +228,9 @@ files:
|
|
242
228
|
- spec/dummy/config/routes.rb
|
243
229
|
- spec/dummy/db/seeds.rb
|
244
230
|
- spec/lib/generators/lokalise_rails/install_generator_spec.rb
|
245
|
-
- spec/lib/lokalise_rails/
|
246
|
-
- spec/lib/lokalise_rails/
|
231
|
+
- spec/lib/lokalise_rails/task_definition/base_spec.rb
|
232
|
+
- spec/lib/lokalise_rails/task_definition/exporter_spec.rb
|
233
|
+
- spec/lib/lokalise_rails/task_definition/importer_spec.rb
|
247
234
|
- spec/lib/lokalise_rails_spec.rb
|
248
235
|
- spec/lib/tasks/export_task_spec.rb
|
249
236
|
- spec/lib/tasks/import_task_spec.rb
|
@@ -299,8 +286,9 @@ test_files:
|
|
299
286
|
- spec/dummy/config/routes.rb
|
300
287
|
- spec/dummy/db/seeds.rb
|
301
288
|
- spec/lib/generators/lokalise_rails/install_generator_spec.rb
|
302
|
-
- spec/lib/lokalise_rails/
|
303
|
-
- spec/lib/lokalise_rails/
|
289
|
+
- spec/lib/lokalise_rails/task_definition/base_spec.rb
|
290
|
+
- spec/lib/lokalise_rails/task_definition/exporter_spec.rb
|
291
|
+
- spec/lib/lokalise_rails/task_definition/importer_spec.rb
|
304
292
|
- spec/lib/lokalise_rails_spec.rb
|
305
293
|
- spec/lib/tasks/export_task_spec.rb
|
306
294
|
- spec/lib/tasks/import_task_spec.rb
|