money-rails 1.10.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +33 -26
  4. data/Rakefile +6 -6
  5. data/lib/generators/templates/money.rb +12 -12
  6. data/lib/money-rails/active_model/validator.rb +11 -6
  7. data/lib/money-rails/active_record/monetizable.rb +12 -12
  8. data/lib/money-rails/configuration.rb +2 -2
  9. data/lib/money-rails/helpers/action_view_extension.rb +12 -12
  10. data/lib/money-rails/money.rb +14 -16
  11. data/lib/money-rails/mongoid/money.rb +2 -2
  12. data/lib/money-rails/mongoid/two.rb +2 -2
  13. data/lib/money-rails/test_helpers.rb +20 -6
  14. data/lib/money-rails/version.rb +1 -1
  15. data/money-rails.gemspec +1 -1
  16. data/spec/active_record/monetizable_spec.rb +46 -40
  17. data/spec/configuration_spec.rb +2 -2
  18. data/spec/dummy/app/models/dummy_product.rb +1 -1
  19. data/spec/dummy/app/models/priceable.rb +2 -2
  20. data/spec/dummy/app/models/product.rb +24 -22
  21. data/spec/dummy/app/models/service.rb +1 -1
  22. data/spec/dummy/app/models/transaction.rb +4 -4
  23. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  24. data/spec/dummy/config/initializers/money.rb +9 -9
  25. data/spec/dummy/config/initializers/session_store.rb +1 -1
  26. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
  27. data/spec/dummy/db/migrate/20120712202655_add_sale_price_cents_to_product.rb +1 -1
  28. data/spec/helpers/action_view_extension_spec.rb +4 -4
  29. data/spec/helpers/form_helper_spec.rb +4 -4
  30. data/spec/mongoid/five_spec.rb +13 -13
  31. data/spec/mongoid/four_spec.rb +14 -14
  32. data/spec/mongoid/three_spec.rb +14 -14
  33. data/spec/mongoid/two_spec.rb +7 -7
  34. data/spec/test_helpers_spec.rb +11 -3
  35. metadata +4 -4
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -5,7 +5,7 @@
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters :format => [:json]
8
+ wrap_parameters format: [:json]
9
9
  end
10
10
 
11
11
  # Disable root element in JSON by default.
@@ -1,7 +1,7 @@
1
1
  class AddSalePriceCentsToProduct < (Rails::VERSION::MAJOR >= 5 ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration)
2
2
  def change
3
3
  add_column :products, :sale_price_amount, :integer,
4
- :default => 0, :null => false
4
+ default: 0, null: false
5
5
  add_column :products, :sale_price_currency_code, :string
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'MoneyRails::ActionViewExtension', :type => :helper do
3
+ describe 'MoneyRails::ActionViewExtension', type: :helper do
4
4
  describe '#currency_symbol' do
5
5
  subject { helper.currency_symbol }
6
6
  it { is_expected.to be_a String }
@@ -16,7 +16,7 @@ describe 'MoneyRails::ActionViewExtension', :type => :helper do
16
16
  it { is_expected.not_to include Money.default_currency.decimal_mark }
17
17
 
18
18
  context 'with symbol options' do
19
- let(:options) { { :symbol => true } }
19
+ let(:options) { { symbol: true } }
20
20
  it { is_expected.to include Money.default_currency.symbol }
21
21
  end
22
22
 
@@ -32,11 +32,11 @@ describe 'MoneyRails::ActionViewExtension', :type => :helper do
32
32
  let(:money_object) { Money.new(125_00, 'SGD') }
33
33
 
34
34
  context 'with symbol options' do
35
- let(:options) { { :symbol => true } }
35
+ let(:options) { { symbol: true } }
36
36
  it { is_expected.to include Money::Currency.new(:sgd).symbol }
37
37
 
38
38
  context 'with disambiguate options' do
39
- let(:options) { { :symbol => true, :disambiguate => true } }
39
+ let(:options) { { symbol: true, disambiguate: true } }
40
40
  it { is_expected.to include Money::Currency.new(:sgd).disambiguate_symbol }
41
41
  end
42
42
  end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  if defined? ActiveRecord
4
- describe "Test helper in form blocks", :type => :helper do
4
+ describe "Test helper in form blocks", type: :helper do
5
5
 
6
6
  let :product do
