Sha256: 746e2b727fa8619922f9b1ac5ffbc774104530fe7d73a4d377a76422b2dbe171

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'

describe OverlapValidator do
  context 'validation message' do
    it 'should have default message' do
      subject = OverlapValidator.new(attributes: [:starts_at, :ends_at])
      meeting = Meeting.new
      expect(subject).to receive(:overlapped_exists?) { true }
      subject.validate(meeting)
      expect(meeting.errors[:starts_at]).to eq ['overlaps with another record']
    end

    it 'should be possible to configure message' do
      subject = OverlapValidator.new(attributes: [:starts_at, :ends_at])
      meeting = Meeting.new
      expect(subject).to receive(:overlapped_exists?) { true }
      allow(subject).to receive(:options) { { message_title: :optional_key, message_content: 'Message content' } }
      subject.validate(meeting)
      expect(meeting.errors[:optional_key]).to eq ['Message content']
    end

    it 'should be possible to configure multiple keys for message' do
      subject = OverlapValidator.new(attributes: [:starts_at, :ends_at])
      meeting = Meeting.new
      expect(subject).to receive(:overlapped_exists?) { true }
      allow(subject).to receive(:options) { { message_title: [:optional_key_1, 'optional_key_2'], message_content: 'Message content' } }
      subject.validate(meeting)
      expect(meeting.errors[:optional_key_1]).to eq ['Message content']
      expect(meeting.errors[:optional_key_2]).to eq ['Message content']
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
validates_overlap-1.0.0 spec/dummy/spec/overlap_validator_spec.rb
validates_overlap-0.8.6 spec/dummy/spec/overlap_validator_spec.rb
validates_overlap-0.8.5 spec/dummy/spec/overlap_validator_spec.rb
validates_overlap-0.8.4 spec/dummy/spec/overlap_validator_spec.rb