Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: highfidelity/fake_braintree
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.8.0
Choose a base ref
...
head repository: highfidelity/fake_braintree
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 6 commits
  • 12 files changed
  • 3 contributors

Commits on Nov 19, 2015

  1. Bugfix: Ignore empty discount/addon arrays

    The Braintree API is just fine with accepting an empty array – so FakeBraintree
    should be fine with this as well.
    
    Example:
    
    Braintree::Subscription.update(subscription_id, discounts: {
    	add: [],
    	update: [{ existing_id: some_id, amount: some_amount }]
    })
    
    This previously failed because FakeBraintree would stop at the `add` key since
    it can be found and isn't nil. After this patch, FakeBraintree continues on the
    empty array and correctly updates the discount.
    Clemens Kofler committed Nov 19, 2015
    Copy the full SHA
    cc82653 View commit details

Commits on Dec 8, 2015

  1. Merge pull request #109 from clemens/bugfix/ignore-empty-discounts-array

    Bugfix: Ignore empty discount/addon arrays
    birarda committed Dec 8, 2015
    Copy the full SHA
    5f5aae1 View commit details

Commits on Dec 14, 2015

  1. Bugfix: Ensure creation time is set when records are created

    According go the API docs, pretty much every record in the Braintree API has a created_at field – so we should have them as well.
    Clemens Kofler committed Dec 14, 2015
    Copy the full SHA
    c8bea45 View commit details

Commits on Apr 20, 2016

  1. Merge pull request #112 from clemens/bugfix/ensure-creation-time-is-s…

    …et-when-records-are-created
    
    Bugfix: Ensure creation time is set when records are created
    birarda committed Apr 20, 2016
    Copy the full SHA
    630217c View commit details

Commits on Jul 28, 2016

  1. Fixed broken spec.

    Braintree::PaymentMethod.delete returns success object instead of boolean
    Manjot Sangha committed Jul 28, 2016
    Copy the full SHA
    42ff29b View commit details

Commits on Aug 12, 2016

  1. Merge pull request #115 from finventures/ms-fixed-failing-test

    Fixed broken spec
    birarda authored Aug 12, 2016
    Copy the full SHA
    2a7f517 View commit details
1 change: 1 addition & 0 deletions lib/fake_braintree/address.rb
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ def initialize(address_hash_from_params, options)

def create
@address['id'] = generate_id
@address['created_at'] = Time.now
FakeBraintree.registry.addresses[id] = @address
customer['addresses'] << @address
response_for_updated_address
1 change: 1 addition & 0 deletions lib/fake_braintree/credit_card.rb
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ def create
if token.nil?
@credit_card['token'] = generate_token
end
@credit_card['created_at'] = Time.now
FakeBraintree.registry.credit_cards[token] = @credit_card
if customer = FakeBraintree.registry.customers[@credit_card['customer_id']]
customer['credit_cards'] << @credit_card
1 change: 1 addition & 0 deletions lib/fake_braintree/customer.rb
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ def create
create_customer_with(customer_hash)
credit_cards.each { |card| add_credit_card_to_registry(card) }
set_default_credit_card credit_cards.first
@customer_hash['created_at'] = Time.now
response_for_created_customer(customer_hash)
end
end
2 changes: 1 addition & 1 deletion lib/fake_braintree/sinatra_app.rb
Original file line number Diff line number Diff line change
@@ -253,7 +253,7 @@ def hash_from_request_body_with_key(key)
post '/merchants/:merchant_id/transactions/:transaction_id/refund' do
transaction = hash_from_request_body_with_key('transaction')
transaction_id = md5("#{params[:merchant_id]}#{Time.now.to_f}")
transaction_response = {'id' => transaction_id, 'amount' => transaction['amount'], 'type' => 'credit'}
transaction_response = {'id' => transaction_id, 'amount' => transaction['amount'], 'type' => 'credit', 'created_at' => Time.now}
FakeBraintree.registry.transactions[transaction_id] = transaction_response
gzipped_response(200, transaction_response.to_xml(root: 'transaction'))
end
5 changes: 3 additions & 2 deletions lib/fake_braintree/subscription.rb
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ def initialize(subscription_hash_from_params, options)
end

def create
@subscription_hash['created_at'] = Time.now
create_subscription_with(subscription_hash)
if credit_card = FakeBraintree.registry.credit_cards[payment_method_token]
credit_card['subscriptions'] ||= []
@@ -87,15 +88,15 @@ def discounts
def discounts_or_add_ons(discount_or_add_on)
return [] unless discount_or_add_on.is_a?(Hash)

