<commit_before>require 'spec_helper'

describe ActiveRecord::MTI::Calculations do
  context 'when an exception occurs' do
    it 'does not continue to adversely affect additional queries' do
      Admin.create(email: 'bob')
      expect { Admin.joins(Transportation::Vehicle).count }.to raise_error(RuntimeError)
      expect(Thread.current['skip_tableoid_cast']).to_not eq(true)
      expect(Admin.count).to eq(1)
    end
  end

  context "don't project tableoid on" do
    it 'grouping' do
      Admin.create(email: '<EMAIL>', god_powers: 3)
      Admin.create(email: '<EMAIL>', god_powers: 3)
      Admin.create(email: '<EMAIL>', god_powers: 3)

      grouped_count = Admin.group(:email).count

      expect(grouped_count['<EMAIL>']).to eq(1)
      expect(grouped_count['<EMAIL>']).to eq(2)
    end

    it 'count calculations' do
      Admin.create(email: '<EMAIL>', god_powers: 3)
      Admin.create(email: '<EMAIL>', god_powers: 3)
      Admin.create(email: '<EMAIL>', god_powers: 3)

      expect(Admin.count(:email)).to eq(3)
    end
  end

  context 'projects tableoid' do
    before do
      # Make sure to load the child table so Admin will be recognized as a parent
      Hacker = Class.new(Admin)
    end

    it 'and groups tableoid when selecting :tableoid' do
      sql = Admin.select(:email, :tableoid).group(:email).to_sql

      expect(sql).to match(/SELECT .*, \"admins\".\"tableoid\" AS tableoid FROM \"admins\"/)

      expect(sql).to match(/GROUP BY .*, \"admins\".\"tableoid\"/)
    end

    it 'when grouping :tableoid' do
      sql = Admin.select(:email).group(:email, :tableoid).to_sql

      expect(sql).to match(/SELECT .*, \"admins\".\"tableoid\" AS tableoid FROM \"admins\"/)

      expect(sql).to match(/GROUP BY .*, \"admins\".\"tableoid\"/)
    end
  end<commit_msg>Remove unneeded test setup<commit_after>require 'spec_helper'

describe ActiveRecord::MTI::Calculations do
  context 'when an exception occurs' do
    it 'does not continue to adversely affect additional queries' do
      Admin.create(email: 'bob')
      expect { Admin.joins(Transportation::Vehicle).count }.to raise_error(RuntimeError)
      expect(Thread.current['skip_tableoid_cast']).to_not eq(true)
      expect(Admin.count).to eq(1)
    end
  end

  context "don't project tableoid on" do
    it 'grouping' do
      Admin.create(email: '<EMAIL>', god_powers: 3)
      Admin.create(email: '<EMAIL>', god_powers: 3)
      Admin.create(email: '<EMAIL>', god_powers: 3)

      grouped_count = Admin.group(:email).count

      expect(grouped_count['<EMAIL>']).to eq(1)
      expect(grouped_count['<EMAIL>']).to eq(2)
    end

    it 'count calculations' do
      Admin.create(email: '<EMAIL>', god_powers: 3)
      Admin.create(email: '<EMAIL>', god_powers: 3)
      Admin.create(email: '<EMAIL>', god_powers: 3)

      expect(Admin.count(:email)).to eq(3)
    end
  end

  context 'projects tableoid' do
    it 'and groups tableoid when selecting :tableoid' do
      sql = Admin.select(:email, :tableoid).group(:email).to_sql

      expect(sql).to match(/SELECT .*, \"admins\".\"tableoid\" AS tableoid FROM \"admins\"/)

      expect(sql).to match(/GROUP BY .*, \"admins\".\"tableoid\"/)
    end

    it 'when grouping :tableoid' do
      sql = Admin.select(:email).group(:email, :tableoid).to_sql

      expect(sql).to match(/SELECT .*, \"admins\".\"tableoid\" AS tableoid FROM \"admins\"/)

      expect(sql).to match(/GROUP BY .*, \"admins\".\"tableoid\"/)
    end
  end
{'fraction_non_alphanumeric': 0.154487917146145, 'fraction_numerical': 0.005753739930955121, 'mean_word_length': 3.2402439024390244, 'pattern_counts': {'":': 0, '<': 19, '<?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': '6709384', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1122, 'n_words': 280}