<commit_before>require 'rails_helper'

RSpec.describe PrecomputeStudentHashesJob do

  # set time at 2017-06-22 10:07:42
  let(:time_now) { Time.at(1498126062) }
  let(:outcome) { PrecomputedQueryDoc.all }
  let(:first_json_blob) { JSON.parse!(outcome.first.json) }
  let(:log) { LogHelper::Redirect.instance.file }

  describe '#school_overview_precompute_jobs' do

    context 'educator with students' do
      let!(:school) { FactoryGirl.create(:healey) }
      let!(:educator) { FactoryGirl.create(:educator, school: school, schoolwide_access: true) }
      let!(:student) { FactoryGirl.create(:student, school: school) }

      before { PrecomputeStudentHashesJob.new(log).precompute_all!(time_now) }

      let(:first_json_blob_key) { first_json_blob.keys.first }
      let(:first_json_blob_value) { first_json_blob[first_json_blob_key] }

      it 'creates a doc with the correct key and correct data inside' do
        expect(outcome.size).to eq 1
        expect(outcome.first.key.split(':')[0]).to eq "short"
        expect(outcome.first.key.split(':')[1]).to eq "1498104000"
        expect(outcome.first.key.split(':')[2]).to eq "1"

        expect(first_json_blob_key).to eq "student_hashes"
        expect(first_json_blob_value.first["id"]).to eq student.id
      end
    end

    context 'educator without students' do
      let!(:school) { FactoryGirl.create(:healey) }
      let!(:educator) { FactoryGirl.create(:educator, school: school, schoolwide_access: true) }

      before { PrecomputeStudentHashesJob.new(log).precompute_all!(Time.now) }

      it 'returns an empty array' do
        expect(outcome).to eq []
      end
    end

  end

end<commit_msg>Add another test case to PrecomputeStudentHashesJob spec<commit_after>require 'rails_helper'

RSpec.describe PrecomputeStudentHashesJob do

  # set time at 2017-06-22 10:07:42
  let(:time_now) { Time.at(1498126062) }
  let(:outcome) { PrecomputedQueryDoc.all }
  let(:first_json_blob) { JSON.parse!(outcome.first.json) }
  let(:log) { LogHelper::Redirect.instance.file }

  describe '#school_overview_precompute_jobs' do

    context 'educator with students' do
      let!(:school) { FactoryGirl.create(:healey) }
      let!(:educator) { FactoryGirl.create(:educator, school: school, schoolwide_access: true) }
      let!(:student) { FactoryGirl.create(:student, school: school) }

      before { PrecomputeStudentHashesJob.new(log).precompute_all!(time_now) }

      let(:first_json_blob_key) { first_json_blob.keys.first }
      let(:first_json_blob_value) { first_json_blob[first_json_blob_key] }

      it 'creates a doc with the correct key and correct data inside' do
        expect(outcome.size).to eq 1
        expect(outcome.first.key.split(':')[0]).to eq "short"
        expect(outcome.first.key.split(':')[1]).to eq "1498104000"
        expect(outcome.first.key.split(':')[2]).to eq "1"

        expect(first_json_blob_key).to eq "student_hashes"
        expect(first_json_blob_value.first["id"]).to eq student.id
      end
    end

    context 'educators without students' do
      let!(:school) { FactoryGirl.create(:healey) }
      let!(:educator) { FactoryGirl.create(:educator, school: school, schoolwide_access: true) }
      let!(:educator_not_schoolwide) { FactoryGirl.create(:educator, school: school) }

      before { PrecomputeStudentHashesJob.new(log).precompute_all!(Time.now) }

      it 'returns an empty array' do
        expect(outcome).to eq []
      end
    end

  end

end
{'fraction_non_alphanumeric': 0.1282714984181766, 'fraction_numerical': 0.022433132010353754, 'mean_word_length': 3.8440111420612815, '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': '126948', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1132, 'n_words': 217}