Permalink
Browse files

return entered rate by default

  • Loading branch information...
1 parent 23859be commit e342e783c839f581da96fa229ff446d5890bf268 @malomalo malomalo committed Aug 29, 2013
Showing with 12 additions and 12 deletions.
  1. +4 −3 lib/mls/models/listing.rb
  2. +1 −1 mls.gemspec
  3. +7 −8 test/units/models/test_listing.rb
View
7 lib/mls/models/listing.rb
@@ -153,9 +153,10 @@ def rate?
end
# TODO: remove /desk/mo conversions
- def rate(units='/sqft/mo')
+ def rate(units=nil)
return nil if !@rate
-
+ units ||= rate_units
+
price = if rate_units == '/sqft/mo'
if units == '/sqft/mo'
@rate
@@ -220,7 +221,7 @@ def rate(units='/sqft/mo')
if units == '/sqft/mo'
@rate / 200.0
elsif units == '/sqft/yr'
- ((@rate / 200.0) * 12) / @size.to_f
+ (@rate * 12) / 200.0
elsif units == '/mo'
@rate
elsif units == '/yr'
View
2 mls.gemspec
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = "mls"
- s.version = '0.9.4'
+ s.version = '0.9.5'
s.authors = ["James R. Bracy", "Jon Bracy"]
s.email = ["james@42floors.com"]
s.homepage = "http://mls.42floors.com"
View
15 test/units/models/test_listing.rb
@@ -194,7 +194,7 @@ def test_rate_per_sqft_per_month
def test_rate_per_sqft_per_year
listing = MLS::Listing.new(:rate => 126, :rate_units => '/sqft/yr', :size => 5)
- assert_equal 10.5, listing.rate
+ assert_equal 126, listing.rate
assert_equal 10.5, listing.rate('/sqft/mo')
assert_equal 126, listing.rate('/sqft/yr')
assert_equal 52.5, listing.rate('/mo')
@@ -208,7 +208,7 @@ def test_rate_per_sqft_per_year
def test_rate_per_month
listing = MLS::Listing.new(:rate => 52.5, :rate_units => '/mo', :size => 5)
- assert_equal 10.5, listing.rate
+ assert_equal 52.5, listing.rate
assert_equal 10.5, listing.rate('/sqft/mo')
assert_equal 126, listing.rate('/sqft/yr')
assert_equal 52.5, listing.rate('/mo')
@@ -222,7 +222,7 @@ def test_rate_per_month
def test_rate_per_year
listing = MLS::Listing.new(:rate => 630, :rate_units => '/yr', :size => 5)
- assert_equal 10.5, listing.rate
+ assert_equal 630, listing.rate
assert_equal 10.5, listing.rate('/sqft/mo')
assert_equal 126, listing.rate('/sqft/yr')
assert_equal 52.5, listing.rate('/mo')
@@ -234,13 +234,13 @@ def test_rate_per_year
end
def test_rate_per_desk_per_month
- listing = MLS::Listing.new(:rate => 630, :rate_units => '/yr', :size => 5)
+ listing = MLS::Listing.new(:rate => 2100, :rate_units => '/desk/mo', :size => 5)
- assert_equal 10.5, listing.rate
+ assert_equal 2100, listing.rate
assert_equal 10.5, listing.rate('/sqft/mo')
assert_equal 126, listing.rate('/sqft/yr')
- assert_equal 52.5, listing.rate('/mo')
- assert_equal 630, listing.rate('/yr')
+ assert_equal 2100, listing.rate('/mo')
+ assert_equal 25200, listing.rate('/yr')
assert_equal 2100, listing.rate('/desk/mo')
assert_raises RuntimeError do
listing.rate('/random')
@@ -250,7 +250,6 @@ def test_rate_per_desk_per_month
def test_rate_percision
listing = MLS::Listing.new(:rate => 47, :rate_units => '/sqft/yr', :size => 5)
- assert_equal 3.92, listing.rate
assert_equal 3.92, listing.rate('/sqft/mo')
assert_equal 47, listing.rate('/sqft/yr')
assert_equal 19.58, listing.rate('/mo')

0 comments on commit e342e78

Please sign in to comment.