Sha256: 27952f8dd8c5ec58aac936d0b3df6521afae755ee761973fc852ab43827ad825

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

describe Journey::Resource::Attachments do

  let(:klass) do 
    Class.new(Journey::Resource) do
      self.element_name = 'job'
      attachment :important_file
      attachment :boring_file
    end
  end

  describe '.attachment' do
    let(:instance) do
      klass.new(display_attachments: OpenStruct.new({
        'important_file' => OpenStruct.new({
          'original' => 'O.jpg',
          'thumbnail' => 'T.jpg'
        })
      }))
    end

    describe '##{attachment}_path' do

      it 'defaults to original size' do
        expect(instance.important_file_path).to eq 'O.jpg'
      end

      it 'returns path from #display_attachments for a given size' do
        expect(instance.important_file_path(:thumbnail)).to eq 'T.jpg'
      end

      it 'is blank when attachment doesnt exist' do
        expect(instance.boring_file_path).to be_nil
      end

      it 'handles missing display_attachments gracefully' do
        instance.display_attachments = nil
        expect{ instance.important_file_path }.not_to raise_error
      end
    end

    describe '##{attachment}_url' do
      it 'is blank when attachment doesnt exist' do
        expect(instance.boring_file_url).to be_blank
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
embark-journey-0.0.24 spec/models/journey/resource/attachments_spec.rb
embark-journey-0.0.23 spec/models/journey/resource/attachments_spec.rb
embark-journey-0.0.22 spec/models/journey/resource/attachments_spec.rb
embark-journey-0.0.21 spec/models/journey/resource/attachments_spec.rb
embark-journey-0.0.20 spec/models/journey/resource/attachments_spec.rb
embark-journey-0.0.19 spec/models/journey/resource/attachments_spec.rb
embark-journey-0.0.18 spec/models/journey/resource/attachments_spec.rb
embark-journey-0.0.17 spec/models/journey/resource/attachments_spec.rb
embark-journey-0.0.16 spec/models/journey/resource/attachments_spec.rb