Skip to content

Commit

Permalink
Merge pull request #1190 from fatfreecrm/fix-custom-field
Browse files Browse the repository at this point in the history
Fix custom field error
  • Loading branch information
CloCkWeRX authored Oct 28, 2023
2 parents d8fc400 + 79b5aab commit 3e4ab48
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/models/fields/custom_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def column_options
#------------------------------------------------------------------------------
def add_column
self.name = generate_column_name if name.blank?
klass.connection.add_column(table_name, name, column_type, column_options)
klass.connection.add_column(table_name, name, column_type, **column_options)
klass.reset_column_information
klass.serialize_custom_fields!
end
Expand All @@ -142,7 +142,7 @@ def add_ransack_translation
#------------------------------------------------------------------------------
def update_column
if errors.empty? && db_transition_safety(as_was) == :safe
klass.connection.change_column(table_name, name, column_type, column_options)
klass.connection.change_column(table_name, name, column_type, **column_options)
klass.reset_column_information
klass.serialize_custom_fields!
end
Expand Down
19 changes: 16 additions & 3 deletions spec/models/fields/custom_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
describe CustomField do
it "should add a column to the database" do
expect(CustomField.connection).to receive(:add_column)
.with("contacts", "cf_test_field", 'string', {})
.with("contacts", "cf_test_field", 'string')
expect(Contact).to receive(:reset_column_information)
expect(Contact).to receive(:serialize_custom_fields!)

Expand All @@ -42,6 +42,19 @@
field_group: create(:field_group, klass_name: "Contact"))
end

it "should add a column to the database and include column_options" do
expect(CustomField.connection).to receive(:add_column)
.with("contacts", "cf_test_field", 'decimal', {"precision" => 15, "scale" => 2})
expect(Contact).to receive(:reset_column_information)
expect(Contact).to receive(:serialize_custom_fields!)

create(:custom_field,
as: "decimal",
name: "cf_test_field",
label: "Test Field",
field_group: create(:field_group, klass_name: "Contact"))
end

it "should generate a unique column name for a custom field" do
field_group = build(:field_group, klass_name: "Contact")
c = build(:custom_field, label: "Test Field", field_group: field_group)
Expand Down Expand Up @@ -75,9 +88,9 @@

it "should change a column's type for safe transitions" do
expect(CustomField.connection).to receive(:add_column)
.with("contacts", "cf_test_field", 'string', {})
.with("contacts", "cf_test_field", 'string')
expect(CustomField.connection).to receive(:change_column)
.with("contacts", "cf_test_field", 'text', {})
.with("contacts", "cf_test_field", 'text')
expect(Contact).to receive(:reset_column_information).twice
expect(Contact).to receive(:serialize_custom_fields!).twice

Expand Down

0 comments on commit 3e4ab48

Please sign in to comment.