Sha256: fb59756d1606688d41b2e27e4d53ff367403349c187c0143cd68e000847fba19

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

require 'spec_helper'

describe SerialTranslator::SerialTranslatorPresenceValidator do
  let(:example) { FakeObject.new }

  describe 'validation' do
    it 'validates presence correctly if attribute is nil' do
      example.description = nil
      expect(example).to have(1).error_on(:description)
    end

    it 'validates presence correctly if attribute is empty' do
      example.description = ''
      expect(example).to have(1).error_on(:description)
    end

    it 'has no error if everything is fine' do
      example.description = 'This is a nice foo thing'
      expect(example).to have(:no).errors_on(:description)
    end

    it 'is valid if any language has a value' do
      example.description_translations = { en: '', de: '' }
      expect(example).to have(1).error_on(:description)

      example.description_translations = { en: '', de: 'foobar' }
      expect(example).to have(:no).errors_on(:description)

      example.description_translations = { en: 'foobar', de: nil }
      expect(example).to have(:no).errors_on(:description)
    end
  end

  it 'is of kind "presence"' do
    expect(described_class.new(attributes: %i(foo)).kind)
      .to eq :presence
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
serial_translator-1.1.3 spec/lib/serial_translator/serial_translator_presence_validator_spec.rb
serial_translator-1.1.0 spec/lib/serial_translator/serial_translator_presence_validator_spec.rb
serial_translator-1.0.2 spec/lib/serial_translator/serial_translator_presence_validator_spec.rb
serial_translator-1.0.1 spec/lib/serial_translator/serial_translator_presence_validator_spec.rb
serial_translator-1.0.0 spec/lib/serial_translator/serial_translator_presence_validator_spec.rb