money-rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,16 +5,16 @@ describe "configuration" do
5
5
  describe "initializer" do
6
6
 
7
7
  it "sets default currency" do
8
- Money.default_currency.should == Money::Currency.new(:eur)
8
+ expect(Money.default_currency).to eq(Money::Currency.new(:eur))
9
9
  end
10
10
 
11
11
  it "registers a custom currency" do
12
- Money::Currency.table.should include(:eu4)
12
+ expect(Money::Currency.table).to include(:eu4)
13
13
  end
14
14
 
15
15
  it "adds exchange rates given in config initializer" do
16
- Money.us_dollar(100).exchange_to("CAD").should == Money.new(124, "CAD")
17
- Money.ca_dollar(100).exchange_to("USD").should == Money.new(80, "USD")
16
+ expect(Money.us_dollar(100).exchange_to("CAD")).to eq(Money.new(124, "CAD"))
17
+ expect(Money.ca_dollar(100).exchange_to("USD")).to eq(Money.new(80, "USD"))
18
18
  end
19
19
 
20
20
  it "sets no_cents_if_whole value for formatted output globally" do
@@ -23,15 +23,15 @@ describe "configuration" do
23
23
 
24
24
  value = Money.new(12345600, "EUR")
25
25
  mark = Money::Currency.find(:eur).decimal_mark
