Sha256: 941510535aeeb5a0c258d8901528d7861cab6b464fe51c1b1016f78e8a71d0e5

Contents?: true

Size: 1.69 KB

Versions: 6

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

describe Contentful::Asset do
  let(:asset) { vcr('asset') { create_client.asset('nyancat') } }

  describe 'SystemProperties' do
    it 'has a #sys getter returning a hash with symbol keys' do
      expect(asset.sys).to be_a Hash
      expect(asset.sys.keys.sample).to be_a Symbol
    end

    it 'has #id' do
      expect(asset.id).to eq 'nyancat'
    end

    it 'has #type' do
      expect(asset.type).to eq 'Asset'
    end

    it 'has #space' do
      expect(asset.space).to be_a Contentful::Link
    end

    it 'has #created_at' do
      expect(asset.created_at).to be_a DateTime
    end

    it 'has #updated_at' do
      expect(asset.updated_at).to be_a DateTime
    end

    it 'has #revision' do
      expect(asset.revision).to eq 1
    end
  end

  describe 'Fields' do
    it 'has #title' do
      expect(asset.title).to eq 'Nyan Cat'
    end

    it 'could have #description' do
      expect(asset).to respond_to :description
    end

    it 'has #file' do
      expect(asset.file).to be_a Contentful::File
    end
  end

  describe '#image_url' do
    it 'returns #url of #file without parameter' do
      expect(asset.image_url).to eq asset.file.url
    end

    it 'adds image options if given' do
      url = asset.image_url(width: 100, format: 'jpg', quality: 50, focus: 'top_right', fit: 'thumb', fl: 'progressive')
      expect(url).to include asset.file.url
      expect(url).to include '?w=100&fm=jpg&q=50&f=top_right&fit=thumb&fl=progressive'
    end
  end

  it 'can be marshalled' do
    marshalled = Marshal.dump(asset)
    unmarshalled = Marshal.load(marshalled)

    expect(unmarshalled.title).to eq 'Nyan Cat'
    expect(unmarshalled.file).to be_a Contentful::File
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contentful-1.0.2 spec/asset_spec.rb
contentful-1.0.1 spec/asset_spec.rb
contentful-1.0.0 spec/asset_spec.rb
contentful-0.12.0 spec/asset_spec.rb
contentful-0.11.0 spec/asset_spec.rb
contentful-0.10.0 spec/asset_spec.rb