<commit_before>require "#{File.dirname(__FILE__)}/test_helper"

module MockAttributes
  def self.included(base)
    base.column :foo, :string
    base.column :bar, :string
    base.column :biz, :string
    base.column :baz, :string
  end
end

class StripAllMockRecord < ActiveRecord::Base
  include MockAttributes
  strip_attributes!
end

class StripOnlyOneMockRecord < ActiveRecord::Base
  include MockAttributes
  strip_attributes! :only => :foo
end

class StripOnlyThreeMockRecord < ActiveRecord::Base
  include MockAttributes
  strip_attributes! :only => [:foo, :bar, :biz]
end

class StripExceptOneMockRecord < ActiveRecord::Base
  include MockAttributes
  strip_attributes! :except => :foo
end

class StripExceptThreeMockRecord < ActiveRecord::Base
  include MockAttributes
  strip_attributes! :except => [:foo, :bar, :biz]
end

class StripAttributesTest < Test::Unit::TestCase
  def setup
    @init_params = { :foo => "\tfoo", :bar => "bar \t ", :biz => "\tbiz ", :baz => "" }
  end

  def test_should_exist
    assert Object.const_defined?(:StripAttributes)
  end

  def test_should_strip_all_fields
    record = StripAllMockRecord.new(@init_params)
    record.valid?
    assert_equal "foo", record.foo
    assert_equal "bar", record.bar
    assert_equal "biz", record.biz
    assert_nil record.baz
  end

  def test_should_strip_only_one_field
    record = StripOnlyOneMockRecord.new(@init_params)
    record.valid?
    assert_equal "foo",     record.foo
    assert_equal "bar \t ", record.bar
    assert_equal "\tbiz ",  record.biz
    assert_equal "",        record.baz
  end

  def test_should_strip_only_three_fields
    record = StripOnlyThreeMockRecord.new(@init_params)
    record.valid?
    assert_equal "foo", record.foo
    assert_equal "bar", record.bar
    assert_equal "biz", record.biz
    assert_equal "",    record.baz
  end

  def test_should_strip_all_except_one_field
    record = StripExceptOneMockRecord.new(@init_params)
    record.valid?
    assert_equal "\tfoo", record.foo
    assert_equal "bar",   record.bar
    assert_equal "biz",   record.biz
    assert_nil record.baz
  end

  def test_should_strip_all_except_three_fields
    record = StripExceptThreeMockRecord.new(@init_params)
    record.valid?
    assert_equal "\tfoo",   record.foo
    assert_equal "bar \t ", record.bar
    assert_equal "\tbiz ",  record.biz
    assert_nil record.baz
  end
end<commit_msg>Update strip_attribute tests to work with our existing modifications<commit_after>require "#{File.dirname(__FILE__)}/test_helper"

module MockAttributes
  def self.included(base)
    base.column :foo, :string
    base.column :bar, :string
    base.column :biz, :string
    base.column :baz, :string
  end
end

class StripAllMockRecord < ActiveRecord::Base
  include MockAttributes
  strip_attributes!
end

class StripOnlyOneMockRecord < ActiveRecord::Base
  include MockAttributes
  strip_attributes! :only => :foo
end

class StripOnlyThreeMockRecord < ActiveRecord::Base
  include MockAttributes
  strip_attributes! :only => [:foo, :bar, :biz]
end

class StripExceptOneMockRecord < ActiveRecord::Base
  include MockAttributes
  strip_attributes! :except => :foo
end

class StripExceptThreeMockRecord < ActiveRecord::Base
  include MockAttributes
  strip_attributes! :except => [:foo, :bar, :biz]
end

class StripAttributesTest < Test::Unit::TestCase
  def setup
    @init_params = { :foo => "\tfoo", :bar => "bar \t ", :biz => "\tbiz ", :baz => "" }
  end

  def test_should_exist
    assert Object.const_defined?(:StripAttributes)
  end

  def test_should_strip_all_fields
    record = StripAllMockRecord.new(@init_params)
    record.valid?
    assert_equal "foo", record.foo
    assert_equal "bar", record.bar
    assert_equal "biz", record.biz
    assert_equal "",    record.baz
  end

  def test_should_strip_only_one_field
    record = StripOnlyOneMockRecord.new(@init_params)
    record.valid?
    assert_equal "foo",     record.foo
    assert_equal "bar \t ", record.bar
    assert_equal "\tbiz ",  record.biz
    assert_equal "",        record.baz
  end

  def test_should_strip_only_three_fields
    record = StripOnlyThreeMockRecord.new(@init_params)
    record.valid?
    assert_equal "foo", record.foo
    assert_equal "bar", record.bar
    assert_equal "biz", record.biz
    assert_equal "",    record.baz
  end

  def test_should_strip_all_except_one_field
    record = StripExceptOneMockRecord.new(@init_params)
    record.valid?
    assert_equal "\tfoo", record.foo
    assert_equal "bar",   record.bar
    assert_equal "biz",   record.biz
    assert_equal "",      record.baz
  end

  def test_should_strip_all_except_three_fields
    record = StripExceptThreeMockRecord.new(@init_params)
    record.valid?
    assert_equal "\tfoo",   record.foo
    assert_equal "bar \t ", record.bar
    assert_equal "\tbiz ",  record.biz
    assert_equal "",        record.baz
  end
end
{'fraction_non_alphanumeric': 0.09627964022894522, 'fraction_numerical': 0.0, 'mean_word_length': 3.9274924471299095, 'pattern_counts': {'":': 0, '<': 15, '<?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': '4440186', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1510, 'n_words': 357}