Skip to content

Commit

Permalink
Merge pull request #554 from projecthydra/has_content
Browse files Browse the repository at this point in the history
Convenience methods from Rubydora
  • Loading branch information
jcoyne committed Nov 3, 2014
2 parents cb97142 + e240fca commit d55ebcd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/active_fedora/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ def size
ldp_source.head.headers['Content-Length'].to_i
end

def has_content?
size > 0
end

def empty?
!has_content?
end

def content_changed?
return true if new_record? and !local_or_remote_content(false).blank?
local_or_remote_content(false) != @ds_content
Expand Down
44 changes: 41 additions & 3 deletions spec/unit/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
end
end

describe ".size" do
context "content" do

let(:mock_conn) do
Faraday.new do |builder|
builder.adapter :test, conn_stubs do |stub|
Expand All @@ -82,9 +83,46 @@
allow(subject).to receive(:ldp_connection).and_return(mock_client)
end

it "should load the datastream size attribute from the fedora repository" do
expect(subject.size).to eq 9999
describe ".size" do
it "should load the datastream size attribute from the fedora repository" do
expect(subject.size).to eq 9999
end
end

describe ".empty?" do
it "should not be empty" do
expect(subject.empty?).to be false
end
end

describe ".has_content?" do
context "when there's content" do
it "should return true" do
expect(subject.has_content?).to be true
end
end
context "when content is nil" do
let(:conn_stubs) do
Faraday::Adapter::Test::Stubs.new do |stub|
stub.head('/fedora/rest/test/1234/abcd') { [200] }
end
end
it "should return false" do
expect(subject.has_content?).to be false
end
end
context "when content is zero" do
let(:conn_stubs) do
Faraday::Adapter::Test::Stubs.new do |stub|
stub.head('/fedora/rest/test/1234/abcd') { [200, {'Content-Length' => '0' }] }
end
end
it "should return false" do
expect(subject.has_content?).to be false
end
end
end

end

context "when the datastream has local content" do
Expand Down

0 comments on commit d55ebcd

Please sign in to comment.