require File.expand_path(File.dirname(__FILE__) + '/../../test_helper') class FooFormBuilder < ExtensibleFormBuilder end class TestFormBuilder < ExtensibleFormBuilder def self.reset! self.labels = true self.wrap = true self.default_class_names.clear end end module ExtensibleFormsBuilderTests class RailsExtTest < ActionView::TestCase tests ActionView::Helpers::FormHelper def setup super @article = Article.new :title => 'article title' @controller = Class.new { def url_for(options); 'url' end }.new end def build_form(&block) block ||= Proc.new { |f| concat f.field_set { f.text_field(:title) } } form_for(:article, @article, :builder => TestFormBuilder, &block) output_buffer end test "renders a fieldset" do build_form =~ /
'article title' @controller = Class.new { def url_for(options); 'url' end }.new @builder = TestFormBuilder.new(nil, nil, self, {}, nil) @assigns = {} TestFormBuilder.reset! end def teardown reset_form_callbacks end def build_form(*args) options = args.extract_options! method = args.shift || :title form_for(:article, @article, :builder => TestFormBuilder) do |f| concat f.text_field(method, options) end output_buffer end test "builds the form" do assert build_form =~ / 'foo', :legend => 'legend', :class => 'bar') { 'baz' } end # labels test "uses the given string as label text (labels enabled)" do assert build_form(:label => 'the article label') =~ /