i18n_alchemy 0.2.1 → 0.2.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 +4 -4
- data/CHANGELOG.md +6 -2
- data/lib/i18n_alchemy/proxy.rb +8 -1
- data/lib/i18n_alchemy/version.rb +1 -1
- data/test/action_view_test.rb +19 -11
- data/test/db/test_schema.rb +2 -2
- data/test/i18n_alchemy/proxy/attributes_parsing_test.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68f198998d37ed939ead93b7a86d836fa73b8e7c
|
4
|
+
data.tar.gz: 880e2dbb5699e4a714922e5fc40958929b3b7d48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca5de87fe772476d5f48507a1d0b8ae2cd9dc40521a878a1a61c0d24ccfb1f338a096fde002fbd38540eed82fd574b6055657d7717b338c2aaa71a5e96c64b51
|
7
|
+
data.tar.gz: 9c5ceb2c9203ac97686f7f0f6b45bf3e27aa184985b22eb7451c5cc063b60b215763a2307a691375fd39f930433fd2fe420b035192b365167b36ff859fded590
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
## v0.2.2 - 2015-08-26
|
2
|
+
|
3
|
+
* Rails 4.2 and Ruby 2.2 support (Rails 4.2.1+ support by [@Danielpk](https://github.com/Danielpk))
|
4
|
+
|
1
5
|
## v0.2.1 - 2014-05-05
|
2
6
|
|
3
|
-
* Rails 4.1 support ([@sobrinho]
|
7
|
+
* Rails 4.1 support ([@sobrinho](https://github.com/sobrinho))
|
4
8
|
|
5
9
|
## v0.2.0 - 2013-11-28
|
6
10
|
|
@@ -14,7 +18,7 @@
|
|
14
18
|
* Improve localization for non-AR objects
|
15
19
|
* Allow custom parsers to accept a parser module
|
16
20
|
* Add support for localizing methods
|
17
|
-
* Add support for custom parsers ([@caironoleto]
|
21
|
+
* Add support for custom parsers ([@caironoleto](https://github.com/caironoleto))
|
18
22
|
|
19
23
|
## v0.0.1 - 2012-5-8
|
20
24
|
|
data/lib/i18n_alchemy/proxy.rb
CHANGED
@@ -46,6 +46,7 @@ module I18n
|
|
46
46
|
# Allow calling localized methods with :send. This allows us to integrate
|
47
47
|
# with action view methods.
|
48
48
|
alias :send :__send__
|
49
|
+
alias :public_send :__send__
|
49
50
|
|
50
51
|
# Allow calling localized methods with :try. If the method is not declared
|
51
52
|
# here, it'll be delegated to the target, losing localization capabilities.
|
@@ -69,7 +70,7 @@ module I18n
|
|
69
70
|
def build_attributes
|
70
71
|
@target_class.columns.each do |column|
|
71
72
|
column_name = column.name
|
72
|
-
next if
|
73
|
+
next if skip_column?(column_name)
|
73
74
|
|
74
75
|
parser = detect_parser_from_column(column)
|
75
76
|
build_attribute(column_name, parser)
|
@@ -142,6 +143,12 @@ module I18n
|
|
142
143
|
type_or_parser
|
143
144
|
end
|
144
145
|
end
|
146
|
+
|
147
|
+
def skip_column?(column_name)
|
148
|
+
column_name == @target_class.primary_key ||
|
149
|
+
column_name.ends_with?("_id") ||
|
150
|
+
@localized_attributes.key?(column_name)
|
151
|
+
end
|
145
152
|
end
|
146
153
|
end
|
147
154
|
end
|
data/lib/i18n_alchemy/version.rb
CHANGED
data/test/action_view_test.rb
CHANGED
@@ -21,37 +21,45 @@ class ActionViewTest < I18n::Alchemy::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_text_field_with_string_attribute
|
24
|
-
|
25
|
-
@template.text_field(:product, :name, :object => @localized)
|
24
|
+
assert_same_text_input :name, 'Potato'
|
26
25
|
end
|
27
26
|
|
28
27
|
def test_text_field_with_integer_attribute
|
29
|
-
|
30
|
-
@template.text_field(:product, :quantity, :object => @localized)
|
28
|
+
assert_same_text_input :quantity, '10'
|
31
29
|
end
|
32
30
|
|
33
31
|
def test_text_field_with_decimal_attribute
|
34
|
-
|
35
|
-
@template.text_field(:product, :price, :object => @localized)
|
32
|
+
assert_same_text_input :price, '1,99'
|
36
33
|
end
|
37
34
|
|
38
35
|
def test_text_field_with_date_attribute
|
39
|
-
|
40
|
-
@template.text_field(:product, :released_at, :object => @localized)
|
36
|
+
assert_same_text_input :released_at, '28/02/2011'
|
41
37
|
end
|
42
38
|
|
43
39
|
def test_text_field_with_time_attribute
|
44
|
-
|
45
|
-
@template.text_field(:product, :last_sale_at, :object => @localized)
|
40
|
+
assert_same_text_input :last_sale_at, '28/02/2011 13:25:30'
|
46
41
|
end
|
47
42
|
|
48
43
|
private
|
49
44
|
|
50
|
-
|
45
|
+
# Since we do not want to rely on Rails dom-assertions (neither from the
|
46
|
+
# framework nor from the extracted gem), we build our own :).
|
47
|
+
def assert_same_text_input(attribute, value)
|
48
|
+
assert_includes [
|
49
|
+
text_input_sorted_attributes(attribute, value),
|
50
|
+
text_input_unsorted_attributes(attribute, value)
|
51
|
+
], @template.text_field(:product, attribute, :object => @localized)
|
52
|
+
end
|
53
|
+
|
54
|
+
def text_input_sorted_attributes(attribute_name, value)
|
51
55
|
size = rails4? ? ' ' : ' size="30" '
|
52
56
|
%Q[<input id="product_#{attribute_name}" name="product[#{attribute_name}]"#{size}type="text" value="#{value}" />]
|
53
57
|
end
|
54
58
|
|
59
|
+
def text_input_unsorted_attributes(attribute_name, value)
|
60
|
+
%Q[<input type="text" value="#{value}" name="product[#{attribute_name}]" id="product_#{attribute_name}" />]
|
61
|
+
end
|
62
|
+
|
55
63
|
def rails4?
|
56
64
|
ActionPack::VERSION::STRING.start_with? "4"
|
57
65
|
end
|
data/test/db/test_schema.rb
CHANGED
@@ -8,7 +8,7 @@ ActiveRecord::Schema.define do
|
|
8
8
|
|
9
9
|
create_table :products do |t|
|
10
10
|
t.string :name
|
11
|
-
t.decimal :price
|
11
|
+
t.decimal :price, precision: 10, scale: 2
|
12
12
|
t.integer :quantity
|
13
13
|
t.date :released_at
|
14
14
|
t.date :released_month
|
@@ -25,6 +25,6 @@ ActiveRecord::Schema.define do
|
|
25
25
|
create_table :accounts do |t|
|
26
26
|
t.references :supplier
|
27
27
|
t.string :account_number
|
28
|
-
t.decimal :total_money
|
28
|
+
t.decimal :total_money, precision: 10, scale: 2
|
29
29
|
end
|
30
30
|
end
|
@@ -88,7 +88,7 @@ class ProxyAttributesParsingTest < I18n::Alchemy::ProxyTestCase
|
|
88
88
|
def test_should_assign_for_nested_attributes_for_one_to_one_association
|
89
89
|
@supplier_localized.assign_attributes(:account_attributes => {:account_number => 10, :total_money => '100,87'})
|
90
90
|
account = @supplier_localized.account
|
91
|
-
assert_equal 10, account.account_number
|
91
|
+
assert_equal '10', account.account_number.to_s
|
92
92
|
assert_equal '100,87', account.localized.total_money
|
93
93
|
end
|
94
94
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_alchemy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Antonio da Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 3.2.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 5.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 3.2.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 5.0.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: i18n
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
version: 3.2.0
|
54
54
|
- - "<"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: 5.0.0
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -63,7 +63,7 @@ dependencies:
|
|
63
63
|
version: 3.2.0
|
64
64
|
- - "<"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
66
|
+
version: 5.0.0
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: activerecord
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
version: 3.2.0
|
74
74
|
- - "<"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: 5.0.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -83,7 +83,7 @@ dependencies:
|
|
83
83
|
version: 3.2.0
|
84
84
|
- - "<"
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
86
|
+
version: 5.0.0
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
88
|
name: minitest
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project: i18n_alchemy
|
171
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.4.5.1
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: I18n date/number parsing/localization
|