embedded_localization 1.3.1 → 1.4.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 +10 -0
- data/Gemfile +14 -3
- data/README.md +133 -5
- data/Rakefile +4 -14
- data/embedded_localization.gemspec +16 -13
- data/lib/embedded_localization/active_record/act_macro.rb +29 -67
- data/lib/embedded_localization/active_record/class_methods.rb +14 -0
- data/lib/embedded_localization/active_record/instance_methods.rb +52 -32
- data/lib/embedded_localization/storage/hstore.rb +61 -0
- data/lib/embedded_localization/storage/json.rb +25 -0
- data/lib/embedded_localization/version.rb +1 -1
- data/lib/embedded_localization.rb +6 -3
- metadata +11 -28
- data/.github/dependabot.yml +0 -8
- data/.github/workflows/codeql-analysis.yml +0 -72
- data/.github/workflows/ruby.yml +0 -64
- data/.gitignore +0 -7
- data/.rspec +0 -1
- data/lib/extensions/hash.rb +0 -7
- data/spec/embedded_localization/native_column_spec.rb +0 -191
- data/spec/embedded_localization/simple_model_spec.rb +0 -190
- data/spec/models.rb +0 -7
- data/spec/schema.rb +0 -18
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -36
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require 'spec_helper'
|
|
3
|
-
|
|
4
|
-
I18n.locale = :en
|
|
5
|
-
|
|
6
|
-
# e.g. the model "Genre" has :name as a translated field,
|
|
7
|
-
# but does not have :name as a native attribute for the model.
|
|
8
|
-
# It is only defined as a virtual attribute in the :i18n hash.
|
|
9
|
-
|
|
10
|
-
describe 'model has translated field without attribute of that same name' do
|
|
11
|
-
let(:genre){ Genre.new }
|
|
12
|
-
|
|
13
|
-
describe "basic things that need to work" do
|
|
14
|
-
|
|
15
|
-
it 'reports it translates' do
|
|
16
|
-
Genre.translates?.should be_truthy
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it 'correctly reports the list of translated_attributes' do
|
|
20
|
-
Genre.translated_attributes.sort.should eq [:description, :name]
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'correctly reports the list of translated_attribute_names' do
|
|
24
|
-
Genre.translated_attribute_names.sort.should eq [:description, :name]
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it 'correcty shows the translated attribute as translated' do
|
|
28
|
-
Genre.translated?(:name).should be_truthy
|
|
29
|
-
Genre.translated?(:description).should be_truthy
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it 'correcty shows not translated attribute' do
|
|
33
|
-
Genre.translated?(:other).should be_falsy
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe "new DB records" do
|
|
38
|
-
|
|
39
|
-
it 'correctly reports translated_locales for new record' do
|
|
40
|
-
genre.translated_locales.should eq [I18n.default_locale]
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'correctly reports translation_missing for new record' do
|
|
44
|
-
genre.translation_missing.should be_truthy
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it 'creates the accessor methods' do
|
|
48
|
-
genre.methods.should include(:name)
|
|
49
|
-
genre.methods.should include(:name=)
|
|
50
|
-
genre.methods.should include(:description)
|
|
51
|
-
genre.methods.should include(:description=)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'correctly reports translated field for new record for default locale' do
|
|
55
|
-
genre.name.should be_nil
|
|
56
|
-
genre.description.should be_nil
|
|
57
|
-
genre.description( I18n.default_locale ).should be_nil
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'correctly reports translated field for new record for other locale' do
|
|
61
|
-
genre.name(:ko).should be_nil
|
|
62
|
-
genre.description(:de).should be_nil
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it 'correctly reports translation_coverage for new record' do
|
|
66
|
-
genre.translation_coverage.should eq Hash.new
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'correctly reports translation_goverate for attributes of new record' do
|
|
70
|
-
genre.translation_coverage(:name).should eq []
|
|
71
|
-
genre.translation_coverage(:description).should eq []
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it 'translated_coverage returns nil for not-translated attributes' do
|
|
75
|
-
genre.translation_coverage(:other).should be_nil
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it 'correctly reports translation_missing for new record' do
|
|
79
|
-
genre.translation_missing.should == {:description=>[:en], :name=>[:en]}
|
|
80
|
-
genre.translation_missing(:name).should eq [:en]
|
|
81
|
-
genre.translation_missing(:description).should eq [:en]
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
describe "DB record with pre-set fields" do
|
|
86
|
-
let(:genre_name_en){"Science Fiction"}
|
|
87
|
-
let(:scifi){ Genre.new(:name => genre_name_en) }
|
|
88
|
-
|
|
89
|
-
it 'correctly shows the attribute for new record' do
|
|
90
|
-
scifi.name.should eq genre_name_en
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
describe "updated DB record" do
|
|
95
|
-
let(:genre_name_en){"Science Fiction"}
|
|
96
|
-
let(:genre_name_jp){"サイエンスフィクション"}
|
|
97
|
-
let(:genre_name_ko){"공상 과학 소설"}
|
|
98
|
-
let(:scifi){ Genre.new(:name => genre_name_en) }
|
|
99
|
-
|
|
100
|
-
describe 'updating just default locale' do
|
|
101
|
-
|
|
102
|
-
before :each do
|
|
103
|
-
genre.name = genre_name_en
|
|
104
|
-
genre.description = "an awesome genre"
|
|
105
|
-
genre.save
|
|
106
|
-
genre.reload
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it 'correctly reports the translated_locales' do
|
|
110
|
-
genre.translated_locales.should eq [:en]
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# when setting all fields in the default locale's languange:
|
|
114
|
-
it 'correctly reports translation_missing for updated record' do
|
|
115
|
-
genre.translation_missing.should eq Hash.new
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
it 'correctly reports translation_missing for attributes' do
|
|
119
|
-
genre.translation_missing(:name).should eq nil
|
|
120
|
-
genre.translation_missing(:description).should eq nil
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it 'correctly reports translated_coverage for updated record' do
|
|
124
|
-
genre.translation_coverage.should == {:name=>[:en], :description=>[:en]}
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
it 'correctly reports translated_coverage for attributes' do
|
|
128
|
-
genre.translation_coverage(:name).should eq [:en]
|
|
129
|
-
genre.translation_coverage(:description).should eq [:en]
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
describe 'updating other locales' do
|
|
135
|
-
before :each do
|
|
136
|
-
genre.name = genre_name_en
|
|
137
|
-
genre.description = "an awesome genre"
|
|
138
|
-
I18n.locale = :jp
|
|
139
|
-
genre.name = genre_name_jp
|
|
140
|
-
genre.set_localized_attribute(:name, :ko, genre_name_ko)
|
|
141
|
-
I18n.locale = :de
|
|
142
|
-
genre.description = "ein grossartiges Genre"
|
|
143
|
-
I18n.locale = I18n.default_locale # MAKE SURE you switch back to your default locale if you tweak it
|
|
144
|
-
genre.save
|
|
145
|
-
genre.reload
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
it 'correctly reports the translated_locales' do
|
|
149
|
-
genre.translated_locales.should eq [:en, :jp, :ko, :de]
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
it 'can assign the translated field' do
|
|
153
|
-
genre.name = genre_name_en
|
|
154
|
-
genre.save.should be_truthy
|
|
155
|
-
genre.name.should eq genre_name_en
|
|
156
|
-
genre.name(:en).should eq genre_name_en
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
# when setting all fields in additional languanges:
|
|
160
|
-
it 'correctly reports values for updated record via attr(:locale)' do
|
|
161
|
-
genre.name(:ko).should eq genre_name_ko
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it 'correctly reports values for updated record via getter' do
|
|
165
|
-
genre.get_localized_attribute(:name, :jp).should eq genre_name_jp
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
it 'correctly reports translation_coverage for updated record' do
|
|
169
|
-
# what values are actually present
|
|
170
|
-
genre.translation_coverage.should == {:name=>[:en, :jp, :ko], :description=>[:en, :de]}
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
it 'correctly reports translation_coverage for attributes' do
|
|
174
|
-
genre.translation_coverage(:name).should eq [:en, :jp, :ko]
|
|
175
|
-
genre.translation_coverage(:description).should eq [:en,:de]
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
it 'correctly reports translation_missing for updated record' do
|
|
179
|
-
# what values are missing
|
|
180
|
-
genre.translation_missing.should == {:description=>[:jp, :ko], :name=>[:de]}
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
it 'correctly reports translation_missing for attributes' do
|
|
184
|
-
genre.translation_missing(:name).should eq [:de]
|
|
185
|
-
genre.translation_missing(:description).should eq [:jp, :ko]
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
end
|
|
190
|
-
end
|
data/spec/models.rb
DELETED
data/spec/schema.rb
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
ActiveRecord::Schema.define do
|
|
2
|
-
self.verbose = false
|
|
3
|
-
|
|
4
|
-
create_table :genres, :force => true do |t|
|
|
5
|
-
t.text :i18n
|
|
6
|
-
|
|
7
|
-
t.string :other
|
|
8
|
-
t.timestamps
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
create_table :movies, :force => true do |t|
|
|
12
|
-
t.string :title
|
|
13
|
-
t.text :i18n
|
|
14
|
-
|
|
15
|
-
t.string :other
|
|
16
|
-
t.timestamps
|
|
17
|
-
end
|
|
18
|
-
end
|
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
require 'active_record'
|
|
2
|
-
require 'i18n'
|
|
3
|
-
|
|
4
|
-
require 'simplecov'
|
|
5
|
-
SimpleCov.start do
|
|
6
|
-
add_filter '/spec/'
|
|
7
|
-
add_filter "/pkg/"
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
if ENV['CI'] == 'true' || ENV['CODECOV_TOKEN']
|
|
11
|
-
require 'codecov'
|
|
12
|
-
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
require 'embedded_localization'
|
|
16
|
-
|
|
17
|
-
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
|
18
|
-
|
|
19
|
-
load File.dirname(__FILE__) + '/schema.rb'
|
|
20
|
-
require File.dirname(__FILE__) + '/models.rb'
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
I18n.enforce_available_locales = false
|
|
24
|
-
I18n.config.available_locales = [:ru,:jp,:ko,:fr,:en,:de]
|
|
25
|
-
|
|
26
|
-
RSpec.configure do |config|
|
|
27
|
-
config.expect_with :rspec do |expectations|
|
|
28
|
-
expectations.syntax = :should
|
|
29
|
-
end
|
|
30
|
-
config.mock_with :rspec do |mocks|
|
|
31
|
-
mocks.syntax = :should
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
config.filter_run_including :focus => true
|
|
35
|
-
config.run_all_when_everything_filtered = true
|
|
36
|
-
end
|