Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Treeify algorithm should raise ArgumentError when passed nil or empty string #47

Merged
merged 1 commit into from
Oct 26, 2016
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
1 change: 1 addition & 0 deletions lib/active_fedora/noid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/noid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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