Sha256: 8ed9fa9194b9fce40c3e74c23f4dac9beeef8ede7a746a27ebf37baaf206f944

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe LinkedVocabs::Validators::PropertyValidator do
  before do
    class DummyAuthority < ActiveTriples::Resource
      include LinkedVocabs::Controlled
      use_vocabulary :dcmitype, class: RDF::Vocab::DCMIType

      property :dctype, predicate: RDF::Vocab::DC.type, class_name: DummyAuthority
    end

    class DummyResource < ActiveTriples::Resource
      validates_vocabulary_of :dctype

      property :dctype, predicate: RDF::Vocab::DC.type, class_name: DummyAuthority
    end
  end

  after do
    Object.send(:remove_const, 'DummyAuthority') if Object
    Object.send(:remove_const, 'DummyResource') if Object
  end

  subject { DummyResource.new }
  let(:authority) { DummyAuthority }

  context 'with value in vocabulary' do
    before do
      subject.dctype = authority.list_terms.first
    end
    it 'is valid' do
      expect(subject).to be_valid
    end

    it 'is invalid with other invalid values' do
      subject.dctype << 'freetext value'
      expect(subject).not_to be_valid
    end
  end

  context 'with value out of vocabulary' do
    before do
      subject.dctype = authority.new
    end
    it 'is invalid' do
      expect(subject).not_to be_valid
    end
  end

  context 'with value of wrong class' do
    before do
      class NotAuthority < ActiveTriples::Resource; end
      subject.dctype = NotAuthority.new
    end

    after do
      Object.send(:remove_const, 'NotAuthority') if Object
    end

    it 'is invalid' do
      expect(subject).not_to be_valid
    end
  end

  context 'with literal value' do
    before do
      subject.dctype = 'freetext value'
    end

    it 'is invalid' do
      expect(subject).not_to be_valid
      expect(subject.errors.full_messages).to eq ["`freetext value' for `dctype' property is expected to be a URI, but it is a String"]
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linked_vocabs-0.3.1 spec/property_validator_spec.rb