releaf-i18n_database 2.0.0 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26da56d1b3cb25df3efd5f142096f56eb3a0254b53c406a87d9093964524fa61
4
- data.tar.gz: 86e216014dce28f62e0c48cf9bbcb70a82f2bd5bb71291678b2f745ae2fec9ef
3
+ metadata.gz: afc6d90826c0b3f735b41f966a7b8cc75534a2aaf48767d58e206827af9d518c
4
+ data.tar.gz: 6a77acd32a7f86f1e044816529b3a57ba284b8ffff18bf7af13358d8e4ff37a8
5
5
  SHA512:
6
- metadata.gz: 748958207fd580b1cc080ef73eb313114a4f0a9bdf1aa0a4e5e97191bac7f030998e2fb6f8fcefbf802e1a114102169e5d3ccec4965152f7cb12815781fb004e
7
- data.tar.gz: f926dc8be53963f55a08346e7a0526cdd85689a6c1f5a5a9f7fee61ccb83084c576b6c9d957c37fc10b35db7b1ee9f01d885dbc63944c779ecddd3eabc0d07bc
6
+ metadata.gz: c0c6ea46f74fe2de5bcf734a115af278fc0c7f4e52af3d640150a1801e6786a959ab71e9983d9b4d1ff189a4e900f3fc5c5c7daeb74a256b8ebd044fa055ef34
7
+ data.tar.gz: 4352e52cd0d81b365c6fdfedb2cbb7c3d8059a2ed9bf7932805f2025396e3a9407d5953f1fc46335ce181529bec8a7bf76017e2ff0c930889bd379f32a72d34f
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: releaf-i18n_database
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - CubeSystems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-29 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: releaf-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: 2.0.1
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: 2.0.0
26
+ version: 2.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails-i18n
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,26 +94,6 @@ files:
94
94
  - lib/releaf/i18n_database/engine.rb
95
95
  - lib/releaf/i18n_database/humanize_missing_translations.rb
96
96
  - misc/translations.xlsx
97
- - spec/builders/translations/builder_common_spec.rb
98
- - spec/builders/translations/edit_builder_spec.rb
99
- - spec/builders/translations/index_builder_spec.rb
100
- - spec/builders/translations/table_builder_spec.rb
101
- - spec/controllers/i18n_backend/translations_controller_spec.rb
102
- - spec/features/translations_spec.rb
103
- - spec/fixtures/all_translations_exported.xlsx
104
- - spec/fixtures/invalid.xls
105
- - spec/fixtures/invalid.xlsx
106
- - spec/fixtures/time.formats.xlsx
107
- - spec/fixtures/translations_import.xlsx
108
- - spec/fixtures/unsupported_import_file.png
109
- - spec/lib/releaf/i18n_database/backend_spec.rb
110
- - spec/lib/releaf/i18n_database/configuration_spec.rb
111
- - spec/lib/releaf/i18n_database/humanize_missing_translations_spec.rb
112
- - spec/lib/releaf/i18n_database/parse_spreadsheet_translations_spec.rb
113
- - spec/lib/releaf/i18n_database/translations_store_spec.rb
114
- - spec/lib/releaf/i18n_database/translations_utilities_spec.rb
115
- - spec/models/i18n_database/i18n_entry_spec.rb
116
- - spec/models/i18n_database/i18n_entry_translation_spec.rb
117
97
  homepage: https://github.com/cubesystems/releaf
118
98
  licenses:
119
99
  - MIT
@@ -137,24 +117,4 @@ rubygems_version: 3.0.8
137
117
  signing_key:
138
118
  specification_version: 4
139
119
  summary: i18n database gem for releaf
