Sha256: fd14a81169e62ac45badedd85cd6ccf2c9af96412ca75ce9a6099deb9ef27cca

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'
require 'volt/models/url'

describe Volt::URL do
  let(:uri) { 'http://voltframework.com:8888/path/1?query=val#fragment' }

  let(:fake_location) do
    double(
      'Location',
      host: 'voltframework.com',
      protocol: 'http:'
    )
  end

  before do
    allow(Location).to receive(:new).and_return fake_location
    subject.parse uri
  end

  subject { described_class.new fake_router }

  describe '#parse' do
    let(:fake_router) { double('Router', url_to_params: { foo: 'bar' }) }
    context 'with a valid url' do
      it 'returns "http" for scheme' do
        expect(subject.scheme).to eq 'http'
      end

      it 'returns "voltframework.com" for #host' do
        expect(subject.host).to eq 'voltframework.com'
      end

      it 'returns 8888 for #port' do
        expect(subject.port).to eq 8888
      end

      it 'returns "/path/1" for #path' do
        expect(subject.path).to eq '/path/1'
      end

      it 'returns "query=val" for #query' do
        expect(subject.query).to eq 'query=val'
      end

      it 'returns "fragment" for #fragment' do
        expect(subject.fragment).to eq 'fragment'
      end
    end
  end

  describe '#url_for' do
    let(:fake_router) do
      router = Volt::Routes.new

      router.define do
        client '/path/{{ id }}', view: 'blog/show'
      end
    end

    it 'regenerates the URL for the given params' do
      params = { view: 'blog/show', id: '1', query: 'val' }

      expect(subject.url_for params).to eq uri
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
volt-0.9.4.pre1 spec/models/url_spec.rb
volt-0.9.3 spec/models/url_spec.rb
volt-0.9.3.pre6 spec/models/url_spec.rb
volt-0.9.3.pre5 spec/models/url_spec.rb
volt-0.9.3.pre4 spec/models/url_spec.rb
volt-0.9.3.pre3 spec/models/url_spec.rb
volt-0.9.3.pre2 spec/models/url_spec.rb
volt-0.9.3.pre1 spec/models/url_spec.rb
volt-0.9.2 spec/models/url_spec.rb