armot 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/armot/active_record_extensions.rb +6 -0
- data/lib/armot/version.rb +1 -1
- data/test/armot_test.rb +23 -0
- metadata +1 -1
@@ -17,16 +17,22 @@ module Armot
|
|
17
17
|
end
|
18
18
|
|
19
19
|
define_method :define_localized_accessors_for do |*localizable_attributes|
|
20
|
+
reload_localized_accessors_for *localizable_attributes
|
21
|
+
end
|
22
|
+
|
23
|
+
define_method :reload_localized_accessors_for do |*localizable_attributes|
|
20
24
|
localizable_attributes = armotized_attributes if localizable_attributes == [:all]
|
21
25
|
|
22
26
|
localizable_attributes.each do |attr|
|
23
27
|
I18n.available_locales.each do |locale|
|
28
|
+
next if respond_to?(:"#{attr}_#{locale}")
|
24
29
|
define_method "#{attr}_#{locale}" do
|
25
30
|
armot_wrap_in_locale(locale) do
|
26
31
|
send attr
|
27
32
|
end
|
28
33
|
end
|
29
34
|
|
35
|
+
next if respond_to?(:"#{attr}_#{locale}=")
|
30
36
|
define_method "#{attr}_#{locale}=" do |value|
|
31
37
|
armot_wrap_in_locale(locale) do
|
32
38
|
send "#{attr}=", value
|
data/lib/armot/version.rb
CHANGED
data/test/armot_test.rb
CHANGED
@@ -487,4 +487,27 @@ class ArmotTest < ActiveSupport::TestCase
|
|
487
487
|
assert_equal true, foo.respond_to?(:text_en)
|
488
488
|
assert_equal true, foo.respond_to?(:"text_en=")
|
489
489
|
end
|
490
|
+
|
491
|
+
test "reload_localized_accessors_for" do
|
492
|
+
class FuzzBar < Post
|
493
|
+
define_localized_accessors_for :title
|
494
|
+
end
|
495
|
+
|
496
|
+
foo = FuzzBar.new
|
497
|
+
foo.title = "EN - title"
|
498
|
+
foo.save!
|
499
|
+
|
500
|
+
assert_equal [:en].sort, I18n.available_locales.sort
|
501
|
+
assert_equal false, foo.respond_to?(:title_sk)
|
502
|
+
|
503
|
+
I18n.locale = :sk
|
504
|
+
foo.title = "Skandinavian title"
|
505
|
+
foo.save!
|
506
|
+
|
507
|
+
assert_equal [:en, :sk].sort, I18n.available_locales.sort
|
508
|
+
assert_equal false, foo.respond_to?(:title_sk)
|
509
|
+
|
510
|
+
FuzzBar.reload_localized_accessors_for :title
|
511
|
+
assert_equal true, foo.respond_to?(:title_sk)
|
512
|
+
end
|
490
513
|
end
|