Browse files

Small refactor to make testing custom inputs easier

Added a `raw_input` method to return the input
after it has been initialized, but before it's
converted to html. This means that developers who
have created custom inputs can get an instance
of their input after it has been properly
initialized and test its instance methods.
  • Loading branch information...
1 parent f68d4c8 commit 409eaba52bac54278244f2afe83b4f2fdb50680b Nathan Long committed May 15, 2012
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/formtastic/helpers/input_helper.rb
10 lib/formtastic/helpers/input_helper.rb
@@ -232,16 +232,20 @@ module InputHelper
# @todo Many many more examples. Some of the detail probably needs to be pushed out to the relevant methods too.
# @todo More i18n examples.
def input(method, options = {})
+ raw_input(method, options).to_html
+ end
+ protected
+ def raw_input(method, options = {})
options = options.dup # Allow options to be shared without being tainted by Formtastic
options[:as] ||= default_input_type(method, options)
klass = input_class(options[:as])
-, template, @object, @object_name, method, options).to_html
+, template, @object, @object_name, method, options)
- protected
# First try if we can detect special things like :file. With CarrierWave the method does have
# an underlying column so we don't want :string to get selected.

0 comments on commit 409eaba

Please sign in to comment.