<commit_before>require 'test_helper'

# Trap Kernel#warn to check that deprecated warning is added :)
module Kernel
  @@LAST_WARNING = nil
  def warn(msg)
    @@LAST_WARNING = msg
  end
  
  def self.last_warning; @@LAST_WARNING; end
end

class FindersTest < ActiveSupport::TestCase  
  def setup
    reload_db
  end

  test "find all with :gender => :female" do
    girls = Dummy.find :all, :conditions => { :gender_cd => Dummy.genders[:female] }
    
    assert_equal 2, girls.length
  end
  
  test "that inst.values_for_... is deprecated (by trapping Kernel\#warn)" do
    g = Dummy.new
    g.values_for_gender
    
    assert_match /\ADEPRECATION WARNING.*values_for_gender.*genders/, Kernel.last_warning
  end
end<commit_msg>added more ActiveRecord#find tests (different variants and combinations)<commit_after>require 'test_helper'

# Trap Kernel#warn to check that deprecated warning is added :)
module Kernel
  @@LAST_WARNING = nil
  def warn(msg)
    @@LAST_WARNING = msg
  end
  
  def self.last_warning; @@LAST_WARNING; end
end

class FindersTest < ActiveSupport::TestCase  
  def setup
    reload_db
  end

  test "find all where :gender = :female" do
    girls = Dummy.find :all, :conditions => { :gender_cd => Dummy.genders[:female] }, :order => 'name ASC'
    
    assert_equal 2, girls.length
    
    assert_equal 'Anna', girls.first.name
    assert_equal :female, girls.first.gender
    assert_equal true, girls.first.female?
  end
  
  test "find all where :word is 'gamma'" do
    gammas = Dummy.find :all, :conditions => { :word_cd => Dummy.words(:gamma) }
    
    assert_equal 1, gammas.length
    assert_equal 'Chris', gammas.first.name
    assert_equal true, gammas.first.male?
    assert_equal 'gamma', gammas.first.word_cd
    assert_equal :gamma, gammas.first.word
  end
  
  test "find with string conditions for all :didum = :foo" do
    foos = Dummy.find :all, :conditions => ['other = ?', Dummy.didums(:foo)]
    
    assert_equal 1, foos.length
    assert_equal false, foos.first.foobar?
  end
  
  test "find using insecure inline string conditions" do
    men = Dummy.find :all, :conditions => "gender_cd = #{Dummy.genders(:male)}"
    
    assert_equal 1, men.length
    assert_equal true, men.first.male?
  end
  
  test "that Klass.genders[:sym] == Klass.genders(:sym)" do
    assert_equal 0, Dummy.genders(:male)
    assert_equal Dummy.genders(:male), Dummy.genders[:male]
    assert_nil Dummy.genders(:inexistent)
    assert_nil Dummy.genders[:inexistent]
  end
  
  test "that inst.values_for_... is deprecated (by trapping Kernel\#warn)" do
    g = Dummy.new
    g.values_for_gender
    
    assert_match /\ADEPRECATION WARNING.*values_for_gender.*genders/, Kernel.last_warning
  end
end
{'fraction_non_alphanumeric': 0.10695970695970695, 'fraction_numerical': 0.002197802197802198, 'mean_word_length': 3.469721767594108, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '7208606', 'n_tokens_mistral': 949, 'n_tokens_neox': 908, 'n_words': 242}