Sha256: e4cdb90be56027c44e381e8b270d59b6b285cc9498b1903a3be83acf058d296d

Contents?: true

Size: 1.31 KB

Versions: 15

Compression:

Stored size: 1.31 KB

Contents

require 'sitehub/location_rewriters'
class SiteHub
  describe LocationRewriters do
    it 'is an array' do
      expect(subject).to be_kind_of(Array)
    end

    describe '#initialize' do
      context 'hash key is a regexp' do
        it 'leaves the key has a regexp' do
          key = %r{/.*/}
          value = '/'
          expect(described_class.new(key => value)).to eq([LocationRewriter.new(key, value)])
        end
      end

      context 'hash key is a string' do
        it 'converts the key to a regexp' do
          key = 'string'
          value = '/'
          expect(described_class.new(key => value)).to eq([LocationRewriter.new(Regexp.new(key), value)])
        end
      end
    end

    describe '#find' do
      let(:matcher) { Regexp.new('/orders/(.*)') }
      let(:path_template) { '/orders/$1' }
      subject do
        described_class.new(matcher => path_template)
      end
      context 'url matches matcher' do
        it 'returns the path directive' do
          expect(subject.find('http://url.com/orders/123')).to eq(LocationRewriter.new(matcher, path_template))
        end
      end
      context 'url does not match a matcher' do
        it 'returns default matcher' do
          expect(subject.find('http://url.com/mismatch')).to eq(described_class::DEFAULT)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
sitehub-0.5.0.alpha12 spec/sitehub/location_rewriters_spec.rb
sitehub-0.4.10 spec/sitehub/location_rewriters_spec.rb
sitehub-0.5.0.alpha11 spec/sitehub/location_rewriters_spec.rb
sitehub-0.5.0.alpha10 spec/sitehub/location_rewriters_spec.rb
sitehub-0.5.0.alpha8 spec/sitehub/location_rewriters_spec.rb
sitehub-0.5.0.alpha7 spec/sitehub/location_rewriters_spec.rb
sitehub-0.5.0.alpha6 spec/sitehub/location_rewriters_spec.rb
sitehub-0.5.0.alpha5 spec/sitehub/location_rewriters_spec.rb
sitehub-0.5.0.alpha4 spec/sitehub/location_rewriters_spec.rb
sitehub-0.5.0.alpha3 spec/sitehub/location_rewriters_spec.rb
sitehub-0.5.0.alpha2 spec/sitehub/location_rewriters_spec.rb
sitehub-0.4.9 spec/sitehub/location_rewriters_spec.rb
sitehub-0.4.8 spec/sitehub/location_rewriters_spec.rb
sitehub-0.4.7 spec/sitehub/location_rewriters_spec.rb
sitehub-0.4.6 spec/sitehub/location_rewriters_spec.rb