Skip to content

Commit

Permalink
handle base-encoding errors. #315
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 17, 2019
1 parent 4db8931 commit 3608fc8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 8 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def self.import_by_ids(options={})

# get every id between from_id and end_id
(from_id..until_id).step(500).each do |id|
DoiImportByIdJob.perform_later(id: id)
DoiImportByIdJob.perform_later(options.merge(id: id))
puts "Queued importing for DOIs with IDs starting with #{id}."
end

Expand All @@ -470,7 +470,13 @@ def self.import_by_id(options={})
return nil unless options[:id].present?

id = options[:id].to_i
index = Rails.env.test? ? "dois-test" : self.inactive_index
index = if Rails.env.test?
"dois-test"
elsif options[:index].present?
options[:index]
else
self.inactive_index
end
errors = 0
count = 0

Expand Down
6 changes: 5 additions & 1 deletion app/serializers/doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class DoiSerializer
has_many :media, if: Proc.new { |object, params| params && params[:detail] }

attribute :xml, if: Proc.new { |object, params| params && params[:detail] } do |object|
xml_encoded
begin
Base64.strict_encode64(object.xml) if object.xml.present?
rescue ArgumentError
nil
end
end

attribute :doi do |object|
Expand Down
5 changes: 2 additions & 3 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@

expect(last_response.status).to eq(200)
expect(json['data'].size).to eq(3)
json['data'].each{
|doi|
json['data'].each do |doi|
expect(doi.dig('attributes')).to include('xml')
}
end
end
end

Expand Down

0 comments on commit 3608fc8

Please sign in to comment.