Skip to content

Commit

Permalink
TW-155 lsid model spec - test that #identifier is validly formatted. …
Browse files Browse the repository at this point in the history
…Model and spec.
  • Loading branch information
TuckerJD committed Mar 17, 2015
1 parent a44bdb6 commit 146346f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,3 @@ public/system

# temp until we decide how will we deal with repeatability in integration tests with external APIs
/spec/fixtures/vcr_cassettes

coverage
23 changes: 20 additions & 3 deletions app/models/identifier/global/lsid.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
class Identifier::Global::Lsid < Identifier::Global
# urn:lsid:Orthoptera.speciesfile.org:TaxonName:1
=begin
• "URN"
• "LSID"
• authority identification
• namespace identification
• object identification
• optionally: revision identification. If revision field is omitted then the trailing colon is also omitted.
=end
validate :using_lsid_class

def using_lsid_class
retval = true
unless identifier.nil?
lsid = identifier
lsid = identifier.split(':')
# this is a test of http://rubular.com/regexes/13295
/SID=([\s\S]*?)LSID=([\s\S]*?)Auth=([\s\S]*)/ =~ identifier

errors.add(:identifier, "'#{identifier}' is not a valid LSID.")
return false
unless lsid.length.between?(5, 6)
unless lsid[0].upcase == 'URN' and lsid[1].upcase == 'LSID'
errors.add(:identifier, "'#{identifier}' is not a valid LSID.")
retval = false
end
end
end
return retval
end
end
2 changes: 1 addition & 1 deletion app/models/identifier/global/uri.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
URI_SCHEMES = URI.scheme_list.keys # + ['UDP']
URI_SCHEMES = # + ['UDP']

class Identifier::Global::Uri < Identifier::Global
# Universal Resource Identifier
Expand Down
25 changes: 24 additions & 1 deletion spec/models/identifier/global/lsid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,35 @@
specify 'empty' do
# identifier is empty
expect(id.valid?).to be_falsey
expect(id.errors.messages[:identifier][0]).to eq('can\'t be blank')
end

specify 'any old word' do
id.identifier = Faker::Lorem.word
phrase = Faker::Lorem.word
id.identifier = phrase
expect(id.valid?).to be_falsey
expect(id.errors.messages[:identifier][0]).to eq("'#{phrase}' is not a valid LSID.")
end

specify 'urn:lsid:orthoptera.speciesfile.org:Taxonname:1' do
phrase = 'urn:lsid:orthoptera.speciesfile.org:Taxonname:1'
id.identifier = phrase
expect(id.valid?).to be_truthy
end

specify 'ISBN-10: 978-0-59652-068-7' do
phrase = 'ISBN-10: 978-0-59652-068-7'
id.identifier = phrase
expect(id.valid?).to be_falsey
expect(id.errors.messages[:identifier][0]).to eq("'#{phrase}' is not a valid LSID.")
end

specify 'urn:lsid:orthoptera.speciesfile.org:Taxonname:1:revision=44' do
phrase = 'urn:lsid:orthoptera.speciesfile.org:Taxonname:1:revision=44'
id.identifier = phrase
expect(id.valid?).to be_truthy
end

end
end
end

0 comments on commit 146346f

Please sign in to comment.