Sha256: e978a30b144f732581b4207a6bfc7dbc7a30ae3d3e436e7d151a25981f1aab71

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 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
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linked_vocabs-0.3.0 spec/property_validator_spec.rb