Sha256: 9c6ae2ee2d9223eef9800b0327657b58af819e7f88bd589508e4470d24b37708

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe DHS::Record do
  let(:datastore) do
    'http://datastore/v2'
  end

  let(:response) do
    { body: [{ name: 'Steve' }] }
  end

  before do
    DHC.config.placeholder('datastore', datastore)
    class Record < DHS::Record
      endpoint '{+datastore}/records/'
      scope :blue, -> { where(color: 'blue') }
      scope :available, -> { where(availalbe: 'true') }
      scope :limited_to, ->(limit) { where(limit: limit) }
    end
  end

  context 'scope chains' do
    it 'allows chaining multiple scopes' do
      stub_request(:get, 'http://datastore/v2/records/?availalbe=true&color=blue&limit=20').to_return(response)
      expect(
        Record.blue.available.limited_to(20).first.name
      ).to eq 'Steve'
    end

    it 'allows to chain multiple scopes when first one has arguments' do
      stub_request(:get, 'http://datastore/v2/records/?availalbe=true&color=blue&limit=20').to_return(response)
      expect(
        Record.limited_to(20).blue.available.first.name
      ).to eq 'Steve'
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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