Sha256: 6aeb9a73c68989bda3e6c1afc8365ad6fb939b08b1b3f5b3b61dd7da7ee5d952

Contents?: true

Size: 804 Bytes

Versions: 3

Compression:

Stored size: 804 Bytes

Contents

require 'spec_helper'

describe 'Grape::Rabl partials' do
  let(:parsed_response) { JSON.parse(last_response.body) }

  subject do
    Class.new(Grape::API)
  end

  before do
    subject.format :json
    subject.formatter :json, Grape::Formatter::Rabl
    subject.before { env['api.tilt.root'] = "#{File.dirname(__FILE__)}/views" }
  end

  def app
    subject
  end

  it 'proper render partials' do
    subject.get('/home', rabl: 'project') do
      @author   = OpenStruct.new(author: 'LTe')
      @type     = OpenStruct.new(type: 'paper')
      @project  = OpenStruct.new(name: 'First', type: @type, author: @author)
    end

    get('/home')
    parsed_response.should ==
      JSON.parse("{\"project\":{\"name\":\"First\",\"info\":{\"type\":\"paper\"},\"author\":{\"author\":\"LTe\"}}}")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-rabl-0.4.1 spec/grape_rabl_partials_spec.rb
grape-rabl-0.4.0 spec/grape_rabl_partials_spec.rb
grape-rabl-0.3.1 spec/grape_rabl_partials_spec.rb