Skip to content

Commit 5de71a9

Browse files
jamespriorbarmintor
authored andcommitted
Fix response for AR Wrappers w/ bad ID
1 parent b75b61a commit 5de71a9

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/oai/provider/model/activerecord_wrapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def find(selector, options={})
6161
find_scope.where(conditions)
6262
end
6363
else
64-
find_scope.where(conditions).find_by!(identifier_field => selector)
64+
find_scope.where(conditions).where(identifier_field => selector).first
6565
end
6666
end
6767

test/activerecord_provider/tc_ar_provider.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ def test_handles_empty_collections
142142
REXML::Document.new(@provider.list_records(:metadata_prefix => 'oai_dc'))
143143
end
144144
end
145+
146+
def test_bad_id_raises_exception
147+
badIdentifiers = [
148+
'invalid"id',
149+
'oai:test/5000',
150+
'oai:test/-1',
151+
'oai:test/one',
152+
'oai:test/\\$1\1!']
153+
badIdentifiers.each do |id|
154+
assert_raise(OAI::IdException) do
155+
@provider.get_record(:identifier => id, :metadata_prefix => 'oai_dc')
156+
end
157+
end
158+
end
159+
145160

146161
def setup
147162
@provider = ARProvider.new

0 commit comments

Comments
 (0)