lokalise_rails 1.1.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 951a2d142a56078d2d9509fa36c13f87f7069b8f2defa9bd158a90a67aba2b9a
4
- data.tar.gz: ac2360ad608a4251c9061454c0fea986f868facb90567a5bcd94ae01d33bd8e3
3
+ metadata.gz: 6448a3718185d09a6712428f671e02121e59c967199ae6e24f27b8623f12b280
4
+ data.tar.gz: c0f2501d9c937b26088ee23a6603a842121cb6a88516ae19d09d40abe1968161
5
5
  SHA512:
6
- metadata.gz: 4f41072fa0c0e138fc3f6a838b672c50e0f3af799e151b0cbc2b66aa1792446c6cdde4a1426ed1a5243871c48cc55bc9e12439ecc7eb00be090629ad0a77bd4c
7
- data.tar.gz: ae1acd8d95ce227c8c16a362d2fb0d0bc371a986e5108043a7d9f3037bf292e1da2a48efa4c84720e7a4f1f1e66c13e757ba59ababe1ab081d77960516340803
6
+ metadata.gz: be178f379eb4abbb4d50c4f3817422c665bed0c8a75f256c083b0229a57594956ca8c42648fe98be40ed1c4183f0e00fd51fcaf153a87ed408279c1d2ac152ec
7
+ data.tar.gz: db7dd0efdb0d9a7b72116adba959a04b899e41d5ccd89181f48e2ec2e1d097ebfebb732e6592c725b831cebf89134e77e0639deb8591876267306583064efa96
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0 (29-Jun-21)
4
+
5
+ * Re-worked exception handling. Now when something goes wrong during the import or export process, this gem will re-raise all such errors (previously it just printed out some errors to the `$stdout`). If you run a Rake task, it will exit with a status code `1` and the actual error message. If you run a task programattically, you'll get an exception.
6
+ * Dropped support for Ruby 2.5
7
+ * Test against Ruby 3
8
+
9
+ ## 1.3.1 (01-Apr-21)
10
+
11
+ * A bit better exception handling
12
+ * Update dependencies
13
+
14
+ ## 1.3.0 (02-Feb-21)
15
+
16
+ * Use ruby-lokalise-api v3
17
+
18
+ ## 1.2.0 (11-Nov-20)
19
+
20
+ * New option `translations_loader`
21
+ * New option `translations_converter`
22
+ * New option `lang_iso_inferer`
23
+
3
24
  ## 1.1.0 (23-Oct-20)
4
25
 
