Add a test, fix tests, improve regex

This commit is contained in:
Seth Ringling 2017-04-14 08:02:44 -07:00 committed by Seth Ringling
parent 5f97512dd1
commit be6ab69974
No known key found for this signature in database
GPG Key ID: 3F8B3402E1446BE7
3 changed files with 12 additions and 7 deletions

View File

@ -552,12 +552,12 @@ module SimpleForm
:datetime
when :string, :citext, nil
case attribute_name.to_s
when /\bpassword\b/ then :password
when /\btime_zone\b/ then :time_zone
when /\bcountry\b/ then :country
when /\bemail\b/ then :email
when /\bphone\b/ then :tel
when /\burl\b/ then :url
when /(?:\b|\W|_)password(?:\b|\W|_)/ then :password
when /(?:\b|\W|_)time_zone(?:\b|\W|_)/ then :time_zone
when /(?:\b|\W|_)country(?:\b|\W|_)/ then :country
when /(?:\b|\W|_)email(?:\b|\W|_)/ then :email
when /(?:\b|\W|_)phone(?:\b|\W|_)/ then :tel
when /(?:\b|\W|_)url(?:\b|\W|_)/ then :url
else
file_method?(attribute_name) ? :file : (input_type || :string)
end

View File

@ -271,6 +271,11 @@ class FormBuilderTest < ActionView::TestCase
assert_select 'form select#user_age.select'
end
test 'builder does not generate url fields for columns that contain only the letters url' do
with_form_for @user, :hourly
assert_no_select 'form input#user_url.string.url'
end
test 'builder allows overriding default input type for text' do
with_form_for @user, :name, as: :text
assert_no_select 'form input#user_name'

View File

@ -91,7 +91,7 @@ class User
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
:extra_special_company_id, :pictures, :picture_ids, :special_pictures,
:special_picture_ids, :uuid, :friends, :friend_ids, :special_tags, :special_tag_ids,
:citext, :hstore, :json, :jsonb
:citext, :hstore, :json, :jsonb, :hourly
def self.build(extra_attributes = {})
attributes = {