Sha256: b0dd25b2b88b188cca7b1d34b3a87e99eda8325a721dedfb0aa7463f36d4a115
Contents?: true
Size: 1.43 KB
Versions: 5
Compression:
Stored size: 1.43 KB
Contents
require 'spec_helper_models' describe Gaku::Grading::Single::Score 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: 5, student:student, exam_portion: exam_portion1) end let(:exam_portion_score2) do create(:exam_portion_score, score: 10, 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: 15.0 }) end end end
Version data entries
5 entries across 5 versions & 1 rubygems