Sha256: 367ed07de362e13cf6458f6bf56aacdc1f482eee6b930dbd8424640248cac5db

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

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
      instance.stub(: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
      instance.stub(:validator).and_return(validator)
    end

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

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
link_thumbnailer-2.1.0 spec/models/image_spec.rb
link_thumbnailer-2.0.4 spec/models/image_spec.rb
link_thumbnailer-2.0.3 spec/models/image_spec.rb
link_thumbnailer-2.0.2 spec/models/image_spec.rb
link_thumbnailer-2.0.1 spec/models/image_spec.rb
link_thumbnailer-2.0.0 spec/models/image_spec.rb