Skip to content

Instantly share code, notes, and snippets.

@janx
Created July 9, 2009 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janx/143370 to your computer and use it in GitHub Desktop.
Save janx/143370 to your computer and use it in GitHub Desktop.
# application/moneyhats/test/test_helper.rb
include ActiveMerchant::Billing
# application/moneyhats/test/test_helper.rb
def credit_card_hash(options = {})
{ :number => '1',
:first_name => 'Cody',
:last_name => 'Fauser',
:month => '8',
:year => "#{ Time.now.year + 1 }",
:verification_value => '123',
:type => 'visa'
}.update(options)
end
def credit_card(options = {})
ActiveMerchant::Billing::CreditCard.new( credit_card_hash(options) )
end
def address(options = {})
{ :name => 'Cody Fauser',
:address1 => '2500 Oak Mills Road',
:address2 => 'Suite 1000',
:city => 'Beverly Hills',
:state => 'CA',
:country => 'US',
:zip => '90210'
}.update(options)
end
# application/moneyhats/test/unit/order_transaction_test.rb
def setup
@amount = 100
end
def test_successful_authorization
auth = OrderTransaction.authorize(
@amount,
credit_card(:number => '1')
)
assert auth.success
assert_equal 'authorization', auth.action
assert_equal BogusGateway::SUCCESS_MESSAGE, auth.message
assert_equal BogusGateway::AUTHORIZATION, auth[:reference]
end
def test_failed_authorization
auth = OrderTransaction.authorize(
@amount,
credit_card(:number => '2')
)
assert !auth.success
assert_equal 'authorization', auth.action
assert_equal BogusGateway::FAILURE_MESSAGE, auth.message
end
def test_exception_during_authorization
auth = OrderTransaction.authorize(
@amount,
credit_card(:number => '3')
)
assert !auth.success
assert_equal 'authorization', auth.action
assert_equal BogusGateway::ERROR_MESSAGE, auth.message
end
# application/moneyhats/test/unit/order_transaction_test.rb
def test_successful_capture
capt = OrderTransaction.capture(@amount, '123')
assert capt.success
assert_equal 'capture', capt.action
assert_equal BogusGateway::SUCCESS_MESSAGE, capt.message
end
def test_failed_capture
capt = OrderTransaction.capture(@amount, '2')
assert !capt.success
assert_equal 'capture', capt.action
assert_equal BogusGateway::FAILURE_MESSAGE, capt.message
end
def test_error_during_capture
capt = OrderTransaction.capture(@amount, '1')
assert !capt.success
assert_equal 'capture', capt.action
assert_equal BogusGateway::CAPTURE_ERROR_MESSAGE, capt.message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment