Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
Update according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Xin (Sean) Li committed Dec 5, 2018
1 parent c93d4f2 commit 6b589c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
11 changes: 9 additions & 2 deletions lib/orbital/models/response.rb
Expand Up @@ -6,6 +6,8 @@ class OrbitalResponse < ::Killbill::Plugin::ActiveMerchant::ActiveRecord::Respon

has_one :orbital_transaction

scope :succeeded, -> { where(:success => true) }

def self.from_response(api_call, kb_account_id, kb_payment_id, kb_payment_transaction_id, transaction_type, payment_processor_account_id, kb_tenant_id, response, extra_params = {}, model = ::Killbill::Orbital::OrbitalResponse)
super(api_call,
kb_account_id,
Expand Down Expand Up @@ -188,9 +190,14 @@ def self.search_where_clause(t, search_key)
return where_clause
end

# not needed, put a big number beyond the accurate limit (20k) here to make the pagination work
SIMPLE_PAGINATION_THRESHOLD = 20000

def self.max_nb_records
20001
if self.succeeded.limit(1).offset(SIMPLE_PAGINATION_THRESHOLD).nil?
self.succeeded.count
else
SIMPLE_PAGINATION_THRESHOLD + 1
end
end
end
end
Expand Down
25 changes: 23 additions & 2 deletions spec/orbital/response_spec.rb
Expand Up @@ -68,10 +68,31 @@
end

describe '.max_nb_records' do
before(:each) do
described_class.stub_chain(:succeeded, :limit, :offset, :nil?).and_return(target_response_nil?)
end

subject { described_class.max_nb_records }

it 'should be equal to a fixed number 20001' do
expect(subject).to eq(20001)
context 'when the target response exists' do
let(:target_response_nil?) { false }

it 'should be equal to a fixed number' do
expect(subject).to eq(described_class::SIMPLE_PAGINATION_THRESHOLD + 1)
end
end

context 'when the target response does not exist' do
let(:target_response_nil?) { true }
let(:success_response_count) { 123 }

before(:all) do
described_class.stub_chain(:succeeded, :count) { :success_response_count }
end

it 'should be equal to the actual response count' do
expect(subject).to eq(:success_response_count)
end
end
end
end

0 comments on commit 6b589c4

Please sign in to comment.