if discount_or_add_on['add']
if Array(discount_or_add_on['add']).any?
discount_or_add_on['add'].map do |hsh|
{
'id' => hsh['inherited_from_id'],
'quantity' => hsh['quantity'],
'amount' => hsh['amount']
}
end
elsif discount_or_add_on['update']
elsif Array(discount_or_add_on['update']).any?
discount_or_add_on['update'].map do |hsh|
{
'id' => hsh['existing_id'],
3 changes: 2 additions & 1 deletion lib/fake_braintree/transaction.rb
Original file line number Diff line number Diff line change
@@ -12,7 +12,8 @@ def create
"id" => id,
"amount" => data["amount"],
"status" => status,
"type" => "sale"
"type" => "sale",
"created_at" => Time.now
}

FakeBraintree.registry.transactions[id] = response
13 changes: 10 additions & 3 deletions spec/fake_braintree/address_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
require 'spec_helper'

describe "Braintree::Address.create" do
it "successfully creates address with valid data" do
customer_response = create_customer
let(:customer) { create_customer.customer }

it "successfully creates address with valid data" do
address_response = Braintree::Address.create(
customer_id: customer_response.customer.id,
customer_id: customer.id,
postal_code: 30339
)

expect(address_response).to be_success
end

it "sets the creation time" do
address = Braintree::Address.create(customer_id: customer.id).address

creation_time = Time.parse(address.created_at)
expect(creation_time).to be_within(1).of(Time.now)
end
end
7 changes: 7 additions & 0 deletions spec/fake_braintree/credit_card_spec.rb
Original file line number Diff line number Diff line change
@@ -77,6 +77,13 @@ def token_for(month, year)
end
end

it "sets the creation time" do
credit_card = Braintree::CreditCard.create(build_credit_card_hash).credit_card

creation_time = Time.parse(credit_card.created_at)
expect(creation_time).to be_within(1).of(Time.now)
end

def build_credit_card_hash
{
customer_id: @customer && @customer.id,
12 changes: 12 additions & 0 deletions spec/fake_braintree/customer_spec.rb
Original file line number Diff line number Diff line change
@@ -114,6 +114,18 @@
expect(billing_address.street_address).to eq '1 E Main St'
expect(billing_address.postal_code).to eq '60622'
end

it "sets the creation time" do
customer = Braintree::Customer.create(
credit_card: {
number: TEST_CC_NUMBER,
expiration_date: '04/2016'
}
).customer

creation_time = Time.parse(customer.created_at)
expect(creation_time).to be_within(1).of(Time.now)
end
end

describe 'Braintree::Customer.create', 'when passed verify_card: true' do
2 changes: 1 addition & 1 deletion spec/fake_braintree/payment_method_spec.rb
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ def token_for(month, year)

result = Braintree::PaymentMethod.delete(token)

expect(result).to eq true
expect(result).to be_success

expect {
Braintree::PaymentMethod.find(token)
17 changes: 17 additions & 0 deletions spec/fake_braintree/subscription_spec.rb
Original file line number Diff line number Diff line change
@@ -88,6 +88,12 @@
end
end

it "sets the creation time" do
subscription = create_subscription.subscription

creation_time = Time.parse(subscription.created_at)
expect(creation_time).to be_within(1).of(Time.now)
end
end

describe 'Braintree::Subscription.find' do
@@ -152,6 +158,17 @@
expect(discounts.first.quantity).to eq 5
end

it 'updates an existing discount if an empty :add array is given' do
discount_id = 'abc123'
subscription_id = create_subscription(discounts: { add: [{ inherited_from_id: discount_id, quantity: 2 }] }).subscription.id
update_subscription(subscription_id, discounts: { add: [], update: [{ existing_id: discount_id, quantity: 5 }] })
subscription = Braintree::Subscription.find(subscription_id)
discounts = subscription.discounts
expect(discounts.size).to eq 1
expect(discounts.first.id).to eq discount_id
expect(discounts.first.quantity).to eq 5
end

it 'finds subscriptions created with custom id' do
create_subscription(id: 'bob-smiths-subscription')
expect(Braintree::Subscription.find('bob-smiths-subscription')).to be_a Braintree::Subscription
17 changes: 17 additions & 0 deletions spec/fake_braintree/transaction_spec.rb
Original file line number Diff line number Diff line change
@@ -11,6 +11,16 @@
expect(result.transaction.type).to eq 'sale'
end

it "sets the creation time" do
transaction = Braintree::Transaction.sale(
payment_method_token: cc_token,
amount: 10.00
).transaction

creation_time = Time.parse(transaction.created_at)
expect(creation_time).to be_within(1).of(Time.now)
end

context 'when all cards are declined' do
before { FakeBraintree.decline_all_cards! }

@@ -77,6 +87,13 @@
result = Braintree::Transaction.refund(create_id('foobar'), '1')
expect(result).to be_success
end

it "sets the creation time" do
transaction = Braintree::Transaction.refund(create_id('foobar'), '1').transaction

creation_time = Time.parse(transaction.created_at)
expect(creation_time).to be_within(1).of(Time.now)
end
end
end