Skip to content

Commit

Permalink
Merge pull request #77 from projecthydra/conflict
Browse files Browse the repository at this point in the history
Raise Ldp::Conflict when creating existing resource
  • Loading branch information
cbeer committed Feb 13, 2017
2 parents 1333244 + 48b99b4 commit 69b1c20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/ldp/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def save
##
# Create a new resource at the URI
# @return [RdfSource] the new representation
# @raise [Ldp::Conflict] if you attempt to call create on an existing resource
def create &block
raise Ldp::Error, "Can't call create on an existing resource" unless new?
raise Ldp::Conflict, "Can't call create on an existing resource" unless new?
verb = subject.nil? ? :post : :put
resp = client.send(verb, (subject || @base_path), content) do |req|
req.headers["Link"] = "<#{interaction_model}>;rel=\"type\"" if interaction_model
Expand Down
14 changes: 13 additions & 1 deletion spec/lib/ldp/resource/rdf_source_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'stringio'
require 'spec_helper'
require 'rdf/vocab/dc'

describe Ldp::Resource::RdfSource do
let(:simple_graph) do
Expand Down Expand Up @@ -34,7 +35,18 @@


describe "#create" do
subject { Ldp::Resource::RdfSource.new mock_client, nil }
subject { rdf_source }
let(:rdf_source) { Ldp::Resource::RdfSource.new mock_client, nil }

context "if the resource already exists" do
subject { rdf_source.create }
before do
allow(rdf_source).to receive(:new?).and_return(false)
end
it "raises an error" do
expect { subject }.to raise_error Ldp::Conflict
end
end

it "should return a new resource" do
created_resource = subject.create
Expand Down

0 comments on commit 69b1c20

Please sign in to comment.