<commit_before>require "cases/helper"
require 'models/topic'
require 'models/reply'

class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
  def setup
    reset_callbacks Topic
    @topic = Topic.new
    I18n.backend.store_translations('en-US', :activerecord => {:errors => {:messages => {:custom => nil}}})
  end

  def teardown
    reset_callbacks Topic
    I18n.load_translations File.dirname(__FILE__) + '/../../lib/active_record/locale/en-US.yml'
  end

  def unique_topic
    @unique ||= Topic.create :title => 'unique!'
  end

  def replied_topic
    @replied_topic ||= begin
      topic = Topic.create(:title => "topic")
      topic.replies << Reply.new
      topic
    end
  end

  def reset_callbacks(*models)
    models.each do |model|
      model.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
      model.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
      model.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
    end
  end

  def test_default_error_messages_is_deprecated
    assert_deprecated('ActiveRecord::Errors.default_error_messages') do
      ActiveRecord::Errors.default_error_messages
    end
  end

  # ActiveRecord::Errors
  uses_mocha 'ActiveRecord::Errors' do
<commit_msg>add activerecord tests for deprecation of %s and %d in error messages (and translations in general)<commit_after>require "cases/helper"
require 'models/topic'
require 'models/reply'

class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
  def setup
    reset_callbacks Topic
    @topic = Topic.new
    I18n.backend.store_translations('en-US', :activerecord => {:errors => {:messages => {:custom => nil}}})
  end

  def teardown
    reset_callbacks Topic
    I18n.load_translations File.dirname(__FILE__) + '/../../lib/active_record/locale/en-US.yml'
  end

  def unique_topic
    @unique ||= Topic.create :title => 'unique!'
  end

  def replied_topic
    @replied_topic ||= begin
      topic = Topic.create(:title => "topic")
      topic.replies << Reply.new
      topic
    end
  end

  def reset_callbacks(*models)
    models.each do |model|
      model.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
      model.instance_variable_set("@validate_on_create_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
      model.instance_variable_set("@validate_on_update_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
    end
  end

  def test_default_error_messages_is_deprecated
    assert_deprecated('ActiveRecord::Errors.default_error_messages') do
      ActiveRecord::Errors.default_error_messages
    end
  end

  def test_percent_s_interpolation_syntax_in_error_messages_is_deprecated
    assert_deprecated('using %s in messages') do
      I18n.t :does_not_exist, :default => "%s interpolation syntax is deprected", :value => 'this'
    end
  end

  def test_percent_d_interpolation_syntax_in_error_messages_is_deprecated
    assert_deprecated('using %d in messages') do
      I18n.t :does_not_exist, :default => "%d interpolation syntax is deprected", :count => 1
    end
  end

  # ActiveRecord::Errors
  uses_mocha 'ActiveRecord::Errors' do

{'fraction_non_alphanumeric': 0.1058427653716733, 'fraction_numerical': 0.005200367084735393, 'mean_word_length': 4.5423728813559325, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1684063', 'n_tokens_mistral': 1037, 'n_tokens_neox': 998, 'n_words': 199}