require 'rails_helper'
describe 'Hamlit rails integration', type: :request do
it 'renders views' do
get root_path
expect(response).to be_ok
expect(response).to render_template('application/index')
expect(response).to render_template('layouts/application')
expect(response.body).to include('Hamlit')
end
it 'renders params' do
get users_path(q: 'hello')
expect(response.body).to include('hello')
end
it 'renders instance variable' do
get users_path
expect(response.body).to include('
k0kubun
')
end
it 'does not escape the object whose to_s returns SafeBuffer' do
get safe_buffer_users_path
expect(response.body).to include('')
end
it 'renders a complex old attributes' do
get old_attributes_users_path
expect(response.body).to include("")
expect(response.body).to include("")
expect(response.body).to include("")
expect(response.body).to include("")
expect(response.body).to include("")
end
describe 'escaping' do
it 'escapes script' do
get users_path(q: '')
expect(response.body).to include(
'<script>alert("a");</script>',
)
end
it 'escapes block script' do
get users_path(q: '<>')
expect(response.body).to include(<<-HTML.strip_heredoc)
<>
<>
HTML
end
end
describe 'rails helpers' do
it 'renders rails helper' do
get users_path
expect(response.body).to include('root')
end
it 'allows capture method to work' do
get capture_users_path
expect(response.body).to include(<<-HTML.strip_heredoc)
HTML
end
it 'renders haml tags in the form block' do
get form_users_path
expect(response.body).to include('row')
end
it 'renders whitespace removal inside #capture' do
get whitespace_users_path
expect(response.body).to include('foo')
end
end
describe 'haml helpers' do
it 'accepts find_and_preserve' do
get helpers_users_path
expect(response.body).to include(<<-HTML.strip_heredoc)
Foo
Bar
Baz
HTML
end
it 'accepts capture_haml' do
get capture_users_path
expect(response.body).to include(<<-HTML.strip_heredoc)
HTML
end
it 'renders succeed' do
get helpers_users_path
expect(response.body).to include('succeed.')
end
it 'renders precede' do
get helpers_users_path
expect(response.body).to include(',precede')
end
it 'renders surround' do
get helpers_users_path
expect(response.body).to include('[surround]')
end
end
end