Skip to content

Commit

Permalink
Merge pull request #85 from samvera/fix_conditional
Browse files Browse the repository at this point in the history
Conditional in BinarySource should check for LDP::Response
  • Loading branch information
carrickr authored Mar 14, 2018
2 parents 6b52272 + 8b56cf4 commit 021ff6a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/ldp/resource/binary_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ module Ldp
class Resource::BinarySource < Ldp::Resource
attr_accessor :content

# @param client [Ldp::Client]
# @param subject [String] the URI for the resource
# @param content_or_response [String,Ldp::Response]
# @param base_path [String] ('')
def initialize client, subject, content_or_response = nil, base_path = ''
super

case content_or_response
when Faraday::Response
when Ldp::Response
else
@content = content_or_response
end
end

# @return [Ldp::Response]
def content
@content ||= get.body
end
Expand Down
1 change: 1 addition & 0 deletions lib/ldp/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Response

attr_writer :etag, :last_modified

# @param response [Faraday::Response]
def initialize(response)
@response = response
end
Expand Down
29 changes: 23 additions & 6 deletions spec/lib/ldp/resource/binary_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
let(:client) { instance_double(Ldp::Client) }
let(:uri) { 'http://example.com/foo/bar' }
let(:content) { 'somecontent' }
subject { described_class.new(client, uri, content) }
let(:instance) { described_class.new(client, uri, content) }

it "should not display content to inspect" do
expect(subject.inspect).to match /subject=\"http:\/\/example\.com\/foo\/bar\"/
expect(subject.inspect).not_to match /somecontent/
describe "#inspect" do
subject { instance.inspect }

it "does not display content" do
expect(subject).to match /subject=\"http:\/\/example\.com\/foo\/bar\"/
expect(subject).not_to match /somecontent/
end
end

describe '#described_by' do
subject { instance.described_by }
context 'without a description' do
before do
allow(client).to receive(:head).and_return(instance_double(Ldp::Response, links: { }))
end

it 'retrieves the description object' do
expect(subject.described_by).to eq nil
expect(subject).to eq nil
end
end

Expand All @@ -31,8 +36,20 @@
let(:desc) { double }

it 'retrieves the description object' do
expect(subject.described_by).to eq desc
expect(subject).to eq desc
end
end
end

describe "#content" do
context "when an Ldp::Response is passed in" do
let(:mock_response) { instance_double(Faraday::Response, headers: {}, env: { url: "info:a" }) }
let(:content) { Ldp::Response.new(mock_response) }
let(:client) { instance_double(Ldp::Client, get: double(body: 'retrieved value')) }

subject { instance.content }

it { is_expected.to eq 'retrieved value' }
end
end
end

0 comments on commit 021ff6a

Please sign in to comment.