diff --git a/lib/oai/provider/model/activerecord_wrapper.rb b/lib/oai/provider/model/activerecord_wrapper.rb index edfcffc..6c18ac0 100755 --- a/lib/oai/provider/model/activerecord_wrapper.rb +++ b/lib/oai/provider/model/activerecord_wrapper.rb @@ -44,7 +44,7 @@ def latest # returns all the sets the model supports. See the # activerecord_provider tests for an example. def sets - model.sets if model.respond_to?(:sets) + model.respond_to?(:sets) ? model.sets : [] end def find(selector, options={}) @@ -177,7 +177,7 @@ def sql_conditions(opts) sql << "#{model.base_class.table_name}.#{timestamp_field} < :until" esc_values[:until] = parse_to_local(opts[:until]) { |t| t + 1 } end - + return [sql.join(" AND "), esc_values] end @@ -197,7 +197,7 @@ def parse_to_local(time) raise OAI::ArgumentException.new, "unparsable date: '#{time}'" end end - + time_obj = yield(time_obj) if block_given? if time_obj.kind_of?(Date) diff --git a/test/activerecord_provider/tc_ar_provider.rb b/test/activerecord_provider/tc_ar_provider.rb index 30e1973..fd58794 100755 --- a/test/activerecord_provider/tc_ar_provider.rb +++ b/test/activerecord_provider/tc_ar_provider.rb @@ -40,6 +40,11 @@ def test_list_records_scope assert_equal expected_count, doc.elements['OAI-PMH/ListRecords'].to_a.size end + def test_invalid_set_raises_no_match + assert_raises(OAI::NoMatchException) do + @provider.list_records(:metadata_prefix => 'oai_dc', :set => "invalid_does_not_exist") + end + end def test_get_record_alternate_identifier_column @provider = ARProviderCustomIdentifierField.new @@ -127,7 +132,7 @@ def test_from_and_until ) assert_equal 40, doc.elements['OAI-PMH/ListRecords'].to_a.size end - + def test_bad_until_raises_exception DCField.order(id: :asc).limit(10).update_all(updated_at: 1.year.ago) DCField.order(id: :desc).limit(10).update_all(updated_at: 1.year.from_now) @@ -140,11 +145,11 @@ def test_bad_until_raises_exception end end end - + def test_bad_from_raises_exception DCField.order(id: :asc).limit(10).update_all(updated_at: 1.year.ago) DCField.order(id: :desc).limit(10).update_all(updated_at: 1.year.from_now) - + badTimes = [ 'junk', 'February 92nd, 2015'] @@ -169,7 +174,7 @@ def test_handles_empty_collections REXML::Document.new(@provider.list_records(:metadata_prefix => 'oai_dc')) end end - + def test_bad_id_raises_exception badIdentifiers = [ 'invalid"id', @@ -183,7 +188,7 @@ def test_bad_id_raises_exception end end end - + def setup @provider = ARProvider.new