Sha256: edbeb29b2f225d2c8693c43814986d21e6db88ce8bac63ae5623df6521827e7a

Contents?: true

Size: 1.79 KB

Versions: 15

Compression:

Stored size: 1.79 KB

Contents

require 'rails_helper'

describe LHS::Item do

  before(:each) do
    LHC.config.placeholder('datastore', datastore)
    class SomeService < LHS::Service
      endpoint ':datastore/v2/:campaign_id/feedbacks'
      endpoint ':datastore/v2/feedbacks'
    end
  end

  let(:datastore) do
    'http://local.ch'
  end

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

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

  let(:item) do
    data[0]
  end

  context 'destroy' do

    it 'destroys the item on the backend' do
      stub_request(:delete, "#{datastore}/v2/feedbacks/0sdaetZ-OWVg4oBiBJ-7IQ")
      .to_return(status: 200)
      expect(item.destroy._raw).to eq item._raw
    end

    it 'updates the request information on the item' do
      no_content = 204
      stub_request(:delete, "#{datastore}/v2/feedbacks/0sdaetZ-OWVg4oBiBJ-7IQ")
        .to_return(status: no_content)
      expect(item.destroy._request.response.code).to eq no_content
    end

    context 'includes and empty response' do
      before(:each) do
        class AnotherService < LHS::Service
          endpoint ':datastore/v2/:campaign_id/restaurants'
        end
      end

      it 'destroys an item even though it includes additonal services and an empty response body' do
        stub_request(:delete, "#{datastore}/v2/feedbacks/1")
          .to_return(status: 204, body: '')
        data = { href: "#{datastore}/v2/feedbacks/1", restaurant: {href: "#{datastore}/v2/restaurants/1"} }
        stub_request(:get, "#{datastore}/v2/feedbacks?id=1")
          .to_return(status: 200, body: data.to_json)
        stub_request(:get, "#{datastore}/v2/restaurants/1")
          .to_return(status: 200, body: {name: 'Casa Ferlin'}.to_json)
        item = SomeService.includes(:restaurant).find(1)
        item.destroy
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
lhs-2.2.2 spec/item/destroy_spec.rb
lhs-1.6.1 spec/item/destroy_spec.rb
lhs-2.2.1 spec/item/destroy_spec.rb
lhs-2.2.0 spec/item/destroy_spec.rb
lhs-1.6.0 spec/item/destroy_spec.rb
lhs-2.1.1 spec/item/destroy_spec.rb
lhs-2.1.0 spec/item/destroy_spec.rb
lhs-2.0.5 spec/item/destroy_spec.rb
lhs-2.0.4 spec/item/destroy_spec.rb
lhs-2.0.3 spec/item/destroy_spec.rb
lhs-2.0.2 spec/item/destroy_spec.rb
lhs-2.0.1 spec/item/destroy_spec.rb
lhs-2.0.0 spec/item/destroy_spec.rb
lhs-1.5.0 spec/item/destroy_spec.rb
lhs-1.4.0 spec/item/destroy_spec.rb