有一個類似於RailsCasts ActiveMerchant tutorial的交易模式。使用ActiveMerchant響應強制假響應
如何創建假回覆?
試過類似下面的東西,但沒有運氣。
response = @success=true, @params = {"ref" => "123"}, @authorization = "54321", ...
型號/ order_transaction.rb
class OrderTransaction < ActiveRecord::Base
belongs_to :order
serialize :params
def response=(response)
self.success = response.success?
self.authorization = response.authorization
self.message = response.message
self.params = response.params
rescue ActiveMerchant::ActiveMerchantError => e
self.success = false
self.authorization = nil
self.message = e.message
self.params = {}
end
end
使用OpenStruct? – rogerdpack 2010-08-24 22:00:53
是,是,是。除response.success之外的所有內容?工作中。我像上面一樣使用它。 response = OpenStruct.new,然後傳入response.success = true – pcasa 2010-08-24 22:31:10