<commit_before>require 'rails_helper'
include AsyncHelper

describe FastAssignWorker, type: :worker do
  include_context "Unit Assignments Variables"
  let!(:unit) {create(:unit, name: unit_template1.name, user_id: teacher.id)}

  context 'creates a new unit' do
    it "can create new units and classroom activities" do
      FastAssignWorker.new.perform(teacher.id, unit_template1.id)
      expect(unit_templates_have_a_corresponding_unit?([unit_template1.id])).to eq(true)
      eventually { expect(units_have_a_corresponding_classroom_activities?([unit_template1.id])).to eq(true) }
    end
  end

  context 'updates an existing unit' do
    it "does not duplicate the existing unit" do
      units_with_a_specific_name = Unit.where(name: unit_template1.name).count
      FastAssignWorker.new.perform(teacher.id, unit_template1.id)
      expect(Unit.where(name: unit_template1.name).count).to eq(units_with_a_specific_name)
    end

    it "and adds new classroom activities to the existing unit" do
      # TODO: something is wrong with the associations
      original_units_cas = ClassroomActivity.where(unit_id: unit.id).count
      FastAssignWorker.new.perform(teacher.id, unit_template1.id)
      new_units_cas = ClassroomActivity.where(unit_id: unit.id).count
      eventually { expect(new_units_cas - original_units_cas).to eq(1)}
    end

    it "that assigns the new activities to all students" do
      original_classroom_activity = ClassroomActivity.create!(unit_id: unit.id, activity_id: unit_template1.activities.first.id, classroom_id: classroom.id, assigned_student_ids: [student.id])
      FastAssignWorker.new.perform(teacher.id, unit_template1.id)
      expect(unit.classroom_activities.find(original_classroom_activity.id).assign_on_join).to eq(true)
    end
  end


end<commit_msg>fix fast assign worker spec<commit_after>require 'rails_helper'
include AsyncHelper

describe FastAssignWorker, type: :worker do
  include_context "Unit Assignments Variables"
  let!(:unit) {create(:unit, name: unit_template1.name, user_id: teacher.id)}

  context 'creates a new unit' do
    it "can create new units and classroom activities" do
      FastAssignWorker.new.perform(teacher.id, unit_template1.id)
      expect(unit_templates_have_a_corresponding_unit?([unit_template1.id])).to eq(true)
      eventually { expect(units_have_corresponding_unit_activities?([unit_template1.id])).to eq(true) }
    end
  end

  context 'updates an existing unit' do
    it "does not duplicate the existing unit" do
      units_with_a_specific_name = Unit.where(name: unit_template1.name).count
      FastAssignWorker.new.perform(teacher.id, unit_template1.id)
      expect(Unit.where(name: unit_template1.name).count).to eq(units_with_a_specific_name)
    end

    it "and adds new classroom activities to the existing unit" do
      original_units_cus = ClassroomUnit.where(unit_id: unit.id).count
      FastAssignWorker.new.perform(teacher.id, unit_template1.id)
      new_units_cus = ClassroomUnit.where(unit_id: unit.id).count
      eventually { expect(new_units_cus - original_units_cus).to eq(1)}
    end

    it "that assigns the new activities to all students" do
      original_classroom_unit = ClassroomUnit.create!(unit_id: unit.id, classroom_id: classroom.id, assigned_student_ids: [student.id])
      FastAssignWorker.new.perform(teacher.id, unit_template1.id)
      expect(unit.classroom_units.find(original_classroom_unit.id).assign_on_join).to eq(true)
    end
  end


end
{'fraction_non_alphanumeric': 0.09088302752293578, 'fraction_numerical': 0.006020642201834863, 'mean_word_length': 4.663961038961039, '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': '6984511', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1079, 'n_words': 240}