Skip to content

Commit c3c4479

Browse files
authored
Merge pull request #338 from minnestar/mdecuir/participant-coc-cleanup
Participant required fields + CoC checkbox cleanup
2 parents 0c3fa12 + 0bece08 commit c3c4479

File tree

13 files changed

+55
-81
lines changed

13 files changed

+55
-81
lines changed

app/assets/stylesheets/formtastic.css

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ form.formtastic fieldset ol li ul.errors li { padding:0; border:none; display:li
8484
/* STRING & NUMERIC OVERRIDES
8585
--------------------------------------------------------------------------------------------------*/
8686
form.formtastic fieldset ol li.string input { width:74%; }
87+
form.formtastic fieldset ol li.email input { width: 74%; }
8788
form.formtastic fieldset ol li.password input { width:74%; }
8889
form.formtastic fieldset ol li.numeric input { width:74%; }
8990

app/controllers/admin/legacy/sessions_controller.rb

-27
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ def edit
1111
respond_with(@session)
1212
end
1313

14-
def new
15-
respond_with(@session)
16-
end
17-
1814
def update
1915
if @session.update(session_params)
2016
redirect_to admin_legacy_sessions_path
@@ -23,29 +19,6 @@ def update
2319
end
2420
end
2521

26-
def build_presenter
27-
name = params[:session].delete(:name)
28-
# find exact match by name
29-
Participant.where(name: name).first_or_initialize do |p|
30-
p.save(validate: false) if p.new_record?
31-
end
32-
end
33-
34-
def create
35-
@session.participant = build_presenter
36-
@session.attributes = session_params
37-
@session.event = Event.current_event
38-
@session.timeslot_id = params[:session][:timeslot_id]
39-
@session.room_id = params[:session][:room_id]
40-
41-
if @session.save
42-
flash[:notice] = "Presentation added"
43-
redirect_to admin_legacy_sessions_path
44-
else
45-
render :new
46-
end
47-
end
48-
4922
def destroy
5023
@session.destroy!
5124
flash[:notice] = "Session has been deleted"

app/controllers/participants_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def send_confirmation_email
7979

8080
def confirm_email
8181
@participant = Participant.find_using_perishable_token(params[:token])
82-
if @participant.update!(email_confirmed_at: Time.now)
82+
if @participant.update!(email_confirmed_at: Time.current)
8383
flash[:notice] = "Email confirmed. Thank you!"
8484
redirect_to root_path
8585
else

app/models/event.rb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Event < ActiveRecord::Base
44
has_many :rooms, dependent: :destroy
55

66
has_many :presenter_timeslot_restrictions, :through => :timeslots
7+
has_many :code_of_conduct_agreements, dependent: :destroy
78

89
# Careful! Large joins here; use with caution:
910
has_many :attendances, through: :sessions

app/models/participant.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ class Participant < ActiveRecord::Base
55
has_many :presentations
66
has_many :sessions_presenting, :through => :presentations, :source => :session
77
has_many :presenter_timeslot_restrictions, dependent: :destroy
8+
has_many :code_of_conduct_agreements, dependent: :destroy
89

9-
validates_presence_of :name
10-
validates_uniqueness_of :email, :case_sensitive => false, :allow_blank => true
10+
validates :name, presence: true
11+
validates :email, presence: true
12+
validates_uniqueness_of :email, :case_sensitive => false
13+
validates :password, presence: true, on: :create
1114
validate :bio_does_not_include_example_links
1215

1316
# used for formtastic form to allow sending a field related to a separate model

app/views/admin/legacy/sessions/index.html.erb

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<% title('Admin: All sessions') %>
22

3-
<h2><%= link_to 'Add a session', new_admin_legacy_session_path %></h2>
4-
53
<div class="row">
64
<div class="column grid_6" style="margin-left:0px">
75
<ul class="sessionsList">

app/views/participants/new.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<%=
1515
f.input :code_of_conduct_agreement,
1616
as: :boolean,
17+
required: true, # this only adds an asterisk to the label, it doesn't make the field required
1718
label: ("I agree to the #{link_to 'Code of Conduct', 'https://minnestar.org/code-of-conduct'} governing this event.").html_safe,
1819
input_html: {
1920
checked: @participant.signed_code_of_conduct_for_current_event?,

app/views/sessions/_form.html.erb

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
as: :boolean,
1717
required: true,
1818
label: ("I agree to the #{link_to 'Code of Conduct', 'https://minnestar.org/code-of-conduct'} governing this event.").html_safe,
19-
input_html: { checked: current_participant.signed_code_of_conduct_for_current_event? }
19+
input_html: {
20+
checked: current_participant.signed_code_of_conduct_for_current_event?,
21+
disabled: current_participant.signed_code_of_conduct_for_current_event?
22+
}
2023
%>
2124
<% end %>
2225

config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
get '/legacy', to: 'legacy/admin#show', as: :legacy
4646
namespace :legacy do
4747
resource :config, only: [:show, :create]
48-
resources :sessions
48+
resources :sessions, except: [:new, :create]
4949
resources :markdown_contents, path: 'markdown-contents'
5050
resources :events do
5151
resources :timeslots, only: [:index, :new, :create]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class AddNotNullConstraintsToParticipants < ActiveRecord::Migration[7.1]
2+
def change
3+
# update any existing NULL values, just in case
4+
Participant.where(email: nil).update_all(email: 'INVALID')
5+
Participant.where(crypted_password: nil).update_all(crypted_password: 'INVALID')
6+
7+
change_column_null :participants, :email, false
8+
change_column_null :participants, :crypted_password, false
9+
end
10+
11+
def down
12+
change_column_null :participants, :email, true
13+
change_column_null :participants, :crypted_password, true
14+
end
15+
end

db/schema.rb

+3-3
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_03_09_183552) do
13+
ActiveRecord::Schema[7.1].define(version: 2025_03_13_020004) do
1414
create_schema "heroku_ext"
1515

1616
# These are extensions that must be enabled in order to support this database
@@ -69,11 +69,11 @@
6969

7070
create_table "participants", id: :serial, force: :cascade do |t|
7171
t.string "name", limit: 255
72-
t.string "email", limit: 255
72+
t.string "email", limit: 255, null: false
7373
t.text "bio"
7474
t.datetime "created_at", precision: nil, null: false
7575
t.datetime "updated_at", precision: nil, null: false
76-
t.string "crypted_password", limit: 255
76+
t.string "crypted_password", limit: 255, null: false
7777
t.string "persistence_token", limit: 255
7878
t.string "perishable_token", limit: 255, default: "", null: false
7979
t.datetime "email_confirmed_at", precision: nil

spec/controllers/admin/legacy/sessions_controller_spec.rb

-44
Original file line numberDiff line numberDiff line change
@@ -43,48 +43,4 @@
4343
end
4444
end
4545
end
46-
47-
describe "create" do
48-
let!(:event) { create(:event) }
49-
let(:category) { Category.last }
50-
before do
51-
Participant.destroy_all
52-
create(:participant, name: "Joe Schmoe")
53-
end
54-
55-
context "with valid values" do
56-
it "creates a new session " do
57-
58-
expect {
59-
expect {
60-
post :create, params: { session: { title: 'new title', description: 'new description', category_ids: [category.id], level_id: '2', name: "Ada Lovelace"} }
61-
}.to change { Session.count }.by(1)
62-
}.to change { Participant.count }.by(1)
63-
expect(response).to redirect_to admin_legacy_sessions_path
64-
expect(assigns[:session].title).to eq 'new title'
65-
expect(assigns[:session].participant.name).to eq 'Ada Lovelace'
66-
expect(assigns[:session].event).to eq event
67-
expect(assigns[:session].category_ids).to include category.id
68-
expect(flash[:notice]).to eq "Presentation added"
69-
end
70-
end
71-
72-
context "with invalid values" do
73-
it "shows the errors" do
74-
75-
expect {
76-
post :create, params: { session: { title: ''} }
77-
}.not_to change { Session.count }
78-
expect(response).to render_template('new')
79-
end
80-
end
81-
end
82-
83-
describe "new" do
84-
it "should be successful" do
85-
get :new
86-
expect(response).to be_successful
87-
expect(assigns[:session]).to be_kind_of Session
88-
end
89-
end
9046
end

spec/features/sign_in_and_out_spec.rb

+23
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,28 @@
8585
expect(page).to have_content "has already been taken"
8686
end
8787
end
88+
89+
scenario "As a user I cannot register without entering required fields" do
90+
visit root_path
91+
92+
click_link "Log in"
93+
click_link 'Register here'
94+
95+
click_button "Create My Account"
96+
97+
expect(page).to have_content "There was a problem creating your account."
98+
within("#participant_name_input") { expect(page).to have_content "can't be blank" }
99+
within("#participant_email_input") { expect(page).to have_content "can't be blank" }
100+
within("#participant_password_input") { expect(page).to have_content "can't be blank" }
101+
102+
name = FFaker::Name.name
103+
fill_in 'Your name*', with: name
104+
fill_in 'Your email', with: FFaker::Internet.safe_email
105+
fill_in 'Password', with: "anything, it doesnt matter"
106+
click_button "Create My Account"
107+
108+
expect(page).to have_content "Thanks for registering an account. Please check your email to confirm your account."
109+
expect(page).to have_content "Welcome #{name}"
110+
end
88111
end
89112
end

0 commit comments

Comments
 (0)