Sha256: 4dc398de06f5ea268a6bf710cc3fcc893b6c9f656ecdcf8abecf0bd42ad4b570

Contents?: true

Size: 1.67 KB

Versions: 19

Compression:

Stored size: 1.67 KB

Contents

require 'rails_helper'

describe LHS::Proxy do
  before do
    class Record < LHS::Record
      endpoint '{+datastore}/v2/feedbacks'
    end

    stub_request(:get, 'http://local.ch/v2/content-ads/51dfc5690cf271c375c5a12d')
      .to_return(status: 200, body: load_json(:localina_content_ad))
  end

  let(:json) do
    load_json(:feedbacks)
  end

  let(:data) do
    LHS::Data.new(json, nil, Record)
  end

  let(:item) do
    data[0]
  end

  let(:link) do
    item.campaign
  end

  context 'load' do
    it 'is loading data remotely when not present yet' do
      expect(link.load!.id).to be_present
      expect(link.id).to be_present
    end

    it 'can be reloaded' do
      expect(link.load!.id).to be_present
      stub_request(:get, 'http://local.ch/v2/content-ads/51dfc5690cf271c375c5a12d')
        .to_return(status: 404)
      expect(-> { link.reload!.id })
        .to raise_error LHC::NotFound
    end
  end

  context 'endpoint options' do
    before do
      class AnotherRecord < LHS::Record
        endpoint '{+datastore}/v2/feedbacks', params: { color: :blue }
      end
    end

    let(:record) do
      AnotherRecord.new(href: 'http://datastore/v2/feedbacks')
    end

    it 'applies endpoint options on load!' do
      stub_request(:get, 'http://datastore/v2/feedbacks?color=blue')
        .to_return(body: {}.to_json)
      record.load!
    end
  end

  context 'per request options' do
    let(:record) do
      Record.new(href: 'http://datastore/v2/feedbacks')
    end

    it 'applies options passed to load' do
      stub_request(:get, 'http://datastore/v2/feedbacks?color=blue')
        .to_return(body: {}.to_json)
      record.load!(params: { color: 'blue' })
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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