File: locale_loading_spec.rb

package info (click to toggle)
ruby-doorkeeper-i18n 5.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 288 kB
  • sloc: ruby: 118; makefile: 4
file content (68 lines) | stat: -rw-r--r-- 2,064 bytes parent folder | download
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
# encoding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe 'Locale loading' do
  let(:app) do
    DoorkeeperI18n::Spec::FakeApp
  end

  let(:translate_stuff) do
    lambda do
      <<-EOS.gsub(/^  */, '')
        In French: #{I18n.t('doorkeeper.layouts.admin.nav.oauth2_provider', locale: :fr)}
        In Italian: #{I18n.t('doorkeeper.layouts.admin.nav.oauth2_provider', locale: :it)}
        In Japanese: #{I18n.t('doorkeeper.layouts.admin.nav.oauth2_provider', locale: :ja)}
      EOS
    end
  end

  context 'when i18n.available_locales are specified in config' do
    let(:translations) do
      app.run(translate_stuff) do |config|
        config.i18n.available_locales = [:fr, :it]
      end
    end

    it 'loads only specified locales' do
      expected_translations = <<-EOS.gsub(/^  */, '')
        In French: Fournisseur OAuth2
        In Italian: OAuth2 Provider
        In Japanese: translation missing: ja.doorkeeper.layouts.admin.nav.oauth2_provider
      EOS

      expect(translations) == expected_translations
    end
  end

  context 'when single locale is assigned to i18n.available_locales' do
    let(:translations) do
      app.run(translate_stuff) do |config|
        config.i18n.available_locales = 'fr'
      end
    end

    it 'loads only this locale' do
      expected_translations = <<-EOS.gsub(/^  */, '')
        In French: Fournisseur OAuth2
        In Italian: translation missing: it.doorkeeper.layouts.admin.nav.oauth2_provider
        In Japanese: translation missing: ja.doorkeeper.layouts.admin.nav.oauth2_provider
      EOS

      expect(translations) == expected_translations
    end
  end

  context 'when i18n.available_locales is not set' do
    let(:translations) { app.run(translate_stuff) }

    it 'loads all locales' do
      expected_translations = <<-EOS.gsub(/^  */, '')
        In French: Fournisseur OAuth2
        In Italian: OAuth2 Provider
        In Japanese: OAuth2 プロバイダー
      EOS

      expect(translations) == expected_translations
    end
  end
end