Skip to content
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
6 changes: 6 additions & 0 deletions lib/rubydora/datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ def versions
end
end

def current_version?
Copy link
Contributor

Choose a reason for hiding this comment

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

If versioning isn't enabled, versions may be an empty array (and so, should return true)

return true if new?
vers = versions
return vers.empty? || dsVersionID == vers.first.dsVersionID
end

# Add datastream to Fedora
# @return [Rubydora::Datastream]
def create
Expand Down
39 changes: 39 additions & 0 deletions spec/lib/datastream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
@datastream.versionable.should be_false
end

it "should be the current version" do
@datastream.current_version?.should be_true
end

# it "should cast versionable to boolean" do
# @datastream.profile['versionable'] = 'true'
# @datastream.versionable.should be_true
Expand Down Expand Up @@ -466,6 +470,36 @@
Rubydora::Datastream.any_instance.stub(:new? => false)
@datastream.versions.last.content
end

it "should be the current version" do
@mock_repository.stub(:datastream).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return <<-XML
<datastreamProfile>
<dsVersionID>dsid.1</dsVersionID>
<dsCreateDate>2010-01-02T00:00:00.012Z</dsCreateDate>
</datastreamProfile>
XML
@datastream.current_version?.should be_true
end

it "should be the current version if it's the first version" do
@mock_repository.stub(:datastream).with(hash_including(:pid => 'pid', :dsid => 'dsid', :asOfDateTime =>'2010-01-02T00:00:00.012Z')).and_return <<-XML
<datastreamProfile>
<dsVersionID>dsid.1</dsVersionID>
<dsCreateDate>2010-01-02T00:00:00.012Z</dsCreateDate>
</datastreamProfile>
XML
@datastream.versions.first.current_version?.should be_true
end

it "should not be the current version if it's the second version" do
@mock_repository.stub(:datastream).with(hash_including(:pid => 'pid', :dsid => 'dsid', :asOfDateTime => '2008-08-05T01:30:05.012Z')).and_return <<-XML
<datastreamProfile>
<dsVersionID>dsid.0</dsVersionID>
<dsCreateDate>2008-08-05T01:30:05.012Z</dsCreateDate>
</datastreamProfile>
XML
@datastream.versions[1].current_version?.should be_false
end
end
describe "when no versions are found" do
before(:each) do
Expand All @@ -477,6 +511,11 @@
@datastream.versions.should be_empty
end

it "should be the current version" do
@datastream.stub(:new? => false)
@datastream.current_version?.should be_true
end

end

end
Expand Down