Permalink
Browse files

Gem now works with Ruby 1.9.2

  • Loading branch information...
1 parent d62e5e5 commit ab7bc08979c1b542f14bd1b760221ae4fb00156a jeroen committed Jun 3, 2011
Showing with 8 additions and 6 deletions.
  1. +5 −5 lib/acts_as_price.rb
  2. +3 −1 lib/acts_as_price_helper.rb
View
@@ -29,13 +29,13 @@ def acts_as_price column_name, options = {}
#getters
define_method(column_name) do
- if super.blank? or super == 0.0
+ if super().blank? or super() == 0.0
""
else
if comma
- return_val = sprintf("%.2f", super.to_f / 100).gsub(".", ",")
+ return_val = sprintf("%.2f", super().to_f / 100).gsub(".", ",")
else
- return_val = sprintf("%.2f", super.to_f / 100)
+ return_val = sprintf("%.2f", super().to_f / 100)
end
return_val = currency ? "#{currency}. #{return_val}" : return_val
return_val
@@ -45,9 +45,9 @@ def acts_as_price column_name, options = {}
define_method("price_in_cents") do
if currency
- ((send column_name).gsub("#{currency}. ", "").gsub(",", ".").to_f * 100).to_s.to_i
+ ((send column_name).gsub("#{currency}. ", "").gsub(",", ".").to_f * 100).round
else
- ((send column_name).gsub(",", ".").to_f * 100).to_s.to_i
+ ((send column_name).gsub(",", ".").to_f * 100).round
end
end
alias_method "#{column_name}_in_cents", "price_in_cents"
@@ -20,6 +20,7 @@ def test_acts_as_price_methods column_name, seperator, options = {}
#normal test for setter
test_setter_in_cents "144", seperator
+
if @acts_as_price_model.currency
currency = @acts_as_price_model.currency
test_setter_in_doubles "#{currency}. 1.41", seperator
@@ -30,6 +31,7 @@ def test_acts_as_price_methods column_name, seperator, options = {}
test_setter_in_doubles "#{currency}. 1.5", seperator
test_setter_in_doubles "#{currency}. 1.505", seperator
test_setter_in_doubles "#{currency}. 1.504", seperator
+
#test if 1,5 is returned as 1.50
test_setter_in_doubles "#{currency}. 1,5", seperator
test_setter_in_doubles "#{currency}. 1,505", seperator
@@ -100,7 +102,7 @@ def test_setter_in_doubles double, seperator
@acts_as_price_model.send(getter).should == ""
else
if currency
- @acts_as_price_model.send(getter).should == currency + ". " + sprintf("%.2f", (double.gsub(",", ".").to_f + 0.001).to_s).gsub(".", seperator)
+ @acts_as_price_model.send(getter).should == currency + ". " + sprintf("%.2f", double.gsub(",", ".").to_f + 0.0001).gsub(".", seperator)
else
@acts_as_price_model.send(getter).should == sprintf("%.2f", double.gsub(",", ".").to_s).gsub(".", seperator)
end

0 comments on commit ab7bc08

Please sign in to comment.