Sha256: d9d19d1281698fc91d86ec7f1e263139acc0ebd95082cefcbd10a9cce6c00bbc

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

describe Gaku::ClassGroup do

  describe 'concerns' do
    it_behaves_like 'notable'
  end

  describe 'associations' do
    it { should have_many :enrollments }
    it { should have_many(:students).through(:enrollments) }
    it { should have_many(:class_group_course_enrollments).dependent(:destroy) }
    it { should have_many(:courses).through(:class_group_course_enrollments) }
    it { should have_many(:semester_class_groups).dependent(:destroy) }
    it { should have_many(:semesters).through(:semester_class_groups) }
  end

  describe 'validations' do
    it { should validate_presence_of :name }
  end

  describe '#to_s' do
    let(:class_group) { build(:class_group) }
    specify { class_group.to_s.should eq "#{class_group.grade} - #{class_group.name}" }
  end

  context 'counter_cache' do

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

    context 'notes_count' do

      let(:note) { build(:note) }
      let(:class_group_with_note) { create(:class_group, :with_note) }

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

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

end

Version data entries

3 entries across 3 versions & 1 rubygems

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