5
26
  * New option `branch`
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # LokaliseRails
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/lokalise_rails.svg)](https://badge.fury.io/rb/lokalise_rails)
4
- [![Build Status](https://travis-ci.org/bodrovis/lokalise_rails.svg?branch=master)](https://travis-ci.org/bodrovis/lokalise_rails)
3
+ ![Gem](https://img.shields.io/gem/v/lokalise_rails)
4
+ [![Build Status](https://travis-ci.com/bodrovis/lokalise_rails.svg?branch=master)](https://travis-ci.com/github/bodrovis/lokalise_rails)
5
5
  [![Test Coverage](https://codecov.io/gh/bodrovis/lokalise_rails/graph/badge.svg)](https://codecov.io/gh/bodrovis/lokalise_rails)
6
+ ![Downloads total](https://img.shields.io/gem/dt/lokalise_rails)
6
7
 
7
8
  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
9
 
@@ -92,7 +93,6 @@ Options are specified in the `config/lokalise_rails.rb` file.
92
93
  * `api_token` (`string`, required) - Lokalise API token with read/write permissions.
93
94
  * `project_id` (`string`, required) - Lokalise project ID. You must have import/export permissions in the specified project.
94
95
  * `locales_path` (`string`) - path to the directory with your translation files. Defaults to `"#{Rails.root}/config/locales"`.
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
96
  * `branch` (`string`) - Lokalise project branch to use. Defaults to `"master"`.
97
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.
98
98
 
@@ -134,6 +134,15 @@ en_US:
134
134
  c.skip_file_export = ->(file) { f.split[1].to_s.include?('fr') }
135
135
  ```
136
136
 
137
+ ### Settings to work with formats other than YAML
138
+
139
+ If your translation files are not in YAML format, you will need to adjust the following options:
140
+
141
+ * `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).
142
+ * `translations_loader` (`lambda` or `proc`) - loads translations data and makes sure they are valid before saving them to a translation file. Defaults to `->(raw_data) { YAML.safe_load raw_data }`. In the simplest case you may just return the data back, for example `-> (raw_data) { raw_data }`.
143
+ * `translations_converter` (`lambda` or `proc`) - converts translations data to a proper format before saving them to a translation file. Defaults to `->(raw_data) { raw_data.to_yaml }`. In the simplest case you may just return the data back, for example `-> (raw_data) { raw_data }`.
144
+ * `lang_iso_inferer` (`lambda` or `proc`) - infers language ISO code based on the translation file data before uploading it to Lokalise. Defaults to `->(data) { YAML.safe_load(data)&.keys&.first }`.
145
+
137
146
  ## Running tests
138
147
 
139
148
  1. Copypaste `.env.example` file as `.env`. Put your Lokalise API token and project ID inside. The `.env` file is excluded from version control so your data is safe. All in all, we use pre-recorded VCR cassettes, so the actual API requests won’t be sent. However, providing at least some values is required.
@@ -35,6 +35,16 @@ LokaliseRails.config do |c|
35
35
  # Provide additional file exclusion criteria for exports (by default, any file with the proper extension will be exported)
36
36
  # c.skip_file_export = ->(file) { file.split[1].to_s.include?('fr') }
37
37
 
38
- # Regular expression to use when choosing the files to extract from the downloaded archive and upload to Lokalise
39
- # c.file_ext_regexp = /\.ya?ml\z/i
38
+ # Set the options below if you would like to work with format other than YAML
39
+ ## Regular expression to use when choosing the files to extract from the downloaded archive and upload to Lokalise
40
+ ## c.file_ext_regexp = /\.ya?ml\z/i
41
+
42
+ ## Load translations data and make sure they are valid:
43
+ ## c.translations_loader = ->(raw_data) { YAML.safe_load raw_data }
44
+
45
+ ## Convert translations data to a proper format:
46
+ ## c.translations_converter = ->(raw_data) { raw_data.to_yaml }
47
+
48
+ ## Infer language ISO code for the translation file:
49
+ ## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first }
40
50
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'lokalise_rails/error'
3
4
  require 'lokalise_rails/task_definition/base'
4
5
  require 'lokalise_rails/task_definition/importer'
5
6
  require 'lokalise_rails/task_definition/exporter'
@@ -8,7 +9,8 @@ module LokaliseRails
8
9
  class << self
9
10
  attr_accessor :api_token, :project_id
10
11
  attr_writer :import_opts, :import_safe_mode, :export_opts, :locales_path,
11
- :file_ext_regexp, :skip_file_export, :branch, :timeouts
12
+ :file_ext_regexp, :skip_file_export, :branch, :timeouts,
13
+ :translations_loader, :translations_converter, :lang_iso_inferer
12
14
 
13
15
  # Main interface to provide configuration options for rake tasks
14
16
  def config
@@ -61,6 +63,20 @@ module LokaliseRails
61
63
  def skip_file_export
62
64
  @skip_file_export || ->(_) { false }
63
65
  end
66
+
67
+ def translations_loader
68
+ @translations_loader || ->(raw_data) { YAML.safe_load raw_data }
69
+ end
70
+
71
+ # Converts translations data to the proper format
72
+ def translations_converter
73
+ @translations_converter || ->(raw_data) { raw_data.to_yaml }
74
+ end
75
+
76
+ # Infers lang ISO for the given translation file
77
+ def lang_iso_inferer
78
+ @lang_iso_inferer || ->(data) { YAML.safe_load(data)&.keys&.first }
79
+ end
64
80
  end
65
81
  end
66
82
 
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LokaliseRails
4
+ class Error < StandardError
5
+ # Initializes a new Error object
6
+ def initialize(message = '')
7
+ super(message)
8
+ end
9
+ end
10
+ end
@@ -25,11 +25,12 @@ module LokaliseRails
25
25
  # Checks task options
26
26
  #
27
27
  # @return Array
28
- def opt_errors
28
+ def check_options_errors!
29
29
  errors = []
30
- errors << 'Project ID is not set! Aborting...' if LokaliseRails.project_id.nil? || LokaliseRails.project_id.empty?
31
- errors << 'Lokalise API token is not set! Aborting...' if LokaliseRails.api_token.nil? || LokaliseRails.api_token.empty?
32
- errors
30
+ errors << 'Project ID is not set!' if LokaliseRails.project_id.nil? || LokaliseRails.project_id.empty?
31
+ errors << 'Lokalise API token is not set!' if LokaliseRails.api_token.nil? || LokaliseRails.api_token.empty?
32
+
33
+ raise(LokaliseRails::Error, errors.join(' ')) if errors.any?
33
34
  end
34
35
 
35
36
  private
@@ -10,12 +10,7 @@ module LokaliseRails
10
10
  #
11
11
  # @return [Array]
12
12
  def export!
13
- errors = opt_errors
14
-
15
- if errors.any?
16
- errors.each { |e| $stdout.puts e }
17
- return errors
18
- end
13
+ check_options_errors!
19
14
 
20
15
  queued_processes = []
21
16
  each_file do |full_path, relative_path|
@@ -23,7 +18,7 @@ module LokaliseRails
23
18
  project_id_with_branch, opts(full_path, relative_path)
24
19
  )
25
20
  rescue StandardError => e
26
- $stdout.puts "Error while trying to upload #{full_path}: #{e.inspect}"
21
+ raise e.class, "Error while trying to upload #{full_path}: #{e.message}"
27
22
  end
28
23
 
29
24
  $stdout.print 'Task complete!'
@@ -55,12 +50,10 @@ module LokaliseRails
55
50
  def opts(full_p, relative_p)
56
51
  content = File.read full_p
57
52
 
58
- lang_iso = YAML.safe_load(content)&.keys&.first
59
-
60
53
  initial_opts = {
61
54
  data: Base64.strict_encode64(content.strip),
62
55
  filename: relative_p,
63
- lang_iso: lang_iso
56
+ lang_iso: LokaliseRails.lang_iso_inferer.call(content)
64
57
  }
65
58
 
66
59
  initial_opts.merge LokaliseRails.export_opts
@@ -13,12 +13,7 @@ module LokaliseRails
13
13
  #
14
14
  # @return [Boolean]
15
15
  def import!
16
- errors = opt_errors
17
-
18
- if errors.any?
19
- errors.each { |e| $stdout.puts e }
20
- return false
21
- end
16
+ check_options_errors!
22
17
 
23
18
  unless proceed_when_safe_mode?
24
19
  $stdout.print 'Task cancelled!'
@@ -39,16 +34,18 @@ module LokaliseRails
39
34
 
40
35
  api_client.download_files project_id_with_branch, opts
41
36
  rescue StandardError => e
42
- $stdout.puts "There was an error when trying to download files: #{e.inspect}"
37
+ raise e.class, "There was an error when trying to download files: #{e.message}"
43
38
  end
44
39
 
45
40
  # Opens ZIP archive (local or remote) with translations and processes its entries
46
41
  #
47
42
  # @param path [String]
48
43
  def open_and_process_zip(path)
49
- Zip::File.open_buffer(URI.open(path)) do |zip|
44
+ Zip::File.open_buffer(open_file_or_remote(path)) do |zip|
50
45
  fetch_zip_entries(zip) { |entry| process!(entry) }
51
46
  end
47
+ rescue StandardError => e
48
+ raise e.class, "There was an error when trying to process the downloaded files: #{e.message}"
52
49
  end
53
50
 
54
51
  # Iterates over ZIP entries. Each entry may be a file or folder.
@@ -64,16 +61,16 @@ module LokaliseRails
64
61
 
65
62
  # Processes ZIP entry by reading its contents and creating the corresponding translation file
66
63
  def process!(zip_entry)
67
- data = YAML.safe_load zip_entry.get_input_stream.read
64
+ data = data_from zip_entry
68
65
  subdir, filename = subdir_and_filename_for zip_entry.name
69
66
  full_path = "#{LokaliseRails.locales_path}/#{subdir}"
70
67
  FileUtils.mkdir_p full_path
71
68
 
72
69
  File.open(File.join(full_path, filename), 'w+:UTF-8') do |f|
73
- f.write data.to_yaml
70
+ f.write LokaliseRails.translations_converter.call(data)
74
71
  end
75
72
  rescue StandardError => e
76
- $stdout.puts "Error when trying to process #{zip_entry&.name}: #{e.inspect}"
73
+ raise e.class, "Error when trying to process #{zip_entry&.name}: #{e.message}"
77
74
  end
78
75
 
79
76
  # Checks whether the user wishes to proceed when safe mode is enabled and the target directory is not empty
@@ -87,6 +84,24 @@ module LokaliseRails
87
84
  answer = $stdin.gets
88
85
  answer.to_s.strip == 'Y'
89
86
  end
87
+
88
+ # Opens a local file or a remote URL using the provided patf
89
+ #
90
+ # @return [String]
91
+ def open_file_or_remote(path)
92
+ parsed_path = URI.parse(path)
93
+ if parsed_path&.scheme&.include?('http')
94
+ parsed_path.open
95
+ else
96
+ File.open path
97
+ end
98
+ end
99
+
100
+ private
101
+
102
+ def data_from(zip_entry)
103
+ LokaliseRails.translations_loader.call zip_entry.get_input_stream.read
104
+ end
90
105
  end
91
106
  end
92
107
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LokaliseRails
4
- VERSION = '1.1.0'
4
+ VERSION = '1.4.0'
5
5
  end
@@ -6,9 +6,13 @@ require "#{Rails.root}/config/lokalise_rails"
6
6
  namespace :lokalise_rails do
7
7
  task :import do
8
8
  LokaliseRails::TaskDefinition::Importer.import!
9
+ rescue StandardError => e
10
+ abort e.inspect
9
11
  end
10
12
 
11
13
  task :export do
12
14
  LokaliseRails::TaskDefinition::Exporter.export!
15
+ rescue StandardError => e
16
+ abort e.inspect
13
17
  end
14
18
  end
@@ -23,21 +23,21 @@ Gem::Specification.new do |spec|
23
23
  spec.extra_rdoc_files = ['README.md']
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.add_dependency 'ruby-lokalise-api', '~> 3.1'
26
+ spec.add_dependency 'ruby-lokalise-api', '~> 4.0'
27
27
  spec.add_dependency 'rubyzip', '~> 2.3'
28
28
 
29
- spec.add_development_dependency 'codecov', '~> 0.1'
29
+ spec.add_development_dependency 'codecov', '~> 0.2'
30
30
  spec.add_development_dependency 'dotenv', '~> 2.5'
31
31
  if ENV['TEST_RAILS_VERSION'].nil?
32
- spec.add_development_dependency 'rails', '~> 6.0.3'
32
+ spec.add_development_dependency 'rails', '~> 6.1.0'
33
33
  else
34
34
  spec.add_development_dependency 'rails', ENV['TEST_RAILS_VERSION'].to_s
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 'rubocop', '~> 0.60'
38
+ spec.add_development_dependency 'rubocop', '~> 1.0'
39
39
  spec.add_development_dependency 'rubocop-performance', '~> 1.5'
40
- spec.add_development_dependency 'rubocop-rspec', '~> 1.37'
40
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.4.0'
41
41
  spec.add_development_dependency 'simplecov', '~> 0.16'
42
42
  spec.add_development_dependency 'vcr', '~> 6.0'
43
43
  end
@@ -17,9 +17,7 @@ Rails.application.configure do
17
17
 
18
18
  # Configure public file server for tests with Cache-Control for performance.
19
19
  config.public_file_server.enabled = true
20
- config.public_file_server.headers = {
21
- 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
22
- }
20
+ config.public_file_server.headers = {'Cache-Control' => 'public, max-age=3600'}
23
21
 
24
22
  # Show full error reports and disable caching.
25
23
  config.consider_all_requests_local = true
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'lokalise_rails'
4
2
  LokaliseRails.config do |c|
5
3
  c.api_token = ENV['LOKALISE_API_TOKEN']
@@ -34,23 +34,19 @@ describe LokaliseRails::TaskDefinition::Base do
34
34
  end
35
35
  end
36
36
 
37
- describe '.opt_errors' do
38
- it 'returns an error when the API key is not set' do
37
+ describe '.check_options_errors!' do
38
+ it 'raises an error when the API key is not set' do
39
39
  allow(LokaliseRails).to receive(:api_token).and_return(nil)
40
- errors = described_class.opt_errors
40
+
41
+ expect(-> { described_class.check_options_errors! }).to raise_error(LokaliseRails::Error, /API token is not set/i)
41
42
 
42
43
  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
44
  end
46
45
 
47
46
  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')
47
+ allow_project_id nil do
48
+ expect(-> { described_class.check_options_errors! }).to raise_error(LokaliseRails::Error, /ID is not set/i)
49
+ end
54
50
  end
55
51
  end
56
52
 
@@ -44,15 +44,14 @@ describe LokaliseRails::TaskDefinition::Exporter do
44
44
  it 'halts when the API key is not set' do
45
45
  allow(LokaliseRails).to receive(:api_token).and_return(nil)
46
46
 
47
- expect(-> { described_class.export! }).to output(/API token is not set/).to_stdout
47
+ expect(-> { described_class.export! }).to raise_error(LokaliseRails::Error, /API token is not set/i)
48
48
  expect(LokaliseRails).to have_received(:api_token)
49
49
  end
50
50
 
51
51
  it 'halts when the project_id is not set' do
52
- allow(LokaliseRails).to receive(:project_id).and_return(nil)
53
-
54
- expect(-> { described_class.export! }).to output(/Project ID is not set/).to_stdout
55
- expect(LokaliseRails).to have_received(:project_id)
52
+ allow_project_id nil do
53
+ expect(-> { described_class.export! }).to raise_error(LokaliseRails::Error, /ID is not set/i)
54
+ end
56
55
  end
57
56
  end
58
57
 
@@ -108,17 +107,12 @@ describe LokaliseRails::TaskDefinition::Exporter do
108
107
  end
109
108
 
110
109
  describe '.export!' do
111
- it 'rescues from export errors' do
110
+ it 're-raises export errors' do
112
111
  allow_project_id
113
112
 
114
- processes = VCR.use_cassette('upload_files_error') do
115
- described_class.export!
113
+ VCR.use_cassette('upload_files_error') do
114
+ expect { described_class.export! }.to raise_error(Lokalise::Error::BadRequest, /Unknown `lang_iso`/)
116
115
  end
117
-
118
- expect(processes.length).to eq(1)
119
- process = processes.first
120
- expect(process.project_id).to eq(LokaliseRails.project_id)
121
- expect(process.status).to eq('queued')
122
116
  end
123
117
  end
124
118
 
@@ -4,29 +4,34 @@ describe LokaliseRails::TaskDefinition::Importer do
4
4
  describe '.open_and_process_zip' do
5
5
  let(:faulty_trans) { "#{Rails.root}/public/faulty_trans.zip" }
6
6
 
7
- it 'rescues from errors during file processing' do
7
+ it 're-raises errors during file processing' do
8
8
  expect(-> { described_class.open_and_process_zip(faulty_trans) }).
9
- to output(/Psych::DisallowedClass/).to_stdout
9
+ to raise_error(Psych::DisallowedClass, /Error when trying to process fail\.yml/)
10
+ end
11
+
12
+ it 're-raises errors during file opening' do
13
+ expect(-> { described_class.open_and_process_zip('http://fake.url/wrong/path.zip') }).
14
+ to raise_error(SocketError, /Failed to open TCP connection/)
10
15
  end
11
16
  end
12
17
 
13
18
  describe '.download_files' do
14
19
  it 'returns a proper download URL' do
15
- allow(LokaliseRails).to receive(:project_id).and_return('189934715f57a162257d74.88352370')
16
- response = VCR.use_cassette('download_files') do
17
- described_class.download_files
18
- end
20
+ allow_project_id '189934715f57a162257d74.88352370' do
21
+ response = VCR.use_cassette('download_files') do
22
+ described_class.download_files
23
+ end
19
24
 
20
- expect(LokaliseRails).to have_received(:project_id)
21
- expect(response['project_id']).to eq('189934715f57a162257d74.88352370')
22
- expect(response['bundle_url']).to include('s3-eu-west-1.amazonaws.com')
25
+ expect(response['project_id']).to eq('189934715f57a162257d74.88352370')
26
+ expect(response['bundle_url']).to include('s3-eu-west-1.amazonaws.com')
27
+ end
23
28
  end
24
29
 
25
- it 'rescues from errors during file download' do
30
+ it 're-raises errors during file download' do
26
31
  allow_project_id 'invalid'
27
32
  VCR.use_cassette('download_files_error') do
28
33
  expect(-> { described_class.download_files }).
29
- to output(/Lokalise::Error::BadRequest/).to_stdout
34
+ to raise_error(Lokalise::Error::BadRequest, /Invalid `project_id` parameter/)
30
35
  end
31
36
  end
32
37
  end
@@ -34,16 +39,16 @@ describe LokaliseRails::TaskDefinition::Importer do
34
39
  describe '.import!' do
35
40
  it 'halts when the API key is not set' do
36
41
  allow(LokaliseRails).to receive(:api_token).and_return(nil)
37
- expect(-> { described_class.import! }).to output(/API token is not set/).to_stdout
42
+ expect(-> { described_class.import! }).to raise_error(LokaliseRails::Error, /API token is not set/i)
38
43
  expect(LokaliseRails).to have_received(:api_token)
39
44
  expect(count_translations).to eq(0)
40
45
  end
41
46
 
42
47
  it 'halts when the project_id is not set' do
43
- allow(LokaliseRails).to receive(:project_id).and_return(nil)
44
- expect(-> { described_class.import! }).to output(/Project ID is not set/).to_stdout
45
- expect(LokaliseRails).to have_received(:project_id)
46
- expect(count_translations).to eq(0)
48
+ allow_project_id nil do
49
+ expect(-> { described_class.import! }).to raise_error(LokaliseRails::Error, /ID is not set/i)
50
+ expect(count_translations).to eq(0)
51
+ end
47
52
  end
48
53
  end
49
54
  end
@@ -73,5 +73,23 @@ describe LokaliseRails do
73
73
  allow(fake_class).to receive(:skip_file_export=).with(cond)
74
74
  fake_class.skip_file_export = cond
75
75
  end
76
+
77
+ it 'is possible to set translations_loader' do
78
+ runner = ->(f) { f.to_json }
79
+ allow(fake_class).to receive(:translations_loader=).with(runner)
80
+ fake_class.translations_loader = runner
81
+ end
82
+
83
+ it 'is possible to set translations_converter' do
84
+ runner = ->(f) { f.to_json }
85
+ allow(fake_class).to receive(:translations_converter=).with(runner)
86
+ fake_class.translations_converter = runner
87
+ end
88
+
89
+ it 'is possible to set lang_iso_inferer' do
90
+ runner = ->(f) { f.to_json }
91
+ allow(fake_class).to receive(:lang_iso_inferer=).with(runner)
92
+ fake_class.lang_iso_inferer = runner
93
+ end
76
94
  end
77
95
  end
@@ -1,7 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe LokaliseRails do
4
+ it 'halts when the API key is not set' do
5
+ allow(described_class).to receive(:api_token).and_return(nil)
6
+
7
+ expect(export_executor).to raise_error(SystemExit, /API token is not set/i)
8
+ expect(described_class).to have_received(:api_token)
9
+ end
10
+
11
+ it 'halts when the project ID is not set' do
12
+ allow_project_id nil do
13
+ expect(export_executor).to raise_error(SystemExit, /ID is not set/i)
14
+ end
15
+ end
16
+
4
17
  it 'runs export rake task properly' do
5
18
  expect(export_executor).to output(/complete!/).to_stdout
6
19
  end
20
+
21
+ context 'with two translation files' do
22
+ let(:filename_ru) { 'ru.yml' }
23
+ let(:path_ru) { "#{Rails.root}/config/locales/#{filename_ru}" }
24
+ let(:relative_name_ru) { filename_ru }
25
+
26
+ before :all do
27
+ add_translation_files! with_ru: true
28
+ end
29
+
30
+ after :all do
31
+ rm_translation_files
32
+ end
33
+
34
+ describe '.export!' do
35
+ it 're-raises export errors' do
36
+ allow_project_id
37
+
38
+ VCR.use_cassette('upload_files_error') do
39
+ expect(export_executor).to raise_error(SystemExit, /Unknown `lang_iso`/)
40
+ end
41
+ end
42
+ end
43
+ end
7
44
  end
@@ -7,6 +7,19 @@ RSpec.describe LokaliseRails do
7
7
  let(:local_trans) { "#{Rails.root}/public/trans.zip" }
8
8
  let(:remote_trans) { 'https://github.com/bodrovis/lokalise_rails/blob/master/spec/dummy/public/trans.zip?raw=true' }
9
9
 
10
+ it 'halts when the API key is not set' do
11
+ allow(described_class).to receive(:api_token).and_return(nil)
12
+
13
+ expect(import_executor).to raise_error(SystemExit, /API token is not set/i)
14
+ expect(described_class).to have_received(:api_token)
15
+ end
16
+
17
+ it 'halts when the project ID is not set' do
18
+ allow_project_id nil do
19
+ expect(import_executor).to raise_error(SystemExit, /ID is not set/i)
20
+ end
21
+ end
22
+
10
23
  context 'when directory is empty' do
11
24
  before do
12
25
  mkdir_locales
data/spec/spec_helper.rb CHANGED
@@ -20,7 +20,6 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
20
20
 
21
21
  # Configure Rails Environment
22
22
  ENV['RAILS_ENV'] = 'test'
23
-
24
23
  require_relative '../spec/dummy/config/environment'
25
24
  ENV['RAILS_ROOT'] ||= "#{File.dirname(__FILE__)}../../../spec/dummy"
26
25
 
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SpecAddons
4
- def allow_project_id(value = '189934715f57a162257d74.88352370')
5
- allow(LokaliseRails).to receive(:project_id).
6
- and_return(value)
4
+ def allow_project_id(value = ENV['LOKALISE_PROJECT_ID'])
5
+ allow(LokaliseRails).to receive(:project_id).and_return(value)
6
+ return unless block_given?
7
+
8
+ yield
9
+ expect(LokaliseRails).to have_received(:project_id)
7
10
  end
8
11
  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.1.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Bodrov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-23 00:00:00.000000000 Z
11
+ date: 2021-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-lokalise-api
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubyzip
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.1'
47
+ version: '0.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.1'
54
+ version: '0.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: dotenv
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 6.0.3
75
+ version: 6.1.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 6.0.3
82
+ version: 6.1.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.60'
117
+ version: '1.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.60'
124
+ version: '1.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop-performance
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '1.37'
145
+ version: 2.4.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '1.37'
152
+ version: 2.4.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: simplecov
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -198,6 +198,7 @@ files:
198
198
  - lib/generators/lokalise_rails/install_generator.rb
199
199
  - lib/generators/templates/lokalise_rails_config.rb
200
200
  - lib/lokalise_rails.rb
201
+ - lib/lokalise_rails/error.rb
201
202
  - lib/lokalise_rails/railtie.rb
202
203
  - lib/lokalise_rails/task_definition/base.rb
203
204
  - lib/lokalise_rails/task_definition/exporter.rb
@@ -243,7 +244,7 @@ homepage: https://github.com/bodrovis/lokalise_rails
243
244
  licenses:
244
245
  - MIT
245
246
  metadata: {}
246
- post_install_message:
247
+ post_install_message:
247
248
  rdoc_options: []
248
249
  require_paths:
249
250
  - lib
@@ -258,8 +259,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
259
  - !ruby/object:Gem::Version
259
260
  version: '0'
260
261
  requirements: []
261
- rubygems_version: 3.1.4
262
- signing_key:
262
+ rubygems_version: 3.2.24
263
+ signing_key:
263
264
  specification_version: 4
264
265
  summary: Lokalise integration for Ruby on Rails
265
266
  test_files: