Sha256: 4beb0224941aecc01a381d66ccab514a141281c1cec1e66ec322ed6b8f5e20ed

Contents?: true

Size: 1.69 KB

Versions: 10

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true
require 'spec_helper'
require 'pragmatic_context'

describe 'PragmaticContext integration' do
  before do
    class DummyLicense
      include ActiveTriples::RDFSource
      include PragmaticContext::Contextualizable
      property :title, :predicate => RDF::Vocab::DC.title

      contextualize :title, :as => RDF::Vocab::DC.title.to_s
    end

    class DummyResource
      include ActiveTriples::RDFSource
      include PragmaticContext::Contextualizable

      configure :type => RDF::URI('http://example.org/SomeClass')
      property :license, :predicate => RDF::Vocab::DC.license, 
                         :class_name => DummyLicense
      property :title, :predicate => RDF::Vocab::DC.title

      contextualize :title, :as => RDF::Vocab::DC.title.to_s
      contextualize :license, :as => RDF::Vocab::DC.license.to_s
    end

    license.title = 'cc'
    subject.title = 'my resource'
    subject.license = license
    subject.license << RDF::Literal('Creative Commons')
  end

  after do
    Object.send(:remove_const, "DummyResource")
    Object.send(:remove_const, "DummyLicense")
  end

  subject { DummyResource.new('http://example.org/test') }
  let(:license) { DummyLicense.new }

  xit 'should output a valid jsonld representation of itself' do
    g = RDF::Graph.new << JSON::LD::API.toRdf(subject.as_jsonld)
    expect(subject == g).to be true
  end

  it 'should have contexts' do
    expect(subject.as_jsonld['@context'].keys).to contain_exactly('license', 'title')
  end

  it 'should use context with dump' do
    context = JSON.parse(subject.dump :jsonld)['@context']
    subject.class.properties.keys.each do |prop|
      expect(context).to include prop
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
active-triples-1.1.0 spec/pragmatic_context_spec.rb
active-triples-1.0.0 spec/pragmatic_context_spec.rb
active-triples-1.0.0.rc1 spec/pragmatic_context_spec.rb
active-triples-0.11.0 spec/pragmatic_context_spec.rb
active-triples-0.10.2 spec/pragmatic_context_spec.rb
active-triples-0.10.1 spec/pragmatic_context_spec.rb
active-triples-0.10.0 spec/pragmatic_context_spec.rb
active-triples-0.9.0 spec/pragmatic_context_spec.rb
active-triples-0.8.3 spec/pragmatic_context_spec.rb
active-triples-0.8.2 spec/pragmatic_context_spec.rb