Skip to content

Commit 2eaaebd

Browse files
committed
docs: add code comment for accepts_nested_attributes_for
- Explains why sponsors_controller uses require().permit() instead of params.expect (incompatible with nested attributes) - Removes performance test referring to old implementation details
1 parent 0ec61cd commit 2eaaebd

2 files changed

Lines changed: 3 additions & 25 deletions

File tree

app/controllers/admin/sponsors_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def update
6363
private
6464

6565
def sponsor_params
66+
# Uses require().permit() instead of params.expect because Sponsor model
67+
# uses accepts_nested_attributes_for, which sends hash-with-numeric-keys
68+
# that params.expect cannot handle (e.g., {'0' => {...}, '1' => {...}})
6669
params.require(:sponsor).permit(
6770
:name, :avatar, :website, :seats, :accessibility_info,
6871
:number_of_coaches, :level, :description,

spec/controllers/member/details_controller_spec.rb

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -98,31 +98,6 @@
9898
expect(response.body).to include('You must select one option')
9999
end
100100

101-
it 'validates efficiently by calling member_params only once' do
102-
# This test verifies the fix for the performance issue where member_params
103-
# was called multiple times (previously 6 times!):
104-
# - Old: Line 16 called member_params, line 19 validation called it again, line 32 called it again
105-
# - New: Line 16 calls member_params once, passes result to validation
106-
107-
# Mock to track how many times member_params is called
108-
call_count = 0
109-
allow(controller).to receive(:member_params).and_wrap_original do |method|
110-
call_count += 1
111-
method.call
112-
end
113-
114-
patch :update, params: {
115-
id: member.id,
116-
member: {
117-
how_you_found_us: 'social_media',
118-
how_you_found_us_other_reason: '', # Empty is OK
119-
newsletter: 'true'
120-
}
121-
}
122-
123-
# After fix: member_params is called only once
124-
expect(call_count).to eq(1)
125-
end
126101
end
127102
end
128103
end

0 commit comments

Comments
 (0)