Sha256: 00082fa0d9fbdc4f277e06334933c9061d08e5b6144eaaba881d6096654c0c81

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require File.dirname(__FILE__) + '/test_helper'

class Flight
  extend Conversions::ActiveRecordAccessors
  attr_accessor :distance, :fuel_consumption
  conversion_accessor :distance, :internal => :kilometres, :external => :miles
  conversion_accessor :fuel_consumption, :internal => :litres, :external => :gallons, :scale => 2
  
  Conversions.register(:kilometres, :leagues, 0.179985601)
  conversion_accessor :distance, :internal => :kilometres, :external => :leagues, :scale => 2
end

class AccessorTest < Test::Unit::TestCase

  def setup
    @flight = Flight.new
  end

  def test_include
    assert @flight.respond_to?(:distance)
    assert @flight.respond_to?(:distance_in_miles)
  end

  def test_conversion
    @flight.distance = 1200
    assert_in_delta 745.645430684801, @flight.distance_in_miles, DELTA
  end

  def test_conversion_with_scale
    @flight.fuel_consumption = 3400
    assert_equal 898.18, @flight.fuel_consumption_in_gallons, DELTA
  end
  
  def test_register
    @flight.distance = 1200
    assert_in_delta 215.98, @flight.distance_in_leagues, DELTA
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seamusabshere-conversions-1.3.0 test/accessor_test.rb