<commit_before>require 'rails_spec_helper'

describe GradeSchemeElementsController do
  before(:all) { @course = create(:course) }
  before(:each) do
    session[:course_id] = @course.id
    allow(Resque).to receive(:enqueue).and_return(true)
  end

  context "as professor" do
    before(:all) do
      @professor = create(:user)
      CourseMembership.create user: @professor, course: @course, role: "professor"
    end

    before(:each) do
      @grade_scheme_element = create(:grade_scheme_element, course: @course)
      login_user(@professor)
    end

    describe "GET index" do
      it "assigns all grade scheme elements" do
        get :index
        expect(assigns(:grade_scheme_elements)).to eq([@grade_scheme_element])
      end
    end

    describe "GET mass_edit" do
      it "shows the mass edit form" do
        get :mass_edit
        expect(assigns(:grade_scheme_elements)).to eq(@course.grade_scheme_elements)
      end
    end

    describe "POST mass_update" do
      it "updates the grade scheme elements all at once" do
        skip "not working"
        params = { "grade_scheme_elements_attributes" => [{ id: @grade_scheme_element.id, letter: "C", level: "Sea Slug", 
          low_range: 0, high_range: 100000, course_id: @course.id }, { id: GradeSchemeElement.new, letter: "B", level: "Snail", 
          low_range: 100001, high_range: 200000, course_id: @course.id }], 
        "deleted_ids"=>nil, "grade_scheme_element"=>{} }
        put :mass_edit, params
        expect(@course.grade_scheme_elements.count).to eq(2)
        expect(@grade_scheme_element.reload.level).to eq("Sea Slug")
      end
    end

    describe "GET student predictor data" do
      it "returns grade scheme elements with total points as json" do
        @grade_scheme_element.update(low_range: 1000)
        get :predictor_data, format: :json
        expect(assigns(:grade_scheme_elements)).to eq([@grade_scheme_element])
        expect(assigns(:total_points)).to eq(1100)
        expect(response).to render_template(:predictor_data)
      end
    end
  end

  context "as student" do
    before(:all) do
      @student = create(:user)
      @student.courses << @course<commit_msg>Get the GradeSchemeElements#mass_update spec working<commit_after>require 'rails_spec_helper'

describe GradeSchemeElementsController do
  before(:all) { @course = create(:course) }
  before(:each) do
    session[:course_id] = @course.id
    allow(Resque).to receive(:enqueue).and_return(true)
  end

  context "as professor" do
    before(:all) do
      @professor = create(:user)
      CourseMembership.create user: @professor, course: @course, role: "professor"
    end

    before(:each) do
      @grade_scheme_element = create(:grade_scheme_element, course: @course)
      login_user(@professor)
    end

    describe "GET index" do
      it "assigns all grade scheme elements" do
        get :index
        expect(assigns(:grade_scheme_elements)).to eq([@grade_scheme_element])
      end
    end

    describe "GET mass_edit" do
      it "shows the mass edit form" do
        get :mass_edit
        expect(assigns(:grade_scheme_elements)).to eq(@course.grade_scheme_elements)
      end
    end

    describe "PUT mass_update" do
      it "updates the grade scheme elements all at once" do
        params = { "grade_scheme_elements_attributes" => [{ id: @grade_scheme_element.id, letter: "C", level: "Sea Slug", low_range: 0, high_range: 100000, course_id: @course.id }, { id: GradeSchemeElement.new.id, letter: "B", level: "Snail",
          low_range: 100001, high_range: 200000, course_id: @course.id }],
        "deleted_ids"=>nil, "grade_scheme_element"=>{} }
        put :mass_update, params.merge(format: :json)
        expect(@course.reload.grade_scheme_elements.count).to eq(2)
        expect(@grade_scheme_element.reload.level).to eq("Sea Slug")
      end
    end

    describe "GET student predictor data" do
      it "returns grade scheme elements with total points as json" do
        @grade_scheme_element.update(low_range: 1000)
        get :predictor_data, format: :json
        expect(assigns(:grade_scheme_elements)).to eq([@grade_scheme_element])
        expect(assigns(:total_points)).to eq(1100)
        expect(response).to render_template(:predictor_data)
      end
    end
  end

  context "as student" do
    before(:all) do
      @student = create(:user)
      @student.courses << @course
{'fraction_non_alphanumeric': 0.11032917139614075, 'fraction_numerical': 0.012712826333711692, 'mean_word_length': 3.340886699507389, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1788807', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1325, 'n_words': 343}