<commit_before>require 'spec_helper'

module Cypherites
  describe Query do
    let(:runner){double("runner")}

    describe ".new" do
      it "adapter is set" do
        q = Query.new(runner)
        expect(q.runner).to be runner
      end

      it("adapter is optional"){ is_expected.to be_truthy}
    end

    describe "#execute" do
      it "must call @runner" do
        q = Query.new(runner)
        expect(runner).to receive(:call).with(q, {foo: "bar", baz: "qux"})
        q.execute({foo: "bar", baz: "qux"})
      end
    end

    describe "#statement" do

      it "must return itself" do
        expect(subject.statement(:MATCH, "predicate")).to be subject
      end
      
      it "must store the statement" do
        q = Query.new
        q.statement(:MATCH, "predicate")
        statements = q.statements.first
        expect(statements.keys.first).to be == :MATCH
        expect(statements.values.first.predicates).to be == ["predicate"]
      end
    end

    common_clauses = %w{match optional_match where return order_by limit delete with}

    common_clauses.each do |clause|
      describe "##{clause}" do
        it "must return itself" do
          expect(subject.send(clause, "predicate")).to be subject
        end

        it "must call #statement with correct symbol" do
          sym = clause.upcase.gsub(/_/, " ").to_sym
          
          st_build_mock = double("st_build_mock")
          expect(st_build_mock).to receive(:new).with(sym){Statement.new(sym)}        
          
          subject.statement_builder = st_build_mock
          subject.send(clause, "predicate")
        end
      end
    end

    describe "#return_node" do
      it "must return itself" do
        expect(subject.return_node("node1")).to be subject
      end

      it "must call #statement with correct symbol" do
          st_build_mock = double("st_build_mock")
          expect(st_build_mock).to receive(:new).with(:RETURN){Statement.new(:RETURN)}        
          
          subject.statement_builder = st_build_mock
          subject.return_node("node1")
      end
    end

    describe "#return_rel" do
      it "must return itself" do
        expect(subject.return_rel("rel")).to be subject
      end

      it "must call #statement with correct symbol" do
          st_build_mock = double("st_build_mock")
          expect(st_build_mock).to receive(:new).with(:RETURN){Statement.new(:RETURN)}        
          
          subject.statement_builder = st_build_mock
          subject.return_rel("rel")
      end
    end

    describe "#to_cypher" do
      it "returned sorted statements" do
        subject
          .limit("")
          .match("")
          .order_by("")
          .optional_match("")
          .return("")
          .start("")
          .where("")

        expect(subject.to_cypher).to be == "START  MATCH  OPTIONAL MATCH  WHERE  RETURN  ORDER BY  LIMIT "
      end

      it "break sortwd with new_phase" do
        subject
          .return("")
          .new_phase          
          .start("")

        expect(subject.to_cypher).to be == "RETURN  START "
      end

      it "break sortwd with no_sort" do
        subject
          .no_sort
          .return("")
          .start("")<commit_msg>Fix misspell<commit_after>require 'spec_helper'

module Cypherites
  describe Query do
    let(:runner){double("runner")}

    describe ".new" do
      it "adapter is set" do
        q = Query.new(runner)
        expect(q.runner).to be runner
      end

      it("adapter is optional"){ is_expected.to be_truthy}
    end

    describe "#execute" do
      it "must call @runner" do
        q = Query.new(runner)
        expect(runner).to receive(:call).with(q, {foo: "bar", baz: "qux"})
        q.execute({foo: "bar", baz: "qux"})
      end
    end

    describe "#statement" do

      it "must return itself" do
        expect(subject.statement(:MATCH, "predicate")).to be subject
      end
      
      it "must store the statement" do
        q = Query.new
        q.statement(:MATCH, "predicate")
        statements = q.statements.first
        expect(statements.keys.first).to be == :MATCH
        expect(statements.values.first.predicates).to be == ["predicate"]
      end
    end

    common_clauses = %w{match optional_match where return order_by limit delete with}

    common_clauses.each do |clause|
      describe "##{clause}" do
        it "must return itself" do
          expect(subject.send(clause, "predicate")).to be subject
        end

        it "must call #statement with correct symbol" do
          sym = clause.upcase.gsub(/_/, " ").to_sym
          
          st_build_mock = double("st_build_mock")
          expect(st_build_mock).to receive(:new).with(sym){Statement.new(sym)}        
          
          subject.statement_builder = st_build_mock
          subject.send(clause, "predicate")
        end
      end
    end

    describe "#return_node" do
      it "must return itself" do
        expect(subject.return_node("node1")).to be subject
      end

      it "must call #statement with correct symbol" do
          st_build_mock = double("st_build_mock")
          expect(st_build_mock).to receive(:new).with(:RETURN){Statement.new(:RETURN)}        
          
          subject.statement_builder = st_build_mock
          subject.return_node("node1")
      end
    end

    describe "#return_rel" do
      it "must return itself" do
        expect(subject.return_rel("rel")).to be subject
      end

      it "must call #statement with correct symbol" do
          st_build_mock = double("st_build_mock")
          expect(st_build_mock).to receive(:new).with(:RETURN){Statement.new(:RETURN)}        
          
          subject.statement_builder = st_build_mock
          subject.return_rel("rel")
      end
    end

    describe "#to_cypher" do
      it "returned sorted statements" do
        subject
          .limit("")
          .match("")
          .order_by("")
          .optional_match("")
          .return("")
          .start("")
          .where("")

        expect(subject.to_cypher).to be == "START  MATCH  OPTIONAL MATCH  WHERE  RETURN  ORDER BY  LIMIT "
      end

      it "break sorted with new_phase" do
        subject
          .return("")
          .new_phase          
          .start("")

        expect(subject.to_cypher).to be == "RETURN  START "
      end

      it "break sorted with no_sort" do
        subject
          .no_sort
          .return("")
          .start("")
{'fraction_non_alphanumeric': 0.11081957092143849, 'fraction_numerical': 0.0006173792251890724, 'mean_word_length': 1.9779411764705883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1732452', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1865, 'n_words': 482}