From d421ad65037eb1bf7d7a0762b45ffad185a7664a Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Tue, 28 Oct 2014 14:24:45 -0400 Subject: [PATCH] Use generate_id branch of ActiveTriples; clean tests * Add generate_id branch of ActiveTriples to Gemfile * add reset method for base_uri config * clean up tests ** remove :3000 ** remove id_prefix ** more fully test configuration reset --- Gemfile | 2 +- lib/ld4l/foaf_rdf/configuration.rb | 11 ++++- spec/ld4l/foaf_rdf/configuration_spec.rb | 54 +++++++++++++++++++----- spec/ld4l/foaf_rdf/person_rdf_spec.rb | 4 +- spec/ld4l/foaf_rdf_spec.rb | 29 +++++++------ 5 files changed, 72 insertions(+), 28 deletions(-) diff --git a/Gemfile b/Gemfile index 0b01fbb..424729c 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,4 @@ gemspec # GETTING FROM GEMFILE UNTIL MintLocalName CODE IS PUSHED INTO MASTER, THEN MOVE THIS BACK TO *.gemspec FILE # Use active-triple for handling of triple persistence -gem "active-triples", :git => 'git@github.com:no-reply/ActiveTriples.git' +gem "active-triples", :git => 'git@github.com:no-reply/ActiveTriples.git', :branch => 'generate_id' diff --git a/lib/ld4l/foaf_rdf/configuration.rb b/lib/ld4l/foaf_rdf/configuration.rb index df90422..1dfa80d 100644 --- a/lib/ld4l/foaf_rdf/configuration.rb +++ b/lib/ld4l/foaf_rdf/configuration.rb @@ -4,13 +4,22 @@ class Configuration attr_reader :base_uri + def self.default_base_uri + @default_base_uri = "http://localhost/".freeze + end + private_class_method :default_base_uri + def initialize - @base_uri = "http://localhost:3000/" + @base_uri = self.class.send(:default_base_uri) end def base_uri=(new_base_uri) @base_uri = new_base_uri end + + def reset_base_uri + @base_uri = self.class.send(:default_base_uri) + end end end end diff --git a/spec/ld4l/foaf_rdf/configuration_spec.rb b/spec/ld4l/foaf_rdf/configuration_spec.rb index 3587cdd..edff4ca 100644 --- a/spec/ld4l/foaf_rdf/configuration_spec.rb +++ b/spec/ld4l/foaf_rdf/configuration_spec.rb @@ -14,14 +14,14 @@ class DummyPerson < LD4L::FoafRDF::Person Object.send(:remove_const, "DummyPerson") if Object end it "should generate a Person URI using the default base_uri" do - expect(DummyPerson.new('1').rdf_subject.to_s).to eq "http://localhost:3000/s1" + expect(DummyPerson.new('1').rdf_subject.to_s).to eq "http://localhost/1" end end context "when uri ends with slash" do before do LD4L::FoafRDF.configure do |config| - config.base_uri = "http://localhost:3000/test_slash/" + config.base_uri = "http://localhost/test_slash/" end class DummyPerson < LD4L::FoafRDF::Person configure :type => RDF::FOAF.Person, :base_uri => LD4L::FoafRDF.configuration.base_uri, :repository => :default @@ -32,15 +32,15 @@ class DummyPerson < LD4L::FoafRDF::Person LD4L::FoafRDF.reset end - it "should generate a Person URI using the base_uri" do - expect(DummyPerson.new('1').rdf_subject.to_s).to eq "http://localhost:3000/test_slash/s1" + it "should generate a Person URI using the configured base_uri" do + expect(DummyPerson.new('1').rdf_subject.to_s).to eq "http://localhost/test_slash/1" end end context "when uri does not end with slash" do before do LD4L::FoafRDF.configure do |config| - config.base_uri = "http://localhost:3000/test_no_slash" + config.base_uri = "http://localhost/test_no_slash" end class DummyPerson < LD4L::FoafRDF::Person configure :type => RDF::FOAF.Person, :base_uri => LD4L::FoafRDF.configuration.base_uri, :repository => :default @@ -51,23 +51,57 @@ class DummyPerson < LD4L::FoafRDF::Person LD4L::FoafRDF.reset end - it "should generate a Person URI using the base_uri" do - expect(DummyPerson.new('1').rdf_subject.to_s).to eq "http://localhost:3000/test_no_slash/s1" + it "should generate a Person URI using the configured base_uri" do + expect(DummyPerson.new('1').rdf_subject.to_s).to eq "http://localhost/test_no_slash/1" end end + + + it "should return value of configured base_uri" do + LD4L::FoafRDF.configure do |config| + config.base_uri = "http://localhost/test_config/" + end + expect(LD4L::FoafRDF.configuration.base_uri).to eq "http://localhost/test_config/" + end + + it "should return default base_uri when base_uri is reset" do + LD4L::FoafRDF.configure do |config| + config.base_uri = "http://localhost/test_config/" + end + expect(LD4L::FoafRDF.configuration.base_uri).to eq "http://localhost/test_config/" + LD4L::FoafRDF.configuration.reset_base_uri + expect(LD4L::FoafRDF.configuration.base_uri).to eq "http://localhost/" + end + + it "should return default base_uri when all configs are reset" do + LD4L::FoafRDF.configure do |config| + config.base_uri = "http://localhost/test_config/" + end + expect(LD4L::FoafRDF.configuration.base_uri).to eq "http://localhost/test_config/" + LD4L::FoafRDF.reset + expect(LD4L::FoafRDF.configuration.base_uri).to eq "http://localhost/" + end end end describe "LD4L::FoafRDF::Configuration" do describe "#base_uri" do it "should default to localhost" do - expect(LD4L::FoafRDF::Configuration.new.base_uri).to eq "http://localhost:3000/" + expect(LD4L::FoafRDF::Configuration.new.base_uri).to eq "http://localhost/" end it "should be settable" do config = LD4L::FoafRDF::Configuration.new - config.base_uri = "http://localhost:3000/test" - expect(config.base_uri).to eq "http://localhost:3000/test" + config.base_uri = "http://localhost/test" + expect(config.base_uri).to eq "http://localhost/test" + end + + it "should be re-settable" do + config = LD4L::FoafRDF::Configuration.new + config.base_uri = "http://localhost/test/again" + expect(config.base_uri).to eq "http://localhost/test/again" + config.reset_base_uri + expect(config.base_uri).to eq "http://localhost/" end end end diff --git a/spec/ld4l/foaf_rdf/person_rdf_spec.rb b/spec/ld4l/foaf_rdf/person_rdf_spec.rb index 73820b6..cbee26a 100644 --- a/spec/ld4l/foaf_rdf/person_rdf_spec.rb +++ b/spec/ld4l/foaf_rdf/person_rdf_spec.rb @@ -17,7 +17,7 @@ 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::Person.base_uri}#{LD4L::FoafRDF::Person.id_prefix}123") + expect(subject.rdf_subject).to eq RDF::URI("#{LD4L::FoafRDF::Person.base_uri}123") end describe 'when changing subject' do @@ -159,7 +159,7 @@ end it 'should return the default label as URI when no title property exists' do - expect(subject.rdf_label).to eq ["#{LD4L::FoafRDF::Person.base_uri}#{LD4L::FoafRDF::Person.id_prefix}123"] + expect(subject.rdf_label).to eq ["#{LD4L::FoafRDF::Person.base_uri}123"] end it 'should prioritize configured label values' do diff --git a/spec/ld4l/foaf_rdf_spec.rb b/spec/ld4l/foaf_rdf_spec.rb index c8e9e6d..8416918 100644 --- a/spec/ld4l/foaf_rdf_spec.rb +++ b/spec/ld4l/foaf_rdf_spec.rb @@ -3,41 +3,42 @@ describe "LD4L::FoafRDF" do describe "#configure" do - before :each do + before do LD4L::FoafRDF.configure do |config| - config.base_uri = "http://localhost:3000/test/" + config.base_uri = "http://localhost/test/" + end + class DummyPerson < LD4L::FoafRDF::Person + configure :type => RDF::FOAF.Person, :base_uri => LD4L::FoafRDF.configuration.base_uri, :repository => :default end end + after do + LD4L::FoafRDF.reset + Object.send(:remove_const, "DummyPerson") if Object + end it "should return configured value" do config = LD4L::FoafRDF.configuration - expect(config.base_uri).to eq "http://localhost:3000/test/" + expect(config.base_uri).to eq "http://localhost/test/" end - it "should use configured value in Person class" do + it "should use configured value in Person sub-class" do # FIXME fails if run with all tests because LD4L::FoafRDF::Person is already loaded by other tests with a different base_uri - p = LD4L::FoafRDF::Person.new('1') - expect(p.rdf_subject.to_s).to eq "http://localhost:3000/test/p1" - end - - after :each do - LD4L::FoafRDF.reset + p = DummyPerson.new('1') + expect(p.rdf_subject.to_s).to eq "http://localhost/test/1" end end describe ".reset" do before :each do LD4L::FoafRDF.configure do |config| - config.base_uri = "http://localhost:3000/test/" + config.base_uri = "http://localhost/test/" end end it "resets the configuration" do LD4L::FoafRDF.reset - config = LD4L::FoafRDF.configuration - - expect(config.base_uri).to eq "http://localhost:3000/" + expect(config.base_uri).to eq "http://localhost/" end end end \ No newline at end of file