<commit_before>require 'spec_helper'
require './lib/query_project'

describe QueryProject do

  let(:project_id) { double }
  subject { QueryProject.new(project_id) }

  describe '#params' do

    context 'labels' do
      it 'adds a single label filter' do
        subject.label('apple')
        subject.params[:filter].should eq 'label:apple'
      end

      it 'adds filters for multiple single word labels' do
        subject.labels('apple', 'banana', 'pear')
        subject.params[:filter].should eq 'label:apple+label:banana+label:pear'
      end

      it 'add filters for single word and quotes multi word labels' do
        subject.labels('apple fruit', 'banana', 'pear drop')
        subject.params[:filter].should eq 'label:"apple fruit"+label:banana+label:"pear drop"'
      end

    end

    context 'states' do
      it 'adds a single state filter' do
        subject.status('unstarted')
        subject.params[:filter].should eq '(state:unstarted)'
      end 

      it 'adds filters for multiple states' do
        subject.status('unstarted', 'unfinished')
        subject.params[:filter].should eq '(state:unstarted+OR+state:unfinished)'
      end
    end

    shared_examples 'filter for when state changed' do
      #
      # `state` should be defined e.g. accepted, created, updated
      #
      let(:state_after) { "#{state}_after".to_sym }
      let(:state_before) { "#{state}_before".to_sym }

      context 'not specified' do
        it 'does not add _after' do
          subject.params[state_after].should be_nil
        end

        it 'does not add _before' do
          subject.params[state_before].should be_nil
        end
      end
      
      context 'specified' do
        let(:time) { Time.now }
        let(:time_in_ms) { double }
        before { allow(subject).to receive(:as_msec).with(time).and_return(time_in_ms) }

        it 'adds _after' do
          subject.send(state, since: time)
          subject.params[state_after].should eq time_in_ms
        end

        it 'adds _before' do
          subject.send(state, before: time)
          subject.params[state_before].should eq time_in_ms
        end
      end
    end

    context 'accepted' do
      let(:state) { 'accepted' }
      it_behaves_like 'filter for when state changed'
    end

    context 'created' do
      let(:state) { 'created' }
      it_behaves_like 'filter for when state changed'
    end

    context 'updated' do
      let(:state) { 'updated' }
      it_behaves_like 'filter for when state changed'
    end

  end


end

<commit_msg>Use explicit param for shared example<commit_after>require 'spec_helper'
require './lib/query_project'

describe QueryProject do

  let(:project_id) { double }
  subject { QueryProject.new(project_id) }

  describe '#params' do

    context 'labels' do
      it 'adds a single label filter' do
        subject.label('apple')
        subject.params[:filter].should eq 'label:apple'
      end

      it 'adds filters for multiple single word labels' do
        subject.labels('apple', 'banana', 'pear')
        subject.params[:filter].should eq 'label:apple+label:banana+label:pear'
      end

      it 'add filters for single word and quotes multi word labels' do
        subject.labels('apple fruit', 'banana', 'pear drop')
        subject.params[:filter].should eq 'label:"apple fruit"+label:banana+label:"pear drop"'
      end

    end

    context 'states' do
      it 'adds a single state filter' do
        subject.status('unstarted')
        subject.params[:filter].should eq '(state:unstarted)'
      end 

      it 'adds filters for multiple states' do
        subject.status('unstarted', 'unfinished')
        subject.params[:filter].should eq '(state:unstarted+OR+state:unfinished)'
      end
    end

    shared_examples 'filter for when state changed' do |state|
      #
      # `state` the name of the state change we're filtering for e.g. accepted, created, updated
      #
      let(:state_after) { "#{state}_after".to_sym }
      let(:state_before) { "#{state}_before".to_sym }

      context 'not specified' do
        it 'does not add _after' do
          subject.params[state_after].should be_nil
        end

        it 'does not add _before' do
          subject.params[state_before].should be_nil
        end
      end
      
      context 'specified' do
        let(:time) { Time.now }
        let(:time_in_ms) { double }
        before { allow(subject).to receive(:as_msec).with(time).and_return(time_in_ms) }

        it 'adds _after' do
          subject.send(state, since: time)
          subject.params[state_after].should eq time_in_ms
        end

        it 'adds _before' do
          subject.send(state, before: time)
          subject.params[state_before].should eq time_in_ms
        end
      end
    end

    context 'accepted' do
      it_behaves_like 'filter for when state changed', 'accepted'
    end

    context 'created' do
      it_behaves_like 'filter for when state changed', 'created'
    end

    context 'updated' do
      it_behaves_like 'filter for when state changed', 'updated'
    end

  end


end


{'fraction_non_alphanumeric': 0.10199686765857478, 'fraction_numerical': 0.0, 'mean_word_length': 2.5089285714285716, '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': '7295796', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1486, 'n_words': 433}