Sha256: 09b08d229d294a11ab0025d828f278878a76d34c5512d68e0b8bb4cfa8f9400f

Contents?: true

Size: 1.23 KB

Versions: 19

Compression:

Stored size: 1.23 KB

Contents

require 'rails_helper'

describe LHS::Record do
  before do
    class Record < LHS::Record
      endpoint 'http://datastore/records'
      endpoint 'http://datastore/records/{id}'
    end

    class AnotherRecord < LHS::Record
      endpoint 'http://datastore/otherrecords'
      endpoint 'http://datastore/otherrecords/{id}'

      def id
        another_id
      end
    end
  end

  context 'reload!' do
    it 'reloads the record by id' do
      stub_request(:post, "http://datastore/records")
        .to_return(body: { id: 1, name: 'Steve' }.to_json)
      record = Record.create!(name: 'Steve')
      stub_request(:get, "http://datastore/records/1")
        .to_return(body: { id: 1, name: 'Steve', async: 'data' }.to_json)
      record.reload!
      expect(record.async).to eq 'data'
    end

    it 'reloads the record by id if a record method defines the actual id' do
      stub_request(:post, "http://datastore/otherrecords")
        .to_return(body: { another_id: 2, name: 'Can' }.to_json)
      record = AnotherRecord.create!(name: 'Can')
      stub_request(:get, "http://datastore/otherrecords/2")
        .to_return(body: { id: 2, name: 'Can', async: 'data' }.to_json)
      record.reload!
      expect(record.async).to eq 'data'
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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