Permalink
Browse files

Rename variable to be more descriptive

  • Loading branch information...
1 parent 3230e35 commit 49a38ad6897a6ec3ecf07c6396212e7c83cdd025 @gabebw gabebw committed May 25, 2014
Showing with 34 additions and 34 deletions.
  1. +8 −8 lib/fake_braintree/address.rb
  2. +26 −26 lib/fake_braintree/credit_card.rb
@@ -7,33 +7,33 @@ def initialize(address_hash_from_params, options)
end
def create
- @hash['id'] = generate_id
- FakeBraintree.registry.addresses[id] = @hash
- customer['addresses'] << @hash
+ @address['id'] = generate_id
+ FakeBraintree.registry.addresses[id] = @address
+ customer['addresses'] << @address
response_for_updated_address
end
def customer
- FakeBraintree.registry.customers[@hash['customer_id']]
+ FakeBraintree.registry.customers[@address['customer_id']]
end
def response_for_updated_address
- gzipped_response(200, @hash.to_xml(root: 'address'))
+ gzipped_response(200, @address.to_xml(root: 'address'))
end
def set_up_address(address_hash_from_params, options)
- @hash = {
+ @address = {
"merchant_id" => options[:merchant_id],
"customer_id" => options[:customer_id],
}.merge(address_hash_from_params)
end
def generate_id
- "#{@hash['customer_id']}_#{customer['addresses'].size}"
+ "#{@address['customer_id']}_#{customer['addresses'].size}"
end
def id
- @hash['id']
+ @address['id']
end
end
end
@@ -15,11 +15,11 @@ def initialize(credit_card_hash_from_params, options)
def create
if valid_number?
if token.nil?
- @hash['token'] = generate_token
+ @credit_card['token'] = generate_token
end
- FakeBraintree.registry.credit_cards[token] = @hash
- if customer = FakeBraintree.registry.customers[@hash['customer_id']]
- customer['credit_cards'] << @hash
+ FakeBraintree.registry.credit_cards[token] = @credit_card
+ if customer = FakeBraintree.registry.customers[@credit_card['customer_id']]
+ customer['credit_cards'] << @credit_card
update_default_card
end
response_for_updated_card
@@ -38,14 +38,14 @@ def update
end
def to_xml
- @hash.to_xml(root: 'credit_card')
+ @credit_card.to_xml(root: 'credit_card')
end
def valid_number?
if FakeBraintree.decline_all_cards?
false
elsif FakeBraintree.verify_all_cards
- FakeBraintree::VALID_CREDIT_CARDS.include?(@hash['number'])
+ FakeBraintree::VALID_CREDIT_CARDS.include?(@credit_card['number'])
else
true
end
@@ -54,23 +54,23 @@ def valid_number?
private
def update_existing_credit_card
- @hash = credit_card_from_registry.merge!(@hash)
+ @credit_card = credit_card_from_registry.merge!(@credit_card)
update_default_card
end
# When updating a card that has 'default' set to true, make sure only one
# card has the flag.
def update_default_card
- if @hash['default']
- FakeBraintree.registry.customers[@hash['customer_id']]['credit_cards'].each do |card|
+ if @credit_card['default']
+ FakeBraintree.registry.customers[@credit_card['customer_id']]['credit_cards'].each do |card|
card['default'] = false
end
- @hash['default'] = true
+ @credit_card['default'] = true
end
end
def response_for_updated_card
- gzipped_response(200, @hash.to_xml(root: 'credit_card'))
+ gzipped_response(200, @credit_card.to_xml(root: 'credit_card'))
end
def credit_card_exists_in_registry?
@@ -87,7 +87,7 @@ def response_for_card_not_found
def response_for_invalid_card
body = FakeBraintree.failure_response.merge(
- 'params' => {credit_card: @hash}
+ 'params' => {credit_card: @credit_card}
).to_xml(root: 'api_error_response')
gzipped_response(422, body)
@@ -102,7 +102,7 @@ def expiration_year
end
def set_up_credit_card(credit_card_hash_from_params, options)
- @hash = {
+ @credit_card = {
'token' => options[:token],
'merchant_id' => options[:merchant_id],
'customer_id' => options[:customer_id],
@@ -111,52 +111,52 @@ def set_up_credit_card(credit_card_hash_from_params, options)
end
def set_billing_address
- if @hash["billing_address_id"]
- @hash["billing_address"] = FakeBraintree.registry.addresses[@hash['billing_address_id']]
+ if @credit_card["billing_address_id"]
+ @credit_card["billing_address"] = FakeBraintree.registry.addresses[@credit_card['billing_address_id']]
end
end
def set_bin
- @hash['bin'] = number[0, 6]
+ @credit_card['bin'] = number[0, 6]
end
def set_card_type
- @hash['card_type'] = 'FakeBraintree'
+ @credit_card['card_type'] = 'FakeBraintree'
end
def set_expiration_month_and_year
if expiration_month
- @hash['expiration_month'] = expiration_month
+ @credit_card['expiration_month'] = expiration_month
end
if expiration_year
- @hash['expiration_year'] = expiration_year
+ @credit_card['expiration_year'] = expiration_year
end
end
def set_last_4
- @hash['last_4'] = number[-4, 4]
+ @credit_card['last_4'] = number[-4, 4]
end
def number
- @hash['number'].to_s
+ @credit_card['number'].to_s
end
def set_unique_number_identifier
- @hash["unique_number_identifier"] = number
+ @credit_card["unique_number_identifier"] = number
end
def generate_token
- md5("#{@hash['number']}#{@hash['merchant_id']}")
+ md5("#{@credit_card['number']}#{@credit_card['merchant_id']}")
end
def token
- @hash['token']
+ @credit_card['token']
end
def expiration_date_parts
- if @hash.key?('expiration_date')
- @hash['expiration_date'].split('/')
+ if @credit_card.key?('expiration_date')
+ @credit_card['expiration_date'].split('/')
else
[]
end

0 comments on commit 49a38ad

Please sign in to comment.