Sha256: 6a55c28f805b5f46be7cc59ab5d25cc316fb2a802d250f324330986b3b081156

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

require 'spec_helper'

describe Gaku::Guardian do

  describe 'concerns' do
    it_behaves_like 'person'
    it_behaves_like 'addressable'
    it_behaves_like 'contactable'
    it_behaves_like 'avatarable'
    it_behaves_like 'thrashable'
  end

  describe 'relations' do
    it { should belong_to :user }
    it { should have_many :student_guardians }
    it { should have_many(:students).through(:student_guardians) }
  end

  context 'counter_cache' do

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

    context 'addresses_count' do

      let(:address) { build(:address) }
      let(:guardian_with_address) { create(:guardian, :with_address) }

      it 'increments addresses_count' do
        expect do
          guardian.addresses << address
        end.to change { guardian.reload.addresses_count }.by 1
      end

      it 'decrements addresses_count' do
        expect do
          guardian_with_address.addresses.last.destroy
        end.to change { guardian_with_address.reload.addresses_count }.by -1
      end
    end

    context 'contacts_count' do

      let(:contact) { build(:contact) }
      let(:guardian_with_contact) { create(:guardian, :with_contact) }

      it 'increments contacts_count' do
        expect do
          guardian.contacts << contact
        end.to change { guardian.reload.contacts_count }.by 1
      end

      it 'decrements contacts_count' do
        expect do
          guardian_with_contact.contacts.last.destroy
        end.to change { guardian_with_contact.reload.contacts_count }.by -1
      end
    end
  end

  context 'methods' do
    xit 'primary_contact'
    xit 'primary_address'
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

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