Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom fields date pair and datetime pair not saving #1319

Merged
merged 4 commits into from
Aug 23, 2024

Conversation

stanleylhs
Copy link
Member

@stanleylhs stanleylhs commented Aug 6, 2024

In Custom Field admin, it was not possible to create date_pair and datetime_pair due to errors in parameter passing and find_class methods.

This PR cleans up the pair parameters (strong params issues) and ensures CustomFieldDatePair and CustomFieldDateTimePair classes are seen by Rails on startup.

@stanleylhs stanleylhs requested a review from steveyken August 6, 2024 11:04
app/controllers/admin/fields_controller.rb Fixed Show resolved Hide resolved
app/controllers/admin/fields_controller.rb Fixed Show resolved Hide resolved
app/controllers/admin/fields_controller.rb Fixed Show resolved Hide resolved
@steveyken
Copy link
Member

This addresses a bug in saving 'pair' fields. I can help to finish this off in a couple of weeks time.

@steveyken steveyken self-assigned this Aug 9, 2024
…es they are 'seen' by ActiveRecord whe autoloading (usually in development mode) is turned on.
Copy link
Member

@steveyken steveyken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to revise the specs for custom fields and address the mass assignment issues below before merging this

…tered custom_fields in development mode. Added strong params to custom fields. Improve specs.
app/controllers/admin/fields_controller.rb Dismissed Show dismissed Hide dismissed
app/controllers/admin/fields_controller.rb Dismissed Show dismissed Hide dismissed
app/models/fields/custom_field_pair.rb Dismissed Show dismissed Hide dismissed
app/controllers/admin/fields_controller.rb Dismissed Show dismissed Hide dismissed
end

def pair_params
params.require(:pair).permit("0": [:hint, :required, :disabled, :id], "1": [:hint, :required, :disabled, :id])

Check notice

Code scanning / Rubocop

Use %i or %I for arrays of symbols. Note

Style/SymbolArray: Use %i or %I for an array of symbols.
end

def pair_params
params.require(:pair).permit("0": [:hint, :required, :disabled, :id], "1": [:hint, :required, :disabled, :id])

Check notice

Code scanning / Rubocop

Use %i or %I for arrays of symbols. Note

Style/SymbolArray: Use %i or %I for an array of symbols.
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Admin::FieldsController do

Check notice

Code scanning / Rubocop

Keeps track of empty lines around block bodies. Note test

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
end

it "should create a new custom field pair" do
post :create, params: { field: { as: "date_pair", label: "Date Pair", field_group_id: field_group.id }, pair: {"0" => {hint: "Hint"}, "1" => {hint: "Hint"}} }, xhr: true

Check notice

Code scanning / Rubocop

Use spaces inside hash literal braces - or don't. Note test

Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
expect(response).to render_template("admin/fields/create")
end
end

Check notice

Code scanning / Rubocop

Keeps track of empty lines around block bodies. Note test

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.
@pair2 = { 'name' => 'pair2' }
@params = { 'id' => '3', 'field' => @field, 'pair' => { '0' => @pair1, '1' => @pair2 } }
end
let!(:field1) { CustomFieldPair.create!(name: 'cf_pair1', label: 'Date Pair', as: 'date_pair', hint: "", field_group: field_group, required: false, disabled: 'false') }

Check notice

Code scanning / Rubocop

Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }. Note test

Style/HashSyntax: Omit the hash value.
@params = { 'id' => '3', 'field' => @field, 'pair' => { '0' => @pair1, '1' => @pair2 } }
end
let!(:field1) { CustomFieldPair.create!(name: 'cf_pair1', label: 'Date Pair', as: 'date_pair', hint: "", field_group: field_group, required: false, disabled: 'false') }
let!(:field2) { CustomFieldPair.create!(name: 'cf_pair2', label: 'Date Pair', as: 'date_pair', hint: "", field_group: field_group, required: false, disabled: 'false', pair_id: field1.id) }

Check notice

Code scanning / Rubocop

Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }. Note test

Style/HashSyntax: Omit the hash value.
@field1 = CustomFieldDatePair.new(name: 'cf_event_from')
@field2 = CustomFieldDatePair.new(name: 'cf_event_to')
end
let!(:field1) { CustomFieldPair.create!(name: 'cf_event_from', label: 'From', as: 'date_pair', field_group: field_group) }

Check notice

Code scanning / Rubocop

Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }. Note test

Style/HashSyntax: Omit the hash value.
@field2 = CustomFieldDatePair.new(name: 'cf_event_to')
end
let!(:field1) { CustomFieldPair.create!(name: 'cf_event_from', label: 'From', as: 'date_pair', field_group: field_group) }
let!(:field2) { CustomFieldPair.create!(name: 'cf_event_to', label: 'To', as: 'date_pair', field_group: field_group, pair_id: field1.id) }

Check notice

Code scanning / Rubocop

Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }. Note test

Style/HashSyntax: Omit the hash value.
Copy link
Member

@steveyken steveyken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now ready to merge

@steveyken steveyken merged commit d28e1fd into fatfreecrm:master Aug 23, 2024
8 checks passed
@steveyken steveyken deleted the fix-custom-fields-datepair branch August 23, 2024 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants