Sha256: 204a0a05e88aa30d425b2178c7c48564dbd65fa4917aaa8865b600396bf41a63

Contents?: true

Size: 1.06 KB

Versions: 76

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

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

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

  before do
    LHC.config.placeholder('datastore', datastore)
    class Record < LHS::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

76 entries across 76 versions & 1 rubygems

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