Sha256: aa69bb352cfeff23304418dc692b991d1e1ecf20d2f89b8bb628bf9db18b361d

Contents?: true

Size: 1.73 KB

Versions: 5

Compression:

Stored size: 1.73 KB

Contents

require 'spec_helper_models'

describe Gaku::Guardian do

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

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

  describe '#primary_contact' do
    it('responds to primary_contact') { should respond_to(:primary_contact) }
  end

  describe '#primary_address' do
    it('responds to primary_address') { should respond_to(:primary_address) }
  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

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gaku-0.2.4 core/spec/models/guardian_spec.rb
gaku-0.2.3 core/spec/models/guardian_spec.rb
gaku-0.2.2 core/spec/models/guardian_spec.rb
gaku-0.2.1 core/spec/models/guardian_spec.rb
gaku-0.2.0 core/spec/models/guardian_spec.rb