Sha256: fcc9ad9fe39c9aea003078fbfbfba375305bf1cb5f179c0241ba73267914827c

Contents?: true

Size: 1.54 KB

Versions: 29

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require "rails_helper"

describe LHS, type: :request do
  context 'autoloading' do

    let(:endpoints) { LHS::Record::Endpoints.all }

    it "pre/re-loads all LHS 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 LHS classes that inherited from an LHS 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

29 entries across 29 versions & 1 rubygems

Version Path
lhs-26.2.0 spec/autoloading_spec.rb
lhs-26.1.0 spec/autoloading_spec.rb
lhs-26.0.1 spec/autoloading_spec.rb
lhs-26.0.0 spec/autoloading_spec.rb
lhs-25.2.0 spec/autoloading_spec.rb
lhs-25.1.0 spec/autoloading_spec.rb
lhs-25.0.4 spec/autoloading_spec.rb
lhs-25.0.3 spec/autoloading_spec.rb
lhs-25.0.2 spec/autoloading_spec.rb
lhs-25.0.1 spec/autoloading_spec.rb
lhs-25.0.0 spec/autoloading_spec.rb
lhs-24.1.2 spec/autoloading_spec.rb
lhs-24.1.1 spec/autoloading_spec.rb
lhs-24.1.0 spec/autoloading_spec.rb
lhs-24.1.0.pre.2 spec/autoloading_spec.rb
lhs-24.1.0.pre.1 spec/autoloading_spec.rb
lhs-24.0.0 spec/autoloading_spec.rb
lhs-23.0.2 spec/autoloading_spec.rb
lhs-23.0.1 spec/autoloading_spec.rb
lhs-23.0.0 spec/autoloading_spec.rb