aboutsummaryrefslogtreecommitdiffstats
path: root/spec/helpers/link_to_helper_spec.rb
blob: 63daf1a752032b1332744a9087b30706fcc459ce (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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')
            RoutingFilter.active = false
        end
        after do
            RoutingFilter.active = true
        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

    describe 'when displaying a user admin link for a request' do

        it 'should return the text "An anonymous user (external)" in the case where there is no external username' do
            info_request = mock_model(InfoRequest, :external_user_name => nil,
                                                   :is_external? => true)
            user_admin_link_for_request(info_request).should == 'Anonymous user (external)'
        end

    end

    describe 'admin_url' do
        context 'with no ADMIN_BASE_URL set' do
            it 'should prepend the admin general index path to a simple string' do
                admin_url('unclassified').should == 'http://test.host/en/admin/unclassified'
            end

            it 'should prepend the admin general index path to a deeper URL' do
                admin_url('request/show/123').should == 'http://test.host/en/admin/request/show/123'
            end
        end

        context 'with ADMIN_BASE_URL set' do
            before(:each) do
                AlaveteliConfiguration::should_receive(:admin_base_url).and_return('https://www.example.com/secure/alaveteli-admin/')
            end

            it 'should prepend the admin base URL to a simple string' do
                admin_url('unclassified').should == 'https://www.example.com/secure/alaveteli-admin/unclassified'
            end

            it 'should prepend the admin base URL to a deeper URL' do
                admin_url('request/show/123').should == 'https://www.example.com/secure/alaveteli-admin/request/show/123'
            end
        end
    end

    describe 'simple_date' do
        it 'should respect time zones' do
            Time.use_zone('Australia/Sydney') do
                simple_date(Time.utc(2012, 11, 07, 21, 30, 26)).should == 'November 08, 2012'
            end
        end

        it 'should handle Date objects' do
            simple_date(Date.new(2012, 11, 21)).should == 'November 21, 2012'
        end
    end
end