Sha256: 3bd364d7fbb019312f264235f088fc5a3c855c3c5a5229afe7f657a9093fc016

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe 'Grape::EndpointExtension' do

  subject { Grape::Endpoint.new({}, {path: '/', method: 'foo'}) }

  let(:serializer) { Grape::Formatter::ActiveModelSerializers }

  let(:user) do
    Object.new do
      def name
        'sven'
      end
    end
  end

  let(:users) { [user, user] }

  describe "#render" do
    it { should respond_to(:render) }
    let (:meta_content) { { total: 2 } }
    let (:meta_full) { { meta: meta_content } }
    context 'supplying meta' do
      it 'passes through the Resource and uses given meta settings' do
        expect(serializer).to receive(:meta=).with(meta_content)
        expect(subject.render(users, meta_full)).to eq(users)
      end
    end
    context 'supplying meta and key' do
      let (:meta_key) { { meta_key: :custom_key_name } }
      it 'passes through the Resource and uses given meta settings' do
        expect(serializer).to receive(:meta=).with(meta_content)
        expect(serializer).to receive(:meta_key=).with(meta_key[:meta_key])
        expect(subject.render(users, meta_full.merge(meta_key))).to eq(users)
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-active_model_serializers-1.3.1 spec/grape-active_model_serializers/endpoint_extension_spec.rb