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-26.2.0 spec/record/scope_chains_spec.rb
lhs-26.1.0 spec/record/scope_chains_spec.rb
lhs-26.0.1 spec/record/scope_chains_spec.rb
lhs-26.0.0 spec/record/scope_chains_spec.rb
lhs-25.2.0 spec/record/scope_chains_spec.rb
lhs-25.1.0 spec/record/scope_chains_spec.rb
lhs-25.0.4 spec/record/scope_chains_spec.rb
lhs-25.0.3 spec/record/scope_chains_spec.rb
lhs-25.0.2 spec/record/scope_chains_spec.rb
lhs-25.0.1 spec/record/scope_chains_spec.rb
lhs-25.0.0 spec/record/scope_chains_spec.rb
lhs-24.1.2 spec/record/scope_chains_spec.rb
lhs-24.1.1 spec/record/scope_chains_spec.rb
lhs-24.1.0 spec/record/scope_chains_spec.rb
lhs-24.1.0.pre.2 spec/record/scope_chains_spec.rb
lhs-24.1.0.pre.1 spec/record/scope_chains_spec.rb
lhs-24.0.0 spec/record/scope_chains_spec.rb
lhs-23.0.2 spec/record/scope_chains_spec.rb
lhs-23.0.1 spec/record/scope_chains_spec.rb
lhs-23.0.0 spec/record/scope_chains_spec.rb