7
- Product.create(:price_cents => 3000, :discount => 150,
8
- :bonus_cents => 200, :optional_price => 100,
9
- :sale_price_amount => 1200)
7
+ Product.create(price_cents: 3000, discount: 150,
8
+ bonus_cents: 200, optional_price: 100,
9
+ sale_price_amount: 1200)
10
10
  end
11
11
 
12
12
  context "textfield" do
@@ -3,20 +3,20 @@ require 'spec_helper'
3
3
  if defined?(Mongoid) && ::Mongoid::VERSION =~ /^5(.*)/
4
4
 
5
5
  describe Money do
6
- let!(:priceable) { Priceable.create(:price => Money.new(100, 'EUR')) }
7
- let!(:priceable_from_num) { Priceable.create(:price => 1) }
8
- let!(:priceable_from_string) { Priceable.create(:price => '1 EUR' )}
9
- let!(:priceable_from_hash) { Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"} )}
6
+ let!(:priceable) { Priceable.create(price: Money.new(100, 'EUR')) }
7
+ let!(:priceable_from_num) { Priceable.create(price: 1) }
8
+ let!(:priceable_from_string) { Priceable.create(price: '1 EUR' )}
9
+ let!(:priceable_from_hash) { Priceable.create(price: {cents: 100, currency_iso: "EUR"} )}
10
10
  let!(:priceable_from_hash_with_indifferent_access) {
11
- Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"}.with_indifferent_access)
11
+ Priceable.create(price: {cents: 100, currency_iso: "EUR"}.with_indifferent_access)
12
12
  }
13
- let(:priceable_from_string_with_hyphen) { Priceable.create(:price => '1-2 EUR' )}
14
- let(:priceable_from_string_with_unknown_currency) { Priceable.create(:price => '1 TLDR') }
15
- let(:priceable_with_infinite_precision) { Priceable.create(:price => Money.new(BigDecimal.new('100.1'), 'EUR')) }
13
+ let(:priceable_from_string_with_hyphen) { Priceable.create(price: '1-2 EUR' )}
14
+ let(:priceable_from_string_with_unknown_currency) { Priceable.create(price: '1 TLDR') }
15
+ let(:priceable_with_infinite_precision) { Priceable.create(price: Money.new(BigDecimal.new('100.1'), 'EUR')) }
16
16
  let(:priceable_with_hash_field) {
17
- Priceable.create(:price_hash => {
18
- :key1 => Money.new(100, "EUR"),
19
- :key2 => Money.new(200, "USD")
17
+ Priceable.create(price_hash: {
18
+ key1: Money.new(100, "EUR"),
19
+ key2: Money.new(200, "USD")
20
20
  })
21
21
  }
22
22
 
@@ -103,14 +103,14 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^5(.*)/
103
103
  expect(nil_priceable.price.currency).to eq(Money.default_currency)
104
104
  end
105
105
  it 'returns nil if an unknown value was stored' do
106
- zero_priceable = Priceable.create(:price => [])
106
+ zero_priceable = Priceable.create(price: [])
107
107
  expect(zero_priceable.price).to be_nil
108
108
  end
109
109
  end
110
110
 
111
111
  context "evolve" do
112
112
  it "correctly transforms a Money object into a Mongo friendly value" do
113
- expect(Priceable.where(:price => Money.new(100, 'EUR')).first).to eq(priceable)
113
+ expect(Priceable.where(price: Money.new(100, 'EUR')).first).to eq(priceable)
114
114
  end
115
115
  end
116
116
  end
@@ -3,21 +3,21 @@ require 'spec_helper'
3
3
  if defined?(Mongoid) && ::Mongoid::VERSION =~ /^4(.*)/
4
4
 
5
5
  describe Money do
6
- let!(:priceable) { Priceable.create(:price => Money.new(100, 'EUR')) }
7
- let(:priceable_from_nil) { Priceable.create(:price => nil) }
8
- let(:priceable_from_num) { Priceable.create(:price => 1) }
9
- let(:priceable_from_string) { Priceable.create(:price => '1 EUR' )}
10
- let(:priceable_from_hash) { Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"} )}
6
+ let!(:priceable) { Priceable.create(price: Money.new(100, 'EUR')) }
7
+ let(:priceable_from_nil) { Priceable.create(price: nil) }
8
+ let(:priceable_from_num) { Priceable.create(price: 1) }
9
+ let(:priceable_from_string) { Priceable.create(price: '1 EUR' )}
10
+ let(:priceable_from_hash) { Priceable.create(price: {cents: 100, currency_iso: "EUR"} )}
11
11
  let(:priceable_from_hash_with_indifferent_access) {
12
- Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"}.with_indifferent_access)
12
+ Priceable.create(price: {cents: 100, currency_iso: "EUR"}.with_indifferent_access)
13
13
  }
14
- let(:priceable_from_string_with_hyphen) { Priceable.create(:price => '1-2 EUR' )}
15
- let(:priceable_from_string_with_unknown_currency) { Priceable.create(:price => '1 TLDR') }
16
- let(:priceable_with_infinite_precision) { Priceable.create(:price => Money.new(BigDecimal.new('100.1'), 'EUR')) }
14
+ let(:priceable_from_string_with_hyphen) { Priceable.create(price: '1-2 EUR' )}
15
+ let(:priceable_from_string_with_unknown_currency) { Priceable.create(price: '1 TLDR') }
16
+ let(:priceable_with_infinite_precision) { Priceable.create(price: Money.new(BigDecimal.new('100.1'), 'EUR')) }
17
17
  let(:priceable_with_hash_field) {
18
- Priceable.create(:price_hash => {
19
- :key1 => Money.new(100, "EUR"),
20
- :key2 => Money.new(200, "USD")
18
+ Priceable.create(price_hash: {
19
+ key1: Money.new(100, "EUR"),
20
+ key2: Money.new(200, "USD")
21
21
  })
22
22
  }
23
23
 
@@ -109,14 +109,14 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^4(.*)/
109
109
  end
110
110
 
111
111
  it 'returns nil if an unknown value was stored' do
112
- zero_priceable = Priceable.create(:price => [])
112
+ zero_priceable = Priceable.create(price: [])
113
113
  expect(zero_priceable.price).to be_nil
114
114
  end
115
115
  end
116
116
 
117
117
  context "evolve" do
118
118
  it "correctly transforms a Money object into a Mongo friendly value" do
119
- expect(Priceable.where(:price => Money.new(100, 'EUR')).first).to eq(priceable)
119
+ expect(Priceable.where(price: Money.new(100, 'EUR')).first).to eq(priceable)
120
120
  end
121
121
  end
122
122
  end
@@ -3,21 +3,21 @@ require 'spec_helper'
3
3
  if defined?(Mongoid) && ::Mongoid::VERSION =~ /^3(.*)/
4
4
 
5
5
  describe Money do
6
- let!(:priceable) { Priceable.create(:price => Money.new(100, 'EUR')) }
7
- let(:priceable_from_nil) { Priceable.create(:price => nil) }
8
- let(:priceable_from_num) { Priceable.create(:price => 1) }
9
- let(:priceable_from_string) { Priceable.create(:price => '1 EUR' )}
10
- let(:priceable_from_hash) { Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"} )}
6
+ let!(:priceable) { Priceable.create(price: Money.new(100, 'EUR')) }
7
+ let(:priceable_from_nil) { Priceable.create(price: nil) }
8
+ let(:priceable_from_num) { Priceable.create(price: 1) }
9
+ let(:priceable_from_string) { Priceable.create(price: '1 EUR' )}
10
+ let(:priceable_from_hash) { Priceable.create(price: {cents: 100, currency_iso: "EUR"} )}
11
11
  let(:priceable_from_hash_with_indifferent_access) {
12
- Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"}.with_indifferent_access)
12
+ Priceable.create(price: {cents: 100, currency_iso: "EUR"}.with_indifferent_access)
13
13
  }
14
- let(:priceable_from_string_with_hyphen) { Priceable.create(:price => '1-2 EUR' )}
15
- let(:priceable_from_string_with_unknown_currency) { Priceable.create(:price => '1 TLDR') }
16
- let(:priceable_with_infinite_precision) { Priceable.create(:price => Money.new(BigDecimal.new('100.1'), 'EUR')) }
14
+ let(:priceable_from_string_with_hyphen) { Priceable.create(price: '1-2 EUR' )}
15
+ let(:priceable_from_string_with_unknown_currency) { Priceable.create(price: '1 TLDR') }
16
+ let(:priceable_with_infinite_precision) { Priceable.create(price: Money.new(BigDecimal.new('100.1'), 'EUR')) }
17
17
  let(:priceable_with_hash_field) {
18
- Priceable.create(:price_hash => {
19
- :key1 => Money.new(100, "EUR"),
20
- :key2 => Money.new(200, "USD")
18
+ Priceable.create(price_hash: {
19
+ key1: Money.new(100, "EUR"),
20
+ key2: Money.new(200, "USD")
21
21
  })
22
22
  }
23
23
 
@@ -108,14 +108,14 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^3(.*)/
108
108
  end
109
109
 
110
110
  it 'returns nil if an unknown value was stored' do
111
- zero_priceable = Priceable.create(:price => [])
111
+ zero_priceable = Priceable.create(price: [])
112
112
  expect(zero_priceable.price).to be_nil
113
113
  end
114
114
  end
115
115
 
116
116
  context "evolve" do
117
117
  it "transforms correctly a Money object to a Mongo friendly value" do
118
- expect(Priceable.where(:price => Money.new(100, 'EUR')).first).to eq(priceable)
118
+ expect(Priceable.where(price: Money.new(100, 'EUR')).first).to eq(priceable)
119
119
  end
120
120
  end
121
121
  end
@@ -3,12 +3,12 @@ require 'spec_helper'
3
3
  if defined?(Mongoid) && ::Mongoid::VERSION =~ /^2(.*)/
4
4
 
5
5
  describe Money do
6
- let(:priceable) { Priceable.create(:price => Money.new(100, 'EUR')) }
7
- let(:priceable_from_nil) { Priceable.create(:price => nil) }
8
- let(:priceable_from_num) { Priceable.create(:price => 1) }
9
- let(:priceable_from_string) { Priceable.create(:price => '1 EUR' )}
10
- let(:priceable_with_infinite_precision) { Priceable.create(:price => Money.new(BigDecimal.new('100.1'), 'EUR')) }
11
- let(:priceable_from_string_with_hyphen) { Priceable.create(:price => '1-2 EUR' )}
6
+ let(:priceable) { Priceable.create(price: Money.new(100, 'EUR')) }
7
+ let(:priceable_from_nil) { Priceable.create(price: nil) }
8
+ let(:priceable_from_num) { Priceable.create(price: 1) }
9
+ let(:priceable_from_string) { Priceable.create(price: '1 EUR' )}
10
+ let(:priceable_with_infinite_precision) { Priceable.create(price: Money.new(BigDecimal.new('100.1'), 'EUR')) }
11
+ let(:priceable_from_string_with_hyphen) { Priceable.create(price: '1-2 EUR' )}
12
12
 
13
13
  context "serialize" do
14
14
  it "mongoizes correctly nil to nil" do
@@ -72,7 +72,7 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^2(.*)/
72
72
  end
73
73
 
74
74
  it 'returns nil if an unknown value was stored' do
75
- zero_priceable = Priceable.create(:price => [])
75
+ zero_priceable = Priceable.create(price: [])
76
76
  expect(zero_priceable.price).to be_nil
77
77
  end
78
78
  end
@@ -8,9 +8,9 @@ if defined? ActiveRecord
8
8
  include MoneyRails::TestHelpers
9
9
 
10
10
  let(:product) do
11
- Product.create(:price_cents => 3000, :discount => 150,
12
- :bonus_cents => 200,
13
- :sale_price_amount => 1200)
11
+ Product.create(price_cents: 3000, discount: 150,
12
+ bonus_cents: 200,
13
+ sale_price_amount: 1200)
14
14
  end
15
15
 
16
16
  describe "monetize matcher" do
@@ -37,6 +37,14 @@ if defined? ActiveRecord
37
37
  is_expected.to monetize(:bonus).with_currency(:gbp)
38
38
  end
39
39
 
40
+ it "matches model attribute with currency attribute specified by :with_model_currency chain" do
41
+ is_expected.to(
42
+ monetize(:sale_price_amount)
43
+ .as(:sale_price)
44
+ .with_model_currency(:sale_price_currency_code)
45
+ )
46
+ end
47
+
40
48
  it "does not match non existed attribute" do
41
49
  is_expected.not_to monetize(:price_fake)
42
50
  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.10.0
4
+ version: 1.11.0
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: 2018-01-15 00:00:00.000000000 Z
13
+ date: 2018-04-10 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.10.0
21
+ version: 6.11.0
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.10.0
28
+ version: 6.11.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: monetize
31
31
  requirement: !ruby/object:Gem::Requirement