spec/mongoid/three_spec.rb in money-rails-0.9.0 vs spec/mongoid/three_spec.rb in money-rails-0.10.0
- old
+ new
@@ -8,10 +8,11 @@
let!(:priceable_from_string) { Priceable.create(:price => '1 EUR' )}
let!(:priceable_from_hash) { Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"} )}
let!(:priceable_from_hash_with_indifferent_access) {
Priceable.create(:price => {:cents=>100, :currency_iso=>"EUR"}.with_indifferent_access)
}
+ let(:priceable_from_string_with_hyphen) { Priceable.create(:price => '1-2 EUR' )}
let(:priceable_with_infinite_precision) { Priceable.create(:price => Money.new(BigDecimal.new('100.1'), 'EUR')) }
let(:priceable_with_hash_field) {
Priceable.create(:price_hash => {
:key1 => Money.new(100, "EUR"),
:key2 => Money.new(200, "USD")
@@ -30,9 +31,24 @@
end
it "mongoizes correctly a String object to a hash of cents and currency" do
priceable_from_string.price.cents.should == 100
priceable_from_string.price.currency.should == Money::Currency.find('EUR')
+ end
+
+ context "when MoneyRails.raise_error_on_money_parsing is true" do
+ before { MoneyRails.raise_error_on_money_parsing = true }
+ after { MoneyRails.raise_error_on_money_parsing = false }
+
+ it "raises exception if the mongoized value is a String with a hyphen" do
+ expect { priceable_from_string_with_hyphen }.to raise_error
+ end
+ end
+
+ context "when MoneyRails.raise_error_on_money_parsing is false" do
+ it "does not mongoizes correctly a String with hyphen in its middle" do
+ priceable_from_string_with_hyphen.price.should == nil
+ end
end
it "mongoizes correctly a hash of cents and currency" do
priceable_from_hash.price.cents.should == 100
priceable_from_hash.price.currency.should == Money::Currency.find('EUR')