Sha256: 4627056408bb8ef903163afedac594ea4644400b0fccb689685f9d2a1fdad685

Contents?: true

Size: 1.3 KB

Versions: 16

Compression:

Stored size: 1.3 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(:each) 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

16 entries across 16 versions & 1 rubygems

Version Path
lhs-15.3.1 spec/collection/meta_data_spec.rb
lhs-15.3.1.pre.fixlhc.1 spec/collection/meta_data_spec.rb
lhs-15.3.0 spec/collection/meta_data_spec.rb
lhs-15.2.5 spec/collection/meta_data_spec.rb
lhs-15.2.4 spec/collection/meta_data_spec.rb
lhs-15.2.3 spec/collection/meta_data_spec.rb
lhs-15.2.3.pre.favorites.1 spec/collection/meta_data_spec.rb
lhs-15.2.2.pre.favorites.1 spec/collection/meta_data_spec.rb
lhs-15.2.2 spec/collection/meta_data_spec.rb
lhs-15.2.1 spec/collection/meta_data_spec.rb
lhs-15.2.0 spec/collection/meta_data_spec.rb
lhs-15.1.1 spec/collection/meta_data_spec.rb
lhs-15.1.0 spec/collection/meta_data_spec.rb
lhs-15.0.2 spec/collection/meta_data_spec.rb
lhs-15.0.1 spec/collection/meta_data_spec.rb
lhs-15.0.0 spec/collection/meta_data_spec.rb