Sha256: f4188dd8fb05b18a0acd82cc1b5eb6d3c815974bc954ea897f789ad3fd367e02

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'

describe Shortener::ShortenerHelper, type: :helper do
  describe '#short_url' do
    let(:destination) { Faker::Internet.url }

    context 'without user or custom key' do
      before do
        expect(Shortener::ShortenedUrl).to receive(:generate).with(destination, owner: nil, custom_key: nil).and_return(shortened_url)
      end

      context 'short url was generated' do
        let(:shortened_url) { instance_double('ShortenedUrl', unique_key: '12345') }

        it "shortens the url" do
          expect(helper.short_url(destination)).to eq "http://test.host/12345"
        end
      end

      context 'short url could not be generated' do
        let(:shortened_url) { nil }

        it 'returns the original url' do
          expect(helper.short_url(destination)).to eq destination
        end
      end
    end

    context 'with owner' do
      let(:owner) { double('User') }
      it 'sends user to generate function' do
        expect(Shortener::ShortenedUrl).to receive(:generate).with(destination, owner: owner, custom_key: nil)
        helper.short_url(destination, owner: owner)
      end
    end

    context 'with custom_key' do
      it 'sends custom key code to generate function' do
        expect(Shortener::ShortenedUrl).to receive(:generate).with(destination, owner: nil, custom_key: 'custkey')
        helper.short_url(destination, custom_key: 'custkey')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shortener-0.5.3 spec/helpers/shortener_helper_spec.rb
shortener-0.5.2 spec/helpers/shortener_helper_spec.rb
shortener-0.5.1 spec/helpers/shortener_helper_spec.rb
shortener-0.5.0 spec/helpers/shortener_helper_spec.rb