[#4554] Fix the markup calculation to work with plain numerics
This commit is contained in:
1 parent
8582ad0ecd
commit
0a80a54be3
2 files changed
+45
-3
No files matched your search
@@ -32,8 +32,10 @@ class FixedBudget < ActiveRecord::Base
|
|||||||
when percent_markup?
|
when percent_markup?
|
||||||
percent = markup.gsub('%','').to_f
|
percent = markup.gsub('%','').to_f
|
||||||
return budget.to_f * (percent / 100)
|
return budget.to_f * (percent / 100)
|
||||||
when straight_markup?
|
when dollar_markup?
|
||||||
markup.gsub('$','').gsub(',','').to_f
|
markup.gsub('$','').gsub(',','').to_f
|
||||||
|
when straight_markup?
|
||||||
|
markup.to_f
|
||||||
else
|
else
|
||||||
0 # Invalid markup
|
0 # Invalid markup
|
||||||
end
|
end
|
||||||
@@ -49,11 +51,15 @@ class FixedBudget < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def percent_markup?
|
def percent_markup?
|
||||||
markup && markup.match(/%/)
|
markup && markup.to_s.match(/%/)
|
||||||
|
end
|
||||||
|
|
||||||
|
def dollar_markup?
|
||||||
|
markup && markup.to_s.match(/[$,]+/)
|
||||||
end
|
end
|
||||||
|
|
||||||
def straight_markup?
|
def straight_markup?
|
||||||
markup && markup.match(/\$/)
|
markup && markup.to_s.match(/[\d.]/)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Is this a blank budget item. Retainers will create blank ones when
|
# Is this a blank budget item. Retainers will create blank ones when
|
||||||
|
|||||||
@@ -27,7 +27,43 @@ class FixedBudgetTest < ActiveSupport::TestCase
|
|||||||
@fixed_budget.markup = '$4,000.57'
|
@fixed_budget.markup = '$4,000.57'
|
||||||
assert_equal 4000.57, @fixed_budget.markup_value
|
assert_equal 4000.57, @fixed_budget.markup_value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "work without the $ sign" do
|
||||||
|
@fixed_budget.markup = '4,000.57'
|
||||||
|
assert_equal 4000.57, @fixed_budget.markup_value
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a straight amount of markup" do
|
||||||
|
should "equal the markup" do
|
||||||
|
@fixed_budget.markup = 4000.57
|
||||||
|
assert_equal 4000.57, @fixed_budget.markup_value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#budget=" do
|
||||||
|
setup do
|
||||||
|
@fixed_budget = FixedBudget.new
|
||||||
|
end
|
||||||
|
|
||||||
|
should "allow a $ string" do
|
||||||
|
@fixed_budget.budget = '$1,000.00'
|
||||||
|
assert_equal 1000.00, @fixed_budget.budget
|
||||||
|
end
|
||||||
|
|
||||||
|
should "allow a plain string" do
|
||||||
|
@fixed_budget.budget = '1,000.00'
|
||||||
|
assert_equal 1000.00, @fixed_budget.budget
|
||||||
|
end
|
||||||
|
|
||||||
|
should "allow a numeric value" do
|
||||||
|
@fixed_budget.budget = 1000.00
|
||||||
|
assert_equal 1000.00, @fixed_budget.budget
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user