Sha256: bf065fc37dc434d276489b6e5c2a9e124cd39629cf9f65060e8b74948f880cc4

Contents?: true

Size: 1.38 KB

Versions: 19

Compression:

Stored size: 1.38 KB

Contents

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/'

      def uppercase_name
        name.upcase
      end
    end
  end

  context 'where chains' do
    before do
      stub_request(:get, "http://datastore/v2/records/?available=true&color=blue&range=%3E26")
        .to_return(response)
    end

    let(:records) { Record.where(color: 'blue').where(range: '>26').where(available: true) }

    it 'allows chaining where statements' do
      expect(records.class).to eq Record
      expect(records._raw).to eq [{ name: 'Steve' }]
      expect(records.first.uppercase_name).to eq 'STEVE'
    end

    it 'resolves triggered by method missing' do
      expect(records._raw).to eq [{ name: 'Steve' }]
      expect(
        Record.where(color: 'blue').where(range: '>26', available: true).first.name
      ).to eq 'Steve'
    end
  end

  context 'multiple parameters' do
    before do
      stub_request(:get, "http://datastore/v2/records/?parameter=last").to_return(response)
    end

    it 'takes the last value for chains with same name parameters' do
      records = Record.where(parameter: 'first').where(parameter: 'last')
      records.first
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
lhs-16.1.5 spec/record/where_chains_spec.rb
lhs-16.1.4 spec/record/where_chains_spec.rb
lhs-16.1.3 spec/record/where_chains_spec.rb
lhs-16.1.2 spec/record/where_chains_spec.rb
lhs-16.1.1 spec/record/where_chains_spec.rb
lhs-16.1.0 spec/record/where_chains_spec.rb
lhs-16.0.1 spec/record/where_chains_spec.rb
lhs-16.0.0 spec/record/where_chains_spec.rb
lhs-15.7.0 spec/record/where_chains_spec.rb
lhs-15.6.1 spec/record/where_chains_spec.rb
lhs-15.6.0 spec/record/where_chains_spec.rb
lhs-15.5.1 spec/record/where_chains_spec.rb
lhs-15.5.0 spec/record/where_chains_spec.rb
lhs-15.4.1 spec/record/where_chains_spec.rb
lhs-15.4.0 spec/record/where_chains_spec.rb
lhs-15.4.0.pre.hasone.1 spec/record/where_chains_spec.rb
lhs-15.3.3 spec/record/where_chains_spec.rb
lhs-15.3.3.pre.fixoptions.1 spec/record/where_chains_spec.rb
lhs-15.3.2 spec/record/where_chains_spec.rb