Sha256: 5dce2493bb9bc9191ae31274fba50c4da0eac601b0a3f4b4accab63603b7fccf

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

module Locomotive
  module Plugin
    describe RackAppHelpers do

      before(:all) do
        PluginWithRackApp.set_mountpoint('http://www.example.com/my/path')
      end

      before(:each) do
        @config = {}
        @plugin = PluginWithRackApp.new(@config)
      end

      it 'should supply an absolute path based on where it is mounted' do
        @plugin.full_path('/plugin/path').should == '/my/path/plugin/path'
        @plugin.full_path('another//path').should == '/my/path/another//path'
      end

      it 'should supply a full URL based on where it is mounted' do
        @plugin.full_url('/plugin/path').should ==
          'http://www.example.com/my/path/plugin/path'
        @plugin.full_url('another//path').should ==
          'http://www.example.com/my/path/another//path'
      end

      it 'should only allow URLs with proper format' do
        old_mountpoint = PluginWithRackApp.mountpoint

        bad_mountpoints = [
          'my/path',
          'my.server.com/my/path',
          'ftp://my.server.com',
          'http://my.server.com/my/path?q=value',
          'http://my.server.com/my/path#fragment',
          'https://my.server.com/my/path?q=value',
          'https://my.server.com/my/path#fragment'
        ]

        good_mountpoints = [
          'http://my.server.com/my/path',
          'http://my.server.com:3000/my/path',
          'https://my.server.com/my/path',
          'https://my.server.com:3000/my/path'
        ]

        bad_mountpoints.each do |mountpoint|
          lambda do
            PluginWithRackApp.set_mountpoint(mountpoint)
          end.should raise_exception(Locomotive::Plugin::Error)
          PluginWithRackApp.mountpoint.should == old_mountpoint
        end

        good_mountpoints.each do |mountpoint|
          lambda do
            PluginWithRackApp.set_mountpoint(mountpoint)
          end.should_not raise_exception
          PluginWithRackApp.mountpoint.to_s.should == mountpoint
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
locomotive_plugins-1.0.0.beta7 spec/lib/locomotive/plugin/rack_app_helpers_spec.rb