Sha256: 29f4331e66f5930b0a7eca529c251be46d736893f206efc60de718b79eada013

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

require "#{File.dirname(__FILE__)}/../../../spec_helper"

describe DocumentWithEnum do
  context '2 overlapping documents with same kind' do
    it 'are invalid' do

      document_1 = FactoryGirl.create(
        :document_with_enum,
        kind: :draft,
        valid_from: '2011-01-05'.to_date,
        valid_until: '2011-01-08'.to_date
      )

      document_2 = FactoryGirl.build(
        :document_with_enum,
        kind: :draft,
        valid_from: '2011-01-06'.to_date,
        valid_until: '2011-01-07'.to_date
      )

      expect(document_2).not_to be_valid
      expect(document_2.errors[:valid_from]).to eq ["overlaps with another record"]
    end
  end

  context '2 overlapping documents with different kind' do
    it 'are valid' do
      document_1 = FactoryGirl.create(
        :document_with_enum,
        kind: :draft,
        valid_from: '2011-01-05'.to_date,
        valid_until: '2011-01-08'.to_date
      )

      document_2 = FactoryGirl.build(
        :document_with_enum,
        kind: :contract,
        valid_from: '2011-01-06'.to_date,
        valid_until: '2011-01-07'.to_date
      )

      expect(document_2).to be_valid
    end
  end

  describe '#kind' do
    it 'save and read attribute properly' do
      docuemnt = FactoryGirl.create(:document_with_enum, kind: :contract)
      docuemnt.reload
      expect(docuemnt.kind.to_s).to eq "contract"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
validates_overlap-1.0.0 spec/dummy/spec/models/document_with_enum_spec.rb
validates_overlap-0.8.6 spec/dummy/spec/models/document_with_enum_spec.rb
validates_overlap-0.8.5 spec/dummy/spec/models/document_with_enum_spec.rb
validates_overlap-0.8.4 spec/dummy/spec/models/document_with_enum_spec.rb
validates_overlap-0.8.2 spec/dummy/spec/models/document_with_enum_spec.rb