Skip to content

Commit

Permalink
Use generate_id branch of ActiveTriples; clean tests
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
elrayle committed Oct 28, 2014
1 parent 16c5eb1 commit d421ad6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '[email protected]:no-reply/ActiveTriples.git'
gem "active-triples", :git => '[email protected]:no-reply/ActiveTriples.git', :branch => 'generate_id'
11 changes: 10 additions & 1 deletion lib/ld4l/foaf_rdf/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
54 changes: 44 additions & 10 deletions spec/ld4l/foaf_rdf/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/ld4l/foaf_rdf/person_rdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 15 additions & 14 deletions spec/ld4l/foaf_rdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d421ad6

Please sign in to comment.