Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience methods from Rubydora #554

Merged
merged 1 commit into from
Nov 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing an 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