require_relative '../spec_helper'
require 'angelo/tilt/erb'
describe Angelo::Base do
describe Angelo::Tilt::ERB do
expected_html = <
test
foo - asdf
locals :bar - bat
HTML
expected_xml = <asdf
XML
expected_json = <asdf
XML
expected_json_nl = < 'text/html'}
last_response_must_be_html expected_html
end
it 'renders templates by Accept header xml' do
get '/', {foo: 'asdf'}, {'Accept' => 'application/xml'}
last_response.body.must_equal expected_xml
last_response.headers['Content-Type'].must_equal 'application/xml'
end
it 'renders templates by Accept header javascript' do
get '/', {foo: 'asdf'}, {'Accept' => 'application/javascript'}
last_response.body.must_equal expected_javascript
last_response.headers['Content-Type'].must_equal 'application/javascript'
end
it 'renders templates by Accept header json' do
get '/', {foo: 'asdf'}, {'Accept' => 'application/json'}
last_response.body.must_equal expected_json
last_response.headers['Content-Type'].must_equal 'application/json'
end
it 'renders html template when unknown Accept header type' do
get '/', {foo: 'asdf'}, {'Accept' => 'forget/about/it'}
last_response_must_be_html expected_html
end
# content_type
it 'renders templates by content_type :html' do
get '/index.html', foo: 'asdf', layout: true
last_response_must_be_html expected_html
end
it 'renders templates by content_type :xml' do
get '/index.xml', foo: 'asdf', layout: true
last_response.body.must_equal expected_xml
last_response.headers['Content-Type'].must_equal 'application/xml'
end
it 'renders templates by content_type :javascript' do
get '/index.js', foo: 'asdf', layout: true
last_response.body.must_equal expected_javascript
last_response.headers['Content-Type'].must_equal 'application/javascript'
end
it 'renders templates by content_type :json' do
get '/index.json', foo: 'asdf', layout: true
last_response.body.must_equal expected_json
last_response.headers['Content-Type'].must_equal 'application/json'
end
it 'renders templates by content_type :html' do
get '/index.html', foo: 'asdf'
last_response_must_be_html expected_html_nl
end
it 'renders templates by content_type :xml' do
get '/index.xml', foo: 'asdf'
last_response.body.must_equal expected_xml_nl
last_response.headers['Content-Type'].must_equal 'application/xml'
end
it 'renders templates by content_type :javascript' do
get '/index.js', foo: 'asdf'
last_response.body.must_equal expected_javascript_nl
last_response.headers['Content-Type'].must_equal 'application/javascript'
end
it 'renders templates by content_type :json' do
get '/index.json', foo: 'asdf'
last_response.body.must_equal expected_json_nl
last_response.headers['Content-Type'].must_equal 'application/json'
end
# opts[:type]
it 'renders templates by opts[:type] :html' do
get '/by_type', foo: 'asdf', type: 'html'
last_response_must_be_html expected_html
end
it 'renders templates by opts[:type] :xml' do
get '/by_type', foo: 'asdf', type: 'xml'
last_response.body.must_equal expected_xml
last_response.headers['Content-Type'].must_equal 'application/xml'
end
it 'renders templates by opts[:type] :javascript' do
get '/by_type', foo: 'asdf', type: 'js'
last_response.body.must_equal expected_javascript
last_response.headers['Content-Type'].must_equal 'application/javascript'
end
it 'renders templates by opts[:type] :json' do
get '/by_type', foo: 'asdf', type: 'json'
last_response.body.must_equal expected_json
last_response.headers['Content-Type'].must_equal 'application/json'
end
end
end