<commit_before>require 'test_helper'

describe Querify do

    before do
        truncate_db
    end

    describe 'Filterable sanity tests' do

        it 'is a module' do
            assert_kind_of Module, Querify
        end

        it 'has access to the test dummy model' do
    		assert Post
    	end

    	it 'can be called on AR models' do
    		assert_respond_to Post, :filterable
    	end

    	it 'can be called on AR relations' do
    		FactoryGirl.create :post
    		assert_respond_to Post.first.comments, :filterable
    	end

    	it 'can be called on AR collection proxies' do
    		assert_respond_to Post.all, :filterable
    	end
    end


    # Set up before tests for filterable

    describe 'filtering' do

        before do

            @one = FactoryGirl.create :post, name: "A. First post"
            @two = FactoryGirl.create :post, name: "B. Second post"
            @three = FactoryGirl.create :post, name: "C. Third post"
            @four = FactoryGirl.create :post, name: "D. Fourth post"

            # Additional comments for multi-sorting
            FactoryGirl.create :comment, post: @one
            FactoryGirl.create :comment, post: @two

            @ascending = [@one, @four, @two, @three]
			@descending = [@three, @two, @four, @one]

            Querify.params.clear
        end

        it 'only has 4 posts for testing' do
            assert_equal 4, Post.count
        end

        describe 'no filterable parameters' do

            it 'returns empty Querify.where and Querify.having arrays' do
                Querify.params = {:where => {}}
                Post.filterable
                assert_equal [], Querify.where_filters
                assert_equal [], Querify.having_filters
            end

        end

        describe 'one filterable parameter' do

            it 'returns greater than' do
                Querify.params = {:where=>{"name"=>{"lt"=>"D. Fourth post"}}}
                assert_equal 3, Post.filterable.count
            end

            it 'returns greater than or equal to' do
                Querify.params = {:where=>{"name"=>{"gteq"=>"C. Third post"}}}
                assert_equal 2, Post.filterable.count
            end

            it 'returns less than' do
                Querify.params = {:where=>{"name"=>{"lt"=>"B. Second post"}}}
                assert_equal 1, Post.filterable.count
            end

            it 'returns less than or equal to' do
                Querify.params = {:where=>{"name"=>{"lteq"=>"B. Second post"}}}
                assert_equal 2, Post.filterable.count
            end

            it 'returns equal to' do
                Querify.params = {:where=>{"name"=>{"eq"=>"B. Second post"}}}
                assert_equal 1, Post.filterable.count
            end

            it 'returns not equal to' do
                Querify.params = {:where=>{"name"=>{"neq"=>"B. Second post"}}}
                assert_equal 3, Post.filterable.count
            end

            # it 'returns is' do
            #     Querify.params = {:where=>{"name"=>{"is"=>"B. Second post"}}}
            #     assert_equal 1, Post.filterable.count
            # end

            # it 'returns is not' do
            #     Querify.params = {:where=>{"name"=>{"isnot"=>"B. Second post"}}}
            #     assert_equal 3, Post.filterable.count
            # end

            it 'returns case insensitive like' do
                Querify.params = {:where=>{"name"=>{"ilike"=>"b."}}}
                assert_equal 1, Post.filterable.count
            end

            it 'returns case sensitive like' do
                Querify.params = {:where=>{"name"=>{"like"=>"b."}}}
                assert_equal 0, Post.filterable.count
            end

            it 'returns in' do
                Querify.params = {:where=>{"name"=>{"in"=>"A. First post,B. Second post"}}}
                assert_equal 2, Post.filterable.count
            end
<commit_msg>stash add<commit_after>require 'test_helper'

describe Querify do

    before do
        truncate_db
    end

    describe 'Filterable sanity tests' do

        it 'is a module' do
            assert_kind_of Module, Querify
        end

        it 'has access to the test dummy model' do
    		assert Post
    	end

    	it 'can be called on AR models' do
    		assert_respond_to Post, :filterable
    	end

    	it 'can be called on AR relations' do
    		FactoryGirl.create :post
    		assert_respond_to Post.first.comments, :filterable
    	end

    	it 'can be called on AR collection proxies' do
    		assert_respond_to Post.all, :filterable
    	end
    end


    # Set up before tests for filterable

    describe 'filtering' do

        before do

            @one = FactoryGirl.create :post, name: "A. First post"
            @two = FactoryGirl.create :post, name: "B. Second post"
            @three = FactoryGirl.create :post, name: "C. Third post"
            @four = FactoryGirl.create :post, name: "D. Fourth post"

            # Additional comments for multi-sorting
            FactoryGirl.create :comment, post: @one
            FactoryGirl.create :comment, post: @two

            @ascending = [@one, @four, @two, @three]
			@descending = [@three, @two, @four, @one]

            Querify.params.clear
        end

        it 'only has 4 posts for testing' do
            assert_equal 4, Post.count
        end

        describe 'no filterable parameters' do

            it 'returns empty Querify.where and Querify.having arrays' do
                Querify.params = {:where => {}}
                Post.filterable
                assert_equal [], Querify.where_filters
                assert_equal [], Querify.having_filters
            end

        end

        describe 'one filterable parameter' do

            it 'returns greater than' do
                Querify.params = {:where=>{"name"=>{"lt"=>"D. Fourth post"}}}
                assert_equal 3, Post.filterable.count
            end

            it 'returns greater than or equal to' do
                Querify.params = {:where=>{"name"=>{"gteq"=>"C. Third post"}}}
                assert_equal 2, Post.filterable.count
            end

            it 'returns less than' do
                Querify.params = {:where=>{"name"=>{"lt"=>"B. Second post"}}}
                assert_equal 1, Post.filterable.count
            end

            it 'returns less than or equal to' do
                Querify.params = {:where=>{"name"=>{"lteq"=>"B. Second post"}}}
                assert_equal 2, Post.filterable.count
            end

            it 'returns equal to' do
                Querify.params = {:where=>{"name"=>{"eq"=>"B. Second post"}}}
                assert_equal 1, Post.filterable.count
            end

            it 'returns not equal to' do
                Querify.params = {:where=>{"name"=>{"neq"=>"B. Second post"}}}
                assert_equal 3, Post.filterable.count
            end
            #
            # it 'returns is' do
            #     FactoryGirl.create(:post, name: nil)
            #     Querify.params = {:where=>{"name"=>{"is"=>"null"}}}
            #     assert_equal 1, Post.filterable.count
            # end
            #
            # it 'returns is not' do
            #     FactoryGirl.create(:post, name: nil)
            #     Querify.params = {:where=>{"name"=>{"isnot"=>"null"}}}
            #     assert_equal 3, Post.filterable.count
            # end

            it 'returns case insensitive like' do
                Querify.params = {:where=>{"name"=>{"ilike"=>"b."}}}
                assert_equal 1, Post.filterable.count
            end

            it 'returns case sensitive like' do
                Querify.params = {:where=>{"name"=>{"like"=>"b."}}}
                assert_equal 0, Post.filterable.count
            end

            it 'returns in' do
                Querify.params = {:where=>{"name"=>{"in"=>"A. First post,B. Second post"}}}
                assert_equal 2, Post.filterable.count
            end

{'fraction_non_alphanumeric': 0.11225256827862691, 'fraction_numerical': 0.003257328990228013, 'mean_word_length': 1.6521594684385381, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 71, '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': '2931483', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2218, 'n_words': 653}