26
- value.format.should =~ /#{mark}/
26
+ expect(value.format).to match(/#{mark}/)
27
27
 
28
28
  MoneyRails.no_cents_if_whole = true
29
- value.format.should_not =~ /#{mark}/
30
- value.format(no_cents_if_whole: false).should =~ /#{mark}/
29
+ expect(value.format).not_to match(/#{mark}/)
30
+ expect(value.format(no_cents_if_whole: false)).to match(/#{mark}/)
31
31
 
32
32
  MoneyRails.no_cents_if_whole = false
33
- value.format.should =~ /#{mark}/
34
- value.format(no_cents_if_whole: true).should_not =~ /#{mark}/
33
+ expect(value.format).to match(/#{mark}/)
34
+ expect(value.format(no_cents_if_whole: true)).not_to match(/#{mark}/)
35
35
 
36
36
  # Reset global settings
37
37
  MoneyRails.no_cents_if_whole = nil
@@ -41,15 +41,15 @@ describe "configuration" do
41
41
  it "sets symbol for formatted output globally" do
42
42
  value = Money.new(12345600, "EUR")
43
43
  symbol = Money::Currency.find(:eur).symbol
44
- value.format.should =~ /#{symbol}/
44
+ expect(value.format).to match(/#{symbol}/)
45
45
 
46
46
  MoneyRails.symbol = false
47
- value.format.should_not =~ /#{symbol}/
48
- value.format(symbol: true).should =~ /#{symbol}/
47
+ expect(value.format).not_to match(/#{symbol}/)
48
+ expect(value.format(symbol: true)).to match(/#{symbol}/)
49
49
 
50
50
  MoneyRails.symbol = true
51
- value.format.should =~ /#{symbol}/
52
- value.format(symbol: false).should_not =~ /#{symbol}/
51
+ expect(value.format).to match(/#{symbol}/)
52
+ expect(value.format(symbol: false)).not_to match(/#{symbol}/)
53
53
 
54
54
  # Reset global setting
55
55
  MoneyRails.symbol = nil
@@ -58,26 +58,43 @@ describe "configuration" do
58
58
  it "sets the location of the negative sign for formatted output globally" do
59
59
  value = Money.new(-12345600, "EUR")
60
60
  symbol = Money::Currency.find(:eur).symbol
61
- value.format.should =~ /#{symbol}-/
61
+ expect(value.format).to match(/#{symbol}-/)
62
62
 
63
63
  MoneyRails.sign_before_symbol = false
64
- value.format.should =~ /#{symbol}-/
65
- value.format(sign_before_symbol: false).should =~ /#{symbol}-/
64
+ expect(value.format).to match(/#{symbol}-/)
65
+ expect(value.format(sign_before_symbol: false)).to match(/#{symbol}-/)
66
66
 
67
67
  MoneyRails.sign_before_symbol = true
68
- value.format.should =~ /-#{symbol}/
69
- value.format(sign_before_symbol: true).should =~ /-#{symbol}/
68
+ expect(value.format).to match(/-#{symbol}/)
69
+ expect(value.format(sign_before_symbol: true)).to match(/-#{symbol}/)
70
70
 
71
71
  # Reset global setting
72
72
  MoneyRails.sign_before_symbol = nil
73
73
  end
74
74
 
75
+ it "passes through arbitrary format options" do
76
+ value = Money.new(-12345600, "EUR")
77
+ symbol = Money::Currency.find(:eur).symbol
78
+
79
+ MoneyRails.default_format = {:symbol_position => :after}
80
+ expect(value.format).to match(/#{symbol}\z/)
81
+
82
+ # Override with "classic" format options for backward compatibility
83
+ MoneyRails.default_format = {:sign_before_symbol => :false}
84
+ MoneyRails.sign_before_symbol = true
85
+ expect(value.format).to match(/-#{symbol}/)
86
+
87
+ # Reset global settings
88
+ MoneyRails.sign_before_symbol = nil
89
+ MoneyRails.default_format = nil
90
+ end
91
+
75
92
  it "changes the amount and currency column settings based on the default currency" do
76
93
  old_currency = MoneyRails.default_currency
77
94
  MoneyRails.default_currency = :inr
78
95
 
79
- MoneyRails.amount_column[:postfix].should == "_#{MoneyRails.default_currency.subunit.downcase.pluralize}"
80
- MoneyRails.currency_column[:default].should == MoneyRails.default_currency.iso_code
96
+ expect(MoneyRails.amount_column[:postfix]).to eq("_#{MoneyRails.default_currency.subunit.downcase.pluralize}")
97
+ expect(MoneyRails.currency_column[:default]).to eq(MoneyRails.default_currency.iso_code)
81
98
 
82
99
  # Reset global setting
83
100
  MoneyRails.default_currency = old_currency
@@ -90,7 +107,7 @@ describe "configuration" do
90
107
  MoneyRails.default_currency = :jpy
91
108
  }.to_not raise_error
92
109
 
93
- MoneyRails.amount_column[:postfix].should == "_cents"
110
+ expect(MoneyRails.amount_column[:postfix]).to eq("_cents")
94
111
 
95
112
  # Reset global setting
96
113
  MoneyRails.default_currency = old_currency
@@ -5,3 +5,4 @@ class DummyProduct < ActiveRecord::Base
5
5
  # Use money-rails macros
6
6
  monetize :price_cents, :with_model_currency => :currency
7
7
  end
8
+
@@ -39,4 +39,8 @@ class Product < ActiveRecord::Base
39
39
  :less_than_or_equal_to => 100,
40
40
  :message => 'Must be greater than zero and less than $100',
41
41
  }
42
+
43
+ alias_attribute :renamed_cents, :aliased_cents
44
+
45
+ monetize :renamed_cents, allow_nil: true
42
46
  end
@@ -15,7 +15,9 @@ require "money-rails"
15
15
  module Dummy
16
16
  class Application < Rails::Application
17
17
 
18
- I18n.enforce_available_locales = false # removes deprecation warning
18
+ if I18n.respond_to?(:enforce_available_locales)
19
+ I18n.enforce_available_locales = false # removes deprecation warning
20
+ end
19
21
 
20
22
  # Settings in config/environments/* take precedence over those specified here.
21
23
  # Application configuration should go into files in config/initializers
@@ -59,4 +61,3 @@ module Dummy
59
61
  config.assets.version = '1.0'
60
62
  end
61
63
  end
62
-
@@ -0,0 +1,5 @@
1
+ en-US:
2
+ number:
3
+ currency:
4
+ format:
5
+ delimiter: ''
@@ -0,0 +1,5 @@
1
+ class AddAliasedAttrToProducts < ActiveRecord::Migration
2
+ def change
3
+ add_column :products, :aliased_cents, :integer
4
+ end
5
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20140110194016) do
14
+ ActiveRecord::Schema.define(version: 20141005075025) do
15
15
 
16
16
  create_table "dummy_products", force: true do |t|
17
17
  t.string "currency"
@@ -31,6 +31,7 @@ ActiveRecord::Schema.define(version: 20140110194016) do
31
31
  t.string "sale_price_currency_code"
32
32
  t.integer "price_in_a_range_cents"
33
33
  t.integer "validates_method_amount_cents"
34
+ t.integer "aliased_cents"
34
35
  end
35
36
 
36
37
  create_table "services", force: true do |t|
@@ -1,62 +1,62 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'MoneyRails::ActionViewExtension' do
3
+ describe 'MoneyRails::ActionViewExtension', :type => :helper do
4
4
  describe '#currency_symbol' do
5
5
  subject { helper.currency_symbol }
6
- it { should be_a String }
7
- it { should include Money.default_currency.symbol }
6
+ it { is_expected.to be_a String }
7
+ it { is_expected.to include Money.default_currency.symbol }
8
8
  end
9
9
 
10
10
  describe '#humanized_money' do
11
11
  let(:options) { {} }
12
12
  subject { helper.humanized_money Money.new(12500), options }
13
- it { should be_a String }
14
- it { should_not include Money.default_currency.symbol }
15
- it { should_not include Money.default_currency.decimal_mark }
13
+ it { is_expected.to be_a String }
14
+ it { is_expected.not_to include Money.default_currency.symbol }
15
+ it { is_expected.not_to include Money.default_currency.decimal_mark }
16
16
 
17
17
  context 'with symbol options' do
18
18
  let(:options) { { :symbol => true } }
19
- it { should include Money.default_currency.symbol }
19
+ it { is_expected.to include Money.default_currency.symbol }
20
20
  end
21
21
 
22
22
  context 'with deprecated symbol' do
23
23
  let(:options) { true }
24
24
  before(:each) do
25
- helper.should_receive(:warn)
25
+ expect(helper).to receive(:warn)
26
26
  end
27
- it { should include Money.default_currency.symbol }
27
+ it { is_expected.to include Money.default_currency.symbol }
28
28
  end
29
29
  end
30
30
 
31
31
  describe '#humanized_money_with_symbol' do
32
32
  subject { helper.humanized_money_with_symbol Money.new(12500) }
33
- it { should be_a String }
34
- it { should_not include Money.default_currency.decimal_mark }
35
- it { should include Money.default_currency.symbol }
33
+ it { is_expected.to be_a String }
34
+ it { is_expected.not_to include Money.default_currency.decimal_mark }
35
+ it { is_expected.to include Money.default_currency.symbol }
36
36
  end
37
37
 
38
38
  describe '#money_without_cents' do
39
39
  let(:options) { {} }
40
40
  subject { helper.money_without_cents Money.new(12500), options }
41
- it { should be_a String }
42
- it { should_not include Money.default_currency.symbol }
43
- it { should_not include Money.default_currency.decimal_mark }
41
+ it { is_expected.to be_a String }
42
+ it { is_expected.not_to include Money.default_currency.symbol }
43
+ it { is_expected.not_to include Money.default_currency.decimal_mark }
44
44
 
45
45
  context 'with deprecated symbol' do
46
46
  let(:options) { true }
47
47
  before(:each) do
48
- helper.should_receive(:warn)
48
+ expect(helper).to receive(:warn)
49
49
  end
50
- it { should include Money.default_currency.symbol }
50
+ it { is_expected.to include Money.default_currency.symbol }
51
51
  end
52
52
  end
53
53
 
54
54
  describe '#money_without_cents_and_with_symbol' do
55
55
  subject { helper.money_without_cents_and_with_symbol Money.new(12500) }
56
- it { should be_a String }
57
- it { should_not include Money.default_currency.decimal_mark }
58
- it { should include Money.default_currency.symbol }
59
- it { should_not include "00" }
56
+ it { is_expected.to be_a String }
57
+ it { is_expected.not_to include Money.default_currency.decimal_mark }
58
+ it { is_expected.to include Money.default_currency.symbol }
59
+ it { is_expected.not_to include "00" }
60
60
  end
61
61
 
62
62
  context 'respects MoneyRails::Configuration settings' do
@@ -70,18 +70,18 @@ describe 'MoneyRails::ActionViewExtension' do
70
70
 
71
71
  describe '#humanized_money' do
72
72
  subject { helper.humanized_money Money.new(12500) }
73
- it { should be_a String }
74
- it { should_not include Money.default_currency.decimal_mark }
75
- it { should_not include Money.default_currency.symbol }
76
- it { should include "00" }
73
+ it { is_expected.to be_a String }
74
+ it { is_expected.not_to include Money.default_currency.decimal_mark }
75
+ it { is_expected.not_to include Money.default_currency.symbol }
76
+ it { is_expected.to include "00" }
77
77
  end
78
78
 
79
79
  describe '#humanized_money_with_symbol' do
80
80
  subject { helper.humanized_money_with_symbol Money.new(12500) }
81
- it { should be_a String }
82
- it { should_not include Money.default_currency.decimal_mark }
83
- it { should include Money.default_currency.symbol }
84
- it { should include "00" }
81
+ it { is_expected.to be_a String }
82
+ it { is_expected.not_to include Money.default_currency.decimal_mark }
83
+ it { is_expected.to include Money.default_currency.symbol }
84
+ it { is_expected.to include "00" }
85
85
  end
86
86
  end
87
87
 
@@ -95,18 +95,18 @@ describe 'MoneyRails::ActionViewExtension' do
95
95
 
96
96
  describe '#humanized_money' do
97
97
  subject { helper.humanized_money Money.new(12500) }
98
- it { should be_a String }
99
- it { should_not include Money.default_currency.decimal_mark }
100
- it { should_not include Money.default_currency.symbol }
101
- it { should_not include "00" }
98
+ it { is_expected.to be_a String }
99
+ it { is_expected.not_to include Money.default_currency.decimal_mark }
100
+ it { is_expected.not_to include Money.default_currency.symbol }
101
+ it { is_expected.not_to include "00" }
102
102
  end
103
103
 
104
104
  describe '#humanized_money_with_symbol' do
105
105
  subject { helper.humanized_money_with_symbol Money.new(12500) }
106
- it { should be_a String }
107
- it { should_not include Money.default_currency.decimal_mark }
108
- it { should include Money.default_currency.symbol }
109
- it { should_not include "00" }
106
+ it { is_expected.to be_a String }
107
+ it { is_expected.not_to include Money.default_currency.decimal_mark }
108
+ it { is_expected.to include Money.default_currency.symbol }
109
+ it { is_expected.not_to include "00" }
110
110
  end
111
111
  end
112
112
 
@@ -120,18 +120,18 @@ describe 'MoneyRails::ActionViewExtension' do
120
120
 
121
121
  describe '#humanized_money' do
122
122
  subject { helper.humanized_money Money.new(12500) }
123
- it { should be_a String }
124
- it { should_not include Money.default_currency.decimal_mark }
125
- it { should_not include Money.default_currency.symbol }
126
- it { should_not include "00" }
123
+ it { is_expected.to be_a String }
124
+ it { is_expected.not_to include Money.default_currency.decimal_mark }
125
+ it { is_expected.not_to include Money.default_currency.symbol }
126
+ it { is_expected.not_to include "00" }
127
127
  end
128
128
 
129
129
  describe '#humanized_money_with_symbol' do
130
130
  subject { helper.humanized_money_with_symbol Money.new(12500) }
131
- it { should be_a String }
132
- it { should_not include Money.default_currency.decimal_mark }
133
- it { should include Money.default_currency.symbol }
134
- it { should_not include "00" }
131
+ it { is_expected.to be_a String }
132
+ it { is_expected.not_to include Money.default_currency.decimal_mark }
133
+ it { is_expected.to include Money.default_currency.symbol }
134
+ it { is_expected.not_to include "00" }
135
135
  end
136
136
  end
137
137
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  if defined? ActiveRecord
4
- describe "Test helper in form blocks" do
4
+ describe "Test helper in form blocks", :type => :helper do
5
5
 
6
6
  let :product do
7
7
  Product.create(:price_cents => 3000, :discount => 150,
@@ -12,7 +12,7 @@ if defined? ActiveRecord
12
12
  context "textfield" do
13
13
  it "uses the current value of money field in textfield" do
14
14
  helper.instance_variable_set :@product, product
15
- helper.text_field(:product, :price).should =~ /value=\"#{product.price.to_s}\"/
15
+ expect(helper.text_field(:product, :price)).to match(/value=\"#{product.price.to_s}\"/)
16
16
  end
17
17
  end
18
18
  end
@@ -22,18 +22,18 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^4(.*)/
22
22
 
23
23
  context "mongoize" do
24
24
  it "correctly mongoizes a Money object to a hash of cents and currency" do
25
- priceable.price.cents.should == 100
26
- priceable.price.currency.should == Money::Currency.find('EUR')
25
+ expect(priceable.price.cents).to eq(100)
26
+ expect(priceable.price.currency).to eq(Money::Currency.find('EUR'))
27
27
  end
28
28
 
29
29
  it "correctly mongoizes a Numeric object to a hash of cents and currency" do
30
- priceable_from_num.price.cents.should == 100
31
- priceable_from_num.price.currency.should == Money.default_currency
30
+ expect(priceable_from_num.price.cents).to eq(100)
31
+ expect(priceable_from_num.price.currency).to eq(Money.default_currency)
32
32
  end
33
33
 
34
34
  it "correctly mongoizes a String object to a hash of cents and currency" do
35
- priceable_from_string.price.cents.should == 100
36
- priceable_from_string.price.currency.should == Money::Currency.find('EUR')
35
+ expect(priceable_from_string.price.cents).to eq(100)
36
+ expect(priceable_from_string.price.currency).to eq(Money::Currency.find('EUR'))
37
37
  end
38
38
 
39
39
  context "when MoneyRails.raise_error_on_money_parsing is true" do
@@ -51,22 +51,22 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^4(.*)/
51
51
 
52
52
  context "when MoneyRails.raise_error_on_money_parsing is false" do
53
53
  it "does not correctly mongoize a String with a hyphen in its middle" do
54
- priceable_from_string_with_hyphen.price.should == nil
54
+ expect(priceable_from_string_with_hyphen.price).to eq(nil)
55
55
  end
56
56
 
57
57
  it "does not correctly mongoize a String with an unknown currency" do
58
- priceable_from_string_with_unknown_currency.price.should == nil
58
+ expect(priceable_from_string_with_unknown_currency.price).to eq(nil)
59
59
  end
60
60
  end
61
61
 
62
62
  it "correctly mongoizes a hash of cents and currency" do
63
- priceable_from_hash.price.cents.should == 100
64
- priceable_from_hash.price.currency.should == Money::Currency.find('EUR')
63
+ expect(priceable_from_hash.price.cents).to eq(100)
64
+ expect(priceable_from_hash.price.currency).to eq(Money::Currency.find('EUR'))
65
65
  end
66
66
 
67
67
  it "correctly mongoizes a HashWithIndifferentAccess of cents and currency" do
68
- priceable_from_hash_with_indifferent_access.price.cents.should == 100
69
- priceable_from_hash_with_indifferent_access.price.currency.should == Money::Currency.find('EUR')
68
+ expect(priceable_from_hash_with_indifferent_access.price.cents).to eq(100)
69
+ expect(priceable_from_hash_with_indifferent_access.price.currency).to eq(Money::Currency.find('EUR'))
70
70
  end
71
71
 
72
72
  context "infinite_precision = true" do
@@ -79,36 +79,36 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^4(.*)/
79
79
  end
80
80
 
81
81
  it "correctly mongoizes a Money object to a hash of cents and currency" do
82
- priceable_with_infinite_precision.price.cents.should == BigDecimal.new('100.1')
83
- priceable_with_infinite_precision.price.currency.should == Money::Currency.find('EUR')
82
+ expect(priceable_with_infinite_precision.price.cents).to eq(BigDecimal.new('100.1'))
83
+ expect(priceable_with_infinite_precision.price.currency).to eq(Money::Currency.find('EUR'))
84
84
  end
85
85
  end
86
86
  end
87
87
 
88
88
  it "correctly serializes a Hash field containing Money objects" do
89
- priceable_with_hash_field.price_hash[:key1][:cents].should == 100
90
- priceable_with_hash_field.price_hash[:key2][:cents].should == 200
91
- priceable_with_hash_field.price_hash[:key1][:currency_iso].should == 'EUR'
92
- priceable_with_hash_field.price_hash[:key2][:currency_iso].should == 'USD'
89
+ expect(priceable_with_hash_field.price_hash[:key1][:cents]).to eq(100)
90
+ expect(priceable_with_hash_field.price_hash[:key2][:cents]).to eq(200)
91
+ expect(priceable_with_hash_field.price_hash[:key1][:currency_iso]).to eq('EUR')
92
+ expect(priceable_with_hash_field.price_hash[:key2][:currency_iso]).to eq('USD')
93
93
  end
94
94
 
95
95
  context "demongoize" do
96
96
  subject { Priceable.first.price }
97
- it { should be_an_instance_of(Money) }
98
- it { should == Money.new(100, 'EUR') }
97
+ it { is_expected.to be_an_instance_of(Money) }
98
+ it { is_expected.to eq(Money.new(100, 'EUR')) }
99
99
  it "returns nil if a nil value was stored" do
100
100
  nil_priceable = Priceable.create(:price => nil)
101
- nil_priceable.price.should be_nil
101
+ expect(nil_priceable.price).to be_nil
102
102
  end
103
103
  it 'returns nil if an unknown value was stored' do
104
104
  zero_priceable = Priceable.create(:price => [])
105
- zero_priceable.price.should be_nil
105
+ expect(zero_priceable.price).to be_nil
106
106
  end
107
107
  end
108
108
 
109
109
  context "evolve" do
110
110
  it "correctly transforms a Money object into a Mongo friendly value" do
111
- Priceable.where(:price => Money.new(100, 'EUR')).first.should == priceable
111
+ expect(Priceable.where(:price => Money.new(100, 'EUR')).first).to eq(priceable)
112
112
  end
113
113
  end
114
114
  end
@@ -22,18 +22,18 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^3(.*)/
22
22
 
23
23
  context "mongoize" do
24
24
  it "mongoizes correctly a Money object to a hash of cents and currency" do
25
- priceable.price.cents.should == 100
26
- priceable.price.currency.should == Money::Currency.find('EUR')
25
+ expect(priceable.price.cents).to eq(100)
26
+ expect(priceable.price.currency).to eq(Money::Currency.find('EUR'))
27
27
  end
28
28
 
29
29
  it "mongoizes correctly a Numeric object to a hash of cents and currency" do
30
- priceable_from_num.price.cents.should == 100
31
- priceable_from_num.price.currency.should == Money.default_currency
30
+ expect(priceable_from_num.price.cents).to eq(100)
31
+ expect(priceable_from_num.price.currency).to eq(Money.default_currency)
32
32
  end
33
33
 
34
34
  it "mongoizes correctly a String object to a hash of cents and currency" do
35
- priceable_from_string.price.cents.should == 100
36
- priceable_from_string.price.currency.should == Money::Currency.find('EUR')
35
+ expect(priceable_from_string.price.cents).to eq(100)
36
+ expect(priceable_from_string.price.currency).to eq(Money::Currency.find('EUR'))
37
37
  end
38
38
 
39
39
  context "when MoneyRails.raise_error_on_money_parsing is true" do
@@ -51,22 +51,22 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^3(.*)/
51
51
 
52
52
  context "when MoneyRails.raise_error_on_money_parsing is false" do
53
53
  it "does not mongoizes correctly a String with hyphen in its middle" do
54
- priceable_from_string_with_hyphen.price.should == nil
54
+ expect(priceable_from_string_with_hyphen.price).to eq(nil)
55
55
  end
56
56
 
57
57
  it "does not mongoize correctly a String with an unknown currency" do
58
- priceable_from_string_with_unknown_currency.price.should == nil
58
+ expect(priceable_from_string_with_unknown_currency.price).to eq(nil)
59
59
  end
60
60
  end
61
61
 
62
62
  it "mongoizes correctly a hash of cents and currency" do
63
- priceable_from_hash.price.cents.should == 100
64
- priceable_from_hash.price.currency.should == Money::Currency.find('EUR')
63
+ expect(priceable_from_hash.price.cents).to eq(100)
64
+ expect(priceable_from_hash.price.currency).to eq(Money::Currency.find('EUR'))
65
65
  end
66
66
 
67
67
  it "mongoizes correctly a HashWithIndifferentAccess of cents and currency" do
68
- priceable_from_hash_with_indifferent_access.price.cents.should == 100
69
- priceable_from_hash_with_indifferent_access.price.currency.should == Money::Currency.find('EUR')
68
+ expect(priceable_from_hash_with_indifferent_access.price.cents).to eq(100)
69
+ expect(priceable_from_hash_with_indifferent_access.price.currency).to eq(Money::Currency.find('EUR'))
70
70
  end
71
71
 
72
72
  context "infinite_precision = true" do
@@ -79,36 +79,36 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^3(.*)/
79
79
  end
80
80
 
81
81
  it "mongoizes correctly a Money object to a hash of cents and currency" do
82
- priceable_with_infinite_precision.price.cents.should == BigDecimal.new('100.1')
83
- priceable_with_infinite_precision.price.currency.should == Money::Currency.find('EUR')
82
+ expect(priceable_with_infinite_precision.price.cents).to eq(BigDecimal.new('100.1'))
83
+ expect(priceable_with_infinite_precision.price.currency).to eq(Money::Currency.find('EUR'))
84
84
  end
85
85
  end
86
86
  end
87
87
 
88
88
  it "serializes correctly a Hash field containing Money objects" do
89
- priceable_with_hash_field.price_hash[:key1][:cents].should == 100
90
- priceable_with_hash_field.price_hash[:key2][:cents].should == 200
91
- priceable_with_hash_field.price_hash[:key1][:currency_iso].should == 'EUR'
92
- priceable_with_hash_field.price_hash[:key2][:currency_iso].should == 'USD'
89
+ expect(priceable_with_hash_field.price_hash[:key1][:cents]).to eq(100)
90
+ expect(priceable_with_hash_field.price_hash[:key2][:cents]).to eq(200)
91
+ expect(priceable_with_hash_field.price_hash[:key1][:currency_iso]).to eq('EUR')
92
+ expect(priceable_with_hash_field.price_hash[:key2][:currency_iso]).to eq('USD')
93
93
  end
94
94
 
95
95
  context "demongoize" do
96
96
  subject { Priceable.first.price }
97
- it { should be_an_instance_of(Money) }
98
- it { should == Money.new(100, 'EUR') }
97
+ it { is_expected.to be_an_instance_of(Money) }
98
+ it { is_expected.to eq(Money.new(100, 'EUR')) }
99
99
  it "returns nil if a nil value was stored" do
100
100
  nil_priceable = Priceable.create(:price => nil)
101
- nil_priceable.price.should be_nil
101
+ expect(nil_priceable.price).to be_nil
102
102
  end
103
103
  it 'returns nil if an unknown value was stored' do
104
104
  zero_priceable = Priceable.create(:price => [])
105
- zero_priceable.price.should be_nil
105
+ expect(zero_priceable.price).to be_nil
106
106
  end
107
107
  end
108
108
 
109
109
  context "evolve" do
110
110
  it "transforms correctly a Money object to a Mongo friendly value" do
111
- Priceable.where(:price => Money.new(100, 'EUR')).first.should == priceable
111
+ expect(Priceable.where(:price => Money.new(100, 'EUR')).first).to eq(priceable)
112
112
  end
113
113
  end
114
114
  end
@@ -11,18 +11,18 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^2(.*)/
11
11
 
12
12
  context "serialize" do
13
13
  it "serializes correctly a Money object to a hash of cents and currency" do
14
- priceable.price.cents.should == 100
15
- priceable.price.currency.should == Money::Currency.find('EUR')
14
+ expect(priceable.price.cents).to eq(100)
15
+ expect(priceable.price.currency).to eq(Money::Currency.find('EUR'))
16
16
  end
17
17
 
18
18
  it "mongoizes correctly a Numeric object to a hash of cents and currency" do
19
- priceable_from_num.price.cents.should == 100
20
- priceable_from_num.price.currency.should == Money.default_currency
19
+ expect(priceable_from_num.price.cents).to eq(100)
20
+ expect(priceable_from_num.price.currency).to eq(Money.default_currency)
21
21
  end
22
22
 
23
23
  it "mongoizes correctly a String object to a hash of cents and currency" do
24
- priceable_from_string.price.cents.should == 100
25
- priceable_from_string.price.currency.should == Money::Currency.find('EUR')
24
+ expect(priceable_from_string.price.cents).to eq(100)
25
+ expect(priceable_from_string.price.currency).to eq(Money::Currency.find('EUR'))
26
26
  end
27
27
 
28
28
  context "infinite_precision = true" do
@@ -35,8 +35,8 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^2(.*)/
35
35
  end
36
36
 
37
37
  it "mongoizes correctly a Money object to a hash of cents and currency" do
38
- priceable_with_infinite_precision.price.cents.should == BigDecimal.new('100.1')
39
- priceable_with_infinite_precision.price.currency.should == Money::Currency.find('EUR')
38
+ expect(priceable_with_infinite_precision.price.cents).to eq(BigDecimal.new('100.1'))
39
+ expect(priceable_with_infinite_precision.price.currency).to eq(Money::Currency.find('EUR'))
40
40
  end
41
41
  end
42
42
 
@@ -51,22 +51,22 @@ if defined?(Mongoid) && ::Mongoid::VERSION =~ /^2(.*)/
51
51
 
52
52
  context "when MoneyRails.raise_error_on_money_parsing is false" do
53
53
  it "does not mongoizes correctly a String with hyphen in its middle" do
54
- priceable_from_string_with_hyphen.price.should == nil
54
+ expect(priceable_from_string_with_hyphen.price).to eq(nil)
55
55
  end
56
56
  end
57
57
  end
58
58
 
59
59
  context "deserialize" do
60
60
  subject { priceable.price }
61
- it { should be_an_instance_of(Money) }
62
- it { should == Money.new(100, 'EUR') }
61
+ it { is_expected.to be_an_instance_of(Money) }
62
+ it { is_expected.to eq(Money.new(100, 'EUR')) }
63
63
  it "returns nil if a nil value was stored" do
64
64
  nil_priceable = Priceable.create(:price => nil)
65
- nil_priceable.price.should be_nil
65
+ expect(nil_priceable.price).to be_nil
66
66
  end
67
67
  it 'returns nil if an unknown value was stored' do
68
68
  zero_priceable = Priceable.create(:price => [])
69
- zero_priceable.price.should be_nil
69
+ expect(zero_priceable.price).to be_nil
70
70
  end
71
71
  end
72
72
  end