Sha256: 63b872cd6ccffdced31be8549d7cc8f6dd87d145ac098a4e2931cf91e82a6157

Contents?: true

Size: 1.24 KB

Versions: 29

Compression:

Stored size: 1.24 KB

Contents

require 'rails_helper'

describe LHS::Record do
  before(:each) 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

29 entries across 29 versions & 1 rubygems

Version Path
lhs-14.6.5 spec/record/reload_by_id_spec.rb
lhs-14.6.4 spec/record/reload_by_id_spec.rb
lhs-14.6.3 spec/record/reload_by_id_spec.rb
lhs-14.6.2 spec/record/reload_by_id_spec.rb
lhs-14.6.1 spec/record/reload_by_id_spec.rb
lhs-14.6.0 spec/record/reload_by_id_spec.rb
lhs-14.5.0 spec/record/reload_by_id_spec.rb
lhs-14.4.0 spec/record/reload_by_id_spec.rb
lhs-14.3.4 spec/record/reload_by_id_spec.rb
lhs-14.3.3 spec/record/reload_by_id_spec.rb
lhs-14.3.2 spec/record/reload_by_id_spec.rb
lhs-14.3.1 spec/record/reload_by_id_spec.rb
lhs-14.3.0 spec/record/reload_by_id_spec.rb
lhs-14.2.0 spec/record/reload_by_id_spec.rb
lhs-14.1.1 spec/record/reload_by_id_spec.rb
lhs-14.1.0 spec/record/reload_by_id_spec.rb
lhs-14.0.3 spec/record/reload_by_id_spec.rb
lhs-14.0.2 spec/record/reload_by_id_spec.rb
lhs-14.0.1 spec/record/reload_by_id_spec.rb
lhs-14.0.0 spec/record/reload_by_id_spec.rb