translatable_ar 1.0.3 → 1.0.4
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.
@@ -1,5 +1,5 @@
|
|
1
1
|
class TranslatableAR
|
2
|
-
module
|
2
|
+
module ActiveRecordBase
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
@@ -33,6 +33,7 @@ class TranslatableAR
|
|
33
33
|
define_translatable_ar_writer(attribute)
|
34
34
|
define_translatable_ar_reader(attribute)
|
35
35
|
define_translatable_ar_changed?(attribute)
|
36
|
+
define_translatable_ar_before_type_cast(attribute)
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
@@ -70,6 +71,16 @@ class TranslatableAR
|
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
74
|
+
def define_translatable_ar_before_type_cast(attribute)
|
75
|
+
define_method("#{attribute}_before_type_cast") do
|
76
|
+
if respond_to?("#{attribute}_i18n")
|
77
|
+
send("#{attribute}_i18n_before_type_cast")[I18n.locale.to_s]
|
78
|
+
else
|
79
|
+
super()
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
73
84
|
end
|
74
85
|
end
|
75
86
|
end
|
data/lib/railtie.rb
CHANGED
@@ -33,15 +33,11 @@ class TranslatableAr < Rails::Railtie
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def models
|
36
|
-
models
|
37
|
-
|
38
|
-
|
39
|
-
if model.columns_hash["#{attribute}_i18n"].nil?
|
40
|
-
models << model
|
41
|
-
end
|
36
|
+
TranslatableAR.models.select do |model|
|
37
|
+
model.translatable_ar_attributes.any? do |attribute|
|
38
|
+
model.columns_hash["#{attribute}_i18n"].nil?
|
42
39
|
end
|
43
40
|
end
|
44
|
-
models.uniq!
|
45
41
|
end
|
46
42
|
|
47
43
|
def attributes
|
data/lib/templates/setup.rb
CHANGED
data/lib/translatable_ar.rb
CHANGED
@@ -3,5 +3,6 @@ if defined? Rails
|
|
3
3
|
require "railtie"
|
4
4
|
end
|
5
5
|
require 'translatable_ar_class'
|
6
|
-
require '
|
7
|
-
|
6
|
+
require 'active_record_base'
|
7
|
+
|
8
|
+
ActiveRecord::Base.send(:include, TranslatableAR::ActiveRecordBase)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translatable_ar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -33,12 +33,11 @@ executables: []
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
-
- lib/
|
36
|
+
- lib/active_record_base.rb
|
37
37
|
- lib/railtie.rb
|
38
38
|
- lib/templates/setup.rb
|
39
39
|
- lib/translatable_ar.rb
|
40
40
|
- lib/translatable_ar_class.rb
|
41
|
-
- test/rails_3.2.11/test/unit/product_test.rb
|
42
41
|
homepage: http://github.com/kasperbn/translatable_ar
|
43
42
|
licenses: []
|
44
43
|
post_install_message:
|
@@ -64,5 +63,4 @@ rubygems_version: 1.8.25
|
|
64
63
|
signing_key:
|
65
64
|
specification_version: 3
|
66
65
|
summary: i18n for your active record models with HStore / serialized attribute
|
67
|
-
test_files:
|
68
|
-
- test/rails_3.2.11/test/unit/product_test.rb
|
66
|
+
test_files: []
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class ProductTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
# Singular Association
|
6
|
-
|
7
|
-
test "build with nested locale values" do
|
8
|
-
p = Product.new(:name => {'en' => 'Chair', 'da' => 'Stol'}, image_url: '/image1.png')
|
9
|
-
assert_equal 'Chair', p.name_i18n['en']
|
10
|
-
assert_equal 'Stol', p.name_i18n['da']
|
11
|
-
assert_equal '/image1.png', p.image_url
|
12
|
-
end
|
13
|
-
|
14
|
-
test "build with default locale" do
|
15
|
-
p = Product.new(name: 'Table', image_url: '/image1.png')
|
16
|
-
assert_equal('Table', p.name)
|
17
|
-
assert_equal({'en' => 'Table'}, p.name_i18n)
|
18
|
-
assert_equal '/image1.png', p.image_url
|
19
|
-
end
|
20
|
-
|
21
|
-
test "create with nested locale values" do
|
22
|
-
p = Product.create(:name => {'en' => 'Chair', 'da' => 'Stol'}, image_url: '/image1.png', permalink: 'asd')
|
23
|
-
assert_equal 'Chair', p.name_i18n['en']
|
24
|
-
assert_equal 'Stol', p.name_i18n['da']
|
25
|
-
assert_equal '/image1.png', p.image_url
|
26
|
-
assert_equal 1, Product.count
|
27
|
-
end
|
28
|
-
|
29
|
-
test "create with default locale" do
|
30
|
-
p = Product.create(name: 'Table', image_url: '/image1.png')
|
31
|
-
assert_equal 'Table', p.name
|
32
|
-
assert_equal({'en' => 'Table'}, p.name_i18n)
|
33
|
-
assert_equal '/image1.png', p.image_url
|
34
|
-
end
|
35
|
-
|
36
|
-
test "update with nested locale values" do
|
37
|
-
p = Product.new
|
38
|
-
p.update_attributes(:name => {'en' => 'Chair', 'da' => 'Stol'}, image_url: '/image1.png')
|
39
|
-
assert_equal 'Chair', p.name_i18n['en']
|
40
|
-
assert_equal 'Stol', p.name_i18n['da']
|
41
|
-
assert_equal '/image1.png', p.image_url
|
42
|
-
end
|
43
|
-
|
44
|
-
test "update with locale" do
|
45
|
-
p = Product.new
|
46
|
-
p.update_attributes(name: 'Table', image_url: '/image1.png')
|
47
|
-
assert_equal 'Table', p.name
|
48
|
-
assert_equal({'en' => 'Table'}, p.name_i18n)
|
49
|
-
assert_equal '/image1.png', p.image_url
|
50
|
-
end
|
51
|
-
|
52
|
-
test "update with different locale" do
|
53
|
-
p = Product.create(name: 'Table', image_url: '/image1.png')
|
54
|
-
|
55
|
-
assert_equal 'Table', p.name
|
56
|
-
assert_equal '/image1.png', p.image_url
|
57
|
-
|
58
|
-
I18n.locale = :da
|
59
|
-
|
60
|
-
assert_equal nil, p.name
|
61
|
-
assert_equal '/image1.png', p.image_url
|
62
|
-
|
63
|
-
p.name = 'Bord'
|
64
|
-
|
65
|
-
assert_equal 'Bord', p.name
|
66
|
-
assert_equal({'en' => 'Table', 'da' => 'Bord'}, p.name_i18n)
|
67
|
-
|
68
|
-
p.save
|
69
|
-
|
70
|
-
I18n.locale = :en
|
71
|
-
|
72
|
-
assert_equal 'Table', p.name
|
73
|
-
assert_equal({'en' => 'Table', 'da' => 'Bord'}, p.name_i18n)
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
# Collection Association
|
78
|
-
|
79
|
-
test "build from collection with nested locale values" do
|
80
|
-
c = Category.create(name: 'Furniture')
|
81
|
-
p = c.products.build(:name => {'en' => 'Chair', 'da' => 'Stol'}, image_url: '/image1.png')
|
82
|
-
assert_equal 'Chair', p.name_i18n['en']
|
83
|
-
assert_equal 'Stol', p.name_i18n['da']
|
84
|
-
assert_equal '/image1.png', p.image_url
|
85
|
-
end
|
86
|
-
|
87
|
-
test "build from collection with default locale" do
|
88
|
-
c = Category.create(name: 'Furniture')
|
89
|
-
p = c.products.build(name: 'Table', image_url: '/image1.png')
|
90
|
-
assert_equal('Table', p.name)
|
91
|
-
assert_equal({'en' => 'Table'}, p.name_i18n)
|
92
|
-
assert_equal '/image1.png', p.image_url
|
93
|
-
end
|
94
|
-
|
95
|
-
test "create from collection with nested locale values" do
|
96
|
-
c = Category.create(name: 'Furniture')
|
97
|
-
p = c.products.create(:name => {'en' => 'Chair', 'da' => 'Stol'}, image_url: '/image1.png')
|
98
|
-
assert_equal 'Chair', p.name_i18n['en']
|
99
|
-
assert_equal 'Stol', p.name_i18n['da']
|
100
|
-
assert_equal '/image1.png', p.image_url
|
101
|
-
end
|
102
|
-
|
103
|
-
test "create from collection with default locale" do
|
104
|
-
c = Category.create(name: 'Furniture')
|
105
|
-
p = c.products.create(name: 'Table', image_url: '/image1.png')
|
106
|
-
assert_equal 'Table', p.name
|
107
|
-
assert_equal({'en' => 'Table'}, p.name_i18n)
|
108
|
-
assert_equal '/image1.png', p.image_url
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|