Skip to content

Commit

Permalink
move @rounding_method from VariableExchange to Base
Browse files Browse the repository at this point in the history
  • Loading branch information
semmons99 committed Aug 10, 2010
1 parent ada27e7 commit 9ccc593
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/money/bank/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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+
#
Expand Down
2 changes: 1 addition & 1 deletion lib/money/bank/variable_exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VariableExchange < Base
def initialize(&block)
@rates = {}
@mutex = Mutex.new
@rounding_method = block
super
end


Expand Down
10 changes: 8 additions & 2 deletions spec/bank/base_spec.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -53,5 +60,4 @@
lambda{@bank.send(:same_currency?, 'AAA', 'BBB')}.should raise_exception(Money::Currency::UnknownCurrency)
end
end

end

0 comments on commit 9ccc593

Please sign in to comment.