Skip to content

Commit be6ab69

Browse files
Seth Ringlingsringling
Seth Ringling
authored andcommitted
Add a test, fix tests, improve regex
1 parent 5f97512 commit be6ab69

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

lib/simple_form/form_builder.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,12 @@ def default_input_type(attribute_name, column, options)
552552
:datetime
553553
when :string, :citext, nil
554554
case attribute_name.to_s
555-
when /\bpassword\b/ then :password
556-
when /\btime_zone\b/ then :time_zone
557-
when /\bcountry\b/ then :country
558-
when /\bemail\b/ then :email
559-
when /\bphone\b/ then :tel
560-
when /\burl\b/ then :url
555+
when /(?:\b|\W|_)password(?:\b|\W|_)/ then :password
556+
when /(?:\b|\W|_)time_zone(?:\b|\W|_)/ then :time_zone
557+
when /(?:\b|\W|_)country(?:\b|\W|_)/ then :country
558+
when /(?:\b|\W|_)email(?:\b|\W|_)/ then :email
559+
when /(?:\b|\W|_)phone(?:\b|\W|_)/ then :tel
560+
when /(?:\b|\W|_)url(?:\b|\W|_)/ then :url
561561
else
562562
file_method?(attribute_name) ? :file : (input_type || :string)
563563
end

test/form_builder/general_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ def with_custom_form_for(object, *args, &block)
271271
assert_select 'form select#user_age.select'
272272
end
273273

274+
test 'builder does not generate url fields for columns that contain only the letters url' do
275+
with_form_for @user, :hourly
276+
assert_no_select 'form input#user_url.string.url'
277+
end
278+
274279
test 'builder allows overriding default input type for text' do
275280
with_form_for @user, :name, as: :text
276281
assert_no_select 'form input#user_name'

test/support/models.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class User
9191
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
9292
:extra_special_company_id, :pictures, :picture_ids, :special_pictures,
9393
:special_picture_ids, :uuid, :friends, :friend_ids, :special_tags, :special_tag_ids,
94-
:citext, :hstore, :json, :jsonb
94+
:citext, :hstore, :json, :jsonb, :hourly
9595

9696
def self.build(extra_attributes = {})
9797
attributes = {

0 commit comments

Comments
 (0)