Skip to content

Commit b5b3d8f

Browse files
committed
Columns named password defaults to password inputs even if no object was given, resolving issue formtastic#20.
1 parent 1c085e3 commit b5b3d8f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/formtastic.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,6 @@ def field_set_and_list_wrapping_for_method(method, options, contents)
10011001
# default is a :string, a similar behaviour to Rails' scaffolding.
10021002
#
10031003
def default_input_type(method) #:nodoc:
1004-
return :string if @object.nil?
1005-
10061004
column = @object.column_for_attribute(method) if @object.respond_to?(:column_for_attribute)
10071005

10081006
if column
@@ -1017,10 +1015,13 @@ def default_input_type(method) #:nodoc:
10171015
# otherwise assume the input name will be the same as the column type (eg string_input)
10181016
return column.type
10191017
else
1020-
obj = @object.send(method) if @object.respond_to?(method)
1018+
if @object
1019+
return :select if find_reflection(method)
1020+
1021+
file = @object.send(method) if @object.respond_to?(method)
1022+
return :file if file && @@file_methods.any? { |m| file.respond_to?(m) }
1023+
end
10211024

1022-
return :select if find_reflection(method)
1023-
return :file if obj && @@file_methods.any? { |m| obj.respond_to?(m) }
10241025
return :password if method.to_s =~ /password/
10251026
return :string
10261027
end

spec/formtastic_spec.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,20 @@ def custom(arg1, arg2, options = {})
573573

574574
describe 'when not provided' do
575575

576-
it 'should default to a string for forms without objects' do
576+
it 'should default to a string for forms without objects unless column is password' do
577577
semantic_form_for(:project, :url => 'http://test.host') do |builder|
578578
concat(builder.input(:anything))
579579
end
580580
output_buffer.should have_tag('form li.string')
581581
end
582582

583+
it 'should default to password for forms without objects if column is password' do
584+
semantic_form_for(:project, :url => 'http://test.host') do |builder|
585+
concat(builder.input(:password))
586+
end
587+
output_buffer.should have_tag('form li.password')
588+
end
589+
583590
it 'should default to a string for methods on objects that don\'t respond to "column_for_attribute"' do
584591
@new_post.stub!(:method_without_a_database_column)
585592
@new_post.stub!(:column_for_attribute).and_return(nil)

0 commit comments

Comments
 (0)