lokalise_rails 2.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -0
  3. data/Gemfile +12 -1
  4. data/README.md +74 -57
  5. data/lib/generators/lokalise_rails/install_generator.rb +2 -0
  6. data/lib/generators/templates/lokalise_rails_config.rb +2 -4
  7. data/lib/lokalise_rails/global_config.rb +12 -0
  8. data/lib/lokalise_rails/railtie.rb +1 -0
  9. data/lib/lokalise_rails/utils.rb +23 -0
  10. data/lib/lokalise_rails/version.rb +3 -1
  11. data/lib/lokalise_rails.rb +8 -88
  12. data/lib/tasks/lokalise_rails_tasks.rake +6 -3
  13. data/lokalise_rails.gemspec +7 -18
  14. data/spec/dummy/config/lokalise_rails.rb +3 -3
  15. data/spec/lib/generators/lokalise_rails/install_generator_spec.rb +2 -2
  16. data/spec/lib/{lokalise_rails_spec.rb → lokalise_rails/global_config_spec.rb} +17 -5
  17. data/spec/lib/lokalise_rails/version_spec.rb +7 -0
  18. data/spec/lib/tasks/export_task_spec.rb +25 -18
  19. data/spec/lib/tasks/import_task_spec.rb +36 -99
  20. data/spec/lib/utils_spec.rb +16 -0
  21. data/spec/spec_helper.rb +0 -2
  22. data/spec/support/file_manager.rb +8 -11
  23. data/spec/support/spec_addons.rb +8 -3
  24. metadata +21 -178
  25. data/lib/lokalise_rails/error.rb +0 -10
  26. data/lib/lokalise_rails/task_definition/base.rb +0 -80
  27. data/lib/lokalise_rails/task_definition/exporter.rb +0 -79
  28. data/lib/lokalise_rails/task_definition/importer.rb +0 -109
  29. data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -9
  30. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -8
  31. data/spec/dummy/config/initializers/content_security_policy.rb +0 -29
  32. data/spec/dummy/config/initializers/inflections.rb +0 -17
  33. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  34. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -16
  35. data/spec/lib/lokalise_rails/task_definition/base_spec.rb +0 -81
  36. data/spec/lib/lokalise_rails/task_definition/exporter_spec.rb +0 -200
  37. data/spec/lib/lokalise_rails/task_definition/importer_spec.rb +0 -72
  38. data/spec/support/rake_utils.rb +0 -15
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe LokaliseRails::TaskDefinition::Importer do
4
- describe '.open_and_process_zip' do
5
- let(:faulty_trans) { "#{Rails.root}/public/faulty_trans.zip" }
6
-
7
- it 're-raises errors during file processing' do
8
- expect(-> { described_class.open_and_process_zip(faulty_trans) }).
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/)
15
- end
16
- end
17
-
18
- describe '.download_files' do
19
- it 'returns a proper download URL' do
20
- allow_project_id '672198945b7d72fc048021.15940510' do
21
- response = VCR.use_cassette('download_files') do
22
- described_class.download_files
23
- end
24
-
25
- expect(response['project_id']).to eq('672198945b7d72fc048021.15940510')
26
- expect(response['bundle_url']).to include('s3-eu-west-1.amazonaws.com')
27
- expect(described_class.api_client.enable_compression).to eq(true)
28
- expect(LokaliseRails.max_retries_import).to eq(5)
29
- end
30
- end
31
-
32
- it 're-raises errors during file download' do
33
- allow_project_id 'invalid'
34
- VCR.use_cassette('download_files_error') do
35
- expect(-> { described_class.download_files }).
36
- to raise_error(Lokalise::Error::BadRequest, /Invalid `project_id` parameter/)
37
- end
38
- end
39
- end
40
-
41
- describe '.import!' do
42
- let(:fake_class) { described_class }
43
-
44
- it 'handles too many requests' do
45
- allow_project_id '672198945b7d72fc048021.15940510'
46
- allow(LokaliseRails).to receive(:max_retries_import).and_return(2)
47
-
48
- fake_client = double
49
- allow(fake_client).to receive(:download_files).and_raise(Lokalise::Error::TooManyRequests)
50
- allow(fake_class).to receive(:api_client).and_return(fake_client)
51
-
52
- expect(-> { fake_class.import! }).to raise_error(Lokalise::Error::TooManyRequests, /Gave up after 2 retries/i)
53
- expect(LokaliseRails).to have_received(:max_retries_import).exactly(1).times
54
- expect(fake_class).to have_received(:api_client).exactly(3).times
55
- expect(fake_client).to have_received(:download_files).exactly(3).times
56
- end
57
-
58
- it 'halts when the API key is not set' do
59
- allow(LokaliseRails).to receive(:api_token).and_return(nil)
60
- expect(-> { described_class.import! }).to raise_error(LokaliseRails::Error, /API token is not set/i)
61
- expect(LokaliseRails).to have_received(:api_token)
62
- expect(count_translations).to eq(0)
63
- end
64
-
65
- it 'halts when the project_id is not set' do
66
- allow_project_id nil do
67
- expect(-> { described_class.import! }).to raise_error(LokaliseRails::Error, /ID is not set/i)
68
- expect(count_translations).to eq(0)
69
- end
70
- end
71
- end
72
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RakeUtils
4
- def import_executor
5
- -> { Rake::Task['lokalise_rails:import'].execute }
6
- end
7
-
8
- def export_executor
9
- -> { Rake::Task['lokalise_rails:export'].execute }
10
- end
11
-
12
- def install_invoker
13
- Rails::Generators.invoke 'lokalise_rails:install'
14
- end
15
- end