Skip to content

Commit

Permalink
Final updates to tests and models for upgrade to 0.8
Browse files Browse the repository at this point in the history
Tests
* set default repository instead of using allow to receive
* add getComment|Tag|Term tests (should have already been there)

Models
* make reused tag use parent strategy
  • Loading branch information
elrayle committed Apr 14, 2016
1 parent d32c5d2 commit 3259950
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 37 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
source 'https://rubygems.org'

gemspec

# gem 'active-triples', git: 'git@github.com:ActiveTriples/ActiveTriples.git', branch: 'develop'
gem 'active-triples', git: 'git@github.com:ActiveTriples/ActiveTriples.git', branch: 'FIX_194-lazy_load'
2 changes: 1 addition & 1 deletion ld4l-open_annotation_rdf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|

spec.add_dependency('rdf', '~> 1.1')

# spec.add_dependency('active-triples', '0.6.1')
spec.add_dependency('active-triples', '0.6.1')
spec.add_dependency('active_triples-local_name')
spec.add_dependency('ld4l-foaf_rdf', '~> 0.0')

Expand Down
1 change: 1 addition & 0 deletions lib/ld4l/open_annotation_rdf/comment_annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CommentAnnotation < LD4L::OpenAnnotationRDF::Annotation
#
# @return instance of CommentAnnotation
def setComment(comment)
@body ||= hasBody.first if hasBody.size > 0
if self.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
@body ||= LD4L::OpenAnnotationRDF::CommentBody.new(
ActiveTriples::LocalName::Minter.generate_local_name(
Expand Down
21 changes: 16 additions & 5 deletions lib/ld4l/open_annotation_rdf/tag_annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def setTag(tag)
# ** If one found, set @body to this TagBody
# ** If multiple found, use the first one found
# ### the same one may not be the first one found each time the query executes
@body = LD4L::OpenAnnotationRDF.configuration.unique_tags ? LD4L::OpenAnnotationRDF::TagBody.fetch_by_tag_value(tag) : nil
if self.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
@body = LD4L::OpenAnnotationRDF.configuration.unique_tags ? LD4L::OpenAnnotationRDF::TagBody.fetch_by_tag_value(tag,self) : nil
else
@body = LD4L::OpenAnnotationRDF.configuration.unique_tags ? LD4L::OpenAnnotationRDF::TagBody.fetch_by_tag_value(tag) : nil
end
if @body == nil
if self.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
@body = LD4L::OpenAnnotationRDF::TagBody.new(
Expand Down Expand Up @@ -73,10 +77,17 @@ def setTag(tag)
# * [CURRENT] Always create a new TagBody each time setTag is called and update @body
# ### This last options has the potential for orphaned TagBodys that no TagAnnotation references.
# TODO Rethink the current behavior which is always to create a new TagBody potentially leaving around orphans.
@body = LD4L::OpenAnnotationRDF::TagBody.new(
ActiveTriples::LocalName::Minter.generate_local_name(
LD4L::OpenAnnotationRDF::TagBody, 10, @localname_prefix,
LD4L::OpenAnnotationRDF.configuration.localname_minter ))
if self.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
@body = LD4L::OpenAnnotationRDF::TagBody.new(
ActiveTriples::LocalName::Minter.generate_local_name(
LD4L::OpenAnnotationRDF::TagBody, 10, @localname_prefix,
LD4L::OpenAnnotationRDF.configuration.localname_minter ),self)
else # < ActiveTriples 0.8
@body = LD4L::OpenAnnotationRDF::TagBody.new(
ActiveTriples::LocalName::Minter.generate_local_name(
LD4L::OpenAnnotationRDF::TagBody, 10, @localname_prefix,
LD4L::OpenAnnotationRDF.configuration.localname_minter ))
end
@body.tag = tag
end
set_value(:hasBody, @body)
Expand Down
5 changes: 3 additions & 2 deletions lib/ld4l/open_annotation_rdf/tag_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self::annotations_using( tag_value )
# @param [String] tag value
#
# @return instance of TagBody if found; otherwise, nil
def self::fetch_by_tag_value( tag_value )
def self::fetch_by_tag_value( tag_value, parent_annotation=nil )
raise ArgumentError, 'Argument must be a string with at least one character' unless
tag_value.kind_of?(String) && tag_value.size > 0

Expand All @@ -66,7 +66,8 @@ def self::fetch_by_tag_value( tag_value )
results = query.execute(repo)
unless( results.empty? )
tagbody_uri = results[0].to_hash[:tagbody]
tagbody = LD4L::OpenAnnotationRDF::TagBody.new(tagbody_uri)
tagbody = LD4L::OpenAnnotationRDF::TagBody.new(tagbody_uri) if parent_annotation.nil?
tagbody = LD4L::OpenAnnotationRDF::TagBody.new(tagbody_uri,parent_annotation) unless parent_annotation.nil?
end
tagbody
end
Expand Down
7 changes: 1 addition & 6 deletions spec/ld4l/open_annotation_rdf/annotation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,7 @@
before do
# Create inmemory repository
@repo = RDF::Repository.new
allow(subject.class).to receive(:repository).and_return(nil)
if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
allow(subject.persistence_strategy).to receive(:repository).and_return(@repo)
else # < ActiveTriples 0.8
allow(subject).to receive(:repository).and_return(@repo)
end
ActiveTriples::Repositories.repositories[:default] = @repo
subject.motivatedBy = RDFVocabularies::OA.commenting
result
end
Expand Down
26 changes: 20 additions & 6 deletions spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@
expect(subject.getBody.rdf_subject.to_s).to match match /http:\/\/localhost\/[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/
expect(subject.getBody).not_to be_persisted
end

it "should re-use body when changing the comment" do
subject.setComment('Initial comment value.')
expect(subject.getBody).to eq subject.hasBody.first
cb = subject.getBody
subject.setComment('Changed comment value.')
expect(subject.getBody).to eq subject.hasBody.first
expect(subject.getBody.object_id).to eq cb.object_id
end
end

describe '#getComment' do
before do
subject.setComment('Test getting a comment.')
end
it "should get the comment" do
expect(subject.getComment).to eq 'Test getting a comment.'
end
end

describe 'annotatedBy' do
Expand Down Expand Up @@ -241,12 +259,7 @@
before do
# Create inmemory repository
@repo = RDF::Repository.new
allow(subject.class).to receive(:repository).and_return(nil)
if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
allow(subject.persistence_strategy).to receive(:repository).and_return(@repo)
else # < ActiveTriples 0.8
allow(subject).to receive(:repository).and_return(@repo)
end
ActiveTriples::Repositories.repositories[:default] = @repo
subject.motivatedBy = RDFVocabularies::OA.commenting
result
end
Expand Down Expand Up @@ -277,6 +290,7 @@
end
it "should persist body to the repository" do
cb = LD4L::OpenAnnotationRDF::CommentBody.new(subject.getBody.rdf_subject)
expect(cb.content).to eq ['I like this.']
expect(cb).to be_persisted
expect(subject.getBody.rdf_subject.to_s).to eq cb.rdf_subject.to_s
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ld4l/open_annotation_rdf/comment_body_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
expect(expected_results).to include RDFVocabularies::DCTYPES.Text
expect(expected_results).to include RDFVocabularies::CNT.ContentAsText

t = subject.get_values(:type)
t = subject.get_values(:type).to_a
t[0] = RDFVocabularies::OA.Tag # dummy type for testing
t[1] = RDFVocabularies::OA.SemanticTag # dummy type for testing
subject.set_value(:type,t)
Expand Down
16 changes: 10 additions & 6 deletions spec/ld4l/open_annotation_rdf/semantic_tag_annotation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@
end
end

describe '#getTerm' do
before do
subject.setTerm('TestTerm')
end
it "should get the tag" do
expect(subject.getTerm).to eq 'TestTerm'
end
end

context "when term doesn't already exist as a SemanticTagBody" do
before do
stb = LD4L::OpenAnnotationRDF::SemanticTagBody.new('http://example.org/new_term')
Expand Down Expand Up @@ -299,12 +308,7 @@
before do
# Create inmemory repository
@repo = RDF::Repository.new
allow(subject.class).to receive(:repository).and_return(nil)
if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
allow(subject.persistence_strategy).to receive(:repository).and_return(@repo)
else # < ActiveTriples 0.8
allow(subject).to receive(:repository).and_return(@repo)
end
ActiveTriples::Repositories.repositories[:default] = @repo
subject.motivatedBy = RDFVocabularies::OA.commenting
result
end
Expand Down
18 changes: 11 additions & 7 deletions spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
it "should return the existing TagBody unchanged" do
tb1 = subject.setTag('foo')
tb2 = subject.setTag('foo')
expect(tb2).to eq tb1
expect(tb2.object_id).to eq tb1.object_id
end
end

Expand Down Expand Up @@ -222,6 +222,15 @@
end
end

describe '#getTag' do
before do
subject.setTag('TestTag')
end
it "should get the tag" do
expect(subject.getTag).to eq 'TestTag'
end
end

describe 'annotatedBy' do
it "should be empty array if we haven't set it" do
expect(subject.annotatedBy).to match_array([])
Expand Down Expand Up @@ -351,12 +360,7 @@
before do
# Create inmemory repository
@repo = RDF::Repository.new
allow(subject.class).to receive(:repository).and_return(nil)
if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8
allow(subject.persistence_strategy).to receive(:repository).and_return(@repo)
else # < ActiveTriples 0.8
allow(subject).to receive(:repository).and_return(@repo)
end
ActiveTriples::Repositories.repositories[:default] = @repo
subject.motivatedBy = RDFVocabularies::OA.commenting
result
end
Expand Down

0 comments on commit 3259950

Please sign in to comment.