Sha256: 72d1bb9b611c5e5227d07c6df5b30202794a729b4c8a4219a87dca6edea02eba

Contents?: true

Size: 536 Bytes

Versions: 10

Compression:

Stored size: 536 Bytes

Contents

require 'spec_helper'

describe 'Coercion Examples' do
  let(:entry) { vcr('entry') { create_client.entry 'nyancat' } }

  it 'converts contentful to ruby DateTime objects' do
    expect(entry.created_at).to be_a DateTime
    expect(entry.created_at.day).to eq 27
  end

  describe 'custom coercion' do
    class TestCar
      include Contentful::Resource

      property :parts, ->(v) { Array(v) unless v }
    end

    it 'can use proc' do
      car = TestCar.new("parts" => nil)
      expect(car.parts).to be_empty
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
contentful-1.2.2 spec/coercions_spec.rb
contentful-1.2.1 spec/coercions_spec.rb
contentful-1.2.0 spec/coercions_spec.rb
contentful-1.1.1 spec/coercions_spec.rb
contentful-1.1.0 spec/coercions_spec.rb
contentful-1.0.2 spec/coercions_spec.rb
contentful-1.0.1 spec/coercions_spec.rb
contentful-1.0.0 spec/coercions_spec.rb
contentful-0.12.0 spec/coercions_spec.rb
contentful-0.11.0 spec/coercions_spec.rb