Sha256: 3e10bb45aacde2a43dddff73429a9eb0943b0744cce7ea951aad3adc18e576c8

Contents?: true

Size: 1.54 KB

Versions: 12

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe DHS, type: :request do
  context 'autoloading' do
    let(:endpoints) { DHS::Record::Endpoints.all }

    it "pre/re-loads all DHS classes initialy, because it's necessary for endpoint-to-record-class-discovery", reset_before: false do
      expect(endpoints['http://datastore/v2/users']).to be_present
      expect(endpoints['http://datastore/v2/users/{id}']).to be_present

      expect(
        DummyUser.endpoints.detect { |endpoint| endpoint.url == 'http://datastore/v2/users' }
      ).to be_present
      expect(
        DummyUser.endpoints.detect { |endpoint| endpoint.url == 'http://datastore/v2/users/{id}' }
      ).to be_present
    end

    it "also pre/re-loads all DHS classes that inherited from an DHS provider, because it's necessary for endpoint-to-record-class-discovery", reset_before: false do
      expect(endpoints['http://customers']).to be_present
      expect(endpoints['http://customers/{id}']).to be_present

      expect(
        DummyCustomer.endpoints.detect { |endpoint| endpoint.url == 'http://customers' }
      ).to be_present
      expect(
        DummyCustomer.endpoints.detect { |endpoint| endpoint.url == 'http://customers/{id}' }
      ).to be_present

      customer_request = stub_request(:get, 'http://customers/1')
        .with(
          headers: {
            'Authorization' => 'token123'
          }
        )
        .to_return(body: { name: 'Steve' }.to_json)

      DummyCustomer.find(1)

      expect(customer_request).to have_been_requested
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 spec/autoloading_spec.rb
dhs-1.5.0 spec/autoloading_spec.rb
dhs-1.4.2 spec/autoloading_spec.rb
dhs-1.4.1 spec/autoloading_spec.rb
dhs-1.4.0 spec/autoloading_spec.rb
dhs-1.3.0 spec/autoloading_spec.rb
dhs-1.2.0 spec/autoloading_spec.rb
dhs-1.1.0 spec/autoloading_spec.rb
dhs-1.0.3 spec/autoloading_spec.rb
dhs-1.0.2 spec/autoloading_spec.rb
dhs-1.0.1 spec/autoloading_spec.rb
dhs-1.0.0 spec/autoloading_spec.rb