From 8b56cf49eb737424fbc3ff60abd9209f41432283 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Thu, 15 Jun 2017 12:10:46 -0500 Subject: [PATCH] Conditional in BinarySource should check for LDP::Response Previously it was checking for Faraday::Response --- lib/ldp/resource/binary_source.rb | 7 ++++- lib/ldp/response.rb | 1 + spec/lib/ldp/resource/binary_source_spec.rb | 29 ++++++++++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/ldp/resource/binary_source.rb b/lib/ldp/resource/binary_source.rb index d4357ae..767070b 100644 --- a/lib/ldp/resource/binary_source.rb +++ b/lib/ldp/resource/binary_source.rb @@ -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 diff --git a/lib/ldp/response.rb b/lib/ldp/response.rb index 5c69493..9064c92 100644 --- a/lib/ldp/response.rb +++ b/lib/ldp/response.rb @@ -10,6 +10,7 @@ class Response attr_writer :etag, :last_modified + # @param response [Faraday::Response] def initialize(response) @response = response end diff --git a/spec/lib/ldp/resource/binary_source_spec.rb b/spec/lib/ldp/resource/binary_source_spec.rb index ecae8ab..7f0d1f2 100644 --- a/spec/lib/ldp/resource/binary_source_spec.rb +++ b/spec/lib/ldp/resource/binary_source_spec.rb @@ -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 @@ -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