Sha256: 640c441b3776eecf2c37861c9faf30d9caf90c7f3761082915029ede8fd87da3

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

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

      property :type, :predicate => RDF::DC.type, :class_name => DummyAuthority
    end

    class DummyResource < ActiveTriples::Resource
      validates_vocabulary_of :type

      property :type, :predicate => RDF::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.type = authority.list_terms.first
    end
    it 'is valid' do
      expect(subject).to be_valid
    end

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

  context 'with value out of vocabulary' do
    before do
      subject.type = 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.type = 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.type = '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.1.0 spec/property_validator_spec.rb