purizumu 0.1.1 → 0.1.2
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 13e13e8ac2807b2872602bfc6066e18bb4b9c462c3abb09a4d9dc3922ffa93a8
|
|
4
|
+
data.tar.gz: 68f318bb8f0bfd86d86cf7e2f5490bcf1d47cc9c804ee8edb83d2c8c0f56b501
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 818aaf90a7292954a157faa2787d17b1c9dfa643a865d23c7375c211d6a2f10a95e5fddf41f2c8e820b96c9abc1b6e98412873e183b96fe89bc9baf5da0154c2
|
|
7
|
+
data.tar.gz: 4a1784db93876921e7d32ea8f1db7ba9276017ce27f360aa081ce4aff4632f7e07d23f30424d36c7dc3db9489497ee3fda58b994ae7ccebc3e40c2b5473e2637
|
data/lib/purizumu/translator.rb
CHANGED
data/lib/purizumu/version.rb
CHANGED
|
@@ -110,6 +110,76 @@ RSpec.describe Purizumu::Translator do
|
|
|
110
110
|
expect(Purizumu::Translation.where(record_id: blank_record.id)).to be_empty
|
|
111
111
|
end
|
|
112
112
|
|
|
113
|
+
context 'with an unsaved record' do
|
|
114
|
+
let(:unsaved_record) { GemRecord.new(human_name: 'Prism', slug: 'prism') }
|
|
115
|
+
|
|
116
|
+
before do
|
|
117
|
+
allow(Purizumu).to receive(:engine)
|
|
118
|
+
I18n.locale = :jp
|
|
119
|
+
unsaved_record.human_name
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'returns the source content' do
|
|
123
|
+
expect(unsaved_record.human_name).to eq('Prism')
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'does not invoke the engine' do
|
|
127
|
+
expect(Purizumu).not_to have_received(:engine)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it 'does not create a translation row' do
|
|
131
|
+
expect(Purizumu::Translation.where(model_class_name: 'GemRecord')).to be_empty
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context 'when validations read a translated attribute on create' do
|
|
136
|
+
before do
|
|
137
|
+
stub_validated_gem_record
|
|
138
|
+
allow(Purizumu).to receive(:engine)
|
|
139
|
+
I18n.locale = :jp
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'does not raise during create' do
|
|
143
|
+
expect { create_validated_gem_record }.not_to raise_error
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it 'does not invoke the engine' do
|
|
147
|
+
create_validated_gem_record
|
|
148
|
+
|
|
149
|
+
expect(Purizumu).not_to have_received(:engine)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it 'does not create translation rows' do
|
|
153
|
+
create_validated_gem_record
|
|
154
|
+
|
|
155
|
+
expect(Purizumu::Translation.where(model_class_name: 'ValidatedGemRecord')).to be_empty
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
context 'when callbacks read a translated attribute before validation on create' do
|
|
160
|
+
before do
|
|
161
|
+
stub_slugged_gem_record
|
|
162
|
+
allow(Purizumu).to receive(:engine)
|
|
163
|
+
I18n.locale = :jp
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it 'allows the callback to derive values from the source attribute' do
|
|
167
|
+
expect(create_slugged_gem_record.slug).to eq('crystal-clear')
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it 'does not invoke the engine' do
|
|
171
|
+
create_slugged_gem_record
|
|
172
|
+
|
|
173
|
+
expect(Purizumu).not_to have_received(:engine)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it 'does not create translation rows' do
|
|
177
|
+
create_slugged_gem_record
|
|
178
|
+
|
|
179
|
+
expect(Purizumu::Translation.where(model_class_name: 'SluggedGemRecord')).to be_empty
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
113
183
|
it 'clears persisted translations for a changed translated attribute after commit' do
|
|
114
184
|
create_existing_translation
|
|
115
185
|
|
|
@@ -154,6 +224,37 @@ RSpec.describe Purizumu::Translator do
|
|
|
154
224
|
Purizumu::Translation.create!(existing_translation_attributes)
|
|
155
225
|
end
|
|
156
226
|
|
|
227
|
+
def stub_validated_gem_record
|
|
228
|
+
stub_const('ValidatedGemRecord', Class.new(ActiveRecord::Base) do
|
|
229
|
+
self.table_name = 'gems'
|
|
230
|
+
|
|
231
|
+
validates :human_name, presence: true
|
|
232
|
+
attribute_translation :human_name
|
|
233
|
+
end)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def create_validated_gem_record
|
|
237
|
+
ValidatedGemRecord.create!(human_name: 'Prism', slug: 'prism')
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def stub_slugged_gem_record
|
|
241
|
+
stub_const('SluggedGemRecord', Class.new(ActiveRecord::Base) do
|
|
242
|
+
self.table_name = 'gems'
|
|
243
|
+
|
|
244
|
+
validates :human_name, presence: true
|
|
245
|
+
before_validation :generate_slug, if: -> { slug.blank? }
|
|
246
|
+
attribute_translation :human_name
|
|
247
|
+
|
|
248
|
+
def generate_slug
|
|
249
|
+
self.slug = human_name.to_s.parameterize
|
|
250
|
+
end
|
|
251
|
+
end)
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def create_slugged_gem_record
|
|
255
|
+
SluggedGemRecord.create!(human_name: 'Crystal clear')
|
|
256
|
+
end
|
|
257
|
+
|
|
157
258
|
def prepare_regenerated_translation
|
|
158
259
|
create_existing_translation
|
|
159
260
|
allow(Purizumu).to receive(:engine).and_return(
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: purizumu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OpenAI Codex
|
|
@@ -79,7 +79,7 @@ files:
|
|
|
79
79
|
- spec/purizumu/generators/install_generator_spec.rb
|
|
80
80
|
- spec/purizumu/translator_spec.rb
|
|
81
81
|
- spec/spec_helper.rb
|
|
82
|
-
- spec/tmp/generator/db/migrate/
|
|
82
|
+
- spec/tmp/generator/db/migrate/20260413083431_create_purizumu_translations.rb
|
|
83
83
|
homepage: https://example.com/purizumu
|
|
84
84
|
licenses:
|
|
85
85
|
- MIT
|