Sha256: c218e252cea04e33c4fd1c2e108f5247a76879027f51b834fd074bfab98b48c2

Contents?: true

Size: 1.29 KB

Versions: 19

Compression:

Stored size: 1.29 KB

Contents

require 'rails_helper'

describe LHS::Collection do
  let(:total) { 0 }

  let(:limit) { 50 }

  let(:offset) { 0 }

  let(:collection) do
    {
      href: "#{datastore}/feedbacks",
      items: [],
      total: total,
      limit: limit,
      offset: offset
    }
  end

  let(:item) do
    {
      href: "#{datastore}/users/1",
      feedbacks: collection
    }
  end

  let(:datastore) { 'http://local.ch/v2' }

  before do
    LHC.config.placeholder('datastore', datastore)
    class Feedback < LHS::Record
      endpoint '{+datastore}/feedbacks'
      endpoint '{+datastore}/feedbacks/{id}'
    end
    class User < LHS::Record
      endpoint '{+datastore}/users'
      endpoint '{+datastore}/users/{id}'
    end
  end

  it 'provides meta data for collections' do
    stub_request(:get, "#{datastore}/feedbacks").to_return(status: 200, body: collection.to_json)
    feedbacks = Feedback.where
    expect(feedbacks.total).to eq total
    expect(feedbacks.limit).to eq limit
    expect(feedbacks.offset).to eq offset
    expect(feedbacks.href).to eq "#{datastore}/feedbacks"
  end

  it 'provides meta data also when navigating' do
    stub_request(:get, "#{datastore}/users/1").to_return(status: 200, body: item.to_json)
    user = User.find(1)
    expect(user.feedbacks.href).to eq "#{datastore}/feedbacks"
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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