Sha256: 40ca133a063010c9c35e220456d416450621281abd94b0106a762b2ab355af18

Contents?: true

Size: 967 Bytes

Versions: 1

Compression:

Stored size: 967 Bytes

Contents

require 'spec_helper'

describe 'Grape::Jbuilder partials' do
  let(:app) { Class.new(Grape::API) }

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

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

    pattern = {
      project: {
        name: 'First',
        info: {
          type: 'paper'
        },
        author: {
          author: 'LTe'
        }
      }
    }

    get('/home')
    expect(last_response.body).to match_json_expression(pattern)
    expect(last_response.body).to eq(
      "{\"project\":{\"name\":\"First\",\"info\":{\"type\":\"paper\"},\"author\":{\"author\":\"LTe\"}}}"
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-jbuilder-0.2.0 spec/acceptance/partials_spec.rb