money-rails 1.6.0 → 1.6.1
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 +8 -0
- data/README.md +1 -1
- data/lib/money-rails/active_record/monetizable.rb +24 -14
- data/lib/money-rails/helpers/action_view_extension.rb +13 -9
- data/lib/money-rails/version.rb +1 -1
- data/money-rails.gemspec +1 -0
- data/spec/active_record/monetizable_spec.rb +16 -0
- data/spec/helpers/action_view_extension_spec.rb +16 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a8e694d77fe73ebc1b806d1aeb709f74c5e25c2
|
4
|
+
data.tar.gz: 2ed6d897d12f3ff13a08379e97404a9bfe54568f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de46c3822927fd875d5a7fdf8a778562fe501d7837d50ae746b035205f1463782672f6d32ede43271fb34fbf312770183354493d99e57cf2b8e027d7fccd7673
|
7
|
+
data.tar.gz: e3dee272257eaf62e7b631d2486d9bd2ae9ba9c6dfd0c3c04a0ff5e750b747a15a5acdc8544693c264983a220a66c9b034640eb1819fbe2e51ecbe6867c8fc0d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.6.1
|
4
|
+
|
5
|
+
- View helper now respects currency decimal mark and thousands separator
|
6
|
+
- Fix error when monetizing with attribute's name
|
7
|
+
- Fix mime-types dependency issue with ruby 1.9
|
8
|
+
- Fix issue with gem not updating automatically inferred currency column
|
9
|
+
|
3
10
|
## 1.6.0
|
4
11
|
|
5
12
|
- Update Money and Monetize gem reqs.
|
@@ -15,6 +22,7 @@
|
|
15
22
|
- validator was looking for monetizable_attributes using a symbol key, when the keys are all strings. Asserted string key values in rspec and changed validator to look for a string key.
|
16
23
|
- make monetized_attribute hash comparison order independent
|
17
24
|
- Isolate class used for the monetized_attributes tests to prevent cross-contamination
|
25
|
+
- rename `format_with_settings` method to `format`
|
18
26
|
- add gem tasks
|
19
27
|
|
20
28
|
## 1.4.0
|
data/README.md
CHANGED
@@ -455,7 +455,7 @@ So `humanized_money` will ignore `config.default_format = { no_cents_if_whole: f
|
|
455
455
|
|
456
456
|
### Testing
|
457
457
|
|
458
|
-
If you use Rspec there is
|
458
|
+
If you use Rspec there is a test helper implementation.
|
459
459
|
Just write `require "money-rails/test_helpers"` in spec_helper.rb.
|
460
460
|
|
461
461
|
* the `monetize` matcher
|
@@ -32,19 +32,6 @@ module MoneyRails
|
|
32
32
|
":with_currency or :with_model_currency")
|
33
33
|
end
|
34
34
|
|
35
|
-
# Optional accessor to be run on an instance to detect currency
|
36
|
-
instance_currency_name = options[:with_model_currency] ||
|
37
|
-
options[:model_currency] ||
|
38
|
-
MoneyRails::Configuration.currency_column[:column_name]
|
39
|
-
|
40
|
-
instance_currency_name = instance_currency_name &&
|
41
|
-
instance_currency_name.to_s
|
42
|
-
|
43
|
-
# This attribute allows per column currency values
|
44
|
-
# Overrides row and default currency
|
45
|
-
field_currency_name = options[:with_currency] ||
|
46
|
-
options[:field_currency] || nil
|
47
|
-
|
48
35
|
name = options[:as] || options[:target_name] || nil
|
49
36
|
|
50
37
|
# Form target name for the money backed ActiveModel field:
|
@@ -53,6 +40,13 @@ module MoneyRails
|
|
53
40
|
# if none of the previous is the case then use a default suffix
|
54
41
|
if name
|
55
42
|
name = name.to_s
|
43
|
+
|
44
|
+
# Check if the options[:as] parameter is not the same as subunit_name
|
45
|
+
# which would result in stack overflow
|
46
|
+
if name == subunit_name
|
47
|
+
raise ArgumentError, "monetizable attribute name cannot be the same as options[:as] parameter"
|
48
|
+
end
|
49
|
+
|
56
50
|
elsif subunit_name =~ /#{MoneyRails::Configuration.amount_column[:postfix]}$/
|
57
51
|
name = subunit_name.sub(/#{MoneyRails::Configuration.amount_column[:postfix]}$/, "")
|
58
52
|
else
|
@@ -60,6 +54,23 @@ module MoneyRails
|
|
60
54
|
name = [subunit_name, "money"].join("_")
|
61
55
|
end
|
62
56
|
|
57
|
+
# Optional accessor to be run on an instance to detect currency
|
58
|
+
instance_currency_name = options[:with_model_currency] ||
|
59
|
+
options[:model_currency] ||
|
60
|
+
MoneyRails::Configuration.currency_column[:column_name]
|
61
|
+
|
62
|
+
# Infer currency column from name and postfix
|
63
|
+
if !instance_currency_name && MoneyRails::Configuration.currency_column[:postfix].present?
|
64
|
+
instance_currency_name = "#{name}#{MoneyRails::Configuration.currency_column[:postfix]}"
|
65
|
+
end
|
66
|
+
|
67
|
+
instance_currency_name = instance_currency_name && instance_currency_name.to_s
|
68
|
+
|
69
|
+
# This attribute allows per column currency values
|
70
|
+
# Overrides row and default currency
|
71
|
+
field_currency_name = options[:with_currency] ||
|
72
|
+
options[:field_currency] || nil
|
73
|
+
|
63
74
|
# Create a reverse mapping of the monetized attributes
|
64
75
|
track_monetized_attribute name, subunit_name
|
65
76
|
|
@@ -104,7 +115,6 @@ module MoneyRails
|
|
104
115
|
end
|
105
116
|
end
|
106
117
|
|
107
|
-
|
108
118
|
define_method name do |*args|
|
109
119
|
|
110
120
|
# Get the cents
|
@@ -11,19 +11,23 @@ module MoneyRails
|
|
11
11
|
options = { :symbol => options }
|
12
12
|
end
|
13
13
|
|
14
|
+
unless value.is_a?(Money)
|
15
|
+
if value.respond_to?(:to_money)
|
16
|
+
value = value.to_money
|
17
|
+
else
|
18
|
+
return ''
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
14
22
|
options = {
|
15
|
-
:no_cents_if_whole
|
16
|
-
:symbol
|
23
|
+
:no_cents_if_whole => MoneyRails::Configuration.no_cents_if_whole.nil? ? true : MoneyRails::Configuration.no_cents_if_whole,
|
24
|
+
:symbol => false,
|
25
|
+
:decimal_mark => value.currency.decimal_mark,
|
26
|
+
:thousands_separator => value.currency.thousands_separator
|
17
27
|
}.merge(options)
|
18
28
|
options.delete(:symbol) if options[:disambiguate]
|
19
29
|
|
20
|
-
|
21
|
-
value.format(options)
|
22
|
-
elsif value.respond_to?(:to_money)
|
23
|
-
value.to_money.format(options)
|
24
|
-
else
|
25
|
-
""
|
26
|
-
end
|
30
|
+
value.format(options)
|
27
31
|
end
|
28
32
|
|
29
33
|
def humanized_money_with_symbol(value, options={})
|
data/lib/money-rails/version.rb
CHANGED
data/money-rails.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.add_dependency "monetize", "~> 1.4.0"
|
31
31
|
s.add_dependency "activesupport", ">= 3.0"
|
32
32
|
s.add_dependency "railties", ">= 3.0"
|
33
|
+
s.add_dependency "mime-types", "< 3" if RUBY_VERSION < '2.0' # mime-types > 3 depends on mime-types-data, which doesn't support ruby 1.9
|
33
34
|
|
34
35
|
s.add_development_dependency "rails", ">= 3.0"
|
35
36
|
s.add_development_dependency "rspec-rails", "~> 3.0"
|
@@ -85,6 +85,14 @@ if defined? ActiveRecord
|
|
85
85
|
end.to raise_error ArgumentError
|
86
86
|
end
|
87
87
|
|
88
|
+
it "raises an error if Money object has the same attribute name as the monetizable attribute" do
|
89
|
+
expect do
|
90
|
+
class AnotherProduct < Product
|
91
|
+
monetize :price_cents, as: :price_cents
|
92
|
+
end
|
93
|
+
end.to raise_error ArgumentError
|
94
|
+
end
|
95
|
+
|
88
96
|
it "allows subclass to redefine attribute with the same name" do
|
89
97
|
class SubProduct < Product
|
90
98
|
monetize :discount, as: :discount_price, with_currency: :gbp
|
@@ -690,6 +698,14 @@ if defined? ActiveRecord
|
|
690
698
|
expect(dummy_product_with_nil_currency.price.currency).to eq(Money::Currency.find(:gbp))
|
691
699
|
end
|
692
700
|
|
701
|
+
it "updates inferred currency column based on currency column postfix" do
|
702
|
+
product.reduced_price = Money.new(999_00, 'CAD')
|
703
|
+
product.save
|
704
|
+
|
705
|
+
expect(product.reduced_price_cents).to eq(999_00)
|
706
|
+
expect(product.reduced_price_currency).to eq('CAD')
|
707
|
+
end
|
708
|
+
|
693
709
|
context "and field with allow_nil: true" do
|
694
710
|
it "doesn't set currency to nil when setting the field to nil" do
|
695
711
|
t = Transaction.new(:amount_cents => 2500, :currency => "CAD")
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'MoneyRails::ActionViewExtension', :type => :helper do
|
@@ -44,10 +46,18 @@ describe 'MoneyRails::ActionViewExtension', :type => :helper do
|
|
44
46
|
end
|
45
47
|
|
46
48
|
describe '#humanized_money_with_symbol' do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
let(:amount) { 125_010 }
|
50
|
+
let(:expected_values) { {
|
51
|
+
:eur => '€1.250,10',
|
52
|
+
:usd => '$1,250.10',
|
53
|
+
:sek => '1 250,10 kr'
|
54
|
+
} }
|
55
|
+
|
56
|
+
it 'returns the correctly formatted values' do
|
57
|
+
expected_values.each do |currency, result|
|
58
|
+
expect(helper.humanized_money_with_symbol(Money.new(amount, currency))).to eq result
|
59
|
+
end
|
60
|
+
end
|
51
61
|
end
|
52
62
|
|
53
63
|
describe '#money_without_cents' do
|
@@ -86,7 +96,7 @@ describe 'MoneyRails::ActionViewExtension', :type => :helper do
|
|
86
96
|
describe '#humanized_money' do
|
87
97
|
subject { helper.humanized_money Money.new(12500) }
|
88
98
|
it { is_expected.to be_a String }
|
89
|
-
it { is_expected.
|
99
|
+
it { is_expected.to include Money.default_currency.decimal_mark }
|
90
100
|
it { is_expected.not_to include Money.default_currency.symbol }
|
91
101
|
it { is_expected.to include "00" }
|
92
102
|
end
|
@@ -94,7 +104,7 @@ describe 'MoneyRails::ActionViewExtension', :type => :helper do
|
|
94
104
|
describe '#humanized_money_with_symbol' do
|
95
105
|
subject { helper.humanized_money_with_symbol Money.new(12500) }
|
96
106
|
it { is_expected.to be_a String }
|
97
|
-
it { is_expected.
|
107
|
+
it { is_expected.to include Money.default_currency.decimal_mark }
|
98
108
|
it { is_expected.to include Money.default_currency.symbol }
|
99
109
|
it { is_expected.to include "00" }
|
100
110
|
end
|
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.6.
|
4
|
+
version: 1.6.1
|
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: 2016-
|
13
|
+
date: 2016-05-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: money
|
@@ -251,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
251
|
version: '0'
|
252
252
|
requirements: []
|
253
253
|
rubyforge_project:
|
254
|
-
rubygems_version: 2.
|
254
|
+
rubygems_version: 2.5.1
|
255
255
|
signing_key:
|
256
256
|
specification_version: 4
|
257
257
|
summary: Money gem integration with Rails
|