Sha256: 3c2a0f99e83885632d1d5fc00a2c58f8ed68e07d42deb347a8c99099fd99773d

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

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

  before do
    subject.format :xml
    subject.formatter :xml, Grape::Formatter::Rabl
  end

  def app
    subject
  end

  context 'with xml format' do
    before do
      subject.before do
        env['api.tilt.root'] = "#{File.dirname(__FILE__)}/views"
        env['api.format'] = :xml
      end
    end

    it 'should respond with proper content-type' do
      subject.get('/home', rabl: 'user') {}
      get('/home')
      expect(last_response.headers['Content-Type']).to eq('application/xml')
    end

    ['user', 'user.rabl'].each do |rabl_option|
      it "should render rabl template (#{rabl_option})" do
        subject.get('/home', rabl: rabl_option) do
          @user = OpenStruct.new(name: 'LTe', email: 'email@example.com')
          @project = OpenStruct.new(name: 'First')
        end

        get '/home'

        expect(last_response.body).to eq(%(<?xml version="1.0" encoding="UTF-8"?>
<user>
  <name>LTe</name>
  <email>email@example.com</email>
  <project>
    <name>First</name>
  </project>
</user>
))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-rabl-0.5.0 spec/grape_rabl_xml_spec.rb
grape-rabl-0.4.3 spec/grape_rabl_xml_spec.rb
grape-rabl-0.4.2 spec/grape_rabl_xml_spec.rb