Sha256: 6bd6a50ff8a7d55fed512d1c7a3200de7094b69b406c46a86b2ba2c873c49410

Contents?: true

Size: 1.43 KB

Versions: 26

Compression:

Stored size: 1.43 KB

Contents

require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")

describe "LooserTypecasting Extension" do
  before do
    @db = Sequel::Database.new
    def @db.supports_schema_parsing?() true end
    def @db.schema(*args)
      [[:id, {}], [:z, {:type=>:float}], [:b, {:type=>:integer}], [:d, {:type=>:decimal}], [:s, {:type=>:string}]]
    end 
    @c = Class.new(Sequel::Model(@db[:items]))
    @db.extension(:looser_typecasting)
    @c.instance_eval do
      @columns = [:id, :b, :z, :d, :s] 
      def columns; @columns; end 
    end
  end

  specify "should not raise errors for invalid strings in integer columns" do
    @c.new(:b=>'a').b.should == 0
    @c.new(:b=>'a').b.should be_a_kind_of(Integer)
  end

  specify "should not raise errors for invalid strings in float columns" do
    @c.new(:z=>'a').z.should == 0.0
    @c.new(:z=>'a').z.should be_a_kind_of(Float)
  end

  specify "should not raise errors for hash or array input to string columns" do
    @c.new(:s=>'a').s.should == 'a'
    @c.new(:s=>[]).s.should be_a_kind_of(String)
    @c.new(:s=>{}).s.should be_a_kind_of(String)
  end

  specify "should not raise errors for invalid strings in decimal columns" do
    @c.new(:d=>'a').d.should == 0.0
    @c.new(:d=>'a').d.should be_a_kind_of(BigDecimal)
  end

  specify "should not affect conversions of other types in decimal columns" do
    @c.new(:d=>1).d.should == 1
    @c.new(:d=>1).d.should be_a_kind_of(BigDecimal)
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
sequel-4.22.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.21.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.20.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.19.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.18.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.17.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.16.0 spec/extensions/looser_typecasting_spec.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/sequel-4.15.0/spec/extensions/looser_typecasting_spec.rb
sequel-4.15.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.14.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.13.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.12.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.11.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.10.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.9.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.8.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.7.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.6.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.5.0 spec/extensions/looser_typecasting_spec.rb
sequel-4.4.0 spec/extensions/looser_typecasting_spec.rb