diff --git a/lib/active_fedora/noid.rb b/lib/active_fedora/noid.rb index ffdf32f..73cb484 100644 --- a/lib/active_fedora/noid.rb +++ b/lib/active_fedora/noid.rb @@ -17,6 +17,7 @@ def config end def treeify(identifier) + raise ArgumentError, 'Identifier must be a string of size > 0 in order to be treeified' if identifier.blank? head = identifier.split('/').first head.gsub!(/#.*/, '') (head.scan(/..?/).first(4) + [identifier]).join('/') diff --git a/spec/unit/noid_spec.rb b/spec/unit/noid_spec.rb index e314c7f..68e4ae2 100644 --- a/spec/unit/noid_spec.rb +++ b/spec/unit/noid_spec.rb @@ -18,5 +18,17 @@ let(:id) { 'abc123z' } it { is_expected.to eq 'ab/c1/23/z/abc123z' } end + context 'with an empty string' do + let(:id) { '' } + it 'raises ArgumentError' do + expect { subject }.to raise_error(ArgumentError) + end + end + context 'with a nil' do + let(:id) { nil } + it 'raises ArgumentError' do + expect { subject }.to raise_error(ArgumentError) + end + end end end