<commit_before>require "spec_helper"

describe ChorusView, :database_integration => true do
  let(:schema) { gpdb_schemas(:bobs_schema) }

  describe "#validate_query" do
    let(:database) { GpdbIntegration.real_database }
    let(:schema) { database.schemas.find_by_name('public') }
    let(:account) { GpdbIntegration.real_gpdb_account }

    before do
      GpdbIntegration.refresh_chorus
    end

    it "can be valid" do
      chorus_view = ChorusView.new({:name => "query", :schema => schema, :query => "selecT 1;"}, :without_protection => true)
      chorus_view.should be_valid
      chorus_view.query.should == "selecT 1;"
    end

    it "should return only one result set" do
      described_class.new(
          {
              :name => 'multiple result sets',
              :schema => schema,
              :query => "select 1; select 2;"
          },
          :without_protection => true).should_not be_valid
    end

    it 'does not execute the query' do
      schema.with_gpdb_connection(account) do |conn|
        conn.exec_query("drop table if exists bad_chorus_view_table;")
      end

      chorus_view = described_class.new(
          {<commit_msg>remove unnecessary GpdbIntegration.refresh_chorus which is slowing down specs (refreshed data should be in fixtures when test starts)<commit_after>require "spec_helper"

describe ChorusView, :database_integration => true do
  let(:schema) { gpdb_schemas(:bobs_schema) }

  describe "#validate_query" do
    let(:database) { GpdbIntegration.real_database }
    let(:schema) { database.schemas.find_by_name('public') }
    let(:account) { GpdbIntegration.real_gpdb_account }

    it "can be valid" do
      chorus_view = ChorusView.new({:name => "query", :schema => schema, :query => "selecT 1;"}, :without_protection => true)
      chorus_view.should be_valid
      chorus_view.query.should == "selecT 1;"
    end

    it "should return only one result set" do
      described_class.new(
          {
              :name => 'multiple result sets',
              :schema => schema,
              :query => "select 1; select 2;"
          },
          :without_protection => true).should_not be_valid
    end

    it 'does not execute the query' do
      schema.with_gpdb_connection(account) do |conn|
        conn.exec_query("drop table if exists bad_chorus_view_table;")
      end

      chorus_view = described_class.new(
          {
{'fraction_non_alphanumeric': 0.10565723793677205, 'fraction_numerical': 0.0033277870216306157, 'mean_word_length': 2.8915857605177995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '948635', 'n_tokens_mistral': 759, 'n_tokens_neox': 721, 'n_words': 182}