Sha256: d10c4b48071fd2c39b38c5564fbcce9afc847a53c2ffb61e23f4e216f38c1096

Contents?: true

Size: 825 Bytes

Versions: 22

Compression:

Stored size: 825 Bytes

Contents

require 'spec_helper'

describe ApiResource::Typecast::BooleanTypecaster do

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

  context ".from_api" do

    it "should typecast any value in the true array to true" do
      ApiResource::Typecast::TRUE_VALUES.each do |value|
        klass.from_api(value).should be_instance_of(TrueClass)
      end
    end

    it "should return false for any other conceivable input" do
      [Date.new, Time.new, Date.today, Time.now, nil, false, Float, 2.0, 2, "", "bad value"].each do |val|
        klass.from_api(val).should be_instance_of(FalseClass)
      end
    end

  end

  context ".to_api" do

    it "should return whatever value is passed in" do
      [nil, true, 1, 0.5, Time.now].each do |val|
        klass.to_api(val).should eql(val)
      end
    end

  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
api_resource-0.6.21 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.20 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.19 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.18 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.17 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.16 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.15 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.14 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.13 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.12 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.11 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.9 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.10 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.8 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.7 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.6 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.5 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.4 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.3 spec/lib/typecasters/boolean_typecaster_spec.rb
api_resource-0.6.2 spec/lib/typecasters/boolean_typecaster_spec.rb