Sha256: 983e7cafa617d8da4f472b19673f2d91230e9fb221669f5f16289bda119f9d1c

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 KB

Contents

require 'pathname'
require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'

describe DataMapper::Types::URI do

  before(:each) do
    @uri_str = "http://example.com/path/to/resource/"
    @uri = Addressable::URI.parse(@uri_str)
  end

  describe ".dump" do
    it "should return the URI as a String" do
      DataMapper::Types::URI.dump(@uri, :property).should == @uri_str
    end

    it "should return nil if the String is nil" do
      DataMapper::Types::URI.dump(nil, :property).should be_nil
    end

    it "should return an empty URI if the String is empty" do
      DataMapper::Types::URI.dump("", :property).should == ""
    end
  end

  describe ".load" do
    it "should return the URI as Addressable" do
      DataMapper::Types::URI.load(@uri_str, :property).should == @uri
    end

    it "should return nil if given nil" do
      DataMapper::Types::URI.load(nil, :property).should be_nil
    end

    it "should return an empty URI if given an empty String" do
      DataMapper::Types::URI.load("", :property).should == Addressable::URI.parse("")
    end
  end

  describe '.typecast' do
    it 'should do nothing if an Addressable::URI is provided' do
      DataMapper::Types::URI.typecast(@uri, :property).should == @uri
    end

    it 'should defer to .load if a string is provided' do
      DataMapper::Types::URI.should_receive(:load).with(@uri_str, :property)
      DataMapper::Types::URI.typecast(@uri_str, :property)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dm-types-0.9.11 spec/unit/uri_spec.rb
dm-types-0.9.6 spec/unit/uri_spec.rb
dm-types-0.9.5 spec/unit/uri_spec.rb
dm-types-0.9.10 spec/unit/uri_spec.rb
dm-types-0.9.4 spec/unit/uri_spec.rb
dm-types-0.9.3 spec/unit/uri_spec.rb
dm-types-0.9.9 spec/unit/uri_spec.rb
dm-types-0.9.8 spec/unit/uri_spec.rb
dm-types-0.9.7 spec/unit/uri_spec.rb