Skip to content
This repository was archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Display XXXX if last_digits returns nil
Browse files Browse the repository at this point in the history
If last_digits returns nil (because the token is unknown) we want
to display this correctly to the user as well.
  • Loading branch information
tvdeyen committed Sep 14, 2017
1 parent 2bc1a6c commit df75c1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/solidus_paypal_braintree/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def credit_card?
end

def display_number
"XXXX-XXXX-XXXX-#{last_digits}"
"XXXX-XXXX-XXXX-#{last_digits.to_s.rjust(4, 'X')}"
end

private
Expand Down
16 changes: 13 additions & 3 deletions spec/models/solidus_paypal_braintree/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,21 @@
let(:payment_source) { described_class.new }
subject { payment_source.display_number }

before do
allow(payment_source).to receive(:last_digits).and_return('1234')
context "when last_digits is a number" do
before do
allow(payment_source).to receive(:last_digits).and_return('1234')
end

it { is_expected.to eq 'XXXX-XXXX-XXXX-1234' }
end

it { is_expected.to eq 'XXXX-XXXX-XXXX-1234' }
context "when last_digits is nil" do
before do
allow(payment_source).to receive(:last_digits).and_return(nil)
end

it { is_expected.to eq 'XXXX-XXXX-XXXX-XXXX' }
end
end

describe "#card_type" do
Expand Down

0 comments on commit df75c1d

Please sign in to comment.