spec/active_triples/resource_spec.rb in active-triples-0.6.1 vs spec/active_triples/resource_spec.rb in active-triples-0.7.0

- old
+ new

@@ -18,10 +18,16 @@ Object.send(:remove_const, "DummyLicense") if Object end subject { DummyResource.new } + describe '#property' do + it 'raises error when set directly on Resource' do + expect { ActiveTriples::Resource.property :blah, :predicate => RDF::DC.title }.to raise_error + end + end + 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 @@ -427,14 +433,14 @@ expect(subject.title).to eq ['Comet in Moominland'] end end describe 'array setters' do - before do + before do DummyResource.property :aggregates, :predicate => RDF::DC.relation end - + it "should be empty array if we haven't set it" do expect(subject.aggregates).to match_array([]) end context "when set to a URI" do @@ -447,52 +453,52 @@ end it "should have an ID accessor" do expect(subject.aggregates_ids).to eq [aggregates_uri] end end - + it "should be settable" do subject.aggregates = RDF::URI("http://example.org/b1") expect(subject.aggregates.first.rdf_subject).to eq RDF::URI("http://example.org/b1") ['id'] end context 'with values' do let(:bib1) { RDF::URI("http://example.org/b1") } let(:bib2) { RDF::URI("http://example.org/b2") } let(:bib3) { RDF::URI("http://example.org/b3") } - + before do subject.aggregates = bib1 subject.aggregates << bib2 subject.aggregates << bib3 end - + it 'raises error when trying to set nil value' do expect { subject.aggregates[1] = nil }.to raise_error /value must be an RDF URI, Node, Literal, or a valid datatype/ end it "should be changeable for multiple values" do new_bib1 = RDF::URI("http://example.org/b1_NEW") new_bib3 = RDF::URI("http://example.org/b3_NEW") - + aggregates = subject.aggregates.dup aggregates[0] = new_bib1 aggregates[2] = new_bib3 subject.aggregates = aggregates - + expect(subject.aggregates[0].rdf_subject).to eq new_bib1 expect(subject.aggregates[1].rdf_subject).to eq bib2 expect(subject.aggregates[2].rdf_subject).to eq new_bib3 end it "raises an error for out of bounds index" do expect { subject.aggregates[4] = 'blah' }.to raise_error IndexError end end end - + describe 'child nodes' do it 'should return an object of the correct class when the value is a URI' do subject.license = DummyLicense.new('http://example.org/license') expect(subject.license.first).to be_kind_of DummyLicense end @@ -519,11 +525,11 @@ context "when given a URI" do before do subject.set_value(RDF::DC.title, RDF::URI("http://opaquenamespace.org/jokes/1")) end it "should return a resource" do - expect(subject.title.first).to be_kind_of(ActiveTriples::Resource) + expect(subject.title.first).to be_kind_of(ActiveTriples::RDFSource) end context "and it's configured to not cast" do before do subject.class.property :title, predicate: RDF::DC.title, cast: false end @@ -537,11 +543,11 @@ vals = subject.get_values('license') vals << "foo" subject.set_value('license',vals) expect(subject.get_values('license')).to eq ["foo"] end - + it "safely handles terms passed in with pre-existing values" do subject.license = "foo" vals = subject.get_values('license') vals << "bar" subject.set_value('license',vals) @@ -602,11 +608,11 @@ context "literals are set" do let(:literal1) { RDF::Literal.new("test", :language => :en) } let(:literal2) { RDF::Literal.new("test", :language => :fr) } before do - subject.set_value(RDF::DC.title, [literal1, literal2]) + subject.set_value(RDF::DC.title, [literal1, literal2]) end context "and literals are not requested" do it "should return a string" do # Should this de-duplicate? expect(subject.get_values(RDF::DC.title)).to eq ["test", "test"] @@ -641,11 +647,11 @@ end end describe '#type' do it 'should return the type configured on the parent class' do - expect(subject.type).to eq [DummyResource.type] + expect(subject.type).to eq DummyResource.type 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')] @@ -675,21 +681,10 @@ subject.title = 'Comet in Moominland' expect(subject.rdf_label).to eq ['New Label'] 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 'editing the graph' do it 'should write properties when statements are added' do subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, 'Comet in Moominland') expect(subject.title).to include 'Comet in Moominland' end @@ -701,18 +696,20 @@ end end describe 'big complex graphs' do before do - class DummyPerson < ActiveTriples::Resource + class DummyPerson + include ActiveTriples::RDFSource configure :type => RDF::URI('http://example.org/Person') property :foaf_name, :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 + class DummyDocument + include ActiveTriples::RDFSource configure :type => RDF::URI('http://example.org/Document') property :title, :predicate => RDF::DC.title property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson' end @@ -775,10 +772,11 @@ end describe "callbacks" do describe ".before_persist" do before do - class DummyResource < ActiveTriples::Resource + class DummyResource + include ActiveTriples::RDFSource def bla self.title = "test" end end DummyResource.before_persist :bla