Sha256: f3c90598ff8d980ce8fd34f1614e052aabc7dcd5e8d8cec8317b8d6a1f180eae

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'

describe Gaku::Exam do

  let!(:exam) { create(:exam) }

  describe 'concerns' do
    it_behaves_like 'notable'
    it_behaves_like 'thrashable'
  end

  describe 'associations' do
    it { should have_many :exam_portions }
    it { should have_many(:exam_portion_scores).through(:exam_portions) }

    it { should have_many :exam_syllabuses }
    it { should have_many(:syllabuses).through(:exam_syllabuses) }

    it { should have_many :attendances }
    it { should have_many :exam_scores }
    it { should belong_to :grading_method }

    it { should accept_nested_attributes_for :exam_portions }
  end

  describe 'validations' do
    it { should validate_presence_of :name }
    it { should validate_numericality_of :weight }

    it 'errors when name is nil' do
      exam.name = nil
      exam.should_not be_valid
    end

    it 'should validate weight is greater than 0' do
      exam.weight = -1
      exam.should be_invalid
    end

    it 'should validate weight is 0' do
      exam.weight = 0
      exam.should be_valid
    end
  end

  context 'counter_cache' do
    context 'notes_count' do

      let(:note) { build(:note) }
      let(:exam_with_note) { create(:exam, :with_note) }

      it 'increments notes_count' do
        expect do
          exam.notes << note
        end.to change { exam.reload.notes_count }.by 1
      end

      it 'decrements notes_count' do
        expect do
          exam_with_note.notes.last.destroy
        end.to change { exam_with_note.reload.notes_count }.by -1
      end
    end
  end

  context '#max_score' do
    let(:exam_with_portions) { create(:exam, :with_portions) }
    it 'sums' do
      exam_with_portions.max_score.should eq 300
    end
  end

  context 'methods' do
    xit 'total_weight'
    xit 'max_score'
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gaku-0.0.3 core/spec/models/exam_spec.rb
gaku-0.0.2 core/spec/models/exam_spec.rb
gaku-0.0.1 core/spec/models/exam_spec.rb