Skip to content

Commit ae7cc23

Browse files
committed
chore: fix code review issues
1 parent f7f277d commit ae7cc23

File tree

8 files changed

+49
-27
lines changed

8 files changed

+49
-27
lines changed

app/controllers/concerns/member_concerns.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,19 @@ def suppress_notices
2828
def set_member
2929
@member = current_user
3030
end
31+
32+
def how_you_found_us_selections
33+
how_found = Array(member_params[:how_you_found_us]).reject(&:blank?)
34+
other_reason = member_params[:how_you_found_us_other_reason]
35+
36+
how_found << other_reason if other_reason.present?
37+
how_found.uniq!
38+
39+
how_found
40+
end
41+
42+
def member_params_without_how_you_found_us_other_reason
43+
member_params.to_h.except(:how_you_found_us_other_reason)
44+
end
3145
end
3246
end

app/controllers/member/details_controller.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,18 @@ def edit
1313
end
1414

1515
def update
16-
how_found = Array(params.dig(:member, :how_you_found_us)).reject(&:blank?)
17-
other_reason = params.dig(:member, :how_you_found_us_other_reason)
18-
19-
how_found << other_reason if other_reason.present?
20-
how_found.uniq!
21-
22-
if how_found.blank?
23-
@member.assign_attributes(member_params.to_h.except(:how_you_found_us_other_reason))
16+
if how_you_found_us_selections.blank?
17+
@member.assign_attributes(member_params_without_how_you_found_us_other_reason)
2418
@member.errors.add(:how_you_found_us, 'You must select at least one option')
2519
return render :edit
2620
end
2721

28-
attrs = member_params.to_h.except(:how_you_found_us_other_reason)
29-
attrs[:how_you_found_us] = how_found
22+
attrs = member_params_without_how_you_found_us_other_reason
23+
attrs[:how_you_found_us] = how_you_found_us_selections
3024

3125
return render :edit unless @member.update(attrs)
3226

3327
member_params[:newsletter] ? subscribe_to_newsletter(@member) : unsubscribe_from_newsletter(@member)
3428
redirect_to step2_member_path
3529
end
36-
end
30+
end

app/controllers/members_controller.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class MembersController < ApplicationController
99

1010
def new
1111
@page_title = 'Sign up'
12-
1312
end
1413

1514
def edit; end

app/models/member.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
class Member < ApplicationRecord
22
include Permissions
33

4+
HOW_YOU_FOUND_US_OPTIONS = [
5+
'From a friend',
6+
'Search engine (Google etc.)',
7+
'Social Media',
8+
"One of Codebar's hosts or partners"
9+
].freeze
10+
411
has_many :attendance_warnings
512
has_many :bans
613
has_many :eligibility_inquiries
@@ -45,7 +52,7 @@ class Member < ApplicationRecord
4552

4653
acts_as_taggable_on :skills
4754

48-
attr_accessor :attendance, :newsletter
55+
attr_accessor :attendance, :newsletter, :how_you_found_us_other_reason
4956

5057
def banned?
5158
bans.active.present? || bans.permanent.present?

app/views/member/details/edit.html.haml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,25 @@
2525
%ul
2626
- @member.errors.full_messages.each do |msg|
2727
%li= msg
28-
- if @member.errors[:how_you_found_us].any?
28+
- if @member.errors[:how_you_found_us]&.any?
2929
%span.text-danger= @member.errors[:how_you_found_us].first
3030
.col-12.mb-3
31-
%label{ for: 'how_you_found_us' }= t('member.details.edit.how_you_found_us')
32-
%span *
33-
- options = ['From a friend', 'Search engine (Google etc.)', 'Social Media', "One of Codebar's hosts or partners"]
34-
- options.each do |option|
35-
.form-check
36-
= check_box_tag 'member[how_you_found_us][]', option, false, id: "how_you_found_us_#{option.parameterize}", class: 'form-check-input'
37-
= label_tag "how_you_found_us_#{option.parameterize}", option, class: 'form-check-label', style: 'margin-left: 8px;'
38-
= label_tag :how_you_found_us_other_reason, t('member.details.edit.how_you_found_us_other_reason'), class: 'my-1'
39-
= text_field_tag 'member[how_you_found_us_other_reason]', nil, placeholder: "Please specify how you heard about us", class: 'form-control w-100'
31+
%fieldset
32+
%legend= t('member.details.edit.how_you_found_us')
33+
%span *
34+
35+
= f.input :how_you_found_us,
36+
as: :check_boxes,
37+
collection: Member::HOW_YOU_FOUND_US_OPTIONS,
38+
item_wrapper_class: 'form-check',
39+
label_item: true,
40+
input_html: { class: 'form-check-input' },
41+
label_html: { class: 'form-check-label', style: 'margin-left: 8px;' }
42+
43+
= f.input :how_you_found_us_other_reason,
44+
label: t('member.details.edit.how_you_found_us_other_reason'),
45+
placeholder: 'Please specify how you heard about us',
46+
input_html: { class: 'form-control w-100' }
4047
= f.input :newsletter, as: :boolean, checked_value: true, unchecked_value: false
4148
.text-right.mb-4
4249
= hidden_field_tag :next_page, step2_member_path(member_type: @type)

db/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.1].define(version: 2025_08_20_145012) do
13+
ActiveRecord::Schema[7.1].define(version: 2025_08_23_151717) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

spec/controllers/member/details_controller_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
RSpec.describe Member::DetailsController, type: :controller do
1+
RSpec.describe Member::DetailsController do
22
render_views
33
let(:member) { Fabricate(:member) }
44

55
before do
66
allow(controller).to receive(:current_user).and_return(member)
7+
allow_any_instance_of(Services::MailingList).to receive(:subscribe).and_return(true)
78
end
89

910
describe 'PATCH #update' do

spec/features/member_joining_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
end
1616

1717
scenario 'A visitor must fill in all mandatory fields in order to sign up' do
18-
member = Fabricate(:member, name: nil, surname: nil, email: nil, about_you: nil)
18+
member = Fabricate(:member, name: nil, surname: nil, email: nil, about_you: nil, how_you_found_us: [])
1919
member.update(can_log_in: true)
2020
login member
2121

@@ -44,7 +44,7 @@
4444
check 'Vegan'
4545
check 'Other'
4646
fill_in 'Other dietary restrictions', with: 'peanut allergy'
47-
find('#how_you_found_us_from-a-friend').click
47+
find('#member_how_you_found_us_from_a_friend').click
4848
fill_in 'member_how_you_found_us_other_reason', with: 'found on a poster', id: true
4949
click_on 'Next'
5050

0 commit comments

Comments
 (0)