Sha256: e4ca87e7a504aeb8969f4b523fe4060373d23b9bf2cba06c9cd30fef82ae79d6

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe LinkThumbnailer::Models::Image do

  let(:src)       { 'http://foo.com' }
  let(:instance)  { described_class.new(src) }

  before do
    stub_request(:get, src).to_return(status: 200, body: '', headers: {})
  end

  describe '#to_s' do

    let(:action) { instance.to_s }

    it { expect(action).to eq(src) }

  end

  describe '#<=>' do

    let(:other)   { double(size: other_size) }
    let(:action)  { instance <=> other }

    before do
      allow(instance).to receive(:size).and_return([20, 20])
    end

    context 'when other has a smaller image' do

      let(:other_size) { [10, 10] }

      it { expect(action).to eq(-1) }

    end

    context 'when other as identical image size' do

      let(:other_size) { [20, 20] }

      it { expect(action).to eq(0) }

    end

    context 'when other as a bigger image' do

      let(:other_size) { [30, 30] }

      it { expect(action).to eq(1) }

    end

  end

  describe '#valid?' do

    let(:validator) { double }
    let(:action)    { instance.valid? }

    before do
      allow(instance).to receive(:validator).and_return(validator)
    end

    it 'calls validator public method' do
      expect(validator).to receive(:call)
      action
    end

  end

  describe '#as_json' do

    let(:action)  { instance.as_json }
    let(:size)    { [1, 1] }
    let(:type)    { 'foo' }
    let(:result)  {
      {
        src:  src,
        size: size,
        type: type
      }
    }

    before do
      allow(instance).to receive(:size).and_return(size)
      allow(instance).to receive(:type).and_return(type)
    end

    it { expect(action).to eq(result) }

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
link_thumbnailer-3.4.0 spec/models/image_spec.rb
link_thumbnailer-3.3.2 spec/models/image_spec.rb