Sha256: 148fca4a7f08e4bb6275529fe397a0b68dbd095773c77879dc5c32585a88300f

Contents?: true

Size: 1.58 KB

Versions: 12

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'
require 'pragmatic_context'

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

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

    class DummyResource < ActiveTriples::Resource
      include PragmaticContext::Contextualizable

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

      contextualize :title, :as => RDF::DC.title.to_s
      contextualize :license, :as => RDF::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") if Object
    Object.send(:remove_const, "DummyLicense") if Object
  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 eq ["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

12 entries across 12 versions & 1 rubygems

Version Path
active-triples-0.6.1 spec/pragmatic_context_spec.rb
active-triples-0.6.0 spec/pragmatic_context_spec.rb
active-triples-0.5.0 spec/pragmatic_context_spec.rb
active-triples-0.4.0 spec/pragmatic_context_spec.rb
active-triples-0.3.1 spec/pragmatic_context_spec.rb
active-triples-0.3.0 spec/pragmatic_context_spec.rb
active-triples-0.2.3 spec/pragmatic_context_spec.rb
active-triples-0.2.2 spec/pragmatic_context_spec.rb
active-triples-0.2.1 spec/pragmatic_context_spec.rb
active-triples-0.2.0 spec/pragmatic_context_spec.rb
active-triples-0.1.2 spec/pragmatic_context_spec.rb
active-triples-0.1.1 spec/pragmatic_context_spec.rb