<commit_before>require 'spec_helper'

require 'sxle/helpers/i18n_helper'

class I18nHelperTest
  include Sxle::Helpers::I18nHelper
end

describe "I18n" do
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::UrlHelper

  subject { I18nHelperTest.new }
  describe "safe_t" do
    it "escapes unsafe text" do
      subject.stub(:t).with('my_key').and_return('this is <strong>unsafe</strong>')
      subject.safe_t('my_key').should == 'this is &lt;strong&gt;unsafe&lt;/strong&gt;'
    end

    it "escapes unsafe variables" do
      subject.stub(:t).with('my_key').and_return('I am %{username}')
      value = '<b>Bob</b>'
      value.stub(:html_safe?).and_return(false)
      subject.safe_t('my_key', username: value).should == 'I am &lt;b&gt;Bob&lt;/b&gt;'
    end

    it "doesn't escape safe variables" do
      subject.stub(:t).with('my_key').and_return('I am %{username}')
      value = content_tag 'b', 'Bob'
      subject.safe_t('my_key', username: value).should == 'I am <b>Bob</b>'
    end

    it "doesn't escape safe variables (anchors)" do
      subject.stub(:t).with('my_key').and_return('Go to %{link}')
      value = link_to 'Google', 'http://www.google.com'
      subject.safe_t('my_key', link: value).should ==
        'Go to <a href="http://www.google.com">Google</a>'
    end

    it "returns html_safe result" do
      subject.stub(:t).with('my_key').and_return('abc')
      subject.safe_t('my_key').should be_html_safe
    end

    it "passes default argument along to t" do
      subject.stub(:t).with('my_key', default: 'my_default').and_return('abc')
      subject.safe_t('my_key', default: 'my_default').should == 'abc'
    end

  end
end
<commit_msg>Clearer specs for options[:default] passing<commit_after>require 'spec_helper'

require 'sxle/helpers/i18n_helper'

class I18nHelperTest
  include Sxle::Helpers::I18nHelper
end

describe "I18n" do
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::UrlHelper

  subject { I18nHelperTest.new }
  describe "safe_t" do
    it "escapes unsafe text" do
      subject.stub(:t).with('my_key').and_return('this is <strong>unsafe</strong>')
      subject.safe_t('my_key').should == 'this is &lt;strong&gt;unsafe&lt;/strong&gt;'
    end

    it "escapes unsafe variables" do
      subject.stub(:t).with('my_key').and_return('I am %{username}')
      value = '<b>Bob</b>'
      value.stub(:html_safe?).and_return(false)
      subject.safe_t('my_key', username: value).should == 'I am &lt;b&gt;Bob&lt;/b&gt;'
    end

    it "doesn't escape safe variables" do
      subject.stub(:t).with('my_key').and_return('I am %{username}')
      value = content_tag 'b', 'Bob'
      subject.safe_t('my_key', username: value).should == 'I am <b>Bob</b>'
    end

    it "doesn't escape safe variables (anchors)" do
      subject.stub(:t).with('my_key').and_return('Go to %{link}')
      value = link_to 'Google', 'http://www.google.com'
      subject.safe_t('my_key', link: value).should ==
        'Go to <a href="http://www.google.com">Google</a>'
    end

    it "returns html_safe result" do
      subject.stub(:t).with('my_key').and_return('abc')
      subject.safe_t('my_key').should be_html_safe
    end

    context "when options[:default] is defined" do
      it "is passed on to t" do
        subject.should_receive(:t).with('my_key', default: 'my_default').and_return('abc')
        subject.safe_t('my_key', default: 'my_default')
      end
    end

    context "when options[:default] is not defined" do
      it "does not pass options to t" do
        subject.should_receive(:t).with('my_key').and_return('abc')
        subject.safe_t('my_key')
      end
    end

  end
end

{'fraction_non_alphanumeric': 0.16077257889009794, 'fraction_numerical': 0.00544069640914037, 'mean_word_length': 3.6426767676767677, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, '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': '4870335', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1266, 'n_words': 270}