<commit_before># encoding: utf-8

require 'spec_helper'

describe AdhearsionI18n::CallControllerMethods do

  let(:call_id)     { SecureRandom.uuid }
  let(:call)        { Adhearsion::Call.new }
  let(:block)       { nil }

  subject(:controller) { Class.new(Adhearsion::CallController).new call }

  before :all do
    Adhearsion.config.i18n['locale_path'] = ["#{File.dirname(__FILE__)}/fixtures/locale"]
  end

  before do
    I18n.default_locale = :en
    double call, write_command: true, id: call_id
    Adhearsion::Plugin.init_plugins
  end

  describe 'getting and setting the locale' do
    it 'should be able to set and get the locale' do
      controller.locale.should == :en
      controller.locale = :it
      controller.locale.should == :it
    end
  end

  describe 'requesting a translation' do
    it 'should use a default locale' do
      ssml = controller.t :have_many_cats
      ssml['xml:lang'].should =~ /^en/
    end

    it 'should allow overriding the locale per-request' do
      ssml = controller.t :have_many_cats, locale: 'it'
      ssml['xml:lang'].should =~ /^it/
    end

    it 'should allow overriding the locale for the entire call' do<commit_msg>Allow test suite to function with enforcement of available locales<commit_after># encoding: utf-8

require 'spec_helper'

describe AdhearsionI18n::CallControllerMethods do

  let(:call_id)     { SecureRandom.uuid }
  let(:call)        { Adhearsion::Call.new }
  let(:block)       { nil }

  subject(:controller) { Class.new(Adhearsion::CallController).new call }

  before :all do
    Adhearsion.config.i18n['locale_path'] = ["#{File.dirname(__FILE__)}/fixtures/locale"]
    Adhearsion::Plugin.init_plugins
  end

  before do
    I18n.default_locale = :en
    double call, write_command: true, id: call_id
  end

  describe 'getting and setting the locale' do
    it 'should be able to set and get the locale' do
      controller.locale.should == :en
      controller.locale = :it
      controller.locale.should == :it
    end
  end

  describe 'requesting a translation' do
    it 'should use a default locale' do
      ssml = controller.t :have_many_cats
      ssml['xml:lang'].should =~ /^en/
    end

    it 'should allow overriding the locale per-request' do
      ssml = controller.t :have_many_cats, locale: 'it'
      ssml['xml:lang'].should =~ /^it/
    end

    it 'should allow overriding the locale for the entire call' do
{'fraction_non_alphanumeric': 0.10600414078674948, 'fraction_numerical': 0.005797101449275362, 'mean_word_length': 3.1944444444444446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3502074', 'n_tokens_mistral': 795, 'n_tokens_neox': 756, 'n_words': 220}