Skip to content

Commit

Permalink
Added missing id setter
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Mar 10, 2015
1 parent e2a28c0 commit 5df72e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_fedora/core.rb
Expand Up @@ -138,7 +138,7 @@ def id_to_uri(id)
else
id = "/#{id}" unless id.start_with? SLASH
unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/")
id = ActiveFedora.fedora.base_path + id
id = ActiveFedora.fedora.base_path + id
end
ActiveFedora.fedora.host + id
end
Expand Down
6 changes: 6 additions & 0 deletions lib/active_fedora/fedora_attributes.rb
Expand Up @@ -34,6 +34,12 @@ def id
end
end

def id=(id)
raise "ID has already been set to #{self.id}" if self.id
@ldp_source = build_ldp_resource(id.to_s)
end


# TODO: Remove after we no longer support #pid.
def pid
Deprecation.warn FedoraAttributes, "#{self.class}#pid is deprecated and will be removed in active-fedora 10.0. Use #{self.class}#id instead."
Expand Down
24 changes: 24 additions & 0 deletions spec/unit/base_spec.rb
Expand Up @@ -4,6 +4,30 @@
describe ActiveFedora::Base do
it_behaves_like "An ActiveModel"

describe "id=" do
before do
class FooHistory < ActiveFedora::Base
property :title, predicate: ::RDF::DC.title
end
end
after do
Object.send(:remove_const, :FooHistory)
end

subject { FooHistory.new(title: ["A good title"]) }
before { subject.id = 9 }

it "is settable" do
expect(subject.id).to eq '9'
expect(subject.title).to eq ["A good title"]
end

it "is only settable once" do
expect { subject.id = 10 }.to raise_error "ID has already been set to 9"
expect(subject.id).to eq '9'
end
end

describe 'descendants' do
it "should record the decendants" do
expect(ActiveFedora::Base.descendants).to include(ModsArticle, SpecialThing)
Expand Down

0 comments on commit 5df72e5

Please sign in to comment.