-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix custom fields date pair and datetime pair not saving #1319
Conversation
This addresses a bug in saving 'pair' fields. I can help to finish this off in a couple of weeks time. |
…es they are 'seen' by ActiveRecord whe autoloading (usually in development mode) is turned on.
There was a problem hiding this 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.
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
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
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
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
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
@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
@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
@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
@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
There was a problem hiding this 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
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.