Sha256: 59c12389cb4e323e0921d1321245835d8904aeb0f7a05a1ca465715e44dbb274

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__) + '/../lib')

require 'test/unit'
require 'digest/md5'
require 'active_fulfillment'

begin
  require 'mocha'
rescue LoadError
  require 'rubygems'
  require 'mocha'
end

module Test
  module Unit
    class TestCase
      include ActiveMerchant::Fulfillment
      
      LOCAL_CREDENTIALS = ENV['HOME'] + '/.active_merchant/fixtures.yml' unless defined?(LOCAL_CREDENTIALS)
      DEFAULT_CREDENTIALS = File.dirname(__FILE__) + '/fixtures.yml' unless defined?(DEFAULT_CREDENTIALS)
      
      def generate_order_id
        md5 = Digest::MD5.new
        now = Time.now
        md5 << now.to_s
        md5 << String(now.usec)
        md5 << String(rand(0))
        md5 << String($$)
        md5 << self.class.name
        md5.hexdigest
      end

      def all_fixtures
        @@fixtures ||= load_fixtures
      end
      
      def fixtures(key)
        data = all_fixtures[key] || raise(StandardError, "No fixture data was found for '#{key}'")
        
        data.dup
      end
          
      def load_fixtures
        file = File.exists?(LOCAL_CREDENTIALS) ? LOCAL_CREDENTIALS : DEFAULT_CREDENTIALS
        yaml_data = YAML.load(File.read(file))
        symbolize_keys(yaml_data)
      
        yaml_data
      end

      def xml_fixture(path) # where path is like 'usps/beverly_hills_to_ottawa_response'
        open(File.join(File.dirname(__FILE__),'fixtures','xml',"#{path}.xml")) {|f| f.read}
      end
      
      def symbolize_keys(hash)
        return unless hash.is_a?(Hash)
        
        hash.symbolize_keys!
        hash.each{|k,v| symbolize_keys(v)}
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_fulfillment-1.0.3 test/test_helper.rb
active_fulfillment-1.0.2 test/test_helper.rb
active_fulfillment-1.0.1 test/test_helper.rb
active_fulfillment-1.0.0 test/test_helper.rb