Remove ActiveRecord dependence; manually use as: :text

This commit is contained in:
Rob Biedenharn 2017-05-10 12:46:52 -04:00
parent 1beb20ed61
commit bdd57f807c
4 changed files with 8 additions and 11 deletions

View File

@ -46,8 +46,6 @@ matrix:
gemfile: gemfiles/Gemfile.rails-5-1-stable # rack 2.0.1 requires Ruby version >= 2.2.2
- rvm: 2.1.10
gemfile: gemfiles/Gemfile.rails-5-1-stable # rack 2.0.1 requires Ruby version >= 2.2.2
- rvm: 2.2.7
gemfile: gemfiles/Gemfile.rails-5-1-stable # because it now wants activerecord gem, too
notifications:
email: false
slack:

View File

@ -10,7 +10,6 @@ end
gem 'country_select', '~> 2.5.2'
gem 'railties', github: 'rails/rails', branch: '5-1-stable'
gem 'activemodel', github: 'rails/rails', branch: '5-1-stable'
gem 'activerecord', github: 'rails/rails', branch: '5-1-stable'
gem 'actionpack', github: 'rails/rails', branch: '5-1-stable'
gem 'rake'
gem 'tzinfo'

View File

@ -117,8 +117,13 @@ class FormBuilderTest < ActionView::TestCase
assert_select 'form input#user_name.string'
end
test 'builder generates text areas for text columns' do
test 'builder generates text field for un-hinted text columns' do
with_form_for @user, :description
assert_select 'form input#user_description.string'
end
test 'builder generates text areas for text columns when hinted' do
with_form_for @user, :description, as: :text
assert_select 'form textarea#user_description.text'
end

View File

@ -128,11 +128,10 @@ class User
begin
require 'active_model/type'
require 'active_record/type'
def type_for_attribute(attribute)
column_type, limit = case attribute
when 'name', 'status', 'password' then [:string, 100]
when 'description' then [:text, 200]
when 'description' then [:string, 200] # because :text is database-adapter specific
when 'age' then :integer
when 'credit_limit' then [:decimal, 15]
when 'active' then :boolean
@ -149,11 +148,7 @@ class User
when 'uuid' then :string
end
begin
ActiveModel::Type.lookup(column_type, limit: limit)
rescue ArgumentError
ActiveRecord::Type.lookup(column_type, limit: limit)
end
ActiveModel::Type.lookup(column_type, limit: limit)
end
rescue LoadError
end