Revert "Gracefully accept older ActiveModel::Type::Text"

This reverts commit 5b95f1b7be.
This commit is contained in:
Rob Biedenharn 2017-05-17 14:18:32 -04:00
parent 5e6d3066e6
commit b0e06fe174
2 changed files with 22 additions and 23 deletions

View File

@ -117,7 +117,7 @@ class FormBuilderTest < ActionView::TestCase
assert_select 'form input#user_name.string'
end
test 'builder generates text field for text columns' do
test 'builder generates text field for un-hinted text columns' do
with_form_for @user, :description
if @user.respond_to?(:type_for_attribute) &&
@user.type_for_attribute('description').type == :string

View File

@ -128,39 +128,38 @@ class User
begin
require 'active_model/type'
@@types = {
'name' => [:string, 100],
'status' => [:string, 100],
'password' => [:string, 100],
'description' => [:text, 200],
'age' => [:integer, nil],
'credit_limit' => [:decimal, 15],
'active' => [:boolean, nil],
'born_at' => [:date, nil],
'delivery_time' => [:time, nil],
'created_at' => [:datetime, nil],
'updated_at' => [:datetime, nil],
'lock_version' => [:integer, nil],
'home_picture' => [:string, nil],
'amount' => [:integer, nil],
'attempts' => [:integer, nil],
'action' => [:string, nil],
'credit_card' => [:string, nil],
'uuid' => [:string, nil],
}
begin
ActiveModel::Type.lookup(:text)
rescue ArgumentError # :text is no longer an ActiveModel::Type
# But we don't want our tests to depend on ActiveRecord
class ::ActiveModel::Type::Text < ActiveModel::Type::String
def type; :text; end
end
ActiveModel::Type.register(:text, ActiveModel::Type::Text)
end
def type_for_attribute(attribute)
column_type, limit = @@types[attribute]
column_type, limit = case attribute
when 'name', 'status', 'password' then [:string, 100]
when 'description' then [:text, 200]
when 'age' then :integer
when 'credit_limit' then [:decimal, 15]
when 'active' then :boolean
when 'born_at' then :date
when 'delivery_time' then :time
when 'created_at' then :datetime
when 'updated_at' then :datetime
when 'lock_version' then :integer
when 'home_picture' then :string
when 'amount' then :integer
when 'attempts' then :integer
when 'action' then :string
when 'credit_card' then :string
when 'uuid' then :string
end
ActiveModel::Type.lookup(column_type, limit: limit)
end
rescue LoadError # doesn't have active_model/type
rescue LoadError
end
def has_attribute?(attribute)