aboutsummaryrefslogtreecommitdiffstats
path: root/spec/integration/localisation_spec.rb
blob: 4f6b61ae1136be7143edec33fd9c9a4ac62c7785 (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
88
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "when generating urls" do

    before do
        @home_link_regex = /href=".*\/en\//
    end

    it "should generate URLs that include the locale when using one that includes an underscore" do
        get('/en_GB')
        response.body.should match /href="\/en_GB\//
    end

    it "should fall back to the language if the territory is unknown" do
        AlaveteliLocalization.set_locales(available_locales='es en', default_locale='en')
        get('/', {}, {'HTTP_ACCEPT_LANGUAGE' => 'en_US'})
        response.body.should match /href="\/en\//
        response.body.should_not match /href="\/en_US\//
    end

    it "should generate URLs without a locale prepended when there's only one locale set" do
        AlaveteliLocalization.set_locales(available_locales='en', default_locale='en')
        get('/')
        response.should_not contain @home_link_regex
    end

    it 'should redirect requests for a public body in a locale to the canonical name in that locale' do
        get('/es/body/dfh')
        response.should redirect_to "/es/body/edfh"
    end

    it 'should remember a filter view when redirecting a public body request to the canonical name' do
        get('/es/body/tgq/successful')
        response.should redirect_to "/es/body/etgq/successful"
    end

    describe 'when there is more than one locale' do

        before do
            AlaveteliLocalization.set_locales(available_locales='es en', default_locale='en')
        end

        it "should generate URLs with a locale prepended when there's more than one locale set" do
            get('/')
            response.body.should match @home_link_regex
        end

        describe 'when using the default locale' do

            before do
                @default_lang_home_link = /href=".*\/en\//
                @other_lang_home_link = /href=".*\/es\//
                @old_include_default_locale_in_urls = AlaveteliConfiguration::include_default_locale_in_urls
            end

            describe 'when the config value INCLUDE_DEFAULT_LOCALE_IN_URLS is false' do

                before do
                    AlaveteliLocalization.set_default_locale_urls(false)
                end

                it 'should generate URLs without a locale prepended' do
                    get '/'
                    response.should_not contain @default_lang_home_link
                end

                it 'should render the front page in the default language when no locale param
                    is present and the session locale is not the default' do
                    get('/', {:locale => 'es'})
                    response.should_not contain @other_lang_home_link
                end
            end

            it 'should generate URLs with a locale prepended when the config value
                INCLUDE_DEFAULT_LOCALE_IN_URLS is true' do
                AlaveteliLocalization.set_default_locale_urls(true)
                get '/'
                response.body.should match /#{@default_lang_home_link}/
            end

            after do
                AlaveteliLocalization.set_default_locale_urls(@old_include_default_locale_in_urls)
            end

        end
    end

end