diff --git a/lib/money/bank/base.rb b/lib/money/bank/base.rb index a2ddca3137..d9676d3899 100644 --- a/lib/money/bank/base.rb +++ b/lib/money/bank/base.rb @@ -41,6 +41,13 @@ def self.instance @@singleton ||= self.new end + attr_reader :rounding_method + + # Initializes a new Money::Bank::Base object. An optional block can be + # passed to dictate the rounding method that +exchange_with+ can use. + def initialize(&block) + @rounding_method = block + end # @deprecated +#exchange+ will be removed in v3.2.0, use +#exchange_with+ # diff --git a/lib/money/bank/variable_exchange.rb b/lib/money/bank/variable_exchange.rb index b0ab073d39..0838e170d5 100644 --- a/lib/money/bank/variable_exchange.rb +++ b/lib/money/bank/variable_exchange.rb @@ -25,7 +25,7 @@ class VariableExchange < Base def initialize(&block) @rates = {} @mutex = Mutex.new - @rounding_method = block + super end diff --git a/spec/bank/base_spec.rb b/spec/bank/base_spec.rb index d874ec4db3..b7b0a78856 100644 --- a/spec/bank/base_spec.rb +++ b/spec/bank/base_spec.rb @@ -1,11 +1,18 @@ require "spec_helper" describe Money::Bank::Base do - before :each do @bank = Money::Bank::Base.new end + describe '#new with &block' do + it 'should store @rounding_method' do + proc = Proc.new{|n| n.ceil} + bank = Money::Bank::Base.new(&proc) + bank.rounding_method.should == proc + end + end + describe '#exchange' do it 'should raise NotImplementedError' do lambda { @bank.exchange(100, 'USD', 'EUR') }.should raise_exception(NotImplementedError) @@ -53,5 +60,4 @@ lambda{@bank.send(:same_currency?, 'AAA', 'BBB')}.should raise_exception(Money::Currency::UnknownCurrency) end end - end