Sha256: baf35ee638f5b46b9e345a0f64b1fec4f75230b728ae031db64dba9cf7b5d192

Contents?: true

Size: 1.27 KB

Versions: 9

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

describe Utils::ImageUrlFormatter do
  let(:url) { "http://berkin.com/whatever/else/is/here" }
  let(:formatted_url) { Utils::ImageUrlFormatter.new(url, image_url).perform }

  context 'the host is missing from the image url' do
    let(:image_url) { "/some/stupid/path" }

    context 'scheme is http' do
      it 'should return the image as a full url using the host as domain' do
        expect(formatted_url).to eq('http://berkin.com/some/stupid/path')
      end
    end

    context 'scheme is https' do
      let(:url) { "https://berkin.com/whatever/else/is/here" }

      it 'should return the image as a full url using the host as domain' do
        expect(formatted_url).to eq('https://berkin.com/some/stupid/path')
      end
    end
  end

  context 'but the host is present, but the scheme is missing' do
    let(:image_url) { "//berkin.com/some/stupid/path" }

    it 'should return the image as a full url using http as the protocol' do
      expect(formatted_url).to eq('http://berkin.com/some/stupid/path')
    end
  end

  context 'image_url is nil' do
    let(:image_url) { nil }
    it 'fails silently' do
      expect {
        formatted_url
      }.not_to raise_error
    end

    it 'returns nil' do
      expect(formatted_url).to be_nil
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
link_oracle-0.1.11 spec/link_oracle/Utils/image_url_formatter_spec.rb
link_oracle-0.1.10 spec/link_oracle/Utils/image_url_formatter_spec.rb
link_oracle-0.1.9 spec/link_oracle/Utils/image_url_formatter_spec.rb
link_oracle-0.1.8 spec/link_oracle/Utils/image_url_formatter_spec.rb
link_oracle-0.1.7 spec/link_oracle/Utils/image_url_formatter_spec.rb
link_oracle-0.1.6 spec/link_oracle/Utils/image_url_formatter_spec.rb
link_oracle-0.1.5 spec/link_oracle/Utils/image_url_formatter_spec.rb
link_oracle-0.1.4 spec/link_oracle/Utils/image_url_formatter_spec.rb
link_oracle-0.1.3 spec/link_oracle/Utils/image_url_formatter_spec.rb