Sha256: 6de21b7b7e0ca0fdf84f5da2844df118958979f350b08796d381733c89d7a579

Contents?: true

Size: 1.27 KB

Versions: 25

Compression:

Stored size: 1.27 KB

Contents

require 'rails_helper'

describe LHS::Item do

  before(:each) do
    class SomeService < LHS::Service
      endpoint ':datastore/v2/:campaign_id/feedbacks'
      endpoint ':datastore/v2/feedbacks'
    end
  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 'save' do

    it 'persists changes on the backend' do
      stub_request(:post, item.href)
      .with(body: item._raw.merge(name: 'Steve').to_json)
      item.name = 'Steve'
      expect(item.save).to eq true
    end

    it 'returns false if persting goes wrong' do
      stub_request(:post, item.href)
      .with(body: item._raw.to_json)
      .to_return(status: 500)
      expect(item.save).to eq false
    end

    it 'merges reponse data with object' do
      stub_request(:post, item.href)
      .with(body: item._raw.to_json)
      .to_return(status: 200, body: item._raw.merge(name: 'Steve').to_json)
      item.save
      expect(item.name).to eq 'Steve'
    end
  end

  context 'save!' do

    it 'raises if something goes wrong' do
      stub_request(:post, item.href)
      .with(body: item._raw.to_json)
      .to_return(status: 500)
      expect(->{ item.save! }).to raise_error LHC::ServerError
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
lhs-2.2.2 spec/item/save_spec.rb
lhs-1.6.1 spec/item/save_spec.rb
lhs-2.2.1 spec/item/save_spec.rb
lhs-2.2.0 spec/item/save_spec.rb
lhs-1.6.0 spec/item/save_spec.rb
lhs-2.1.1 spec/item/save_spec.rb
lhs-2.1.0 spec/item/save_spec.rb
lhs-2.0.5 spec/item/save_spec.rb
lhs-2.0.4 spec/item/save_spec.rb
lhs-2.0.3 spec/item/save_spec.rb
lhs-2.0.2 spec/item/save_spec.rb
lhs-2.0.1 spec/item/save_spec.rb
lhs-2.0.0 spec/item/save_spec.rb
lhs-1.5.0 spec/item/save_spec.rb
lhs-1.4.0 spec/item/save_spec.rb
lhs-1.3.1 spec/item/save_spec.rb
lhs-1.3.0 spec/item/save_spec.rb
lhs-1.2.3 spec/item/save_spec.rb
lhs-1.2.2 spec/item/save_spec.rb
lhs-1.2.1 spec/item/save_spec.rb