require File.dirname(__FILE__) + '/helper' require 'haml' require 'sinatra/formhelpers' class FormHelpersTest < Test::Unit::TestCase def test_default assert true end describe 'formhelpers link' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= link 'google', 'http://www.google.com'" end } end it 'renders an achor tag' do get '/' assert_equal "google\n", body end end describe 'formhelpers label' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= label :person, :first_name" end } end it 'renders an label tag' do get '/' assert_equal "\n", body end end describe 'formhelpers custom display label' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= label :person, :first_name, 'Hello World'" end } end it 'renders an label tag with display text' do get '/' assert_equal "\n", body end end describe 'formhelpers text without @params' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= text :person, :first_name" end } end it 'renders an input tag type text without @params' do get '/' assert_contains "name='person[first_name]'" assert_equal "\n", body end end describe 'formhelpers text with single arg' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= text :q" end } end it 'renders an input tag type text with single arg' do get '/' assert_equal "\n", body end end describe 'formhelpers text with @params' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do @params = { :person => {"first_name" => "Tom"}} haml "= text :person, :first_name" end } end it 'renders an input tag type text with @params' do get '/' assert_equal "\n", body end end describe 'formhelpers area without @params' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= area :person, :notes" end } end it 'renders an textarea tag type text without @params' do get '/' assert_equal "\n", body end end describe 'formhelpers textarea with @params' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do @params = { :person => {"notes" => "This is a note"}} haml "= area :person, :notes" end } end it 'renders a textarea tag with @params' do get '/' assert_equal "\n", body end end describe 'formhelpers image' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= image '/images/hello.png'" end } end it 'renders a textarea tag with @params' do get '/' assert_equal "\n", body end end describe 'formhelpers submit' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= submit :person, 'Create'" end } end it 'renders an input tag with a submit type' do get '/' assert_equal "\n", body end end describe 'formhelpers submit single arg' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= submit 'Create'" end } end it 'renders an input tag with a submit type with single arg' do get '/' assert_equal "\n", body end end describe 'formhelpers checkbox' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= checkbox :person, :active" end } end it 'renders an input tag with a checkbox type' do get '/' assert_match /name=\'person\[active\]\'/, body assert_match /id=\'person_active\'/, body assert_match /type=\'checkbox\'/, body end end describe 'formhelpers radio' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= radio :person, :gender, 'Male'" end } end it 'renders an input tag with a radio type' do get '/' assert_equal "Male\n", body end end describe 'formhelpers select' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml "= select :person, :relationship, ['Friend','CoWorker','Lead']" end } end it 'renders an select tag' do get '/' assert_equal "\n", body end end describe 'formhelpers hidden' do setup do mock_app { helpers Sinatra::FormHelpers get '/' do haml '= hidden :person, :id, { :value => 1 }' end } end it 'renders a hidden tag with value' do get '/' assert_equal "\n", body end end end