This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from RyanofWoods/add-email-to-braintree-customer
Add email to Braintree customer
- Loading branch information
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -544,6 +544,56 @@ | |
end | ||
end | ||
|
||
describe '#customer_profile_params' do | ||
subject(:params) { gateway.send(:customer_profile_params, payment) } | ||
|
||
let(:payment) do | ||
build(:payment, { | ||
payment_method: gateway, | ||
source: source | ||
}) | ||
end | ||
|
||
context 'when payment does not belong to an order' do | ||
before { allow(payment).to receive(:order).and_return(nil) } | ||
|
||
it 'has the email param as nil' do | ||
expect(subject[:email]).to be_nil | ||
end | ||
end | ||
|
||
context 'when payment belongs to an order' do | ||
it 'has no email param' do | ||
expect(subject[:email]).to eq(payment.order.email) | ||
end | ||
end | ||
end | ||
|
||
describe "Braintree Customer" do | ||
subject(:customer) { braintree.customer.create(params).customer } | ||
|
||
let(:params) { gateway.send(:customer_profile_params, payment) } | ||
|
||
let(:payment) do | ||
build(:payment, { | ||
payment_method: gateway, | ||
source: source | ||
}) | ||
end | ||
|
||
cassette_options = { | ||
cassette_name: 'gateway/customer', | ||
match_requests_on: [:braintree_uri] | ||
} | ||
|
||
context "with customer", vcr: cassette_options do | ||
it 'saves the customer email correctly' do | ||
allow(payment.order).to receive(:email).and_return('[email protected]') | ||
expect(subject.email).to eq(payment.order.email) | ||
end | ||
end | ||
end | ||
|
||
shared_examples "sources_by_order" do | ||
let(:order) { FactoryBot.create :order, user: user, state: "complete", completed_at: Time.current } | ||
let(:gateway) { new_gateway.tap(&:save!) } | ||
|