Sha256: 2fe4f98593d9b8eae4eade0db272d0e73b0ed1fefe3dbe9c5966c4efe4a68213

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

describe Acfs::Resource::Attributes::Dict do
  let(:model) { Class.new(Acfs::Resource) }
  subject { Acfs::Resource::Attributes::Dict.new }

  describe '.cast' do
    context 'with hash' do
      let(:sample) { {3 => true, 'asfd' => 4} }

      it 'should return unmodified hash' do
        expect(subject.cast(sample)).to be sample
      end
    end

    context 'with not hashable object' do
      let(:sample) { Object.new }

      it 'should raise a TypeError' do
        expect do
          subject.cast(sample)
        end.to raise_error TypeError
      end
    end

    context 'with hashable object' do
      let(:sample) do
        o = Object.new
        class << o
          def to_h
            {3 => 4, 'test' => true}
          end
        end
        o
      end

      it 'should cast object to hash' do
        expect(subject.cast(sample)).to eq 3 => 4, 'test' => true
      end
    end

    context 'with hash subclass' do
      let(:sample) { HashWithIndifferentAccess.new :test => :foo, 34 => 12 }

      it 'should return obj unmodified' do
        expect(subject.cast(sample)).to be sample
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
acfs-0.45.0 spec/acfs/resource/attributes/dict_spec.rb
acfs-0.44.0 spec/acfs/resource/attributes/dict_spec.rb
acfs-0.43.2 spec/acfs/resource/attributes/dict_spec.rb
acfs-0.43.1 spec/acfs/resource/attributes/dict_spec.rb
acfs-0.43.0 spec/acfs/resource/attributes/dict_spec.rb