Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Bring code base closer to thoughtbot style #39

Closed
wants to merge 3 commits into from

1 participant

Gabe Berke-Williams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 27, 2012
  1. Gabe Berke-Williams

    Use modern thoughtbot style

    gabebw authored
Commits on Mar 22, 2013
  1. Gabe Berke-Williams

    Use single quotes

    gabebw authored
  2. Gabe Berke-Williams

    Clean up a test

    gabebw authored
This page is out of date. Refresh to see the latest.
2  Gemfile
View
@@ -1,4 +1,4 @@
-source "http://rubygems.org"
+source 'http://rubygems.org'
# Specify your gem's dependencies in fake_braintree.gemspec
gemspec
8 Rakefile
View
@@ -1,8 +1,8 @@
-require "bundler/setup"
-require "bundler/gem_tasks"
-require "rspec/core/rake_task"
+require 'bundler/setup'
+require 'bundler/gem_tasks'
+require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
-desc "Run specs"
+desc 'Run specs'
task :default => [:spec]
20 fake_braintree.gemspec
View
@@ -1,20 +1,20 @@
# -*- encoding: utf-8 -*-
-$:.push File.expand_path("../lib", __FILE__)
-require "fake_braintree/version"
+$:.push File.expand_path('../lib', __FILE__)
+require 'fake_braintree/version'
Gem::Specification.new do |s|
- s.name = "fake_braintree"
+ s.name = 'fake_braintree'
s.version = FakeBraintree::VERSION
- s.authors = ["thoughtbot, inc."]
- s.email = ["gabe@thoughtbot.com", "ben@thoughtbot.com"]
- s.homepage = ""
+ s.authors = ['thoughtbot, inc.']
+ s.email = ['gabe@thoughtbot.com', 'ben@thoughtbot.com']
+ s.homepage = ''
s.summary = %q{A fake Braintree that you can run integration tests against}
s.description = %q{A fake Braintree that you can run integration tests against}
- s.files = `git ls-files`.split("\n")
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
- s.require_paths = ["lib"]
+ s.files = `git ls-files`.split('\n')
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split('\n')
+ s.executables = `git ls-files -- bin/*`.split('\n').map{ |f| File.basename(f) }
+ s.require_paths = ['lib']
s.add_dependency 'capybara'
s.add_dependency 'activesupport'
56 lib/fake_braintree.rb
View
@@ -46,26 +46,26 @@ def self.failure?(card_number)
def self.failure_response(card_number = nil)
failure = registry.failures[card_number] || {}
- failure["errors"] ||= { "errors" => [] }
-
- { "message" => failure["message"],
- "verification" => { "status" => failure["status"],
- "processor_response_text" => failure["message"],
- "processor_response_code" => failure["code"],
- "gateway_rejection_reason" => "cvv",
- "cvv_response_code" => failure["code"] },
- "errors" => failure["errors"],
- "params" => {}}
+ failure['errors'] ||= { 'errors' => [] }
+
+ { 'message' => failure['message'],
+ 'verification' => { 'status' => failure['status'],
+ 'processor_response_text' => failure['message'],
+ 'processor_response_code' => failure['code'],
+ 'gateway_rejection_reason' => 'cvv',
+ 'cvv_response_code' => failure['code'] },
+ 'errors' => failure['errors'],
+ 'params' => {}}
end
def self.create_failure
{
- "message" => "Do Not Honor",
- "verification" => { "status" => "processor_declined",
- "processor_response_text" => "Do Not Honor",
- "processor_response_code" => '2000' },
- "errors" => { 'errors' => [] },
- "params" => {}
+ 'message' => 'Do Not Honor',
+ 'verification' => { 'status' => 'processor_declined',
+ 'processor_response_text' => 'Do Not Honor',
+ 'processor_response_code' => '2000' },
+ 'errors' => { 'errors' => [] },
+ 'params' => {}
}
end
@@ -82,23 +82,27 @@ def self.verify_all_cards!
end
def self.generate_transaction(options = {})
- history_item = { 'timestamp' => Time.now,
- 'amount' => options[:amount],
- 'status' => options[:status] }
+ history_item = {
+ 'timestamp' => Time.now,
+ 'amount' => options[:amount],
+ 'status' => options[:status]
+ }
created_at = options[:created_at] || Time.now
- {'status_history' => [history_item],
- 'subscription_id' => options[:subscription_id],
- 'created_at' => created_at,
- 'amount' => options[:amount] }
+ {
+ 'status_history' => [history_item],
+ 'subscription_id' => options[:subscription_id],
+ 'created_at' => created_at,
+ 'amount' => options[:amount]
+ }
end
private
def self.set_configuration
Braintree::Configuration.environment = :development
- Braintree::Configuration.merchant_id = "xxx"
- Braintree::Configuration.public_key = "xxx"
- Braintree::Configuration.private_key = "xxx"
+ Braintree::Configuration.merchant_id = 'xxx'
+ Braintree::Configuration.public_key = 'xxx'
+ Braintree::Configuration.private_key = 'xxx'
end
def self.boot_server
40 lib/fake_braintree/credit_card.rb
View
@@ -22,12 +22,29 @@ def to_xml
private
+ def set_up_credit_card(credit_card_hash_from_params, options)
+ @hash = {
+ 'token' => options[:token],
+ 'merchant_id' => options[:merchant_id]
+ }.merge(credit_card_hash_from_params)
+ end
+
+ def set_expiration_month_and_year
+ if expiration_month
+ @hash['expiration_month'] = expiration_month
+ end
+
+ if expiration_year
+ @hash['expiration_year'] = expiration_year
+ end
+ end
+
def update_existing_credit_card
@hash = credit_card_from_registry.merge!(@hash)
end
def response_for_updated_card
- gzipped_response(200, @hash.to_xml(:root => 'credit_card'))
+ gzipped_response(200, to_xml)
end
def credit_card_exists_in_registry?
@@ -50,30 +67,13 @@ def expiration_year
expiration_date_parts[1]
end
- def set_up_credit_card(credit_card_hash_from_params, options)
- @hash = {
- "token" => options[:token],
- "merchant_id" => options[:merchant_id]
- }.merge(credit_card_hash_from_params)
- end
-
- def set_expiration_month_and_year
- if expiration_month
- @hash["expiration_month"] = expiration_month
- end
-
- if expiration_year
- @hash["expiration_year"] = expiration_year
- end
- end
-
def token
@hash['token']
end
def expiration_date_parts
- if @hash.key?("expiration_date")
- @hash["expiration_date"].split('/')
+ if @hash.key?('expiration_date')
+ @hash['expiration_date'].split('/')
else
[]
end
48 lib/fake_braintree/customer.rb
View
@@ -4,8 +4,8 @@ class Customer
def initialize(customer_hash_from_params, options)
@customer_hash = {
- "id" => options[:id],
- "merchant_id" => options[:merchant_id]
+ 'id' => options[:id],
+ 'merchant_id' => options[:merchant_id]
}.merge(customer_hash_from_params)
set_customer_id
@@ -15,7 +15,7 @@ def create
if invalid?
response_for_invalid_card
else
- credit_cards = customer_hash["credit_cards"]
+ credit_cards = customer_hash['credit_cards']
create_customer_with(customer_hash)
credit_cards.each { |card| add_credit_card_to_registry(card) }
response_for_created_customer(customer_hash)
@@ -37,7 +37,7 @@ def update
end
def delete
- delete_customer_with_id(customer_id)
+ delete_customer
deletion_response
end
@@ -48,11 +48,11 @@ def invalid?
end
def create_customer_with(hash)
- FakeBraintree.registry.customers[hash["id"]] = hash
+ FakeBraintree.registry.customers[hash['id']] = hash
end
def add_credit_card_to_registry(new_credit_card_hash)
- token = new_credit_card_hash["token"]
+ token = new_credit_card_hash['token']
FakeBraintree.registry.credit_cards[token] = new_credit_card_hash
end
@@ -61,7 +61,7 @@ def update_existing_customer(updates_hash)
end
def customer_hash
- @customer_hash.merge("credit_cards" => generate_credit_cards_from(@customer_hash["credit_card"]))
+ @customer_hash.merge('credit_cards' => generate_credit_cards_from(@customer_hash['credit_card']))
end
def customer_from_registry
@@ -83,11 +83,11 @@ def invalid_credit_card?
def verify_credit_card?(customer_hash_for_verification)
return true if FakeBraintree.verify_all_cards
- credit_card_hash_for_verification = customer_hash_for_verification["credit_card"]
+ credit_card_hash_for_verification = customer_hash_for_verification['credit_card']
if credit_card_hash_for_verification.is_a?(Hash) &&
- credit_card_hash_for_verification.key?("options")
- options = credit_card_hash_for_verification["options"]
- options["verify_card"] == true
+ credit_card_hash_for_verification.key?('options')
+ options = credit_card_hash_for_verification['options']
+ options['verify_card'] == true
end
end
@@ -97,20 +97,20 @@ def has_invalid_credit_card?(customer_hash)
end
def credit_card_number
- credit_card_hash["number"]
+ credit_card_hash['number']
end
def generate_credit_cards_from(new_credit_card_hash)
if new_credit_card_hash.present? && new_credit_card_hash.is_a?(Hash)
- new_credit_card_hash["last_4"] = new_credit_card_hash["number"][-4..-1]
- new_credit_card_hash["token"] = credit_card_token(new_credit_card_hash)
+ new_credit_card_hash['last_4'] = new_credit_card_hash['number'][-4..-1]
+ new_credit_card_hash['token'] = credit_card_token(new_credit_card_hash)
if credit_card_expiration_month
- new_credit_card_hash["expiration_month"] = credit_card_expiration_month
+ new_credit_card_hash['expiration_month'] = credit_card_expiration_month
end
if credit_card_expiration_year
- new_credit_card_hash["expiration_year"] = credit_card_expiration_year
+ new_credit_card_hash['expiration_year'] = credit_card_expiration_year
end
[new_credit_card_hash]
@@ -128,15 +128,15 @@ def credit_card_expiration_year
end
def credit_card_expiration_date
- if credit_card_hash.key?("expiration_date")
- credit_card_hash["expiration_date"].split('/')
+ if credit_card_hash.key?('expiration_date')
+ credit_card_hash['expiration_date'].split('/')
else
[]
end
end
- def delete_customer_with_id(id)
- FakeBraintree.registry.customers[id] = nil
+ def delete_customer
+ FakeBraintree.registry.customers[customer_id] = nil
end
def deletion_response
@@ -164,7 +164,7 @@ def failure_response(code)
end
def customer_id
- customer_hash["id"]
+ customer_hash['id']
end
def has_credit_card?
@@ -172,15 +172,15 @@ def has_credit_card?
end
def credit_card_hash
- @customer_hash["credit_card"] || {}
+ @customer_hash['credit_card'] || {}
end
def set_customer_id
- @customer_hash["id"] ||= create_id(@customer_hash["merchant_id"])
+ @customer_hash['id'] ||= create_id(@customer_hash['merchant_id'])
end
def credit_card_token(credit_card_hash_without_token)
- md5("#{credit_card_hash_without_token["number"]}#{@customer_hash["merchant_id"]}")
+ md5("#{credit_card_hash_without_token['number']}#{@customer_hash['merchant_id']}")
end
end
end
2  lib/fake_braintree/helpers.rb
View
@@ -9,7 +9,7 @@ def gzip(content)
end
def gzipped_response(status_code, uncompressed_content)
- [status_code, { "Content-Encoding" => "gzip" }, gzip(uncompressed_content)]
+ [status_code, { 'Content-Encoding' => 'gzip' }, gzip(uncompressed_content)]
end
def md5(content)
6 lib/fake_braintree/redirect.rb
View
@@ -5,7 +5,7 @@ class Redirect
attr_reader :id
def initialize(params, merchant_id)
- hash, query = *params[:tr_data].split("|", 2)
+ hash, query = *params[:tr_data].split('|', 2)
@transparent_data = Rack::Utils.parse_query(query)
@merchant_id = merchant_id
@id = create_id(@merchant_id)
@@ -17,13 +17,13 @@ def url
end
def confirm
- Customer.new(@params["customer"], {:merchant_id => @merchant_id}).create
+ Customer.new(@params['customer'], {:merchant_id => @merchant_id}).create
end
private
def uri
- URI.parse(@transparent_data["redirect_url"]).merge("?#{base_query}&hash=#{hash(base_query)}")
+ URI.parse(@transparent_data['redirect_url']).merge("?#{base_query}&hash=#{hash(base_query)}")
end
def base_query
98 lib/fake_braintree/sinatra_app.rb
View
@@ -16,14 +16,14 @@ def hash_from_request_body_with_key(request, key)
end
# Braintree::Customer.create
- post "/merchants/:merchant_id/customers" do
- customer_hash = hash_from_request_body_with_key(request, "customer")
+ post '/merchants/:merchant_id/customers' do
+ customer_hash = hash_from_request_body_with_key(request, 'customer')
options = {:merchant_id => params[:merchant_id]}
Customer.new(customer_hash, options).create
end
# Braintree::Customer.find
- get "/merchants/:merchant_id/customers/:id" do
+ get '/merchants/:merchant_id/customers/:id' do
customer = FakeBraintree.registry.customers[params[:id]]
if customer
gzipped_response(200, customer.to_xml(:root => 'customer'))
@@ -33,28 +33,28 @@ def hash_from_request_body_with_key(request, key)
end
# Braintree::Customer.update
- put "/merchants/:merchant_id/customers/:id" do
- customer_hash = hash_from_request_body_with_key(request, "customer")
+ put '/merchants/:merchant_id/customers/:id' do
+ customer_hash = hash_from_request_body_with_key(request, 'customer')
options = {:id => params[:id], :merchant_id => params[:merchant_id]}
Customer.new(customer_hash, options).update
end
# Braintree::Customer.delete
- delete "/merchants/:merchant_id/customers/:id" do
+ delete '/merchants/:merchant_id/customers/:id' do
customer_hash = {}
options = {:id => params[:id], :merchant_id => params[:merchant_id]}
Customer.new(customer_hash, options).delete
end
# Braintree::Subscription.create
- post "/merchants/:merchant_id/subscriptions" do
- subscription_hash = hash_from_request_body_with_key(request, "subscription")
+ post '/merchants/:merchant_id/subscriptions' do
+ subscription_hash = hash_from_request_body_with_key(request, 'subscription')
options = {:merchant_id => params[:merchant_id]}
Subscription.new(subscription_hash, options).create
end
# Braintree::Subscription.find
- get "/merchants/:merchant_id/subscriptions/:id" do
+ get '/merchants/:merchant_id/subscriptions/:id' do
subscription = FakeBraintree.registry.subscriptions[params[:id]]
if subscription
gzipped_response(200, subscription.to_xml(:root => 'subscription'))
@@ -64,104 +64,114 @@ def hash_from_request_body_with_key(request, key)
end
# Braintree::Subscription.update
- put "/merchants/:merchant_id/subscriptions/:id" do
- subscription_hash = hash_from_request_body_with_key(request, "subscription")
+ put '/merchants/:merchant_id/subscriptions/:id' do
+ subscription_hash = hash_from_request_body_with_key(request, 'subscription')
options = {:id => params[:id], :merchant_id => params[:merchant_id]}
Subscription.new(subscription_hash, options).update
end
# Braintree::Subscription.cancel
- put "/merchants/:merchant_id/subscriptions/:id/cancel" do
- updates = {"status" => Braintree::Subscription::Status::Canceled}
+ put '/merchants/:merchant_id/subscriptions/:id/cancel' do
+ updates = {'status' => Braintree::Subscription::Status::Canceled}
options = {:id => params[:id], :merchant_id => params[:merchant_id]}
Subscription.new(updates, options).update
end
# Braintree::CreditCard.find
- get "/merchants/:merchant_id/payment_methods/:credit_card_token" do
+ get '/merchants/:merchant_id/payment_methods/:credit_card_token' do
credit_card = FakeBraintree.registry.credit_cards[params[:credit_card_token]]
- gzipped_response(200, credit_card.to_xml(:root => "credit_card"))
+ gzipped_response(200, credit_card.to_xml(:root => 'credit_card'))
end
- post "/merchants/:merchant_id/payment_methods" do
- opts = {
+ post '/merchants/:merchant_id/payment_methods' do
+ options = {
:token => md5("#{Time.now}#{rand}"),
:merchant_id => params[:merchant_id]
}
data = hash_from_request_body_with_key(request, 'credit_card')
if data[:token]
- opts[:token] = data[:token]
+ options[:token] = data[:token]
end
- credit_card = CreditCard.new(data, opts)
- FakeBraintree.registry.credit_cards[opts[:token]] = credit_card
+ credit_card = CreditCard.new(data, options)
+ FakeBraintree.registry.credit_cards[options[:token]] = credit_card
gzipped_response(200, credit_card.to_xml)
end
# Braintree::CreditCard.update
- put "/merchants/:merchant_id/payment_methods/:credit_card_token" do
+ put '/merchants/:merchant_id/payment_methods/:credit_card_token' do
credit_card = FakeBraintree.registry.credit_cards[params[:credit_card_token]]
- updates = hash_from_request_body_with_key(request, "credit_card")
- options = {:token => params[:credit_card_token], :merchant_id => params[:merchant_id]}
+ updates = hash_from_request_body_with_key(request, 'credit_card')
+ options = {:token => params[:credit_card_token], :merchant_id => params[:merchant_id]}
CreditCard.new(updates, options).update
end
# Braintree::Transaction.sale
# Braintree::CreditCard.sale
- post "/merchants/:merchant_id/transactions" do
+ post '/merchants/:merchant_id/transactions' do
if FakeBraintree.decline_all_cards?
- gzipped_response(422, FakeBraintree.create_failure.to_xml(:root => 'api_error_response'))
+ gzipped_response(422,
+ FakeBraintree.create_failure.to_xml(:root => 'api_error_response'))
else
- transaction = hash_from_request_body_with_key(request, "transaction")
- transaction_id = md5("#{params[:merchant_id]}#{Time.now.to_f}")
- transaction_response = {"id" => transaction_id, "amount" => transaction["amount"]}
+ transaction = hash_from_request_body_with_key(request, 'transaction')
+ transaction_id = create_id(params[:merchant_id])
+ transaction_response = {
+ 'id' => transaction_id,
+ 'amount' => transaction['amount']
+ }
FakeBraintree.registry.transactions[transaction_id] = transaction_response
- gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
+ gzipped_response(200, transaction_response.to_xml(:root => 'transaction'))
end
end
# Braintree::Transaction.find
- get "/merchants/:merchant_id/transactions/:transaction_id" do
+ get '/merchants/:merchant_id/transactions/:transaction_id' do
transaction = FakeBraintree.registry.transactions[params[:transaction_id]]
if transaction
- gzipped_response(200, transaction.to_xml(:root => "transaction"))
+ gzipped_response(200, transaction.to_xml(:root => 'transaction'))
else
gzipped_response(404, {})
end
end
# Braintree::Transaction.refund
- post "/merchants/:merchant_id/transactions/:transaction_id/refund" do
- transaction = hash_from_request_body_with_key(request, "transaction")
+ post '/merchants/:merchant_id/transactions/:transaction_id/refund' do
+ transaction = hash_from_request_body_with_key(request, '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'
+ }
FakeBraintree.registry.transactions[transaction_id] = transaction_response
- gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
+ gzipped_response(200, transaction_response.to_xml(:root => 'transaction'))
end
# Braintree::Transaction.void
- put "/merchants/:merchant_id/transactions/:transaction_id/void" do
+ put '/merchants/:merchant_id/transactions/:transaction_id/void' do
transaction = FakeBraintree.registry.transactions[params[:transaction_id]]
- transaction_response = {"id" => transaction["id"],
- "type" => transaction["sale"],
- "amount" => transaction["amount"],
- "status" => Braintree::Transaction::Status::Voided}
+ transaction_response = {
+ 'id' => transaction['id'],
+ 'type' => transaction['sale'],
+ 'amount' => transaction['amount'],
+ 'status' => Braintree::Transaction::Status::Voided
+ }
FakeBraintree.registry.transactions[transaction['id']] = transaction_response
- gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
+ gzipped_response(200, transaction_response.to_xml(:root => 'transaction'))
end
# Braintree::TransparentRedirect.url
- post "/merchants/:merchant_id/transparent_redirect_requests" do
+ post '/merchants/:merchant_id/transparent_redirect_requests' do
if params[:tr_data]
redirect = Redirect.new(params, params[:merchant_id])
FakeBraintree.registry.redirects[redirect.id] = redirect
redirect to(redirect.url), 303
else
- [422, { "Content-Type" => "text/html" }, ["Invalid submission"]]
+ [422, { 'Content-Type' => 'text/html' }, ['Invalid submission']]
end
end
# Braintree::TransparentRedirect.confirm
- post "/merchants/:merchant_id/transparent_redirect_requests/:id/confirm" do
+ post '/merchants/:merchant_id/transparent_redirect_requests/:id/confirm' do
redirect = FakeBraintree.registry.redirects[params[:id]]
redirect.confirm
end
46 lib/fake_braintree/subscription.rb
View
@@ -3,8 +3,10 @@ class Subscription
include Helpers
def initialize(subscription_hash_from_params, options)
- @subscription_hash = subscription_hash_from_params.merge("merchant_id" => options[:merchant_id],
- "id" => options[:id])
+ @subscription_hash = subscription_hash_from_params.merge(
+ 'merchant_id' => options[:merchant_id],
+ 'id' => options[:id]
+ )
set_subscription_id
set_subscription_status
end
@@ -26,10 +28,12 @@ def update
private
def subscription_hash
- @subscription_hash.merge({"transactions" => [],
- "add_ons" => added_add_ons,
- "discounts" => added_discounts,
- "next_billing_date" => braintree_formatted_date(1.month.from_now)})
+ @subscription_hash.merge({
+ 'transactions' => [],
+ 'add_ons' => added_add_ons,
+ 'discounts' => added_discounts,
+ 'next_billing_date' => braintree_formatted_date(1.month.from_now)
+ })
end
def update_existing_subscription(updates)
@@ -38,7 +42,7 @@ def update_existing_subscription(updates)
end
def create_subscription_with(new_subscription_hash)
- FakeBraintree.registry.subscriptions[new_subscription_hash["id"]] = new_subscription_hash
+ FakeBraintree.registry.subscriptions[new_subscription_hash['id']] = new_subscription_hash
end
def subscription_from_registry
@@ -54,39 +58,43 @@ def braintree_formatted_date(date)
end
def added_add_ons
- if @subscription_hash["add_ons"].is_a?(Hash) && @subscription_hash["add_ons"]["add"]
- @subscription_hash["add_ons"]["add"].map { |add_on| { "id" => add_on["inherited_from_id"] } }
+ if @subscription_hash['add_ons'].is_a?(Hash) && @subscription_hash['add_ons']['add']
+ @subscription_hash['add_ons']['add'].map do |add_on|
+ { 'id' => add_on['inherited_from_id'] }
+ end
else
[]
end
end
def added_discounts
- if @subscription_hash["discounts"].is_a?(Hash) && @subscription_hash["discounts"]["add"]
- @subscription_hash["discounts"]["add"].map { |discount| { "id" => discount["inherited_from_id"] } }
+ if @subscription_hash['discounts'].is_a?(Hash) && @subscription_hash['discounts']['add']
+ @subscription_hash['discounts']['add'].map do |discount|
+ { 'id' => discount['inherited_from_id'] }
+ end
else
[]
end
end
def set_subscription_id
- @subscription_hash["id"] ||= generate_new_subscription_id
+ @subscription_hash['id'] ||= new_subscription_id
end
def set_subscription_status
- @subscription_hash["status"] ||= active_status
+ @subscription_hash['status'] ||= active_status
end
def subscription_id
- subscription_hash["id"]
+ subscription_hash['id']
end
- def generate_new_subscription_id
+ def new_subscription_id
md5("#{payment_method_token}#{Time.now.to_f}")[0,6]
end
def payment_method_token
- @subscription_hash["payment_method_token"]
+ @subscription_hash['payment_method_token']
end
def active_status
@@ -94,15 +102,11 @@ def active_status
end
def response_for_created_subscription(hash)
- gzipped_response(201, hash.to_xml(:root => "subscription"))
+ gzipped_response(201, hash.to_xml(:root => 'subscription'))
end
def response_for_subscription_not_found
gzipped_response(404, {})
end
-
- def response_for_created_subscription(hash)
- gzipped_response(201, hash.to_xml(:root => "subscription"))
- end
end
end
22 lib/fake_braintree/valid_credit_cards.rb
View
@@ -1,9 +1,17 @@
module FakeBraintree
- VALID_CREDIT_CARDS = %w(4111111111111111 4005519200000004
- 4009348888881881 4012000033330026
- 4012000077777777 4012888888881881
- 4217651111111119 4500600000000061
- 5555555555554444 378282246310005
- 371449635398431 6011111111111117
- 3530111333300000)
+ VALID_CREDIT_CARDS = %w(
+ 4111111111111111
+ 4005519200000004
+ 4009348888881881
+ 4012000033330026
+ 4012000077777777
+ 4012888888881881
+ 4217651111111119
+ 4500600000000061
+ 5555555555554444
+ 378282246310005
+ 371449635398431
+ 6011111111111117
+ 3530111333300000
+ )
end
26 spec/fake_braintree/credit_card_spec.rb
View
@@ -1,7 +1,7 @@
require 'spec_helper'
-describe "Braintree::CreditCard.find" do
- it "gets the correct credit card" do
+describe 'Braintree::CreditCard.find' do
+ it 'gets the correct credit card' do
credit_card = Braintree::CreditCard.find(token)
credit_card.last_4.should == TEST_CC_NUMBER[-4,4]
@@ -14,30 +14,32 @@
let(:token) { braintree_credit_card_token(TEST_CC_NUMBER, [month, year].join('/')) }
end
-describe "Braintree::CreditCard.create" do
+describe 'Braintree::CreditCard.create' do
let(:month) { '04' }
let(:year) { '2016' }
let(:token) { braintree_credit_card_token(TEST_CC_NUMBER, [month, year].join('/')) }
- it "successfully creates card with valid data" do
- result = Braintree::CreditCard.create :token => token,
+ it 'successfully creates card with valid data' do
+ result = Braintree::CreditCard.create(
+ :token => token,
:number => TEST_CC_NUMBER
+ )
result.should be_success
Braintree::CreditCard.find(token).should be
end
end
-describe "Braintree::CreditCard.sale" do
- it "successfully creates a sale" do
+describe 'Braintree::CreditCard.sale' do
+ it 'successfully creates a sale' do
result = Braintree::CreditCard.sale(cc_token, :amount => 10.00)
result.should be_success
Braintree::Transaction.find(result.transaction.id).should be
end
end
-describe "Braintree::CreditCard.update" do
- it "successfully updates the credit card" do
- new_expiration_date = "08/2012"
+describe 'Braintree::CreditCard.update' do
+ it 'successfully updates the credit card' do
+ new_expiration_date = '08/2012'
token = cc_token
result = Braintree::CreditCard.update(token, :expiration_date => new_expiration_date)
@@ -45,7 +47,7 @@
Braintree::CreditCard.find(token).expiration_date.should == new_expiration_date
end
- it "raises an error for a nonexistent credit card" do
- lambda { Braintree::CreditCard.update("foo", {:number => TEST_CC_NUMBER}) }.should raise_error(Braintree::NotFoundError)
+ it 'raises an error for a nonexistent credit card' do
+ lambda { Braintree::CreditCard.update('foo', {:number => TEST_CC_NUMBER}) }.should raise_error(Braintree::NotFoundError)
end
end
110 spec/fake_braintree/customer_spec.rb
View
@@ -1,117 +1,129 @@
require 'spec_helper'
-describe "Braintree::Customer.create" do
+describe 'Braintree::Customer.create' do
after { FakeBraintree.verify_all_cards = false }
- it "successfully creates a customer" do
- result = Braintree::Customer.create(:credit_card => { :number => TEST_CC_NUMBER,
- :expiration_date => '04/2016'})
+ it 'successfully creates a customer' do
+ result = Braintree::Customer.create(
+ :credit_card => { :number => TEST_CC_NUMBER,
+ :expiration_date => '04/2016'}
+ )
result.should be_success
end
- it "associates a created credit card with the customer" do
- result = Braintree::Customer.create(:credit_card => { :number => TEST_CC_NUMBER,
- :expiration_date => '04/2016'})
+ it 'associates a created credit card with the customer' do
+ result = Braintree::Customer.create(
+ :credit_card => { :number => TEST_CC_NUMBER,
+ :expiration_date => '04/2016'}
+ )
credit_cards = Braintree::Customer.find(result.customer.id).credit_cards
credit_cards.size.should == 1
- credit_cards.first.expiration_date.should == "04/2016"
+ credit_cards.first.expiration_date.should == '04/2016'
end
it "successfully creates the customer's credit card" do
- result = Braintree::Customer.create(:credit_card => { :number => TEST_CC_NUMBER,
- :expiration_date => '04/2016'})
+ result = Braintree::Customer.create(
+ :credit_card => {
+ :number => TEST_CC_NUMBER,
+ :expiration_date => '04/2016'
+ }
+ )
cc_token = result.customer.credit_cards.first.token
expect { Braintree::CreditCard.find(cc_token) }.not_to raise_error(Braintree::NotFoundError)
end
- it "can handle an empty credit card hash" do
+ it 'can handle an empty credit card hash' do
result = Braintree::Customer.create(:credit_card => {})
result.should be_success
end
- it "does not overwrite a passed customer id" do
- result = Braintree::Customer.create({ "id" => '123' })
+ it 'does not overwrite a passed customer id' do
+ result = Braintree::Customer.create({ 'id' => '123' })
result.customer.id.should eq('123')
end
- it "creates a customer using an expiration month and year" do
- result = Braintree::Customer.create(:credit_card => { :number => TEST_CC_NUMBER,
- :expiration_month => '04',
- :expiration_year => '2016'})
+ it 'creates a customer using an expiration month and year' do
+ result = Braintree::Customer.create(
+ :credit_card => {
+ :number => TEST_CC_NUMBER,
+ :expiration_month => '04',
+ :expiration_year => '2016'
+ }
+ )
result.should be_success
end
- it "records the billing address" do
+ it 'records the billing address' do
result = create_customer(
:billing_address => {
- :street_address => "1 E Main St",
- :extended_address => "Suite 3",
- :locality => "Chicago",
- :region => "Illinois",
- :postal_code => "60622",
- :country_code_alpha2 => "US"
+ :street_address => '1 E Main St',
+ :extended_address => 'Suite 3',
+ :locality => 'Chicago',
+ :region => 'Illinois',
+ :postal_code => '60622',
+ :country_code_alpha2 => 'US'
}
)
billing_address = result.customer.credit_cards[0].billing_address
- billing_address.street_address.should == "1 E Main St"
- billing_address.postal_code.should == "60622"
+ billing_address.street_address.should == '1 E Main St'
+ billing_address.postal_code.should == '60622'
end
end
-describe "Braintree::Customer.create", "when passed :verify_card => true" do
- it "accepts valid cards" do
+describe 'Braintree::Customer.create', 'when passed :verify_card => true' do
+ it 'accepts valid cards' do
create_customer(:options => { :verify_card => true }).should be_success
end
- it "rejects invalid cards" do
+ it 'rejects invalid cards' do
create_customer_with_invalid_card(:options => { :verify_card => true }).should_not be_success
end
end
-describe "Braintree::Customer.create", "when FakeBraintree.verify_all_cards == true" do
+describe 'Braintree::Customer.create', 'when FakeBraintree.verify_all_cards == true' do
before { FakeBraintree.verify_all_cards! }
- it "accepts valid cards" do
+ it 'accepts valid cards' do
create_customer.should be_success
end
- it "rejects invalid cards" do
+ it 'rejects invalid cards' do
create_customer_with_invalid_card.should_not be_success
end
end
-describe "Braintree::Customer.find" do
- it "successfully finds a customer" do
- result = Braintree::Customer.create(:first_name => "Bob",
- :last_name => "Smith")
+describe 'Braintree::Customer.find' do
+ it 'successfully finds a customer' do
+ result = Braintree::Customer.create(:first_name => 'Bob',
+ :last_name => 'Smith')
- Braintree::Customer.find(result.customer.id).first_name.should == "Bob"
+ Braintree::Customer.find(result.customer.id).first_name.should == 'Bob'
end
- it "raises an error for a nonexistent customer" do
- lambda { Braintree::Customer.find("foo") }.should raise_error(Braintree::NotFoundError)
+ it 'raises an error for a nonexistent customer' do
+ lambda { Braintree::Customer.find('foo') }.should raise_error(Braintree::NotFoundError)
end
end
-describe "Braintree::Customer.update" do
- it "successfully updates a customer" do
+describe 'Braintree::Customer.update' do
+ it 'successfully updates a customer' do
customer_id = create_customer.customer.id
- result = Braintree::Customer.update(customer_id, :first_name => "Jerry")
+ result = Braintree::Customer.update(customer_id, :first_name => 'Jerry')
result.should be_success
- Braintree::Customer.find(customer_id).first_name.should == "Jerry"
+ Braintree::Customer.find(customer_id).first_name.should == 'Jerry'
end
- it "raises an error for a nonexistent customer" do
- lambda { Braintree::Customer.update("foo", {:first_name => "Bob"}) }.should raise_error(Braintree::NotFoundError)
+ it 'raises an error for a nonexistent customer' do
+ lambda { Braintree::Customer.update('foo', {:first_name => 'Bob'}) }.should raise_error(Braintree::NotFoundError)
end
- it "does not allow a customer to be updated to a failing credit card" do
- bad_credit_card = "123456"
+ it 'does not allow a customer to be updated to a failing credit card' do
+ bad_credit_card = '123456'
FakeBraintree.registry.failures[bad_credit_card] = FakeBraintree.failure_response
customer = create_customer
@@ -120,8 +132,8 @@
end
end
-describe "Braintree::Customer.delete" do
- it "successfully deletes a customer" do
+describe 'Braintree::Customer.delete' do
+ it 'successfully deletes a customer' do
customer_id = create_customer.customer.id
result = Braintree::Customer.delete(customer_id)
8 spec/fake_braintree/registry_spec.rb
View
@@ -9,7 +9,7 @@
it { should have_hash_accessor_for(:credit_cards) }
end
-describe FakeBraintree::Registry, "#clear!" do
+describe FakeBraintree::Registry, '#clear!' do
it { should clear_hash_when_cleared(:customers) }
it { should clear_hash_when_cleared(:subscriptions) }
it { should clear_hash_when_cleared(:failures) }
@@ -18,12 +18,12 @@
it { should clear_hash_when_cleared(:credit_cards) }
end
-describe FakeBraintree::Registry, "#failure?" do
- it "returns false if the given CC number is not marked as a failure" do
+describe FakeBraintree::Registry, '#failure?' do
+ it 'returns false if the given CC number is not marked as a failure' do
registry.failure?('not-a-failure').should be_false
end
- it "returns true if the given CC number is marked as a failure" do
+ it 'returns true if the given CC number is marked as a failure' do
registry.failures['abc123'] = 'whatever'
registry.failure?('abc123').should be_true
end
75 spec/fake_braintree/subscription_spec.rb
View
@@ -1,59 +1,67 @@
require 'spec_helper'
-describe "Braintree::Subscription.create" do
+describe 'Braintree::Subscription.create' do
let(:plan_id) { 'plan-id-from-braintree-control-panel' }
- let(:expiration_date) { "04/2016" }
+ let(:expiration_date) { '04/2016' }
- it "successfully creates a subscription" do
- Braintree::Subscription.create(:payment_method_token => cc_token,
- :plan_id => 'my_plan_id').should be_success
+ it 'successfully creates a subscription' do
+ Braintree::Subscription.create(
+ :payment_method_token => cc_token,
+ :plan_id => 'my_plan_id'
+ ).should be_success
end
- it "assigns a Braintree-esque ID to the subscription" do
+ it 'assigns a Braintree-esque ID to the subscription' do
create_subscription.subscription.id.should =~ /^[a-z0-9]{6}$/
end
- it "assigns unique IDs to each subscription" do
+ it 'assigns unique IDs to each subscription' do
cc_token_1 = cc_token
cc_token_2 = braintree_credit_card_token(TEST_CC_NUMBER.sub('1', '5'), expiration_date)
- first_result = Braintree::Subscription.create(:payment_method_token => cc_token_1,
- :plan_id => plan_id)
- second_result = Braintree::Subscription.create(:payment_method_token => cc_token_2,
- :plan_id => plan_id)
+ first_result = Braintree::Subscription.create(
+ :payment_method_token => cc_token_1,
+ :plan_id => plan_id
+ )
+ second_result = Braintree::Subscription.create(
+ :payment_method_token => cc_token_2,
+ :plan_id => plan_id
+ )
first_result.subscription.id.should_not == second_result.subscription.id
end
- it "stores created subscriptions in FakeBraintree.registry.subscriptions" do
+ it 'stores created subscriptions in FakeBraintree.registry.subscriptions' do
FakeBraintree.registry.subscriptions[create_subscription.subscription.id].should_not be_nil
end
- it "sets the next billing date to a string of 1.month.from_now in UTC" do
+ it 'sets the next billing date to a string of 1.month.from_now in UTC' do
Timecop.freeze do
create_subscription.subscription.next_billing_date.should == 1.month.from_now.strftime('%Y-%m-%d')
end
end
end
-describe "Braintree::Subscription.find" do
- it "can find a created subscription" do
+describe 'Braintree::Subscription.find' do
+ it 'can find a created subscription' do
payment_method_token = cc_token
- plan_id = "abc123"
- subscription_id =
- create_subscription(:payment_method_token => payment_method_token, :plan_id => plan_id).subscription.id
+ plan_id = 'abc123'
+ subscription_id = create_subscription(
+ :payment_method_token => payment_method_token,
+ :plan_id => plan_id
+ ).subscription.id
subscription = Braintree::Subscription.find(subscription_id)
subscription.should_not be_nil
subscription.payment_method_token.should == payment_method_token
subscription.plan_id.should == plan_id
end
- it "raises a Braintree:NotFoundError when it cannot find a subscription" do
+ it 'raises a Braintree:NotFoundError when it cannot find a subscription' do
create_subscription
expect { Braintree::Subscription.find('abc123') }.to raise_error(Braintree::NotFoundError, /abc123/)
end
- it "returns add-ons added with the subscription" do
- add_on_id = "def456"
+ it 'returns add-ons added with the subscription' do
+ add_on_id = 'def456'
subscription_id = create_subscription(:add_ons => { :add => [{ :inherited_from_id => add_on_id }] }).subscription.id
subscription = Braintree::Subscription.find(subscription_id)
add_ons = subscription.add_ons
@@ -61,9 +69,16 @@
add_ons.first.id.should == add_on_id
end
- it "returns discounts added with the subscription" do
- discount_id = "def456"
- subscription_id = create_subscription(:discounts => { :add => [{ :inherited_from_id => discount_id, :amount => BigDecimal.new("15.00") }]}).subscription.id
+ it 'returns discounts added with the subscription' do
+ discount_id = 'def456'
+ subscription_id = create_subscription(
+ :discounts => {
+ :add => [{
+ :inherited_from_id => discount_id,
+ :amount => BigDecimal.new('15.00')
+ }]
+ }
+ ).subscription.id
subscription = Braintree::Subscription.find(subscription_id)
discounts = subscription.discounts
discounts.size.should == 1
@@ -71,8 +86,8 @@
end
end
-describe "Braintree::Subscription.update" do
- it "can update a subscription" do
+describe 'Braintree::Subscription.update' do
+ it 'can update a subscription' do
Braintree::Subscription.update(subscription_id, :plan_id => 'a_new_plan')
Braintree::Subscription.find(subscription_id).plan_id.should == 'a_new_plan'
end
@@ -81,14 +96,14 @@
let(:subscription) { create_subscription }
end
-describe "Braintree::Subscription.cancel" do
- it "can cancel a subscription" do
+describe 'Braintree::Subscription.cancel' do
+ it 'can cancel a subscription' do
Braintree::Subscription.cancel(subscription_id).should be_success
Braintree::Subscription.find(subscription_id).status.should == Braintree::Subscription::Status::Canceled
end
- it "can't cancel an unknown subscription" do
- expect { Braintree::Subscription.cancel("totally-bogus-id") }.to raise_error(Braintree::NotFoundError)
+ it 'cannot cancel an unknown subscription' do
+ expect { Braintree::Subscription.cancel('totally-bogus-id') }.to raise_error(Braintree::NotFoundError)
end
let(:subscription_id) { subscription.subscription.id }
24 spec/fake_braintree/transaction_spec.rb
View
@@ -1,16 +1,16 @@
require 'spec_helper'
describe FakeBraintree::SinatraApp do
- context "Braintree::Transaction.sale" do
- it "successfully creates a transaction" do
+ context 'Braintree::Transaction.sale' do
+ it 'successfully creates a transaction' do
result = Braintree::Transaction.sale(:payment_method_token => cc_token, :amount => 10.00)
result.should be_success
end
- context "when all cards are declined" do
+ context 'when all cards are declined' do
before { FakeBraintree.decline_all_cards! }
- it "fails" do
+ it 'fails' do
result = Braintree::Transaction.sale(:payment_method_token => cc_token, :amount => 10.00)
result.should_not be_success
end
@@ -19,8 +19,8 @@
end
describe FakeBraintree::SinatraApp do
- context "Braintree::Transaction.refund" do
- it "successfully refunds a transaction" do
+ context 'Braintree::Transaction.refund' do
+ it 'successfully refunds a transaction' do
result = Braintree::Transaction.refund(create_id('foobar'), '1')
result.should be_success
end
@@ -28,8 +28,8 @@
end
describe FakeBraintree::SinatraApp do
- context "Braintree::Transaction.void" do
- it "successfully voids a transaction" do
+ context 'Braintree::Transaction.void' do
+ it 'successfully voids a transaction' do
sale = Braintree::Transaction.sale(:payment_method_token => cc_token, :amount => 10.00)
result = Braintree::Transaction.void(sale.transaction.id)
result.should be_success
@@ -39,19 +39,19 @@
end
describe FakeBraintree::SinatraApp do
- context "Braintree::Transaction.find" do
- it "can find a created sale" do
+ context 'Braintree::Transaction.find' do
+ it 'can find a created sale' do
id = create_transaction.id
result = Braintree::Transaction.find(id)
result.amount.should == amount
end
- it "can find >1 transaction" do
+ it 'can find >1 transaction' do
Braintree::Transaction.find(create_transaction.id).should be
Braintree::Transaction.find(create_transaction.id).should be
end
- it "raises an error when the transaction does not exist" do
+ it 'raises an error when the transaction does not exist' do
expect { Braintree::Transaction.find('foobar') }.to raise_error(Braintree::NotFoundError)
end
34 spec/fake_braintree/transparent_redirect_spec.rb
View
@@ -1,29 +1,29 @@
require 'spec_helper'
describe FakeBraintree::SinatraApp do
- context "Braintree::TransparentRedirect.url" do
- it "returns a URL that will redirect with a token for the specified request" do
- redirect_url = "http://example.com/redirect_path"
+ context 'Braintree::TransparentRedirect.url' do
+ it 'returns a URL that will redirect with a token for the specified request' do
+ redirect_url = 'http://example.com/redirect_path'
response = post_transparent_redirect(:redirect_url => redirect_url, :customer => build_customer_hash)
- response.code.should == "303"
- response["Location"].should =~ %r{http://example\.com/redirect_path}
+ response.code.should == '303'
+ response['Location'].should =~ %r{http://example\.com/redirect_path}
params = parse_redirect(response)
- params[:http_status].should == "200"
+ params[:http_status].should == '200'
params[:id].should_not be_nil
params[:kind].should_not be_nil
end
- it "rejects submissions without transparent redirect data" do
+ it 'rejects submissions without transparent redirect data' do
response = post_transparent_redirect_without_data
- response.code.should == "422"
+ response.code.should == '422'
end
end
- context "Braintree::TransparentRedirect.confirm" do
- it "confirms and runs the specified request" do
- number = "4111111111111111"
+ context 'Braintree::TransparentRedirect.confirm' do
+ it 'confirms and runs the specified request' do
+ number = '4111111111111111'
customer_hash = build_customer_hash(:credit_card => { :number => number })
response = post_transparent_redirect(:customer => customer_hash)
query = parse_query(response)
@@ -33,23 +33,23 @@
result.should be_success
customer = Braintree::Customer.find(result.customer.id)
- customer.credit_cards.first.last_4.should == "1111"
+ customer.credit_cards.first.last_4.should == '1111'
end
end
def build_customer_hash(options = {})
{
:credit_card => {
- :number => "4111111111111111",
- :expiration_date => "4/2015",
- :cardholder_name => "Susie Spender"
+ :number => '4111111111111111',
+ :expiration_date => '4/2015',
+ :cardholder_name => 'Susie Spender'
}.update(options[:credit_card] || {})
}
end
def post_transparent_redirect(data)
params = data.dup
- redirect_url = params.delete(:redirect_url) || "http://example.com/redirect_path"
+ redirect_url = params.delete(:redirect_url) || 'http://example.com/redirect_path'
params[:tr_data] = Braintree::TransparentRedirect.create_customer_data(:redirect_url => redirect_url)
post_transparent_redirect_params(params)
end
@@ -71,6 +71,6 @@ def parse_redirect(response)
end
def parse_query(response)
- URI.parse(response["Location"]).query
+ URI.parse(response['Location']).query
end
end
84 spec/fake_braintree_spec.rb
View
@@ -1,13 +1,13 @@
require 'spec_helper'
-describe FakeBraintree, ".decline_all_cards!" do
- before { FakeBraintree.decline_all_cards! }
-
- it "declines all cards" do
+describe FakeBraintree, '.decline_all_cards!' do
+ it 'declines all cards' do
+ FakeBraintree.decline_all_cards!
create_sale.should_not be_success
end
- it "stops declining cards after clear! is called" do
+ it 'stops declining cards after clear! is called' do
+ FakeBraintree.decline_all_cards!
FakeBraintree.clear!
create_sale.should be_success
end
@@ -17,45 +17,43 @@ def create_sale
end
end
-describe FakeBraintree, ".log_file_path" do
- it "is tmp/log" do
+describe FakeBraintree, '.log_file_path' do
+ it 'is tmp/log' do
FakeBraintree.log_file_path.should == 'tmp/log'
end
end
describe Braintree::Configuration do
- subject { Braintree::Configuration }
-
- it "is running in the development environment" do
- subject.environment.should == :development
+ it 'is running in the development environment' do
+ Braintree::Configuration.environment.should == :development
end
- it "has some fake API credentials" do
- subject.merchant_id.should == "xxx"
- subject.public_key.should == "xxx"
- subject.private_key.should == "xxx"
+ it 'has some fake API credentials' do
+ Braintree::Configuration.merchant_id.should == 'xxx'
+ Braintree::Configuration.public_key.should == 'xxx'
+ Braintree::Configuration.private_key.should == 'xxx'
end
end
describe FakeBraintree do
- it "creates a log file" do
+ it 'creates a log file' do
File.exist?(FakeBraintree.log_file_path).should == true
end
- it "logs to the correct path" do
+ it 'logs to the correct path' do
Braintree::Configuration.logger.info('Logger test')
File.readlines(FakeBraintree.log_file_path).last.should == "Logger test\n"
end
end
-describe FakeBraintree, ".clear_log!" do
- it "clears the log file" do
+describe FakeBraintree, '.clear_log!' do
+ it 'clears the log file' do
write_to_log
- subject.clear_log!
- File.read(FakeBraintree.log_file_path).should == ""
+ FakeBraintree.clear_log!
+ File.read(FakeBraintree.log_file_path).should == ''
end
- it "is called by clear!" do
+ it 'is called by clear!' do
FakeBraintree.expects(:clear_log!)
FakeBraintree.clear!
end
@@ -65,12 +63,12 @@ def write_to_log
end
end
-describe FakeBraintree, "VALID_CREDIT_CARDS" do
- it "includes only credit cards that are valid in the Braintree sandbox" do
+describe FakeBraintree, 'VALID_CREDIT_CARDS' do
+ it 'includes only credit cards that are valid in the Braintree sandbox' do
FakeBraintree::VALID_CREDIT_CARDS.sort.should == valid_credit_cards.sort
end
- let(:valid_credit_cards) do
+ def valid_credit_cards
%w(4111111111111111 4005519200000004
4009348888881881 4012000033330026
4012000077777777 4012888888881881
@@ -82,59 +80,61 @@ def write_to_log
end
end
-describe FakeBraintree, ".failure_response" do
- it "can be called with no arguments" do
+describe FakeBraintree, '.failure_response' do
+ it 'can be called with no arguments' do
expect { FakeBraintree.failure_response }.not_to raise_error
end
end
-describe FakeBraintree, ".generate_transaction" do
- it "allows setting the subscription id" do
+describe FakeBraintree, '.generate_transaction' do
+ it 'allows setting the subscription id' do
transaction = FakeBraintree.generate_transaction(:subscription_id => 'foobar')
transaction['subscription_id'].should == 'foobar'
end
- it "allows setting created_at" do
+ it 'allows setting created_at' do
time = Time.now
transaction = FakeBraintree.generate_transaction(:created_at => time)
transaction['created_at'].should == time
end
- it "sets created_at to Time.now by default" do
+ it 'sets created_at to Time.now by default' do
Timecop.freeze do
transaction = FakeBraintree.generate_transaction
transaction['created_at'].should == Time.now
end
end
- it "has the correct amount" do
- transaction = FakeBraintree.generate_transaction(:amount => "20.00")
- transaction['amount'].should == "20.00"
+ it 'has the correct amount' do
+ transaction = FakeBraintree.generate_transaction(:amount => '20.00')
+ transaction['amount'].should == '20.00'
end
- it "allows no arguments" do
+ it 'allows no arguments' do
expect { FakeBraintree.generate_transaction }.not_to raise_error
end
- context "status_history" do
- it "returns a hash with a status_history key" do
+ context 'status_history' do
+ it 'returns a hash with a status_history key' do
FakeBraintree.generate_transaction(:amount => '20').should have_key('status_history')
end
- it "has a timestamp of Time.now" do
+ it 'has a timestamp of Time.now' do
Timecop.freeze do
- transaction = FakeBraintree.generate_transaction(:status => Braintree::Transaction::Status::Failed,
- :subscription_id => 'my_subscription_id')
+ transaction = FakeBraintree.generate_transaction(
+ :status => Braintree::Transaction::Status::Failed,
+ :subscription_id => 'my_subscription_id'
+ )
transaction['status_history'].first['timestamp'].should == Time.now
end
end
- it "has the desired amount" do
+ it 'has the desired amount' do
transaction = FakeBraintree.generate_transaction(:amount => '20.00')
transaction['status_history'].first['amount'].should == '20.00'
end
- it "has the desired status" do
+ it 'has the desired status' do
status = Braintree::Transaction::Status::Failed
transaction = FakeBraintree.generate_transaction(:status => status)
transaction['status_history'].first['status'].should == status
2  spec/spec_helper.rb
View
@@ -11,7 +11,7 @@ def clear_braintree_log
File.new('tmp/braintree_log', 'w').close
end
- Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}
clear_braintree_log
2  spec/support/braintree_helpers.rb
View
@@ -1,7 +1,7 @@
module BraintreeHelpers
def create_braintree_customer(cc_number, expiration_date)
Braintree::Customer.create(
- :email => "me@example.com",
+ :email => 'me@example.com',
:credit_card => {
:number => cc_number,
:expiration_date => expiration_date
2  spec/support/matchers/clear_hash_when_cleared.rb
View
@@ -1,6 +1,6 @@
RSpec::Matchers.define :clear_hash_when_cleared do |property|
match do |object|
- object.send(property.to_sym)["key"] = "value"
+ object.send(property.to_sym)['key'] = 'value'
object.clear!
object.send(property.to_sym).should be_empty
end
Something went wrong with that request. Please try again.