Sha256: 1cc5f13601cd53ba26b594435f671fcb1afb969a622f033c9d67d30f4ed8a282

Contents?: true

Size: 1.09 KB

Versions: 13

Compression:

Stored size: 1.09 KB

Contents

require 'spec_helper'

describe ApiResource::Typecast::IntegerTypecaster do

  let(:klass) { ApiResource::Typecast::IntegerTypecaster}

  context ".from_api" do

    it "should typecast integers, floats, strings, dates, and times reasonably" do
      klass.from_api(1).should eql(1)
      klass.from_api(1.0).should eql(1)
      klass.from_api(1.67).should eql(1)
      klass.from_api("1.0").should eql(1)
      klass.from_api("1").should eql(1)
      klass.from_api("0.123").should eql(0)
      klass.from_api(false).should eql(0)
      klass.from_api(true).should eql(1)
      klass.from_api(Date.today).should eql(Date.today.year)

      tme = Time.now
      klass.from_api(tme).should eql(tme.to_i)
    end

    it "should be able to typecast any value you can think of" do
      klass.from_api(nil).should eql(0)
      klass.from_api("").should eql(0)
      klass.from_api(BasicObject).should eql(0)
      klass.from_api("abc").should eql(0)
    end

  end

  context ".to_api" do
    it "should return itself" do
      val = 1
      klass.to_api(val).object_id.should eql(val.object_id)
    end
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
api_resource-0.6.12 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.11 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.9 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.10 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.8 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.7 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.6 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.5 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.4 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.3 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.2 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.1 spec/lib/typecasters/integer_typecaster_spec.rb
api_resource-0.6.0 spec/lib/typecasters/integer_typecaster_spec.rb