<commit_before>require 'active_record'

case ENV['DB'].try(:downcase)
when 'mysql', 'mysql2'
  # To test with MySQL: `DB=mysql bundle exec rake spec`
  ActiveRecord::Base.establish_connection(
    adapter:  'mysql2',
    database: 'ransack',
    encoding: 'utf8'
  )
when 'pg', 'postgres', 'postgresql'
  # To test with PostgreSQL: `DB=postgresql bundle exec rake spec`
  ActiveRecord::Base.establish_connection(
    adapter: 'postgresql',
    database: 'ransack',
  # username: 'postgres', # Uncomment the username option if you have set one
    min_messages: 'warning'
  )
else
  # Otherwise, assume SQLite3: `bundle exec rake spec`
  ActiveRecord::Base.establish_connection(
    adapter: 'sqlite3',
    database: ':memory:'
  )
end

class Person < ActiveRecord::Base
  if ActiveRecord::VERSION::MAJOR == 3
    default_scope order('id DESC')
  else
    default_scope { order(id: :desc) }
  end
  belongs_to :parent, class_name: 'Person', foreign_key: :parent_id
  has_many   :children, class_name: 'Person', foreign_key: :parent_id
  has_many   :articles
  if ActiveRecord::VERSION::MAJOR == 3
    has_many :published_articles, conditions: { published: true }, class_name: "Article"
  else
    has_many :published_articles, ->{ where(published: true) }, class_name: "Article"
  end
  has_many   :comments
  has_many   :authored_article_comments, through: :articles,
             source: :comments, foreign_key: :person_id
  has_many   :notes, as: :notable

  scope :restricted,  lambda { where("restricted = 1") }
  scope :active,      lambda { where("active = 1") }
  scope :over_age,    lambda { |y| where(["age > ?", y]) }
  scope :of_age,      lambda { |of_age|
    of_age ? where("age >= ?", 18) : where("age < ?", 18)
  }

  alias_attribute :full_name, :name<commit_msg>Fix specs broken by Rails 3 on Ruby 2.3.0.<commit_after>require 'active_record'

case ENV['DB'].try(:downcase)
when 'mysql', 'mysql2'
  # To test with MySQL: `DB=mysql bundle exec rake spec`
  ActiveRecord::Base.establish_connection(
    adapter:  'mysql2',
    database: 'ransack',
    encoding: 'utf8'
  )
when 'pg', 'postgres', 'postgresql'
  # To test with PostgreSQL: `DB=postgresql bundle exec rake spec`
  ActiveRecord::Base.establish_connection(
    adapter: 'postgresql',
    database: 'ransack',
  # username: 'postgres', # Uncomment the username option if you have set one
    min_messages: 'warning'
  )
else
  # Otherwise, assume SQLite3: `bundle exec rake spec`
  ActiveRecord::Base.establish_connection(
    adapter: 'sqlite3',
    database: ':memory:'
  )
end

class Person < ActiveRecord::Base
  if ActiveRecord::VERSION::MAJOR == 3
    default_scope order('id DESC')
  else
    default_scope { order(id: :desc) }
  end
  belongs_to :parent, class_name: 'Person', foreign_key: :parent_id
  has_many   :children, class_name: 'Person', foreign_key: :parent_id
  has_many   :articles
  if ActiveRecord::VERSION::MAJOR == 3
    if RUBY_VERSION >= '2.3'
      has_many :published_articles, class_name: "Article", conditions: "published = 't'"
    else
      has_many :published_articles, class_name: "Article", conditions: { published: true }
    end
  else
    has_many :published_articles, ->{ where(published: true) }, class_name: "Article"
  end
  has_many   :comments
  has_many   :authored_article_comments, through: :articles,
             source: :comments, foreign_key: :person_id
  has_many   :notes, as: :notable

  scope :restricted,  lambda { where("restricted = 1") }
  scope :active,      lambda { where("active = 1") }
  scope :over_age,    lambda { |y| where(["age > ?", y]) }
  scope :of_age,      lambda { |of_age|
    of_age ? where("age >= ?", 18) : where("age < ?", 18)
  }

  alias_attribute :full_name, :name
{'fraction_non_alphanumeric': 0.13003761418592155, 'fraction_numerical': 0.008597528210639442, 'mean_word_length': 4.051560379918589, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, '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': '6474606', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1226, 'n_words': 331}