Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bh.form_builder configuration option #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/bh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/bh/core_ext/rails/form_for_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions spec/rails/form_for_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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