money-rails 1.13.1 → 1.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4aaf2a0c37bb46472539f30ec9c60f868ffd3ec
4
- data.tar.gz: cdc46c11f65bf4d28afe78dee2de672e66246c2b
3
+ metadata.gz: afde9881744906b6e1095808941f25c35882a6cf
4
+ data.tar.gz: 8124dc1db10118638c59fbd573d5169a10c856a7
5
5
  SHA512:
6
- metadata.gz: e79213ea0c3c9aab5563ae75984e6639045ae87fc6c9a63728482a93f8de6988a1f349a06dc36c71dcd5559dea9a718ba3ac579fd790a429991aca9b49bd4007
7
- data.tar.gz: 92021999f49f2e24efa5cfba40ed18b0d9714dc2c2bb0c8df171aeec295b4cb31a5f94668de55a4a504fac88707aff31155e239c562ccda420177d552628a886
6
+ metadata.gz: db46b687d7785a6003671c6303256b67a7e97f8eba7ae56ef80839a3b0bd09ec8b01b12131e1cf959066b3b59c31d9812fcd3ab31a551a926f83335909c0458b
7
+ data.tar.gz: d40ce1a07d6a8af402c61336b999d8bb41460ec1802df4016fe915613be1e41c6ede7fef65ec8bc711e15b0983dd8a661466a8401e29b15ee581f6734fffb0fe
@@ -1,11 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.13.2
4
+
5
+ - Make validation compatible with Money.locale_backend
6
+
3
7
  ## 1.13.1
4
8
 
5
- Add a guard clause for "blank form" input (Mongoid)
6
- Do not add extra errors in case attribute is not a number
7
- Use Money.locale_backend instead of Money.use_i18n
8
- Add money_only_cents helper method
9
+ - Add a guard clause for "blank form" input (Mongoid)
10
+ - Do not add extra errors in case attribute is not a number
11
+ - Use Money.locale_backend instead of Money.use_i18n
12
+ - Add money_only_cents helper method
9
13
 
10
14
  ## 1.13.0
11
15
 
@@ -43,6 +43,11 @@ module MoneyRails
43
43
 
44
44
  private
45
45
 
46
+ DEFAULTS = {
47
+ decimal_mark: '.',
48
+ thousands_separator: ','
49
+ }.freeze
50
+
46
51
  def record_does_not_have_error?
47
52
  !@record.errors.added?(@attr, :not_a_number, value: @raw_value)
48
53
  end
@@ -60,21 +65,17 @@ module MoneyRails
60
65
  end
61
66
 
62
67
  def decimal_mark
63
- character = currency.decimal_mark || '.'
64
- @_decimal_mark ||= use_backend_locale? ? I18n.t('number.currency.format.separator', default: character) : character
68
+ @_decimal_mark ||= lookup(:decimal_mark)
65
69
  end
66
70
 
67
71
  def thousands_separator
68
- character = currency.thousands_separator || ','
69
- @_thousands_separator ||= use_backend_locale? ? I18n.t('number.currency.format.delimiter', default: character) : character
72
+ @_thousands_separator ||= lookup(:thousands_separator)
70
73
  end
71
74
 
75
+ # TODO: This is supporting legacy behaviour where a symbol can come from a i18n locale,
76
+ # however practical implications of that are most likely non-existent
72
77
  def symbol
73
- @_symbol ||= use_backend_locale? ? I18n.t('number.currency.format.unit', default: currency.symbol) : currency.symbol
74
- end
75
-
76
- def use_backend_locale?
77
- Money.locale_backend.present? || Money.use_i18n
78
+ @_symbol ||= lookup(:symbol) || currency.symbol
78
79
  end
79
80
 
80
81
  def abs_raw_value
@@ -128,6 +129,18 @@ module MoneyRails
128
129
  .gsub(decimal_mark, '.')
129
130
  .gsub(/[\s_]/, '')
130
131
  end
132
+
133
+ def lookup(key)
134
+ if locale_backend
135
+ locale_backend.lookup(key, currency) || DEFAULTS[key]
136
+ else
137
+ DEFAULTS[key]
138
+ end
139
+ end
140
+
141
+ def locale_backend
142
+ Money.locale_backend
143
+ end
131
144
  end
132
145
  end
133
146
  end
