Skip to content

Commit

Permalink
Reapply "Admins skip library selection (#305)"
Browse files Browse the repository at this point in the history
This reverts commit 8ad2c8e.
  • Loading branch information
Ryan Laddusaw committed Aug 19, 2024
1 parent 818540b commit 00e967f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
12 changes: 7 additions & 5 deletions app/controllers/locker_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def show

# GET /locker_applications/new
def new
@locker_application = LockerApplication.new(user: current_user)
@locker_application = LockerApplication.new(user: current_user, building_id: current_user.building_id)
end

# GET /locker_applications/1/edit
Expand All @@ -43,7 +43,7 @@ def toggle_archived
redirect_back(fallback_location: awaiting_assignment_locker_applications_path)
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
# POST /locker_applications or /locker_applications.json
def create
@locker_application = LockerApplication.new(locker_application_params)
Expand All @@ -52,10 +52,10 @@ def create

@locker_application.preferred_size = 2 if @locker_application.building&.name == 'Lewis Library'

@locker_application.complete = true unless Flipflop.lewis_patrons?
@locker_application.complete = true if current_user.admin? || !Flipflop.lewis_patrons?
update_or_create(@locker_application.save, message: 'Locker application was successfully created.', method: :new)
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity

# PATCH/PUT /locker_applications/1 or /locker_applications/1.json
def update
Expand Down Expand Up @@ -131,7 +131,9 @@ def update_or_create(valid, message: 'Locker application was successfully update
respond_to do |format|
if valid
if method == :new && Flipflop.lewis_patrons?
format.html { redirect_to edit_locker_application_url(@locker_application) }
format.html do
redirect_to edit_locker_application_url(@locker_application), notice: { message: 'Application successfully created', type: 'success' }
end
else
format.html { redirect_to @locker_application, notice: { message:, type: 'success' } }
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/locker_applications/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<% content_for :title do %>
Edit application
<% end %>
<% if notice.present? %>
<alert status="<%= notice['type'] %>" dismissible><%= notice['message'] %></alert>
<% end %>
<%= render 'form', locker_application: @locker_application %>

<%= link_to 'Show', @locker_application %> |
Expand Down
6 changes: 3 additions & 3 deletions app/views/locker_applications/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% content_for :title do %>
Locker application
<% end %>
<% if Flipflop.lewis_patrons? %>
<%= render 'building_select_form', locker_application: @locker_application %>
<% else %>
<% if current_user.admin? || !Flipflop.lewis_patrons? %>
<%= render 'form', locker_application: @locker_application %>
<% else %>
<%= render 'building_select_form', locker_application: @locker_application %>
<% end %>
14 changes: 4 additions & 10 deletions spec/features/locker_application_new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,15 @@

it 'can assign the application to an existing user' do
visit root_path
select('Firestone Library', from: :locker_application_building_id)
click_button('Next')
new_application = LockerApplication.last
expect(new_application.user).to eq(admin)
expect(page).to have_content('Firestone Library Locker Application')
expect(page).to have_field('Applicant Netid', with: admin.uid)
check('Keyed entry (rather than combination)')
fill_in('Applicant Netid', with: user.uid, fill_options: { clear: :backspace })
expect(page).to have_field('Applicant Netid', with: user.uid)
click_button('Submit Locker Application')
new_application = LockerApplication.last
expect(page).not_to have_content('User must exist')
expect(page).to have_current_path(locker_application_path(new_application))
expect(page).to have_current_path(edit_locker_application_path(new_application))
expect(new_application.reload.complete).to be true
expect(new_application.reload.user).to eq(user)
end
Expand All @@ -182,18 +179,15 @@
context 'with a valid user that does not exist yet' do
it 'can create and assign an application to a new user' do
visit root_path
select('Firestone Library', from: :locker_application_building_id)
click_button('Next')
new_application = LockerApplication.last
expect(new_application.user).to eq(admin)
expect(page).to have_content('Firestone Library Locker Application')
expect(page).to have_field('Applicant Netid', with: admin.uid)
fill_in('Applicant Netid', with: 'arbitrary netid', fill_options: { clear: :backspace })
fill_in('Additional accessibility needs', with: 'Lower row')
expect(page).to have_field('Applicant Netid', with: 'arbitrary netid')
click_button('Submit Locker Application')
new_application = LockerApplication.last
expect(page).not_to have_content('User must exist')
expect(page).to have_current_path(locker_application_path(new_application))
expect(page).to have_current_path(edit_locker_application_path(new_application))
end
end

Expand Down
4 changes: 1 addition & 3 deletions spec/views/locker_applications/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
it 'renders new locker_application form and allows the user netid to be edited' do
render

assert_select 'form[action=?][method=?]', locker_applications_path, 'post' do
assert_select 'input[type=hidden][name=?]', 'locker_application[user_uid]', count: 1
end
assert_select 'input-text[name=?]', 'locker_application[user_uid]', count: 1
end
end
end
Expand Down

0 comments on commit 00e967f

Please sign in to comment.