Created
July 9, 2009 02:15
-
-
Save janx/143370 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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