140
- test_files:
141
- - spec/builders/translations/table_builder_spec.rb
142
- - spec/builders/translations/index_builder_spec.rb
143
- - spec/builders/translations/builder_common_spec.rb
144
- - spec/builders/translations/edit_builder_spec.rb
145
- - spec/features/translations_spec.rb
146
- - spec/models/i18n_database/i18n_entry_spec.rb
147
- - spec/models/i18n_database/i18n_entry_translation_spec.rb
148
- - spec/lib/releaf/i18n_database/translations_utilities_spec.rb
149
- - spec/lib/releaf/i18n_database/humanize_missing_translations_spec.rb
150
- - spec/lib/releaf/i18n_database/backend_spec.rb
151
- - spec/lib/releaf/i18n_database/configuration_spec.rb
152
- - spec/lib/releaf/i18n_database/translations_store_spec.rb
153
- - spec/lib/releaf/i18n_database/parse_spreadsheet_translations_spec.rb
154
- - spec/fixtures/all_translations_exported.xlsx
155
- - spec/fixtures/unsupported_import_file.png
156
- - spec/fixtures/time.formats.xlsx
157
- - spec/fixtures/translations_import.xlsx
158
- - spec/fixtures/invalid.xlsx
159
- - spec/fixtures/invalid.xls
160
- - spec/controllers/i18n_backend/translations_controller_spec.rb
120
+ test_files: []
@@ -1,39 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::I18nDatabase::Translations::BuildersCommon, type: :class do
4
- class I18nBuildersCommonInheriter < Releaf::Builders::IndexBuilder
5
- include Releaf::I18nDatabase::Translations::BuildersCommon
6
- end
7
- class TableBuilderTestHelper < ActionView::Base; end
8
- let(:template){ TableBuilderTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
9
- let(:subject){ I18nBuildersCommonInheriter.new(template) }
10
-
11
- describe "#action_url" do
12
- before do
13
- request = ActionDispatch::Request.new("X")
14
- allow(request).to receive(:query_parameters).and_return(a: "b", c: "d")
15
- allow(subject).to receive(:request).and_return(request)
16
- end
17
-
18
- it "returns url for given action with current query params" do
19
- allow(subject).to receive(:url_for).with(a: "b", c: "d", action: :edit).and_return("url")
20
- expect(subject.action_url(:edit)).to eq("url")
21
- end
22
-
23
- context "when extra params given" do
24
- it "merges given params to url" do
25
- allow(subject).to receive(:url_for).with(a: "b", c: "z", action: :edit, format: "xx").and_return("url")
26
- expect(subject.action_url(:edit, format: "xx", c: "z")).to eq("url")
27
- end
28
- end
29
- end
30
-
31
- describe "#export_button" do
32
- it "returns export button" do
33
- allow(subject).to receive(:t).with("Export").and_return("exp")
34
- allow(subject).to receive(:action_url).with(:export, format: :xlsx).and_return("_exp_url_")
35
- allow(subject).to receive(:button).with("exp", "download", class: "secondary", href: "_exp_url_").and_return("btn")
36
- expect(subject.export_button).to eq('btn')
37
- end
38
- end
39
- end
@@ -1,93 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::I18nDatabase::Translations::EditBuilder, type: :class do
4
- class TableBuilderTestHelper < ActionView::Base
5
- def protect_against_forgery?; end
6
- end
7
- let(:template){ TableBuilderTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
8
- let(:resource_class){ Releaf::I18nDatabase::Translation }
9
- let(:subject){ described_class.new(template) }
10
-
11
- describe "#section" do
12
- it "returns section blocks wrapped within edit form" do
13
- allow(subject).to receive(:action_url).with(:update).and_return("update_url")
14
- allow(subject).to receive(:section_blocks).and_return(["a", "b"])
15
- result = '<section><form action="update_url" accept-charset="UTF-8" method="post">ab</form></section>'
16
- expect(subject.section).to eq(result)
17
- end
18
- end
19
-
20
- describe "#section_body" do
21
- it "returns section body with form fields partial" do
22
- allow(subject).to receive(:render).with(partial: "form_fields", locals: {builder: subject}).and_return("xxx")
23
- expect(subject.section_body).to eq('<div class="body">xxx</div>')
24
- end
25
- end
26
-
27
- describe "#import?" do
28
- it "returns template `import` value" do
29
- allow(subject).to receive(:template_variable).with("import").and_return("x")
30
- expect(subject.import?).to eq("x")
31
- end
32
- end
33
-
34
- describe "#save_button" do
35
- it "returns localized value for given resource and column(locale)" do
36
- allow(subject).to receive(:save_button_text).and_return("sv_txt")
37
- allow(subject).to receive(:button).with("sv_txt", "check", class: "primary", data: { type: 'ok' }, type: "submit").and_return("save_btn")
38
- expect(subject.save_button).to eq("save_btn")
39
- end
40
- end
41
-
42
- describe "#save_button_text" do
43
- context "when within import view" do
44
- it "returns translated `Import` text" do
45
- allow(subject).to receive(:t).with("Import").and_return("_import_")
46
- allow(subject).to receive(:import?).and_return(true)
47
- expect(subject.save_button_text).to eq("_import_")
48
- end
49
- end
50
-
51
- context "when not within import view" do
52
- it "returns translated `Save` text" do
53
- allow(subject).to receive(:t).with("Save").and_return("_save_")
54
- allow(subject).to receive(:import?).and_return(false)
55
- expect(subject.save_button_text).to eq("_save_")
56
- end
57
- end
58
- end
59
-
60
- describe "#footer_secondary_tools" do
61
- before do
62
- allow(subject).to receive(:back_to_index_button).and_return("indx_btn")
63
- allow(subject).to receive(:export_button).and_return("xprt_btn")
64
- end
65
-
66
- it "returns array with back and export links" do
67
- allow(subject).to receive(:import?).and_return(false)
68
- expect(subject.footer_secondary_tools).to eq(["indx_btn", "xprt_btn"])
69
- end
70
-
71
- context "when within import view" do
72
- it "does not incliude export button" do
73
- allow(subject).to receive(:import?).and_return(true)
74
- expect(subject.footer_secondary_tools).to eq(["indx_btn"])
75
- end
76
- end
77
- end
78
-
79
- describe "#back_to_index_button" do
80
- it "returns localized value for given resource and column(locale)" do
81
- allow(subject).to receive(:t).with("Back to list").and_return("back")
82
- allow(subject).to receive(:action_url).with(:index).and_return("index_path")
83
- allow(subject).to receive(:button).with("back", "caret-left", class: "secondary", href: "index_path").and_return("index_btn")
84
- expect(subject.back_to_index_button).to eq("index_btn")
85
- end
86
- end
87
-
88
- describe "#section_header" do
89
- it "returns nil" do
90
- expect(subject.section_header).to be nil
91
- end
92
- end
93
- end
@@ -1,96 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::I18nDatabase::Translations::IndexBuilder, type: :class do
4
- class IndexBuilderTestHelper < ActionView::Base
5
- include Releaf::ApplicationHelper
6
- delegate :resource_class, :table_options, to: :controller
7
-
8
- def protect_against_forgery?; end
9
-
10
- def controller
11
- @controller ||= begin
12
- c = Releaf::I18nDatabase::TranslationsController.new
13
- c.setup
14
- c
15
- end
16
- end
17
- end
18
- let(:template){ IndexBuilderTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
19
- let(:resource_class){ Releaf::I18nDatabase::Translation }
20
- let(:subject){ described_class.new(template) }
21
-
22
- describe "#text_search_content" do
23
- it "adds blank translation checbox to text search" do
24
- allow(subject).to receive(:t).and_return("search")
25
- allow(subject).to receive(:params).and_return(search: "xx")
26
- allow(subject).to receive(:button).and_return("btn")
27
- allow(subject).to receive(:search_only_blank_ui).and_return("_blank_ui_")
28
- expect(subject.text_search_content).to start_with("_blank_ui_")
29
- end
30
- end
31
-
32
- describe "#search_only_blank_ui" do
33
- before do
34
- allow(subject).to receive(:t).with("Only blank").and_return("trnls")
35
- end
36
-
37
- it "returns only blank translation search ui" do
38
- allow(subject).to receive(:params).and_return(search: "xx")
39
- expect(subject.search_only_blank_ui).to match_html(%Q[
40
- <div class="search-field" data-name="only-blank">
41
- <input type="checkbox" name="only_blank" id="only_blank" value="true" />
42
- <label for="only_blank">trnls</label>
43
- </div>
44
- ])
45
- end
46
-
47
- it "reflects `only_blank` params to checkbox state" do
48
- allow(subject).to receive(:params).and_return(only_blank: "1", search: true)
49
- expect(subject.search_only_blank_ui).to match_html(%Q[
50
- <div class="search-field" data-name="only-blank">
51
- <input type="checkbox" name="only_blank" id="only_blank" value="true" checked="checked" />
52
- <label for=\"only_blank\">trnls</label>
53
- </div>
54
- ])
55
- end
56
- end
57
-
58
- describe "#footer_primary_tools" do
59
- it "returns array with edit button" do
60
- allow(subject).to receive(:edit_button).and_return("btn")
61
- expect(subject.footer_primary_tools).to eq(["btn"])
62
- end
63
- end
64
-
65
- describe "#footer_secondary_tools" do
66
- it "returns array with edit button" do
67
- allow(subject).to receive(:export_button).and_return("a")
68
- allow(subject).to receive(:import_button).and_return("b")
69
- allow(subject).to receive(:import_form).and_return("c")
70
- expect(subject.footer_secondary_tools).to eq(["a", "b", "c"])
71
- end
72
- end
73
-
74
- describe "#import_form" do
75
- it "returns import form" do
76
- allow(subject).to receive(:url_for).with(action: 'import').and_return("import_url")
77
- result = "<form class=\"import\" enctype=\"multipart/form-data\" action=\"import_url\" accept-charset=\"UTF-8\" method=\"post\"><input type=\"file\" name=\"import_file\" id=\"import_file\" /></form>"
78
- expect(subject.import_form).to eq(result)
79
- end
80
- end
81
-
82
- describe "#edit_button" do
83
- it "return edit button" do
84
- allow(subject).to receive(:t).with("Edit").and_return("edt")
85
- allow(subject).to receive(:action_url).with(:edit).and_return("edt_url")
86
- allow(subject).to receive(:button).with("edt", "edit", class: "primary", href: "edt_url").and_return("edt_btn")
87
- expect(subject.edit_button).to eq("edt_btn")
88
- end
89
- end
90
-
91
- describe "#text_search_available?" do
92
- it "return true" do
93
- expect(subject.text_search_available?).to be true
94
- end
95
- end
96
- end
@@ -1,68 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::I18nDatabase::Translations::TableBuilder, type: :class do
4
- class TableBuilderTestHelper < ActionView::Base; end
5
- let(:template){ TableBuilderTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
6
- let(:resource_class){ Releaf::I18nDatabase::I18nEntry }
7
- let(:subject){ described_class.new([], resource_class, template, {}) }
8
-
9
- before do
10
- allow(Releaf.application.config).to receive(:all_locales).and_return(["de", "ze"])
11
- end
12
-
13
- describe "#column_names" do
14
- it "returns key and Releaf.application.config column names array" do
15
- expect(subject.column_names).to eq([:key, "de", "ze"])
16
- end
17
- end
18
-
19
- describe "#head_cell_content" do
20
- context "when locale column given" do
21
- it "returns head cell content with translated locale" do
22
- allow(subject).to receive(:translate_locale).with("de").and_return("gegxxxeg")
23
- expect(subject.head_cell_content("de")).to eq('gegxxxeg')
24
- end
25
- end
26
-
27
- context "when non locale column given" do
28
- it "returns head cell content with translated locale" do
29
- expect(subject).to_not receive(:translate_locale)
30
- expect(subject.head_cell_content("lv")).to eq('Lv')
31
- end
32
- end
33
- end
34
-
35
- describe "#cell_content" do
36
- it "wraps content within span element" do
37
- resource = resource_class.new(key: "xx")
38
- expect(subject.cell_content(resource, :key, format_method: :format_string_content)).to eq("<span>xx</span>")
39
- end
40
- end
41
-
42
- describe "#locale_value" do
43
- it "returns localized value for given resource and column(locale)" do
44
- resource = resource_class.new
45
- allow(resource).to receive(:locale_value).with(:en).and_return("en value")
46
- expect(subject.locale_value(resource, :en)).to eq("en value")
47
- end
48
- end
49
-
50
- describe "#cell_format_method" do
51
- before do
52
- allow(Releaf.application.config).to receive(:all_locales).and_return([:de, :ze])
53
- end
54
-
55
- context "when given column name exists within Releaf.application.config.all_locales" do
56
- it "returns :locale_value" do
57
- expect(subject.cell_format_method(:de)).to eq(:locale_value)
58
- expect(subject.cell_format_method(:ze)).to eq(:locale_value)
59
- end
60
- end
61
-
62
- context "when given column name does not exists within Releaf.application.config.all_locales" do
63
- it "return super" do
64
- expect(subject.cell_format_method(:en)).to eq(:format_string_content)
65
- end
66
- end
67
- end
68
- end
@@ -1,148 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe Releaf::I18nDatabase::TranslationsController do
4
- def file_attachment
5
- test_document = File.expand_path('../../fixtures/translations_import.xlsx', __dir__)
6
- Rack::Test::UploadedFile.new(test_document)
7
- end
8
-
9
- login_as_user :user
10
-
11
- before do
12
- @time_now = Time.parse("1981-02-23 21:00:00 UTC")
13
- allow(Time).to receive(:now).and_return(@time_now)
14
- end
15
-
16
- before build_translations: true do
17
- @t1 = Releaf::I18nDatabase::I18nEntry.create(key: 'test.key1')
18
- @t2 = Releaf::I18nDatabase::I18nEntry.create(key: 'great.stuff')
19
- @t3 = Releaf::I18nDatabase::I18nEntry.create(key: 'geek.stuff')
20
- @t1.i18n_entry_translation.create(locale: 'en', text: 'testa atslēga')
21
- @t2.i18n_entry_translation.create(locale: 'en', text: 'awesome stuff')
22
- @t2.i18n_entry_translation.create(locale: 'lv', text: 'lieliska manta')
23
- @t3.i18n_entry_translation.create(locale: 'en', text: 'geek stuff')
24
- @t3.i18n_entry_translation.create(locale: 'lv', text: 'nūģu lieta')
25
- end
26
-
27
- describe "GET #index", build_translations: true do
28
- context "when not searching" do
29
- it "renders all translations" do
30
- get :index
31
- expect( assigns(:collection).size ).to eq(3)
32
- end
33
- end
34
-
35
- context "when searching" do
36
- it "searches by translation key" do
37
- get :index, params: {search: 'great'}
38
- expect( assigns(:collection).size ).to eq(1)
39
- end
40
-
41
- it "searched by localized values" do
42
- get :index, params: {search: 'manta'}
43
- expect( assigns(:collection).size ).to eq(1)
44
- end
45
- end
46
-
47
- context "when searching blank translations" do
48
- it "returns translations that has blank translation in any localization" do
49
- get :index, params: {only_blank: 'true'}
50
- expect( assigns(:collection).map(&:id) ).to match_array [@t1.id]
51
- end
52
- end
53
- end
54
-
55
- describe "GET #edit", build_translations: true do
56
- context "when search scope is not given" do
57
- it "renders all translations" do
58
- get :edit
59
- expect( assigns(:collection).size ).to eq(3)
60
- end
61
- end
62
-
63
- context "when search scope is given" do
64
- it "renders translations matching search pattern" do
65
- get :index, params: {search: 'stuff'}
66
- expect( assigns(:collection).size ).to eq(2)
67
- end
68
- end
69
- end
70
-
71
- describe "#update" do
72
- context "when save successful" do
73
- it "updates translations updated_at" do
74
- expect(Releaf::I18nDatabase::Backend).to receive("translations_updated_at=").with(@time_now)
75
- put :update, params: {translations: [{key: 'a.b.c', localizations: {en: 'test', lv: 'xxl'}}]}
76
- end
77
-
78
- context "when save with import" do
79
- before do
80
- put :update, params: {translations: [{key: 'a.b.c', localizations: {en: 'test', lv: 'xxl'}}], import: "true"}
81
- end
82
-
83
- it "redirects to index view" do
84
- expect(subject).to redirect_to(action: :index)
85
- end
86
-
87
- it "flash success notification with updated count" do
88
- expect(flash["success"]).to eq("id" => "resource_status", "message" => "successfuly imported 1 translations")
89
- end
90
- end
91
-
92
- context "when save without import" do
93
- before do
94
- put :update, params: {translations: [{key: 'a.b.c', localizations: {en: 'test', lv: 'xxl'}}]}
95
- end
96
-
97
- it "redirects to edit view" do
98
- expect(subject).to redirect_to(action: :edit)
99
- end
100
-
101
- it "flash success notification" do
102
- expect(flash["success"]).to eq("id" => "resource_status", "message" => "Update succeeded")
103
- end
104
- end
105
- end
106
-
107
- context "when save failed" do
108
- it "renders edit view" do
109
- put :update, params: {translations: [{key: '', localizations: {en: 'test', lv: 'xxl'}}]}
110
- expect(response).to render_template(:edit)
111
- end
112
-
113
- it "flash error notification" do
114
- put :update, params: {translations: [{key: '', localizations: {en: 'test', lv: 'xxl'}}]}
115
- expect(flash["error"]).to eq("id" => "resource_status", "message" => "Update failed")
116
- end
117
- end
118
- end
119
-
120
- describe "#import" do
121
- context "when file uploaded" do
122
- before do
123
- file = fixture_file_upload(File.expand_path('../../fixtures/translations_import.xlsx', __dir__),
124
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
125
- post :import, params: {import_file: file}
126
- end
127
-
128
- it "parses uploaded file and assigns content to collection" do
129
- expect( assigns(:collection).size ).to eq(4)
130
- end
131
-
132
- it "assigns @import to true" do
133
- expect( assigns(:import) ).to be true
134
- end
135
-
136
- it "appends breadcrumb with 'import' part" do
137
- expect( assigns(:breadcrumbs).last ).to eq({name: "Import"})
138
- end
139
- end
140
-
141
- context "when no file uploaded" do
142
- it "redirects to index" do
143
- post :import
144
- expect(subject).to redirect_to(action: :index)
145
- end
146
- end
147
- end
148
- end