Sha256: ac009f3f1713213218a30337134b4e66a8ba622de30852262cb5ba191d8844f0

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require_relative '../spec_helper'
require 'common_repository_model/area'
require 'common_repository_model/collection'

describe CommonRepositoryModel::Area do
  after(:each) do
    subject.delete if subject.persisted?
  end

  describe 'without persisting' do
    subject { FactoryGirl.build(:area, name: name) }
    let(:name) { 'My Area Name'}

    it 'should find or create by #name' do
      lambda { subject.save }.must_raise(NoMethodError)
      lambda { subject.save! }.must_raise(NoMethodError)
    end

    it 'should require a #name' do
      subject.name = nil
      subject.valid?.must_equal false
      subject.name = name
      subject.valid?.must_equal true
    end

    it 'should have #name' do
      subject.name.must_equal name
    end

    it 'should build #collections' do
      subject.collections.build.
        must_be_kind_of(CommonRepositoryModel::Collection)
    end
  end

  describe 'integration (with persistence)' do
    subject { FactoryGirl.create(:area) }
    let(:collection) { FactoryGirl.build(:collection, area: nil) }
    it 'should find by name' do
      CommonRepositoryModel::Area.find_by_name(subject.name).must_equal subject
      CommonRepositoryModel::Area.
        find_by_name("#{subject.name}-tmp").must_equal nil
    end
    it 'should save' do
      # Before we can add a collection, the containing object
      # must be saved
      subject.collections << collection
      subject.send(:save).must_equal true
      new_subject = subject.class.find(subject.pid)

      new_subject.collections.size.must_equal 1
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
common_repository_model-0.0.3 spec/common_respository_model/area_spec.rb