aboutsummaryrefslogtreecommitdiffstats
path: root/spec/helpers/link_to_helper_spec.rb
blob: f11f2b5bbb7f45e58bd86ebb1c1021b2eb9a92dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe LinkToHelper do 
    
    include LinkToHelper
    
    describe 'when creating a url for a request' do 
        
        before do
            @mock_request = mock_model(InfoRequest, :url_title => 'test_title')
            @old_filters = ActionController::Routing::Routes.filters
            ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
        end
        after do
            ActionController::Routing::Routes.filters = @old_filters
        end

        
        it 'should return a path like /request/test_title' do 
            request_url(@mock_request).should == '/request/test_title'
        end
        
        it 'should return a path including any extra parameters passed' do 
            request_url(@mock_request, {:update_status => 1}).should == '/request/test_title?update_status=1'
        end
        
    end

    describe "when appending something to a URL" do
        it 'should append to things without query strings' do
            main_url('/a', '.json').should == 'http://test.host/a.json'
        end
        it 'should append to things with query strings' do
            main_url('/a?z=1', '.json').should == 'http://test.host/a.json?z=1'
        end
        it 'should fail silently with invalid URLs' do
            main_url('/a?z=9%', '.json').should == 'http://test.host/a?z=9%'
        end
    end
    
end