Sha256: 14ba965b9d73c7bc7d41e46761bff93b86ef2e965d7e881129b70dd6a88f904f

Contents?: true

Size: 1019 Bytes

Versions: 1

Compression:

Stored size: 1019 Bytes

Contents

require 'nokogiri'
require 'fake_chargify/statement'

module FakeChargify
  class StatementRegistry
    include UrlParser
    
    def repository
      @statements ||= []
    end
    
    def stub_requests!
      stub_list!
    end
    
    private
    
    def stub_list!
      WebMock::API.stub_request(:get, /https:\/\/#{FakeChargify.configuration.api_key}:X@#{FakeChargify.configuration.subdomain}.chargify.com\/subscriptions\/#{/\d/}\/statements.xml/).
        to_return(:status => 200, :body => lambda { |request| 
          subscription_id = request.uri.path.match(/(\/\d.statements.(xml|json)\z)/)[0].match(/\d/)[0].to_i
          statements = FakeChargify.statements.repository.select { |s| s.subscription_id == subscription_id }
          builder = Nokogiri::XML::Builder.new do |xml|
            xml.statements(:type => 'array') {
              statements.each { |statement| xml << Nokogiri.XML(statement.to_xml).root.to_xml }
            }
          end
          builder.to_xml
        })
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fake_chargify-0.1.0 lib/fake_chargify/statement_registry.rb