<commit_before>require File.join(File.dirname(__FILE__), 'test_helper') 

class ValidationsTest < Test::Unit::TestCase
  
  def setup
    load File.join(File.dirname(__FILE__), 'fixtures', 'company.rb')
  end
  
  basic_validations = %w(validate validate_on_create)
  update_validations = %w(validate_on_update)

  conditions = [lambda {|company| company.callback_flag == true}]
  
   conditions.each do |condition|
    basic_validations.each do |validation| 
      define_method "test_#{validation}_with_if_condition_#{condition.class}_which_returns_true_should_change_company_name" do
        Company.send(validation.to_sym, :change_name, :if => condition)

        company = Company.new :name => 'thoughtbot', :callback_flag => true
        assert company.save
        assert_equal 'new name', company.name
      end
      
      define_method "test_#{validation}_with_if_condition_#{condition.class}_which_returns_false_should_not_change_company_name" do
        Company.send(validation.to_sym, :change_name, :if => condition)
        company = Company.new :name => 'thoughtbot', :callback_flag => false
        assert company.save
        assert_equal 'thoughtbot', company.name
      end
      
      define_method "test_#{validation}_with_unless_condition_#{condition.class}_which_returns_true_should_not_change_company_name" do
        Company.send(validation.to_sym, :change_name, :unless => condition)
        company = Company.new :name => 'thoughtbot', :callback_flag => true
        assert company.save
        assert_equal 'thoughtbot', company.name
      end

      define_method "test_#{validation}_with_unless_condition_#{condition.class}_which_returns_false_should_change_company_name" do
        Company.send(validation.to_sym, :change_name, :unless => condition)
        company = Company.new :name => 'thoughtbot', :callback_flag => false
        assert company.save<commit_msg>added tests for symbol and string callbacks for validations<commit_after>require File.join(File.dirname(__FILE__), 'test_helper') 

class ValidationsTest < Test::Unit::TestCase
  
  def setup
    load File.join(File.dirname(__FILE__), 'fixtures', 'company.rb')
  end
  
  basic_validations = %w(validate validate_on_create)
  update_validations = %w(validate_on_update)

  conditions = [lambda {|company| company.callback_flag == true}, :flag?, 'flag?']
  
   conditions.each do |condition|
    basic_validations.each do |validation| 
      define_method "test_#{validation}_with_if_condition_#{condition.class}_which_returns_true_should_change_company_name" do
        Company.send(validation.to_sym, :change_name, :if => condition)

        company = Company.new :name => 'thoughtbot', :callback_flag => true
        assert company.save
        assert_equal 'new name', company.name
      end
      
      define_method "test_#{validation}_with_if_condition_#{condition.class}_which_returns_false_should_not_change_company_name" do
        Company.send(validation.to_sym, :change_name, :if => condition)
        company = Company.new :name => 'thoughtbot', :callback_flag => false
        assert company.save
        assert_equal 'thoughtbot', company.name
      end
      
      define_method "test_#{validation}_with_unless_condition_#{condition.class}_which_returns_true_should_not_change_company_name" do
        Company.send(validation.to_sym, :change_name, :unless => condition)
        company = Company.new :name => 'thoughtbot', :callback_flag => true
        assert company.save
        assert_equal 'thoughtbot', company.name
      end

      define_method "test_#{validation}_with_unless_condition_#{condition.class}_which_returns_false_should_change_company_name" do
        Company.send(validation.to_sym, :change_name, :unless => condition)
        company = Company.new :name => 'thoughtbot', :callback_flag => false
        assert company.save
{'fraction_non_alphanumeric': 0.10023310023310024, 'fraction_numerical': 0.0, 'mean_word_length': 4.2118758434547905, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '5291656', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1109, 'n_words': 213}