diff --git a/lib/bh.rb b/lib/bh.rb index d123687..cdcc70b 100644 --- a/lib/bh.rb +++ b/lib/bh.rb @@ -3,7 +3,9 @@ # Bootstrap Helpers module Bh - mattr_accessor :framework + mattr_accessor :framework, :form_builder + + self.form_builder = true end # Always require every generic helper diff --git a/lib/bh/core_ext/rails/form_for_helper.rb b/lib/bh/core_ext/rails/form_for_helper.rb index c8c925c..11487f5 100644 --- a/lib/bh/core_ext/rails/form_for_helper.rb +++ b/lib/bh/core_ext/rails/form_for_helper.rb @@ -26,7 +26,7 @@ def add_form_options!(options) options[:html] ||= {} options[:html].merge! role: 'form' append_class! options[:html], class_for(options[:layout]) - options.merge! builder: FormBuilder + options.merge! builder: FormBuilder if Bh.form_builder end def class_for(layout) diff --git a/spec/rails/form_for_helper_spec.rb b/spec/rails/form_for_helper_spec.rb index b92c34a..d8d1833 100644 --- a/spec/rails/form_for_helper_spec.rb +++ b/spec/rails/form_for_helper_spec.rb @@ -47,4 +47,28 @@ expect(form).to include 'role="form"' end end + + describe 'form_builder option' do + specify 'by default is true' do + expect(Bh.form_builder).to eq(true) + end + + specify 'when true, uses FormBuilder' do + form_for(:object, options.merge(url: '/', layout: :wat)) do |f| + expect(f.is_a?(Bh::FormBuilder)).to eq(true) + end + end + + specify 'when false, does not use FormBuilder' do + begin + Bh.form_builder = false + form_for(:object, options.merge(url: '/', layout: :wat)) do |f| + expect(f.is_a?(ActionView::Helpers::FormBuilder)).to eq(true) + expect(f.is_a?(Bh::FormBuilder)).to eq(false) + end + ensure + Bh.form_builder = true + end + end + end end \ No newline at end of file