Skip to content

Commit

Permalink
Default to input types text for json & jsonb, string for citext columns
Browse files Browse the repository at this point in the history
  • Loading branch information
swrobel committed Dec 5, 2016
1 parent 06c5d47 commit e1a1d96
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
* Added mapping hstore column to text input (#1203)
* Added support for Rails 5 Attributes API (#1188)
* Changed required Ruby version to >= 2.0 (#1210)
* Default to input types text for json & jsonb, string for citext columns (#1229)

## 3.1.2

Expand Down
4 changes: 3 additions & 1 deletion lib/formtastic/helpers/input_helper.rb
Expand Up @@ -283,8 +283,10 @@ def default_input_type(method, options = {}) # @private
return :time_select
when :date
return :date_select
when :hstore
when :hstore, :json, :jsonb
return :text
when :citext
return :string
end

# Try look for hints in options hash. Quite common senario: Enum keys stored as string in the database.
Expand Down
8 changes: 7 additions & 1 deletion spec/helpers/input_helper_spec.rb
Expand Up @@ -482,8 +482,10 @@ def length_should_be_required(options)
expect(default_input_type(:date)).to eq(:date_select)
end

it 'should default to :text for :hstore column types' do
it 'should default to :text for :hstore, :json and :jsonb column types' do
expect(default_input_type(:hstore)).to eq(:text)
expect(default_input_type(:json)).to eq(:text)
expect(default_input_type(:jsonb)).to eq(:text)
end

it 'should default to :datetime_select for :datetime and :timestamp column types' do
Expand All @@ -503,6 +505,10 @@ def length_should_be_required(options)
expect(default_input_type(:string)).to eq(:string)
end

it 'should default to :string for :citext column types' do
expect(default_input_type(:citext)).to eq(:string)
end

it 'should default to :number for :integer, :float and :decimal column types' do
expect(default_input_type(:integer)).to eq(:number)
expect(default_input_type(:float)).to eq(:number)
Expand Down

0 comments on commit e1a1d96

Please sign in to comment.