<commit_before>describe LabGroup do
  describe "relations" do
    let(:group) { create(:lab_group, students: [create(:student)]) }

    it "should have a given course" do
      group.given_course.should_not be_nil
    end

    it "should have a list of submissions" do
      lab = create(:lab, {given_course: group.given_course})
      lhg = create(:lab_has_group, {
        lab_group: group,
        lab: lab
      })

      create(:submission, lab_has_group: lhg)

      group.should have(1).submissions
    end

    it "should have a list of students" do
      group.should have(1).students
    end

    it "should have a list of labs" do
      lab = create(:active_lab, given_course: group.given_course)
      create(:lab_has_group, lab: lab, lab_group: group)
      group.should have(1).labs
    end
  end

  describe "validations" do
    it "defaults to valid" do
      build(:lab_group).should be_valid
    end

    it "should not be possible to override number" do
      create(:lab_group, number: nil).number.should_not be_nil
    end

    it "should auto increment the number" do
      gc1 = create(:given_course)
      gc2 = create(:given_course)

      list1 = 3.times.map { create(:lab_group, given_course: gc1).number }
      list2 = 3.times.map { create(:lab_group, given_course: gc2).number }

      list1.uniq.count.should eq(3)
      list2.uniq.count.should eq(3)

      list2.should eq(list1)
    end
  end


  describe "dependent destroy" do
    it "should not be possible for a lab_has_group to exist without a lab_group" do
      lg = Factory.create(:lab_group, id: 3)
      lhg = Factory.create(:lab_has_group, lab_group: lg)
      lg.destroy
      lambda{lhg.reload}.should raise_error(ActiveRecord::RecordNotFound)
    end
  end
  
  describe "adding a student" do
    let(:group) { create(:lab_group) }
    
    it "should be possible to add a student" do
      lab = create(:active_lab, given_course: group.given_course)
      create(:lab_has_group, lab: lab, lab_group: group)<commit_msg>Change in dependent destroy test<commit_after>describe LabGroup do
  describe "relations" do
    let(:group) { create(:lab_group, students: [create(:student)]) }

    it "should have a given course" do
      group.given_course.should_not be_nil
    end

    it "should have a list of submissions" do
      lab = create(:lab, {given_course: group.given_course})
      lhg = create(:lab_has_group, {
        lab_group: group,
        lab: lab
      })

      create(:submission, lab_has_group: lhg)

      group.should have(1).submissions
    end

    it "should have a list of students" do
      group.should have(1).students
    end

    it "should have a list of labs" do
      lab = create(:active_lab, given_course: group.given_course)
      create(:lab_has_group, lab: lab, lab_group: group)
      group.should have(1).labs
    end
  end

  describe "validations" do
    it "defaults to valid" do
      build(:lab_group).should be_valid
    end

    it "should not be possible to override number" do
      create(:lab_group, number: nil).number.should_not be_nil
    end

    it "should auto increment the number" do
      gc1 = create(:given_course)
      gc2 = create(:given_course)

      list1 = 3.times.map { create(:lab_group, given_course: gc1).number }
      list2 = 3.times.map { create(:lab_group, given_course: gc2).number }

      list1.uniq.count.should eq(3)
      list2.uniq.count.should eq(3)

      list2.should eq(list1)
    end
  end


  describe "dependent destroy" do
    it "should not be possible for a lab_has_group to exist without a lab_group" do
      lg = Factory.create(:lab_group)
      lhg = Factory.create(:lab_has_group, lab_group: lg)
      lg.destroy
      lambda{lhg.reload}.should raise_error(ActiveRecord::RecordNotFound)
    end
  end
  
  describe "adding a student" do
    let(:group) { create(:lab_group) }
    
    it "should be possible to add a student" do
      lab = create(:active_lab, given_course: group.given_course)
      create(:lab_has_group, lab: lab, lab_group: group)
{'fraction_non_alphanumeric': 0.09594460929772503, 'fraction_numerical': 0.008654797230464886, 'mean_word_length': 2.9157792836398837, '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': '1183359', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1275, 'n_words': 373}