Skip to content

Commit

Permalink
fix: update _params controller method with nested params
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse committed Jan 30, 2025
1 parent 88e194e commit 18273da
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
16 changes: 10 additions & 6 deletions app/controllers/modeles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,16 @@ def set_modele
# Never trust parameters from the scary internet, only allow the white list through.
def modele_params
params.expect(
modele: [:name, :color, :description, :category_id, :architecture_id, :u, :manufacturer_id, :nb_elts,
network_types: [],
enclosures_attributes: [
:id, :modele_id, :_destroy, :position, :display, :grid_areas,
composants_attributes: %i[type_composant_id enclosure_id name position _destroy id],
],]
modele: [
:name, :color, :description, :category_id, :architecture_id, :u, :manufacturer_id, :nb_elts,
{ network_types: [] },
{
enclosures_attributes: [
:id, :modele_id, :_destroy, :position, :display, :grid_areas,
composants_attributes: [%i[type_composant_id enclosure_id name position _destroy id]],
]
},
]
)
end
end
20 changes: 13 additions & 7 deletions app/controllers/servers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,19 @@ def set_server

# Never trust parameters from the scary internet, only allow the white list through.
def server_params
params.expect(server: [:photo, :stack_id, :server_state_id, :comment, :cluster_id, :position, :frame_id, :gestion_id, :fc_futur, :rj45_cm, :name, :modele_id, :numero, :critique, :domaine_id, :fc_total, :fc_utilise, :rj45_total, :rj45_utilise, :rj45_futur, :ipmi_utilise, :ipmi_futur, :ipmi_dedie,
:frame, # TODO: Check if it should be removed or if it's used somewhere
{ network_types: [],
:cards_attributes => %i[composant_id card_type_id _destroy id twin_card_id orientation name first_position],
:disks_attributes => %i[quantity disk_type_id _destroy id],
:memory_components_attributes => %i[quantity memory_type_id _destroy id],
:documents_attributes => %i[document id _destroy] },])
params.expect(
server: [
:photo, :stack_id, :server_state_id, :comment, :cluster_id, :position, :frame_id, :gestion_id, :fc_futur,
:rj45_cm, :name, :modele_id, :numero, :critique, :domaine_id, :fc_total, :fc_utilise, :rj45_total,
:rj45_utilise, :rj45_futur, :ipmi_utilise, :ipmi_futur, :ipmi_dedie,
:frame, # TODO: Check if it should be removed or if it's used somewhere
{ network_types: [] },
{ cards_attributes: [%i[composant_id card_type_id twin_card_id orientation name first_position _destroy id]] },
{ disks_attributes: [%i[quantity disk_type_id _destroy id]] },
{ memory_components_attributes: [%i[quantity memory_type_id _destroy id]] },
{ documents_attributes: [%i[document id _destroy]] },
]
)
end

def search_params
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def set_site
# Never trust parameters from the scary internet, only allow the white list through.
def site_params
params.expect(
site: [:name, :description,
:position,
:street, :country, :city, :latitude, :longitude,
:delivery_address, :delivery_times, :delivery_map,
{ contact_assignments_attributes: %i[contact_id contact_role_id id _destroy] },]
site: [
:name, :description, :position, :street, :country, :city, :latitude, :longitude,
:delivery_address, :delivery_times, :delivery_map,
{ contact_assignments_attributes: [%i[contact_id contact_role_id id _destroy]] },
]
)
end
end
10 changes: 6 additions & 4 deletions spec/requests/servers_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@
end

it "does update cards in a server", :aggregate_failures do # rubocop:disable RSpec/ExampleLength
patch server_path(server), params: { server: { cards_attributes: { id: 1,
composant_id: 1,
twin_card_id: 2,
orientation: "lr-td" } } }
patch server_path(server), params: {
server: {
name: server.name,
cards_attributes: [{ id: 1, composant_id: 1, twin_card_id: 2, orientation: "lr-td" }]
}
}

assigns(:server).reload
server.reload
Expand Down

0 comments on commit 18273da

Please sign in to comment.