Skip to content

Commit

Permalink
tests for container conversion. datacite/bolognese#72
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Aug 4, 2019
1 parent 9f871cb commit fd32e81
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/models/concerns/helpable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,20 @@ def delete_doi(options={})
response
end
end

def parse_attributes(element, options={})
content = options[:content] || "__content__"

if element.is_a?(String) && options[:content].nil?
CGI.unescapeHTML(element)
elsif element.is_a?(Hash)
element.fetch( CGI.unescapeHTML(content), nil)
elsif element.is_a?(Array)
a = element.map { |e| e.is_a?(Hash) ? e.fetch( CGI.unescapeHTML(content), nil) : e }.uniq
a = options[:first] ? a.first : a.unwrap
else
nil
end
end
end
end
47 changes: 47 additions & 0 deletions spec/models/doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,54 @@
end
end

describe "convert_containers" do
let(:doi) { create(:doi)}

context "container nil" do
let(:container) { nil }
let(:doi) { create(:doi, container: container)}

it "convert" do
expect(Doi.convert_container_by_id(id: doi.id)).to eq(1)
end
end

context "container hash with strings" do
let(:container) { {
"type": "Journal",
"issue": "6",
"title": "Journal of Crustacean Biology",
"volume": "32",
"lastPage": "961",
"firstPage": "949",
"identifier": "1937-240X",
"identifierType": "ISSN"
} }
let(:doi) { create(:doi, container: container)}

it "not convert" do
expect(Doi.convert_container_by_id(id: doi.id)).to eq(0)
end
end

context "container hash with hashes" do
let(:container) { {
"type": "Journal",
"issue": { "xmlns:foaf": "http://xmlns.com/foaf/0.1/", "xmlns:rdfs": "http://www.w3.org/2000/01/rdf-schema#", "__content__": "6"},
"title": { "xmlns:foaf": "http://xmlns.com/foaf/0.1/", "xmlns:rdfs": "http://www.w3.org/2000/01/rdf-schema#", "__content__": "Journal of Crustacean Biology"},
"volume": { "xmlns:foaf": "http://xmlns.com/foaf/0.1/", "xmlns:rdfs": "http://www.w3.org/2000/01/rdf-schema#", "__content__": "32"},
"lastPage": "961",
"firstPage": "949",
"identifier": "1937-240X",
"identifierType": "ISSN"
} }
let(:doi) { create(:doi, container: container)}

it "convert" do
expect(Doi.convert_container_by_id(id: doi.id)).to eq(1)
end
end
end

describe "migrates landing page" do
let(:provider) { create(:provider, symbol: "ADMIN") }
Expand Down

0 comments on commit fd32e81

Please sign in to comment.