From 97c22c8cd2c49cd9da00f528f388cf96f9888e6c Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Thu, 21 Apr 2016 12:19:53 -0400 Subject: [PATCH 1/2] Upgrade to compatibility with AT 0.8 Fixes #3 --- ld4l-foaf_rdf.gemspec | 13 +- spec/ld4l/foaf_rdf/agent_rdf_spec.rb | 267 ++++++++++++++++++++++++++ spec/ld4l/foaf_rdf/person_rdf_spec.rb | 25 +-- 3 files changed, 280 insertions(+), 25 deletions(-) create mode 100644 spec/ld4l/foaf_rdf/agent_rdf_spec.rb diff --git a/ld4l-foaf_rdf.gemspec b/ld4l-foaf_rdf.gemspec index 9aea0e7..ceea037 100644 --- a/ld4l-foaf_rdf.gemspec +++ b/ld4l-foaf_rdf.gemspec @@ -17,18 +17,13 @@ Gem::Specification.new do |spec| spec.files = `git ls-files -z`.split("\x0") spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) - # spec.test_files = `git ls-files -- {spec}/*`.split("\n") # FROM ActiveTriples gemspec file - # spec.require_paths = ["lib"] # NOT IN ActiveTriples gemspec file - # spec.add_dependency('ffi', '~> 1.9.5') - spec.add_dependency('rdf', '~> 1.1') - - spec.add_dependency('active-triples', '~> 0.5') - spec.add_dependency('active_triples-local_name', '~> 0.1') + spec.add_dependency('rdf') + spec.add_dependency('active-triples') + spec.add_dependency('active_triples-local_name') spec.add_development_dependency('pry') - # spec.add_development_dependency('pry-byebug') # Works with ruby > 2 - # spec.add_development_dependency('pry-debugger') # Works with ruby < 2 + spec.add_development_dependency('pry-byebug') spec.add_development_dependency('rdoc') spec.add_development_dependency('rspec') spec.add_development_dependency('coveralls') diff --git a/spec/ld4l/foaf_rdf/agent_rdf_spec.rb b/spec/ld4l/foaf_rdf/agent_rdf_spec.rb new file mode 100644 index 0000000..904c56a --- /dev/null +++ b/spec/ld4l/foaf_rdf/agent_rdf_spec.rb @@ -0,0 +1,267 @@ +require 'spec_helper' + +describe 'LD4L::FoafRDF::Agent' do + + subject { LD4L::FoafRDF::Agent.new } + + describe 'rdf_subject' do + it "should be a blank node if we haven't set it" do + expect(subject.rdf_subject.node?).to be true + end + + it "should be settable when it has not been set yet" do + subject.set_subject! RDF::URI('http://example.org/moomin') + expect(subject.rdf_subject).to eq RDF::URI('http://example.org/moomin') + end + + it "should append to base URI when setting to non-URI subject" do + subject.set_subject! '123' + expect(subject.rdf_subject).to eq RDF::URI("#{LD4L::FoafRDF::Agent.base_uri}123") + end + + describe 'when changing subject' do + before do + subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land') + subject.set_subject! RDF::URI('http://example.org/moomin') + end + + it 'should update graph subjects' do + expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be true + end + + it 'should update graph objects' do + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be true + end + + it 'should leave other uris alone' do + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be true + end + end + + describe 'created with URI subject' do + before do + subject.set_subject! RDF::URI('http://example.org/moomin') + end + + it 'should not be settable' do + expect{ subject.set_subject! RDF::URI('http://example.org/moomin2') }.to raise_error + end + end + end + + + # ------------------------------------------------- + # START -- Test attributes specific to this model + # ------------------------------------------------- + + describe 'type' do + it "should be an RDF::FOAF.Agent" do + expect(subject.type.first.value).to eq RDF::FOAF.Agent.value + end + end + + describe '#localname_prefix' do + it "should return default prefix" do + prefix = LD4L::FoafRDF::Agent.localname_prefix + expect(prefix).to eq "a" + end + end + + # ----------------------------------------------- + # END -- Test attributes specific to this model + # ----------------------------------------------- + + + describe "#persisted?" do + context 'with a repository' do + before do + # Create inmemory repository + repository = RDF::Repository.new + allow(subject).to receive(:repository).and_return(repository) + end + + context "when the object is new" do + it "should return false" do + expect(subject).not_to be_persisted + end + end + + context "when it is saved" do + before do + subject.persist! + end + + it "should return true" do + expect(subject).to be_persisted + end + end + end + end + + describe "#persist!" do + context "when the repository is set" do + context "and the item is not a blank node" do + + subject {LD4L::FoafRDF::Agent.new("123")} + let(:result) { subject.persist! } + + before do + # Create inmemory repository + @repo = RDF::Repository.new + ActiveTriples::Repositories.repositories[:default] = @repo + subject.label = "An Agent" + result + end + + it "should return true" do + expect(result).to eq true + end + + it "should persist to the repository" do + expect(@repo.statements.first).to eq subject.statements.first + end + + it "should delete from the repository" do + subject.reload + expect(subject.label.first).to eq "An Agent" + subject.label = [] + expect(subject.label).to eq [] + subject.persist! + subject.reload + expect(subject.label).to eq [] + expect(@repo.statements.to_a.length).to eq 1 # Only the type statement + end + end + end + end + + describe '#destroy!' do + before do + subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE') + end + + subject { LD4L::FoafRDF::Agent.new('456')} + + it 'should return true' do + expect(subject.destroy!).to be true + expect(subject.destroy).to be true + end + + it 'should delete the graph' do + subject.destroy + expect(subject).to be_empty + end + end + + describe '#type' do + it 'should return the type configured on the parent class' do + expected_result = LD4L::FoafRDF::Agent.type.kind_of?(Array) ? LD4L::FoafRDF::Agent.type : [LD4L::FoafRDF::Agent.type] + expect(subject.type).to eq expected_result + end + + it 'should set the type' do + subject.type = RDF::URI('http://example.org/AnotherClass') + expect(subject.type).to eq [RDF::URI('http://example.org/AnotherClass')] + end + + it 'should be the type in the graph' do + subject.query(:subject => subject.rdf_subject, :predicate => RDF.type).statements do |s| + expect(s.object).to eq RDF::URI('http://example.org/AnotherClass') + end + end + end + + describe '#rdf_label' do + subject {LD4L::FoafRDF::Agent.new("123")} + + it 'should return an array of label values' do + expect(subject.rdf_label).to be_kind_of Array + end + + it 'should return the default label as URI when no title property exists' do + expect(subject.rdf_label).to eq ["#{LD4L::FoafRDF::Agent.base_uri}123"] + end + + it 'should prioritize configured label values' do + custom_label = RDF::URI('http://example.org/custom_label') + subject.class.configure :rdf_label => custom_label + subject << RDF::Statement(subject.rdf_subject, custom_label, RDF::Literal('New Label')) + expect(subject.rdf_label).to eq ['New Label'] + end + end + + describe 'big complex graphs' do + before do + class DummyPerson < ActiveTriples::Resource + configure :type => RDF::URI('http://example.org/Person') + property :foafname, :predicate => RDF::FOAF.name + property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument' + property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson + end + + class DummyDocument < ActiveTriples::Resource + configure :type => RDF::URI('http://example.org/Document') + property :title, :predicate => RDF::DC.title + property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson' + end + + LD4L::FoafRDF::Agent.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument + end + + subject { LD4L::FoafRDF::Agent.new } + + let (:document1) do + d = DummyDocument.new + d.title = 'Document One' + d + end + + let (:document2) do + d = DummyDocument.new + d.title = 'Document Two' + d + end + + let (:person1) do + p = DummyPerson.new + p.foafname = 'Alice' + p + end + + let (:person2) do + p = DummyPerson.new + p.foafname = 'Bob' + p + end + + let (:data) { < . +_:1 _:2 . +_:2 . +_:2 "Document One" . +_:2 _:3 . +_:2 _:4 . +_:4 . +_:4 "Bob" . +_:3 . +_:3 "Alice" . +_:3 _:4 ." +END + } + + after do + Object.send(:remove_const, "DummyDocument") + Object.send(:remove_const, "DummyPerson") + end + + it 'should allow access to deep nodes' do + document1.creator = [person1, person2] + document2.creator = person1 + person1.knows = person2 + subject.item = [document1] + expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob'] + end + end +end diff --git a/spec/ld4l/foaf_rdf/person_rdf_spec.rb b/spec/ld4l/foaf_rdf/person_rdf_spec.rb index ee7697d..2f0d74f 100644 --- a/spec/ld4l/foaf_rdf/person_rdf_spec.rb +++ b/spec/ld4l/foaf_rdf/person_rdf_spec.rb @@ -106,19 +106,22 @@ context "and the item is not a blank node" do subject {LD4L::FoafRDF::Person.new("123")} + let(:result) { subject.persist! } before do # Create inmemory repository @repo = RDF::Repository.new - allow(subject.class).to receive(:repository).and_return(nil) - allow(subject).to receive(:repository).and_return(@repo) - subject.persist! + ActiveTriples::Repositories.repositories[:default] = @repo + result + end + + it "should return true" do + expect(result).to eq true end it "should persist to the repository" do expect(@repo.statements.first).to eq subject.statements.first end - end end end @@ -143,7 +146,8 @@ describe '#type' do it 'should return the type configured on the parent class' do - expect(subject.type).to eq [LD4L::FoafRDF::Person.type] + expected_result = LD4L::FoafRDF::Person.type.kind_of?(Array) ? LD4L::FoafRDF::Person.type : [LD4L::FoafRDF::Person.type] + expect(subject.type).to eq expected_result end it 'should set the type' do @@ -177,17 +181,6 @@ end end - describe '#solrize' do - it 'should return a label for bnodes' do - expect(subject.solrize).to eq subject.rdf_label - end - - it 'should return a string of the resource uri' do - subject.set_subject! 'http://example.org/moomin' - expect(subject.solrize).to eq 'http://example.org/moomin' - end - end - describe 'big complex graphs' do before do class DummyPerson < ActiveTriples::Resource From 8ace9a74a91ae5ca1d65c795c425ca2a05d1508b Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Thu, 21 Apr 2016 12:26:30 -0400 Subject: [PATCH 2/2] Update travis dependencies to match AT --- .travis.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 176126c..e5284f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,16 @@ language: ruby bundler_args: --without debug script: "bundle exec rspec spec" +sudo: false +cache: bundler rvm: - - 1.9.3 - - 2.0.0 - - 2.1.0 - - 2.1.1 - - jruby-19mode + - 2.0 + - 2.1 + - 2.2.4 + - 2.3.0 + - jruby-9.0.4.0 + - rbx-2 matrix: allow_failures: - - rvm: jruby-19mode \ No newline at end of file + - rvm: jruby-9.0.4.0 + - rvm: rbx-2