require 'spec_helper'
describe "BootstrapForms::FormBuilder" do
context "given a setup builder" do
before(:each) do
@project = Project.new
@template = ActionView::Base.new
@template.output_buffer = ""
@builder = BootstrapForms::FormBuilder.new(:item, @project, @template, {}, proc {})
end
it_behaves_like 'a bootstrap form'
describe "with no options" do
describe "error_messages" do
it "returns empty string without errors" do
@builder.error_messages.should == ""
end
context "with errors" do
before(:each) do
@project.errors.add("name")
@result = @builder.error_messages
end
it "is wrapped in error div" do
@result.should match /^
.*<\/div>$/
end
it "has a list with errors" do
@result.should match /
- Name is invalid<\/li><\/ul>/
end
it "has error title" do
@result.should match /
#{I18n.t('bootstrap_forms.errors.header', :model => Project.model_name.human)}<\/h4>/
end
it "has error message on field" do
@builder.text_field("name").should == ""
end
it "joins passed error message and validation errors with ', '" do
@builder.text_field("name", :error => 'This is an error!').should == ""
end
end
end
end
context "with errors" do
before(:each) do
@project.errors.add("name")
@result = @builder.error_messages
end
it "is wrapped in error div" do
@result.should match /^.*<\/div>$/
end
it "has a list with errors" do
@result.should match /