Add mapping to citext columns

This commit is contained in:
Carlos Antonio da Silva 2014-07-15 10:47:23 -03:00
parent 5943e07fc4
commit 213f766953
5 changed files with 25 additions and 15 deletions

View File

@ -1,3 +1,6 @@
### enhancements
* Add mapping to `citext` columns.
### bug fix
* Fix `uuid` input to generate proper input[type=text].

View File

@ -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 ||= {}

View File

@ -17,7 +17,7 @@ module SimpleForm
private
def postgresql_type?
input_type == :uuid
input_type == :uuid || input_type == :citext
end
def string?

View File

@ -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'

View File

@ -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