Sha256: c0d2423a4872cdceedf1d3f34dd26fd5b2eeae37399d307829b1f9732953e956

Contents?: true

Size: 905 Bytes

Versions: 3

Compression:

Stored size: 905 Bytes

Contents

module FakeBraintree
  class Address
    include Helpers

    def initialize(address_hash_from_params, options)
      set_up_address(address_hash_from_params, options)
    end

    def create
      @hash['id'] = generate_id
      FakeBraintree.registry.addresses[id] = @hash
      customer['addresses'] << @hash
      response_for_updated_address
    end

    def customer
      FakeBraintree.registry.customers[@hash['customer_id']]
    end

    def response_for_updated_address
      gzipped_response(200, @hash.to_xml(root: 'address'))
    end

    def set_up_address(address_hash_from_params, options)
      @hash = {
        "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}"
    end

    def id
      @hash['id']
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fake_braintree-0.4.3 lib/fake_braintree/address.rb
fake_braintree-0.4.2 lib/fake_braintree/address.rb
fake_braintree-0.4.1 lib/fake_braintree/address.rb