Skip to content

Commit 755a423

Browse files
committed
Adding test to ensure empty collections behave correctly.
1 parent 0be07a2 commit 755a423

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/oai/provider/model/activerecord_wrapper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def initialize(model, options={})
2626
end
2727

2828
def earliest
29-
model.find(:first,
30-
:order => "#{timestamp_field} asc").send(timestamp_field)
29+
earliest_obj = model.find(:first, :order => "#{timestamp_field} asc")
30+
earliest_obj.nil? ? Time.at(0) : earliest_obj.send(timestamp_field)
3131
end
3232

3333
def latest
34-
model.find(:first,
35-
:order => "#{timestamp_field} desc").send(timestamp_field)
34+
latest_obj = model.find(:first, :order => "#{timestamp_field} desc")
35+
latest_obj.nil? ? Time.now : latest_obj.send(timestamp_field)
3636
end
3737
# A model class is expected to provide a method Model.sets that
3838
# returns all the sets the model supports. See the

test/activerecord_provider/tc_ar_provider.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,21 @@ def test_from_and_until
9494
assert_equal 40, doc.elements['OAI-PMH/ListRecords'].to_a.size
9595
end
9696

97+
def test_handles_empty_collections
98+
DCField.delete_all
99+
assert DCField.count == 0
100+
# Identify and ListMetadataFormats should return normally
101+
test_identify
102+
test_metadata_formats
103+
# ListIdentifiers and ListRecords should return "noRecordsMatch" error code
104+
assert_raises(OAI::NoMatchException) {
105+
REXML::Document.new(@provider.list_identifiers)
106+
}
107+
assert_raises(OAI::NoMatchException) {
108+
REXML::Document.new(@provider.list_records)
109+
}
110+
end
111+
97112
def setup
98113
@provider = ARProvider.new
99114
end

0 commit comments

Comments
 (0)