Sha256: 5a767ab47714db91e205bfa8fab7b6c52482c42e7baf0ad0de9043a521e9bed3

Contents?: true

Size: 1.73 KB

Versions: 15

Compression:

Stored size: 1.73 KB

Contents

require 'rails_helper'

describe LHS::Record do
  let(:datastore) { 'http://local.ch/v2' }

  before(:each) do
    LHC.config.placeholder(:datastore, datastore)
    class Record < LHS::Record
      endpoint ':datastore/content-ads/:campaign_id/feedbacks'
      endpoint ':datastore/content-ads/:campaign_id/feedbacks/:id'
      endpoint ':datastore/feedbacks'
      endpoint ':datastore/feedbacks/:id'
    end
  end

  context 'find_by' do
    it 'finds a single record' do
      stub_request(:get, "#{datastore}/feedbacks/z12f-3asm3ngals?limit=1")
        .to_return(status: 200, body: load_json(:feedback))
      record = Record.find_by(id: 'z12f-3asm3ngals')
      expect(record.source_id).to be_kind_of String
      expect(record).to be_kind_of Record
    end

    it 'returns nil if no record was found' do
      stub_request(:get, "#{datastore}/feedbacks/something-inexistent?limit=1")
        .to_return(status: 404)
      expect(
        Record.find_by(id: 'something-inexistent')
      ).to eq nil
    end

    it 'return first item by parameters' do
      json = load_json(:feedbacks)
      stub_request(:get, "#{datastore}/feedbacks?has_reviews=true&limit=1")
        .to_return(status: 200, body: json)
      expect(
        Record.find_by(has_reviews: true).id
      ).to eq json['items'].first['id']
    end

    it 'returns nil if empty id' do
      expect { Record.find_by(id: '') }.to raise_error LHS::Unprocessable
    end
  end

  context 'find_by!' do
    it 'raises if nothing was found with parameters' do
      stub_request(:get, "#{datastore}/feedbacks?has_reviews=true&limit=1")
        .to_return(status: 200, body: { items: [] }.to_json)
      expect { Record.find_by!(has_reviews: true) }
        .to raise_error LHC::NotFound
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
lhs-14.6.5 spec/record/find_by_spec.rb
lhs-14.6.4 spec/record/find_by_spec.rb
lhs-14.6.3 spec/record/find_by_spec.rb
lhs-14.6.2 spec/record/find_by_spec.rb
lhs-14.6.1 spec/record/find_by_spec.rb
lhs-14.6.0 spec/record/find_by_spec.rb
lhs-14.5.0 spec/record/find_by_spec.rb
lhs-14.4.0 spec/record/find_by_spec.rb
lhs-14.3.4 spec/record/find_by_spec.rb
lhs-14.3.3 spec/record/find_by_spec.rb
lhs-14.3.2 spec/record/find_by_spec.rb
lhs-14.3.1 spec/record/find_by_spec.rb
lhs-14.3.0 spec/record/find_by_spec.rb
lhs-14.2.0 spec/record/find_by_spec.rb
lhs-14.1.1 spec/record/find_by_spec.rb