Sha256: 3169c51cbf5439c695652e7fa720748f81a1cbf8a7d7777f0ce8f5071d397d44

Contents?: true

Size: 1.29 KB

Versions: 15

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(:each) do
    LHC.config.placeholder('datastore', datastore)
    class Feedback < LHS::Service
      endpoint ':datastore/feedbacks'
      endpoint ':datastore/feedbacks/:id'
    end
    class User < LHS::Service
      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

15 entries across 15 versions & 1 rubygems

Version Path
lhs-2.2.2 spec/collection/meta_data_spec.rb
lhs-1.6.1 spec/collection/meta_data_spec.rb
lhs-2.2.1 spec/collection/meta_data_spec.rb
lhs-2.2.0 spec/collection/meta_data_spec.rb
lhs-1.6.0 spec/collection/meta_data_spec.rb
lhs-2.1.1 spec/collection/meta_data_spec.rb
lhs-2.1.0 spec/collection/meta_data_spec.rb
lhs-2.0.5 spec/collection/meta_data_spec.rb
lhs-2.0.4 spec/collection/meta_data_spec.rb
lhs-2.0.3 spec/collection/meta_data_spec.rb
lhs-2.0.2 spec/collection/meta_data_spec.rb
lhs-2.0.1 spec/collection/meta_data_spec.rb
lhs-2.0.0 spec/collection/meta_data_spec.rb
lhs-1.5.0 spec/collection/meta_data_spec.rb
lhs-1.4.0 spec/collection/meta_data_spec.rb