<commit_before>require 'abstract_unit'
require 'fixtures/person'
require 'active_support/core_ext/hash/conversions'

class ObservingTest < Test::Unit::TestCase
  cattr_accessor :history

  class PersonObserver < ActiveModel::Observer
    observe :person

    %w( after_create after_destroy after_save after_update
        before_create before_destroy before_save before_update).each do |method|
          define_method(method) { log method }
    end

    private
      def log(method)
        (ObservingTest.history ||= []) << method.to_sym
      end
  end

  def setup
    @matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')

    ActiveResource::HttpMock.respond_to do |mock|
      mock.get    "/people/1.xml", {}, @matz
      mock.post   "/people.xml", {}, @matz, 201, 'Location' => '/people/1.xml'
      mock.put    "/people/1.xml", {}, nil, 204
      mock.delete "/people/1.xml", {}, nil, 200
    end

    PersonObserver.instance
  end

  def teardown
    self.history = nil
  end<commit_msg>Fix for Ruby 1.9 - define_method throws an exception under 1.9 if given incorrect number of args<commit_after>require 'abstract_unit'
require 'fixtures/person'
require 'active_support/core_ext/hash/conversions'

class ObservingTest < Test::Unit::TestCase
  cattr_accessor :history

  class PersonObserver < ActiveModel::Observer
    observe :person

    %w( after_create after_destroy after_save after_update
        before_create before_destroy before_save before_update).each do |method|
          define_method(method) { |*| log method }
    end

    private
      def log(method)
        (ObservingTest.history ||= []) << method.to_sym
      end
  end

  def setup
    @matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')

    ActiveResource::HttpMock.respond_to do |mock|
      mock.get    "/people/1.xml", {}, @matz
      mock.post   "/people.xml", {}, @matz, 201, 'Location' => '/people/1.xml'
      mock.put    "/people/1.xml", {}, nil, 204
      mock.delete "/people/1.xml", {}, nil, 200
    end

    PersonObserver.instance
  end

  def teardown
    self.history = nil
  end
{'fraction_non_alphanumeric': 0.12553495007132667, 'fraction_numerical': 0.015216357584403234, 'mean_word_length': 3.0539499036608864, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '6635747', 'n_tokens_mistral': 694, 'n_tokens_neox': 659, 'n_words': 164}