From 5243e519bfba80072676f99d5b4714cb337bd681 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Thu, 28 May 2020 20:12:52 +0200 Subject: [PATCH] fix pagination --- app/models/concerns/indexable.rb | 2 +- app/models/doi.rb | 2 +- lib/tasks/event.rake | 2 +- spec/models/doi_spec.rb | 33 ++++++++++++++++---------------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/models/concerns/indexable.rb b/app/models/concerns/indexable.rb index 15df9c254..60f59c014 100644 --- a/app/models/concerns/indexable.rb +++ b/app/models/concerns/indexable.rb @@ -169,7 +169,7 @@ def query(query, options={}) from = 0 # make sure we have a valid cursor - search_after = options.dig(:page, :cursor).is_a?(Array) || [1, "1"] + search_after = options.dig(:page, :cursor).is_a?(Array) ? options.dig(:page, :cursor) : [1, "1"] if self.name == "Event" sort = [{ created_at: "asc", uuid: "asc" }] diff --git a/app/models/doi.rb b/app/models/doi.rb index 16cbd5cad..b877fafa9 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -749,7 +749,7 @@ def self.query(query, options={}) from = 0 # make sure we have a valid cursor - search_after = options.dig(:page, :cursor).is_a?(Array) || [1, "1"] + search_after = options.dig(:page, :cursor).is_a?(Array) ? options.dig(:page, :cursor) : [1, "1"] sort = [{ created: "asc", uid: "asc" }] else from = ((options.dig(:page, :number) || 1) - 1) * (options.dig(:page, :size) || 25) diff --git a/lib/tasks/event.rake b/lib/tasks/event.rake index 66fc22a2b..4c66fd470 100644 --- a/lib/tasks/event.rake +++ b/lib/tasks/event.rake @@ -56,7 +56,7 @@ namespace :event do desc 'update registrant metadata' task :update_registrant => :environment do - cursor = ENV['CURSOR'].to_s.split(",") || [Event.minimum(:id), Event.minimum(:id)] + cursor = ENV["CURSOR"].present? ? Base64.urlsafe_decode64(ENV["CURSOR"]).split(",", 2) : [] Event.update_registrant(cursor: cursor, size: ENV['SIZE']) end diff --git a/spec/models/doi_spec.rb b/spec/models/doi_spec.rb index 6acdbde43..c327517e5 100644 --- a/spec/models/doi_spec.rb +++ b/spec/models/doi_spec.rb @@ -523,23 +523,22 @@ end end - # TODO issue with search_after - # describe "transfer", elasticsearch: true do - # let(:provider) { create(:provider) } - # let(:client) { create(:client, provider: provider) } - # let(:target) { create(:client, provider: provider, symbol: provider.symbol + ".TARGET", name: "Target Client") } - # let!(:dois) { create_list(:doi, 5, client: client, aasm_state: "findable") } - - # before do - # Doi.import - # sleep 2 - # end - - # it "transfer all dois" do - # response = Doi.transfer(client_id: client.symbol.downcase, client_target_id: target.symbol.downcase, size: 3) - # expect(response).to eq(5) - # end - # end + describe "transfer", elasticsearch: true do + let(:provider) { create(:provider) } + let(:client) { create(:client, provider: provider) } + let(:target) { create(:client, provider: provider, symbol: provider.symbol + ".TARGET", name: "Target Client") } + let!(:dois) { create_list(:doi, 5, client: client, aasm_state: "findable") } + + before do + Doi.import + sleep 2 + end + + it "transfer all dois" do + response = Doi.transfer(client_id: client.symbol.downcase, client_target_id: target.symbol.downcase, size: 3) + expect(response).to eq(5) + end + end describe "views" do let(:client) { create(:client) }