Sha256: 54cf3bcce043cbeeb52ba4031d531fdce3ed095f7f260895df3aede5d38c0b55

Contents?: true

Size: 970 Bytes

Versions: 5

Compression:

Stored size: 970 Bytes

Contents

require 'spec_helper'
require 'bigdecimal'

module Arel
  describe "Attributes::String" do

    before :all do
      @relation = Model.build do |r|
        r.engine Testing::Engine.new
        r.attribute :name, Attributes::String
      end
    end

    def type_cast(val)
      @relation[:name].type_cast(val)
    end

    describe "#type_cast" do
      it "returns same value if passed a String" do
        val = "hell"
        type_cast(val).should eql(val)
      end

      it "returns nil if passed nil" do
        type_cast(nil).should be_nil
      end

      it "returns String representation of Symbol" do
        type_cast(:hello).should == "hello"
      end

      it "returns string representation of Integer" do
        type_cast(1).should == '1'
      end

      it "calls #to_s on arbitrary objects" do
        obj = Object.new
        obj.extend Module.new { def to_s ; 'hello' ; end }
        type_cast(obj).should == 'hello'
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
arel-1.0.1 spec/attributes/string_spec.rb
arel-1.0.0 spec/attributes/string_spec.rb
arel-1.0.0.rc1 spec/attributes/string_spec.rb
arel-compat-0.4.0 spec/attributes/string_spec.rb
arel-0.4.0 spec/attributes/string_spec.rb