Sha256: 960d3b4849ca1e118332273e4da49cb22fc9ec07c45f42c59b87d1982372ac55

Contents?: true

Size: 1.6 KB

Versions: 76

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Record do
  context 'inherit endpoints' do
    before do
      class Base < LHS::Record
        endpoint 'records/{id}'
      end

      class Example < Base
      end
    end

    it 'inherits endpoints based on ruby class_attribute behaviour' do
      request = stub_request(:get, 'http://records/1').to_return(body: [].to_json)
      Example.find(1)
      Base.find(1)
      assert_requested(request, times: 2)
    end
  end

  context 'define endpoints in subclass' do
    before do
      class Base < LHS::Record
        endpoint 'records/{id}'
      end

      class Example < Base
        endpoint 'records'
      end
    end

    it 'inherits endpoints based on ruby class_attribute behaviour' do
      stub_request(:get, 'http://records?color=blue').to_return(body: [].to_json)
      Example.where(color: 'blue')
      expect(
        -> { Base.all.first }
      ).to raise_error(RuntimeError, 'Compilation incomplete. Unable to find value for id.')
    end
  end

  context 'ambiguous endpoints between super and subclass' do
    before do
      class Base < LHS::Record
        endpoint 'records'
      end

      class Example < Base
        endpoint 'examples/{id}'
      end
    end

    it 'inherits endpoints based on ruby class_attribute behaviour' do
      request = stub_request(:get, 'http://records?limit=100').to_return(body: [].to_json)
      Base.all.first
      assert_requested(request)

      request = stub_request(:get, 'http://examples/1').to_return(body: {}.to_json)
      Example.find(1)
      assert_requested(request)
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
lhs-22.1.1.pre spec/record/endpoint_inheritance_spec.rb
lhs-22.1.0 spec/record/endpoint_inheritance_spec.rb
lhs-22.0.0 spec/record/endpoint_inheritance_spec.rb
lhs-21.3.1 spec/record/endpoint_inheritance_spec.rb
lhs-21.3.0 spec/record/endpoint_inheritance_spec.rb
lhs-21.3.0.pre.autoauth.1 spec/record/endpoint_inheritance_spec.rb
lhs-21.2.4 spec/record/endpoint_inheritance_spec.rb
lhs-21.2.3 spec/record/endpoint_inheritance_spec.rb
lhs-21.2.3.pre.preload.pre.providers.pre.too.1 spec/record/endpoint_inheritance_spec.rb
lhs-21.2.2 spec/record/endpoint_inheritance_spec.rb
lhs-21.2.1 spec/record/endpoint_inheritance_spec.rb
lhs-21.2.0 spec/record/endpoint_inheritance_spec.rb
lhs-21.1.4 spec/record/endpoint_inheritance_spec.rb
lhs-21.1.3 spec/record/endpoint_inheritance_spec.rb
lhs-21.1.2 spec/record/endpoint_inheritance_spec.rb
lhs-21.1.2.pre.keyfix.2 spec/record/endpoint_inheritance_spec.rb
lhs-21.1.2.pre.keyfix.1 spec/record/endpoint_inheritance_spec.rb
lhs-21.1.2.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 spec/record/endpoint_inheritance_spec.rb
lhs-21.1.1.pre.pre.fix.pre.cant.pre.add.pre.new.pre.key.pre.during.pre.iteration.1 spec/record/endpoint_inheritance_spec.rb
lhs-21.1.0 spec/record/endpoint_inheritance_spec.rb