Skip to content

Commit

Permalink
fix tests for #194
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 3, 2019
1 parent d93d45d commit 0e8de78
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 27 deletions.
10 changes: 4 additions & 6 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,11 @@ def get_dois
client_prefix = client.prefixes.where.not('prefix.prefix = ?', "10.5072").first
head :no_content and return unless client_prefix.present?

response = Doi.get_dois(prefix: client_prefix.prefix, username: current_user.uid.upcase, password: current_user.password)
if response.status == 200
render json: { dois: response.body.dig("data", "handles") }.to_json, status: :ok
elsif response.status == 204
head :no_content
dois = Doi.get_dois(prefix: client_prefix.prefix, username: current_user.uid.upcase, password: current_user.password)
if dois.length > 0
render json: { dois: dois }.to_json, status: :ok
else
render json: serialize(response.body["errors"]), status: :bad_request
head :no_content
end
end

Expand Down
6 changes: 4 additions & 2 deletions app/models/concerns/helpable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ def get_dois(options={})
if total > 0
# walk through paginated results
total_pages = (total.to_f / 1000).ceil
dois = []

(0...total_pages).each do |page|
url = "#{ENV['HANDLE_URL']}/api/handles?prefix=#{options[:prefix]}&page=#{page}&pageSize=1000"
response = Maremma.get(url, username: "300%3A#{ENV['HANDLE_USERNAME']}", password: ENV['HANDLE_PASSWORD'], ssl_self_signed: true, timeout: 10)

if response.status == 200
puts (response.body.dig("data", "handles") || []).join("\n")
dois += (response.body.dig("data", "handles") || [])
else
text = "Error " + response.body["errors"].inspect

Expand All @@ -135,6 +135,8 @@ def get_dois(options={})
end

puts "#{total} DOIs found."

dois
end

def get_doi(options={})
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/_version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Lupo
class Application
VERSION = "2.3.14"
VERSION = "2.3.15"
end
end
4 changes: 2 additions & 2 deletions spec/concerns/helpable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@

it 'should get dois' do
options = { prefix: "10.5438", username: client.symbol, password: client.password, role_id: "client_admin" }
dois = Doi.get_dois(options).body.dig("data", "handles")
expect(dois.length).to eq(438)
dois = Doi.get_dois(options)
expect(dois.length).to eq(442)
expect(dois.first).to eq("10.5438/0000-00SS")
end
end
Expand Down
41 changes: 36 additions & 5 deletions spec/fixtures/vcr_cassettes/Doi/get_dois/should_get_dois.yml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@
before { get "/dois/get-dois", headers: headers }

it 'returns all dois' do
expect(json["dois"].length).to eq(438)
expect(json["dois"].length).to eq(442)
expect(json["dois"].first).to eq("10.5438/0000-00SS")
end

Expand Down

0 comments on commit 0e8de78

Please sign in to comment.