Commit 16f98f5c authored by Mark Chao's avatar Mark Chao

Change validation display order

to include network, but not holder name.

Admin requested to display record with different holder name because
payment network may accept incorrectly entered holder name.
parent d95a43df
...@@ -18,7 +18,7 @@ module Users ...@@ -18,7 +18,7 @@ module Users
self.class.where( self.class.where(
expiration_date: expiration_date, expiration_date: expiration_date,
last_digits: last_digits, last_digits: last_digits,
holder_name: holder_name network: network
).order(credit_card_validated_at: :desc).includes(:user) ).order(credit_card_validated_at: :desc).includes(:user)
end end
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
FactoryBot.modify do FactoryBot.modify do
factory :credit_card_validation do factory :credit_card_validation do
user user
credit_card_validated_at { Time.current } sequence(:credit_card_validated_at) { |n| Time.current + n }
expiration_date { 1.year.from_now.end_of_month } expiration_date { 1.year.from_now.end_of_month }
last_digits { 10 } last_digits { 10 }
holder_name { 'John Smith' } holder_name { 'John Smith' }
......
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
FactoryBot.define do FactoryBot.define do
factory :credit_card_validation, class: 'Users::CreditCardValidation' do factory :credit_card_validation, class: 'Users::CreditCardValidation' do
user user
sequence(:credit_card_validated_at) { |n| Time.current + n }
credit_card_validated_at { Time.current } expiration_date { 1.year.from_now.end_of_month }
last_digits { 10 }
holder_name { 'John Smith' }
network { 'AmericanExpress' }
end end
end end
...@@ -10,16 +10,21 @@ RSpec.describe Users::CreditCardValidation do ...@@ -10,16 +10,21 @@ RSpec.describe Users::CreditCardValidation do
it { is_expected.to validate_numericality_of(:last_digits).is_less_than_or_equal_to(9999) } it { is_expected.to validate_numericality_of(:last_digits).is_less_than_or_equal_to(9999) }
describe '.similar_records' do describe '.similar_records' do
let(:card_details) { subject.attributes.slice(:expiration_date, :last_digits, :holder_name) } let(:card_details) do
subject.attributes.with_indifferent_access.slice(:expiration_date, :last_digits, :network, :holder_name)
end
subject(:credit_card_validation) { create(:credit_card_validation) } subject!(:credit_card_validation) { create(:credit_card_validation, holder_name: 'Alice') }
let!(:match1) { create(:credit_card_validation, card_details) } let!(:match1) { create(:credit_card_validation, card_details) }
let!(:other1) { create(:credit_card_validation, card_details.merge(last_digits: 9)) } let!(:match2) { create(:credit_card_validation, card_details.merge(holder_name: 'Bob')) }
let!(:match2) { create(:credit_card_validation, card_details) } let!(:non_match1) { create(:credit_card_validation, card_details.merge(last_digits: 9)) }
let!(:other2) { create(:credit_card_validation, card_details.merge(holder_name: 'foo bar')) } let!(:non_match2) { create(:credit_card_validation, card_details.merge(network: 'unknown')) }
let!(:non_match3) do
create(:credit_card_validation, card_details.dup.tap { |h| h[:expiration_date] += 1.year })
end
it 'returns records with matching credit card, ordered by credit_card_validated_at' do it 'returns matches with the same last_digits, expiration and network, ordered by credit_card_validated_at' do
expect(subject.similar_records).to eq([match2, match1, subject]) expect(subject.similar_records).to eq([match2, match1, subject])
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment