i18n_alchemy 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95fd92a5aea119177568029fbf20b3e2f309ee46e2c60950f176a59856846a53
4
- data.tar.gz: 805c01033647ca546ee400f55c23e7a516d283095b5d55fc52f2d9a6946f018e
3
+ metadata.gz: c7ebc2bc7b34e395b62ef11905c03ab5103350a569c4bc4f5d4d429441c3af19
4
+ data.tar.gz: 2e1b00aa921aa7467a808a0984bf851f21d63d4e1e85a526d675d119c388d261
5
5
  SHA512:
6
- metadata.gz: 9d72611c6332311f5d55438a42756620ffb2c44cd01fc77ef797022ea7500b5b84023a0791ef50ce9200eb06bebeecbfb2f765a5f65d0aec18b92d0190b2cabc
7
- data.tar.gz: 3c97621b2c26f4f546e09d2d82d99f65a78149156dbea3c3bb17ac70664125ea90c958a95f63bb0c686f25300ecd60f4bce92544c1188a62428f479e93918945
6
+ metadata.gz: 521869a7aca148cc53a0fd64f05c7563d4065989cd0332c4ec5ec7a0ecbc36554b3acd085349385c76aebd78e701f3b07ebf76ade0682057a3faca0145420263
7
+ data.tar.gz: d673f02a4c9e275697021e7cb99d88829454d4fc1659c0c2369c6780ad8ac2ccb67bf2488a696df549a89539d31d84235e4cff17df0f7613711a86f5184446eb
@@ -1,3 +1,9 @@
1
+ ## v0.3.1 - 2020-02-11
2
+
3
+ * Ruby 2.6 & 2.7 support (no changes required)
4
+ * Rails 6 support ([@mayordwells](https://github.com/mayordwells))
5
+ * Add support for `update`/`update!` Active Record methods ([@tbk303](https://github.com/tbk303))
6
+
1
7
  ## v0.3.0 - 2018-09-08
2
8
 
3
9
  * Update I18n dependency to require >= 0.7, allowing to install more recent versions ([@nazarhussain](https://github.com/nazarhussain))
@@ -20,7 +20,7 @@ module I18n
20
20
 
21
21
  included do
22
22
  class_attribute :localized_methods,
23
- :instance_reader => false, :instance_writer => false
23
+ instance_reader: false, instance_writer: false
24
24
  self.localized_methods = {}
25
25
  end
26
26
 
@@ -17,6 +17,14 @@ module I18n
17
17
  @target.update_attributes!(parse_attributes(attributes))
18
18
  end
19
19
 
20
+ def update(attributes)
21
+ @target.update(parse_attributes(attributes))
22
+ end
23
+
24
+ def update!(attributes)
25
+ @target.update!(parse_attributes(attributes))
26
+ end
27
+
20
28
  def update_attribute(attribute, value)
21
29
  attributes = parse_attributes(attribute => value)
22
30
  @target.update_attribute(attribute, attributes.values.first)
@@ -28,7 +28,7 @@ module I18n
28
28
  end
29
29
 
30
30
  def i18n_format
31
- I18n.t(:default, :scope => [i18n_scope, :formats])
31
+ I18n.t(:default, scope: [i18n_scope, :formats])
32
32
  end
33
33
 
34
34
  def i18n_scope
@@ -34,7 +34,7 @@ module I18n
34
34
  end
35
35
 
36
36
  def translate(key)
37
- I18n.t(key, :scope => :"number.format")
37
+ I18n.t(key, scope: :"number.format")
38
38
  end
39
39
 
40
40
  def valid_for_localization?(value)
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Alchemy
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -3,13 +3,13 @@ require "action_pack"
3
3
 
4
4
  class ActionViewTest < I18n::Alchemy::TestCase
5
5
  def setup
6
- @template = ActionView::Base.new
6
+ @template = ActionView::Base.respond_to?(:empty) ? ActionView::Base.empty : ActionView::Base.new
7
7
  @product = Product.new(
8
- :name => "Potato",
9
- :quantity => 10,
10
- :price => 1.99,
11
- :released_at => Date.new(2011, 2, 28),
12
- :last_sale_at => Time.mktime(2011, 2, 28, 13, 25, 30)
8
+ name: "Potato",
9
+ quantity: 10,
10
+ price: 1.99,
11
+ released_at: Date.new(2011, 2, 28),
12
+ last_sale_at: Time.mktime(2011, 2, 28, 13, 25, 30)
13
13
  )
14
14
  @localized = @product.localized
15
15
 
@@ -48,7 +48,7 @@ class ActionViewTest < I18n::Alchemy::TestCase
48
48
  assert_includes [
49
49
  text_input_sorted_attributes(attribute, value),
50
50
  text_input_unsorted_attributes(attribute, value)
51
- ], @template.text_field(:product, attribute, :object => @localized)
51
+ ], @template.text_field(:product, attribute, object: @localized)
52
52
  end
53
53
 
54
54
  def text_input_sorted_attributes(attribute_name, value)
@@ -3,12 +3,12 @@ module MyCustomDateParser
3
3
  extend self
4
4
 
5
5
  def localize(value)
6
- I18n.localize value, :format => :custom
6
+ I18n.localize value, format: :custom
7
7
  end
8
8
 
9
9
  protected
10
10
 
11
11
  def i18n_format
12
- I18n.t(:custom, :scope => [:date, :formats])
12
+ I18n.t(:custom, scope: [:date, :formats])
13
13
  end
14
14
  end
@@ -1,6 +1,6 @@
1
1
  ActiveRecord::Base.establish_connection(
2
- :adapter => "sqlite3",
3
- :database => ":memory:"
2
+ adapter: "sqlite3",
3
+ database: ":memory:"
4
4
  )
5
5
 
6
6
  ActiveRecord::Schema.define do
@@ -4,7 +4,7 @@ class ProxyAttributesParsingTest < I18n::Alchemy::ProxyTestCase
4
4
  # Attributes
5
5
  def test_initializes_proxy_with_attributes
6
6
  @localized = @product.localized(
7
- :name => "Banana", :price => "0,99", :released_at => "28/02/2011")
7
+ name: "Banana", price: "0,99", released_at: "28/02/2011")
8
8
 
9
9
  assert_equal 0.99, @product.price
10
10
  assert_equal "0,99", @localized.price
@@ -14,7 +14,7 @@ class ProxyAttributesParsingTest < I18n::Alchemy::ProxyTestCase
14
14
  end
15
15
 
16
16
  def test_assign_attributes
17
- @localized.assign_attributes(:price => '1,99')
17
+ @localized.assign_attributes(price: '1,99')
18
18
  assert_equal "1,99", @localized.price
19
19
  end
20
20
 
@@ -31,7 +31,7 @@ class ProxyAttributesParsingTest < I18n::Alchemy::ProxyTestCase
31
31
  end
32
32
 
33
33
  def test_attributes_assignment
34
- @localized.attributes = { :price => '1,99' }
34
+ @localized.attributes = { price: '1,99' }
35
35
  assert_equal "1,99", @localized.price
36
36
  end
37
37
 
@@ -41,30 +41,46 @@ class ProxyAttributesParsingTest < I18n::Alchemy::ProxyTestCase
41
41
  end
42
42
  end
43
43
 
44
- def test_update_attributes
45
- @localized.update_attributes(:price => '2,88')
44
+ def test_update
45
+ @localized.update(price: '2,88')
46
46
  assert_equal '2,88', @localized.price
47
47
  assert_equal 2.88, @product.reload.price
48
48
  end
49
49
 
50
- def test_update_attributes_does_not_change_given_attributes_hash
50
+ def test_update_does_not_change_given_attributes_hash
51
51
  assert_attributes_hash_is_unchanged do |attributes|
52
- @localized.update_attributes(attributes)
52
+ @localized.update(attributes)
53
53
  end
54
54
  end
55
55
 
56
- def test_update_attributes!
57
- @localized.update_attributes!(:price => '2,88')
56
+ def test_update_attributes
57
+ silence_deprecations {
58
+ @localized.update_attributes(price: '2,88')
59
+ }
60
+ assert_equal '2,88', @localized.price
61
+ assert_equal 2.88, @product.reload.price
62
+ end
63
+
64
+ def test_update!
65
+ @localized.update!(price: '2,88')
58
66
  assert_equal '2,88', @localized.price
59
67
  assert_equal 2.88, @product.reload.price
60
68
  end
61
69
 
62
- def test_update_attributes_bang_does_not_change_given_attributes_hash
70
+ def test_update_bang_does_not_change_given_attributes_hash
63
71
  assert_attributes_hash_is_unchanged do |attributes|
64
- @localized.update_attributes!(attributes)
72
+ @localized.update!(attributes)
65
73
  end
66
74
  end
67
75
 
76
+ def test_update_attributes!
77
+ silence_deprecations {
78
+ @localized.update_attributes!(price: '2,88')
79
+ }
80
+ assert_equal '2,88', @localized.price
81
+ assert_equal 2.88, @product.reload.price
82
+ end
83
+
68
84
  def test_update_attribute
69
85
  @localized.update_attribute(:price, '2,88')
70
86
  assert_equal '2,88', @localized.price
@@ -73,40 +89,40 @@ class ProxyAttributesParsingTest < I18n::Alchemy::ProxyTestCase
73
89
 
74
90
  # Nested Attributes
75
91
  def test_should_assign_for_nested_attributes_for_collection_association
76
- @supplier_localized.assign_attributes(:products_attributes => [{:price => '1,99'}, {:price => '2,93'}])
92
+ @supplier_localized.assign_attributes(products_attributes: [{ price: '1,99' }, { price: '2,93' }])
77
93
  assert_equal 2, @supplier_localized.products.size
78
94
  assert_equal '1,99', @supplier_localized.products.first.localized.price
79
95
  assert_equal '2,93', @supplier_localized.products.last.localized.price
80
96
  end
81
97
 
82
98
  def test_should_assign_for_nested_attributes_passing_a_hash_for_collection_with_unique_keys
83
- @supplier_localized.assign_attributes(:products_attributes => {"0" => {:price => '2,93', "_destroy"=>"false"}, "1" => {:price => '2,85', "_destroy" => "false"}})
99
+ @supplier_localized.assign_attributes(products_attributes: { '0' => { price: '2,93', _destroy: 'false' }, '1' => { price: '2,85', _destroy: 'false' }})
84
100
  prices = @supplier.products.map { |p| p.localized.price }.sort
85
101
  assert_equal ['2,85', '2,93'], prices
86
102
  end
87
103
 
88
104
  def test_should_assign_for_nested_attributes_for_one_to_one_association
89
- @supplier_localized.assign_attributes(:account_attributes => {:account_number => 10, :total_money => '100,87'})
105
+ @supplier_localized.assign_attributes(account_attributes: { account_number: 10, total_money: '100,87' })
90
106
  account = @supplier_localized.account
91
107
  assert_equal '10', account.account_number.to_s
92
108
  assert_equal '100,87', account.localized.total_money
93
109
  end
94
110
 
95
- def test_update_attributes_for_nested_attributes
96
- @supplier_localized.update_attributes(:account_attributes => {:total_money => '99,87'})
111
+ def test_update_for_nested_attributes
112
+ @supplier_localized.update(account_attributes: { total_money: '99,87' })
97
113
  assert_equal '99,87', @supplier_localized.account.localized.total_money
98
114
  end
99
115
 
100
116
  def test_attributes_assignment_for_nested
101
- @supplier_localized.attributes = {:account_attributes => {:total_money => '88,12'}}
117
+ @supplier_localized.attributes = { account_attributes: { total_money: '88,12' }}
102
118
  assert_equal '88,12', @supplier_localized.account.localized.total_money
103
119
  end
104
120
 
105
121
  private
106
122
 
107
123
  def assert_attributes_hash_is_unchanged
108
- attributes = { :quantity => 1 }
124
+ attributes = { quantity: 1 }
109
125
  yield attributes
110
- assert_equal({ :quantity => 1 }, attributes)
126
+ assert_equal({ quantity: 1 }, attributes)
111
127
  end
112
128
  end
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class ProxyTest < I18n::Alchemy::ProxyTestCase
4
4
  def test_delegates_orm_methods_to_target_object
5
5
  assert @product.new_record?
6
- assert @localized.save!(:name => "foo", :price => 1.99)
6
+ assert @localized.save!(name: "foo", price: 1.99)
7
7
  assert !@product.new_record?
8
8
  end
9
9
 
@@ -1,9 +1,9 @@
1
1
  class Product < ActiveRecord::Base
2
2
  include I18n::Alchemy
3
- localize :total, :using => :number
4
- localize :estimated_delivery_at, :using => :date
5
- localize :estimated_last_comission_payment_at, :using => :timestamp
6
- localize :released_month, :using => MyCustomDateParser
3
+ localize :total, using: :number
4
+ localize :estimated_delivery_at, using: :date
5
+ localize :estimated_last_comission_payment_at, using: :timestamp
6
+ localize :released_month, using: MyCustomDateParser
7
7
 
8
8
  belongs_to :supplier
9
9
 
@@ -9,5 +9,5 @@ class Supplier < ActiveRecord::Base
9
9
  end
10
10
 
11
11
  class AnotherSupplier < Supplier
12
- localize :created_at, :using => :timestamp
12
+ localize :created_at, using: :timestamp
13
13
  end
@@ -2,5 +2,5 @@ class User
2
2
  include I18n::Alchemy
3
3
  attr_accessor :created_at
4
4
 
5
- localize :created_at, :using => :date
5
+ localize :created_at, using: :date
6
6
  end
@@ -49,5 +49,15 @@ module I18n::Alchemy
49
49
  def teardown
50
50
  I18n.locale = :en
51
51
  end
52
+
53
+ private
54
+
55
+ def silence_deprecations
56
+ old_silenced = ActiveSupport::Deprecation.silenced
57
+ ActiveSupport::Deprecation.silenced = true
58
+ yield
59
+ ensure
60
+ ActiveSupport::Deprecation.silenced = old_silenced
61
+ end
52
62
  end
53
63
  end
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.3.0
4
+ version: 0.3.1
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: 2018-09-08 00:00:00.000000000 Z
11
+ date: 2020-02-11 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: 4.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 5.3.0
22
+ version: '6.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 4.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 5.3.0
32
+ version: '6.1'
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: 4.0.0
54
54
  - - "<"
55
55
  - !ruby/object:Gem::Version
56
- version: 5.3.0
56
+ version: '6.1'
57
57
  type: :development
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -63,7 +63,7 @@ dependencies:
63
63
  version: 4.0.0
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
- version: 5.3.0
66
+ version: '6.1'
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: 4.0.0
74
74
  - - "<"
75
75
  - !ruby/object:Gem::Version
76
- version: 5.3.0
76
+ version: '6.1'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
@@ -83,7 +83,7 @@ dependencies:
83
83
  version: 4.0.0
84
84
  - - "<"
85
85
  - !ruby/object:Gem::Version
86
- version: 5.3.0
86
+ version: '6.1'
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: minitest
89
89
  requirement: !ruby/object:Gem::Requirement
@@ -102,14 +102,14 @@ dependencies:
102
102
  name: rake
103
103
  requirement: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - "~>"
105
+ - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: '10.1'
108
108
  type: :development
109
109
  prerelease: false
110
110
  version_requirements: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - "~>"
112
+ - - ">="
113
113
  - !ruby/object:Gem::Version
114
114
  version: '10.1'
115
115
  description: I18n date/number parsing/localization
@@ -167,8 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubyforge_project: i18n_alchemy
171
- rubygems_version: 2.7.6
170
+ rubygems_version: 3.0.3
172
171
  signing_key:
173
172
  specification_version: 4
174
173
  summary: I18n date/number parsing/localization