armot 0.3.2 → 0.3.3

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.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Armot
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: armot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: