From 34e9f8a42936f325c4ceec6ad0093f90a62e8ab6 Mon Sep 17 00:00:00 2001 From: Naomi Dushay Date: Thu, 15 Jan 2015 14:57:58 -0800 Subject: [PATCH] add test for CommentAnnotation initializer --- .../comment_annotation_spec.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb b/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb index 1945fad..65870d8 100644 --- a/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb @@ -180,6 +180,55 @@ # END -- Test attributes specific to this model # ---------------------------------------------- + # ------------------------------------------------- + # START -- Test this model's initializer + # ------------------------------------------------- + + describe '#initialize' do + context 'loading from graph' do + before(:each) do + anno_url = "http://my_oa_store/foocom" + @target_url = "http://searchworks.stanford.edu/view/666" + @comment_text = "I am a comment!" + @format = "text/plain" + ttl = "<#{anno_url}> a ; + [ + a , + ; + \"#{@comment_text}\" ; + \"#{@format}\" + ]; + <#{@target_url}>; + ." + anno_graph = RDF::Graph.new.from_ttl ttl + r = ActiveTriples::Repositories.repositories[LD4L::OpenAnnotationRDF::CommentAnnotation.repository] + r << anno_graph + anno_uri = RDF::URI.new(anno_url) + @comment_anno = LD4L::OpenAnnotationRDF::CommentAnnotation.new(anno_uri) + end + it "populates LD4L::OpenAnnotationRDF::TagAnnotation properly" do + expect(@comment_anno).to be_a LD4L::OpenAnnotationRDF::CommentAnnotation + expect(@comment_anno.type).to eq [RDFVocabularies::OA.Annotation] + expect(@comment_anno.motivatedBy).to eq [RDFVocabularies::OA.commenting] + expect(@comment_anno.hasTarget.first.rdf_subject).to eq RDF::URI.new(@target_url) + end + it "populates CommentBody properly" do + body = @comment_anno.hasBody.first + expect(body).to be_a LD4L::OpenAnnotationRDF::CommentBody + expect(body.content).to eq [@comment_text] + expect(body.format).to eq [@format] + expect(body.type).to include RDFVocabularies::CNT.ContentAsText + expect(body.type).to include RDFVocabularies::DCTYPES.Text + expect(body.type).not_to include RDFVocabularies::OA.Tag + expect(body.type.size).to eq 2 + end + end + end + + # ------------------------------------------------- + # End -- Test this model's initializer + # ------------------------------------------------- + describe "#persisted?" do context 'with a repository' do