-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #780 from projecthydra/base_paths
Add optional prefix to resource URI
- Loading branch information
Showing
5 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ActiveFedora | ||
module Pathing | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
def uri_prefix | ||
nil | ||
end | ||
|
||
def has_uri_prefix? | ||
!uri_prefix.nil? | ||
end | ||
|
||
def root_resource_path | ||
if has_uri_prefix? | ||
ActiveFedora.fedora.base_path + "/" + self.uri_prefix | ||
else | ||
ActiveFedora.fedora.base_path | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
|
||
describe ActiveFedora::Base do | ||
describe ".uri_prefix" do | ||
let(:path) { "foo" } | ||
before do | ||
class FooHistory < ActiveFedora::Base | ||
def uri_prefix | ||
"foo" | ||
end | ||
property :title, predicate: ::RDF::DC.title | ||
end | ||
end | ||
after do | ||
Object.send(:remove_const, :FooHistory) | ||
end | ||
subject { FooHistory.new(title: ["Root foo"]) } | ||
it { is_expected.to have_uri_prefix } | ||
it "should use the root path in the uri" do | ||
expect(subject.uri_prefix).to eql path | ||
end | ||
context "when the object is saved" do | ||
before { subject.save } | ||
it "should persist the path in the uri" do | ||
expect(subject.uri).to include(path) | ||
end | ||
|
||
end | ||
end | ||
end |