require 'test_helper' class BootstrapFormBuilder::FormBuilderTest < ActiveSupport::TestCase include ActionView::Helpers include BootstrapFormBuilder::Helpers attr_accessor :output_buffer def protect_against_forgery?() end class ::Book extend ActiveModel::Naming include ActiveModel::Conversion attr_accessor :author_id, :title, :passphrase def persisted?() end end def books_path(*args) '/books' end setup do @output_buffer = '' @book = Book.new end test '#text_field outputs a clearfix div' do concat(bootstrap_form_for(@book) { |f| concat(f.text_field(:title)) }) assert_match output_buffer, %r{
} end test '#text_field outputs a label tag' do concat(bootstrap_form_for(@book) { |f| concat(f.text_field(:title)) }) assert_match output_buffer, %r{} end test '#text_field outputs an input tag' do concat(bootstrap_form_for(@book) { |f| concat(f.text_field(:title)) }) assert_match output_buffer, %r{
} end test '#text_field with hint option outputs a help block' do concat(bootstrap_form_for(@book) { |f| concat(f.text_field(:title, hint: 'The Hobbit')) }) assert_match output_buffer, %r{The Hobbit} end test '#text_field with errors wraps field in error class' do @book.errors.stubs(:[]).returns(["can't be blank"]) concat(bootstrap_form_for(@book) { |f| concat(f.text_field(:title)) }) assert_match output_buffer, %r{
} assert_match output_buffer, %r{
} assert_match output_buffer, %r{can't be blank} end test '#password_field outputs a clearfix div' do concat(bootstrap_form_for(@book) { |f| concat(f.password_field(:passphrase)) }) assert_match output_buffer, %r{
} end test '#password_field outputs a label tag' do concat(bootstrap_form_for(@book) { |f| concat(f.password_field(:passphrase)) }) assert_match output_buffer, %r{} end test '#password_field outputs an input tag' do concat(bootstrap_form_for(@book) { |f| concat(f.password_field(:passphrase)) }) assert_match output_buffer, %r{
} end test '#file_field outputs a clearfix div' do concat(bootstrap_form_for(@book) { |f| concat(f.file_field(:attachment)) }) assert_match output_buffer, %r{
} end test '#file_field outputs a label tag' do concat(bootstrap_form_for(@book) { |f| concat(f.file_field(:attachment)) }) assert_match output_buffer, %r{} end test '#file_field outputs an input tag' do concat(bootstrap_form_for(@book) { |f| concat(f.file_field(:attachment)) }) assert_match output_buffer, %r{
} end test '#collection_select outputs a clearfix div' do concat(bootstrap_form_for(@book) { |f| concat(f.collection_select(:author_id, [], :id, :name)) }) assert_match output_buffer, %r{
} end test '#collection_select outputs a label tag' do concat(bootstrap_form_for(@book) { |f| concat(f.collection_select(:author_id, [], :id, :name)) }) assert_match output_buffer, %r{} end test '#collection_select outputs a select tag' do concat(bootstrap_form_for(@book) { |f| concat(f.collection_select(:author_id, [], :id, :name)) }) assert_match output_buffer, %r{
} end test '#submit outputs a clearfix div' do concat(bootstrap_form_for(@book) { |f| concat(f.submit) }) assert_match output_buffer, %r{
} end test '#submit outputs a submit button' do concat(bootstrap_form_for(@book) { |f| concat(f.submit) }) assert_match output_buffer, %r{} end test '#submit applies provided class to button' do concat(bootstrap_form_for(@book) { |f| concat(f.submit(nil, class: 'primary')) }) assert_match output_buffer, %r{} end test '#uneditable_field outputs a clearfix div' do concat(bootstrap_form_for(@book) { |f| concat(f.uneditable_field(:title)) }) assert_match output_buffer, %r{
} end test '#uneditable_field outputs a label tag' do concat(bootstrap_form_for(@book) { |f| concat(f.uneditable_field(:title)) }) assert_match output_buffer, %r{} end test '#uneditable_field outputs a span tag with class uneditable-input' do concat(bootstrap_form_for(@book) { |f| concat(f.uneditable_field(:title)) }) assert_match output_buffer, %r{
} end end