diff --git a/CHANGELOG.md b/CHANGELOG.md index adc4dc52..dbfea342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### enhancements + * Add mapping to `citext` columns. + ### bug fix * Fix `uuid` input to generate proper input[type=text]. diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index a2b2ba94..b95a72f8 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -17,19 +17,20 @@ module SimpleForm extend MapType include SimpleForm::Inputs - map_type :text, to: SimpleForm::Inputs::TextInput - map_type :file, to: SimpleForm::Inputs::FileInput - map_type :string, :email, :search, :tel, :url, :uuid, to: SimpleForm::Inputs::StringInput - map_type :password, to: SimpleForm::Inputs::PasswordInput - map_type :integer, :decimal, :float, to: SimpleForm::Inputs::NumericInput - map_type :range, to: SimpleForm::Inputs::RangeInput - map_type :check_boxes, to: SimpleForm::Inputs::CollectionCheckBoxesInput - map_type :radio_buttons, to: SimpleForm::Inputs::CollectionRadioButtonsInput - map_type :select, to: SimpleForm::Inputs::CollectionSelectInput - map_type :grouped_select, to: SimpleForm::Inputs::GroupedCollectionSelectInput - map_type :date, :time, :datetime, to: SimpleForm::Inputs::DateTimeInput - map_type :country, :time_zone, to: SimpleForm::Inputs::PriorityInput - map_type :boolean, to: SimpleForm::Inputs::BooleanInput + map_type :text, to: SimpleForm::Inputs::TextInput + map_type :file, to: SimpleForm::Inputs::FileInput + map_type :string, :email, :search, :tel, :url, to: SimpleForm::Inputs::StringInput + map_type :citext, :uuid, to: SimpleForm::Inputs::StringInput + map_type :password, to: SimpleForm::Inputs::PasswordInput + map_type :integer, :decimal, :float, to: SimpleForm::Inputs::NumericInput + map_type :range, to: SimpleForm::Inputs::RangeInput + map_type :check_boxes, to: SimpleForm::Inputs::CollectionCheckBoxesInput + map_type :radio_buttons, to: SimpleForm::Inputs::CollectionRadioButtonsInput + map_type :select, to: SimpleForm::Inputs::CollectionSelectInput + map_type :grouped_select, to: SimpleForm::Inputs::GroupedCollectionSelectInput + map_type :date, :time, :datetime, to: SimpleForm::Inputs::DateTimeInput + map_type :country, :time_zone, to: SimpleForm::Inputs::PriorityInput + map_type :boolean, to: SimpleForm::Inputs::BooleanInput def self.discovery_cache @discovery_cache ||= {} diff --git a/lib/simple_form/inputs/string_input.rb b/lib/simple_form/inputs/string_input.rb index efffecc7..dfbce1af 100644 --- a/lib/simple_form/inputs/string_input.rb +++ b/lib/simple_form/inputs/string_input.rb @@ -17,7 +17,7 @@ module SimpleForm private def postgresql_type? - input_type == :uuid + input_type == :uuid || input_type == :citext end def string? diff --git a/test/form_builder/general_test.rb b/test/form_builder/general_test.rb index 2767b196..9c904d4b 100644 --- a/test/form_builder/general_test.rb +++ b/test/form_builder/general_test.rb @@ -126,6 +126,11 @@ class FormBuilderTest < ActionView::TestCase assert_select 'form input#user_credit_limit.numeric.decimal' end + test 'builder generates text fields for citext columns' do + with_form_for @user, :citext + assert_select 'form input[type=text]#user_citext.string.citext' + end + test 'builder generates text fields for uuid columns' do with_form_for @user, :uuid assert_select 'form input[type=text]#user_uuid.string.uuid' diff --git a/test/support/models.rb b/test/support/models.rb index ed762df1..b88c4ca1 100644 --- a/test/support/models.rb +++ b/test/support/models.rb @@ -74,7 +74,7 @@ class User :avatar, :home_picture, :email, :status, :residence_country, :phone_number, :post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender, :extra_special_company_id, :pictures, :picture_ids, :special_pictures, - :special_picture_ids, :uuid + :special_picture_ids, :uuid, :citext def self.build(extra_attributes = {}) attributes = { @@ -126,6 +126,7 @@ class User when :action then :string when :credit_card then :string when :uuid then :uuid + when :citext then :citext end Column.new(attribute, column_type, limit) end