Sha256: 2c9d55552a4b35972e910d4b621a1e89370096eb39cf817e54edbbe32be21268

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper_models'

describe Gaku::Grading::Single::Percentage do

  let(:student) { create(:student) }
  let(:exam) { create(:exam) }
  let(:exam_portion1) { create(:exam_portion, exam: exam) }
  let(:exam_portion2) { create(:exam_portion, exam: exam) }
  let(:exam_portion_score1) do
    create(:exam_portion_score, score: 28, student:student, exam_portion: exam_portion1)
  end
  let(:exam_portion_score2) do
    create(:exam_portion_score, score: 35, student:student, exam_portion: exam_portion2)
  end

  subject { described_class.new(exam, student) }

  describe 'initialize' do
    it 'initializes with exam' do
      expect(subject.grade_exam).to eq({ id: student.id, score: nil })
    end
  end

  describe 'without exam portion scores' do
    before do
      exam_portion1; exam_portion2;
    end
    it 'creates exam_portion_score if not exist' do
      expect do
        subject.grade_exam
      end.to change(student.reload.exam_portion_scores, :count).by(2)
    end
  end

  describe 'with exam portion scores' do
    before do
      exam
      exam_portion1;exam_portion2
      exam_portion_score1; exam_portion_score2
    end
    it "doesn't create exam_portion_score if exists" do
      expect do
        subject.grade_exam
      end.to_not change(student.reload.exam_portion_scores, :count)
    end

    it 'calculates scores from exam_portion_scores' do
      expect(subject.grade_exam).to eq({ id: student.id, score: 31.5 })
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gaku-0.2.4 core/spec/lib/gaku/grading/single/percentage_spec.rb
gaku-0.2.3 core/spec/lib/gaku/grading/single/percentage_spec.rb
gaku-0.2.2 core/spec/lib/gaku/grading/single/percentage_spec.rb
gaku-0.2.1 core/spec/lib/gaku/grading/single/percentage_spec.rb
gaku-0.2.0 core/spec/lib/gaku/grading/single/percentage_spec.rb