@@ -7,7 +7,6 @@ module MoneyRails
7
7
  # MoneyRails configuration module.
8
8
  # This is extended by MoneyRails to provide configuration settings.
9
9
  module Configuration
10
-
11
10
  # Start a MoneyRails configuration block in an initializer.
12
11
  #
13
12
  # example: Provide a default currency for the application
@@ -59,7 +58,7 @@ module MoneyRails
59
58
  # MoneyRails.configure do |config|
60
59
  # config.default_bank = EuCentralBank.new
61
60
  # end
62
- delegate :default_bank=, :default_bank, to: :Money
61
+ delegate :default_bank=, :default_bank, :locale_backend, :locale_backend=, to: :Money
63
62
 
64
63
  # Provide exchange rates
65
64
  delegate :add_rate, to: :Money
@@ -2,7 +2,7 @@ require "active_support/core_ext/module/aliasing.rb"
2
2
  require "active_support/core_ext/hash/reverse_merge.rb"
3
3
 
4
4
  class Money
5
- class <<self
5
+ class << self
6
6
  alias_method :orig_default_formatting_rules, :default_formatting_rules
7
7
 
8
8
  def default_formatting_rules
@@ -1,3 +1,3 @@
1
1
  module MoneyRails
2
- VERSION = '1.13.1'
2
+ VERSION = '1.13.2'
3
3
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
 
27
27
  s.require_path = "lib"
28
28
 
29
- s.add_dependency "money", "~> 6.13.0"
29
+ s.add_dependency "money", "~> 6.13.2"
30
30
  s.add_dependency "monetize", "~> 1.9.0"
31
31
  s.add_dependency "activesupport", ">= 3.0"
32
32
  s.add_dependency "railties", ">= 3.0"
@@ -738,6 +738,8 @@ if defined? ActiveRecord
738
738
  end
739
739
  end
740
740
 
741
+ # TODO: these specs should mock locale_backend with expected values
742
+ # instead of manipulating it directly
741
743
  context "and an Italian locale" do
742
744
  around(:each) do |example|
743
745
  I18n.with_locale(:it) do
@@ -745,7 +747,7 @@ if defined? ActiveRecord
745
747
  end
746
748
  end
747
749
 
748
- context "when use_i18n is true" do
750
+ context "when using :i18n locale backend" do
749
751
  it "validates with the locale's decimal mark" do
750
752
  transaction.amount = "123,45"
751
753
  expect(transaction.valid?).to be_truthy
@@ -767,46 +769,13 @@ if defined? ActiveRecord
767
769
  end
768
770
  end
769
771
 
770
- context "when locale_backend is true" do
772
+ context "when using :currency locale backend" do
771
773
  around(:each) do |example|
772
774
  begin
773
- Money.locale_backend = :i18n
774
- Money.use_i18n = false
775
+ Money.locale_backend = :currency
775
776
  example.run
776
777
  ensure
777
- Money.locale_backend = nil
778
- Money.use_i18n = true
779
- end
780
- end
781
- it "validates with the locale's decimal mark" do
782
- transaction.amount = "123,45"
783
- expect(transaction.valid?).to be_truthy
784
- end
785
-
786
- it "does not validate with the currency's decimal mark" do
787
- transaction.amount = "123.45"
788
- expect(transaction.valid?).to be_falsey
789
- end
790
-
791
- it "validates with the locale's currency symbol" do
792
- transaction.amount = "€123"
793
- expect(transaction.valid?).to be_truthy
794
- end
795
-
796
- it "does not validate with the transaction's currency symbol" do
797
- transaction.amount = "$123.45"
798
- expect(transaction.valid?).to be_falsey
799
- end
800
- end
801
-
802
- context "when use_i18n is false" do
803
- around(:each) do |example|
804
- begin
805
- Money.locale_backend = nil
806
- Money.use_i18n = false
807
- example.run
808
- ensure
809
- Money.use_i18n = true
778
+ Money.locale_backend = :i18n
810
779
  end
811
780
  end
812
781
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.1
4
+ version: 1.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Loupasakis
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-01-09 00:00:00.000000000 Z
13
+ date: 2019-04-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: money
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 6.13.0
21
+ version: 6.13.2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: 6.13.0
28
+ version: 6.13.2
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: monetize
31
31
  requirement: !ruby/object:Gem::Requirement