Skip to content

Commit

Permalink
Don't show Successfully Created flash message (or link to Show page) …
Browse files Browse the repository at this point in the history
…on applications that are not yet complete
  • Loading branch information
sandbergja committed Aug 20, 2024
1 parent 2b79c4a commit 7aff857
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
12 changes: 10 additions & 2 deletions app/controllers/locker_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def force_admin
return if current_user.admin? && current_user.works_at_enabled_building?

# Non-admins can only edit or update their application if it is not yet complete
return if (action_name == 'update' || action_name == 'edit') && !@locker_application.complete? && @locker_application.user == current_user
return if (action_name == 'update' || action_name == 'edit') && !@locker_application.complete && @locker_application.user == current_user

redirect_to :root, alert: 'Only administrators have access to the everyone\'s Locker Applications!'
end
Expand All @@ -132,7 +132,7 @@ def update_or_create(valid, message: 'Locker application was successfully update
if valid
if method == :new && Flipflop.lewis_patrons?
format.html do
redirect_to edit_locker_application_url(@locker_application), notice: { message: 'Application successfully created', type: 'success' }
redirect_to edit_locker_application_url(@locker_application), notice: creation_notice
end
else
format.html { redirect_to @locker_application, notice: { message:, type: 'success' } }
Expand All @@ -152,6 +152,14 @@ def archived_param

ActiveModel::Type::Boolean.new.cast(params[:archived])
end

def creation_notice
if @locker_application.complete
{ message: 'Application successfully created', type: 'success' }
else
nil
end
end
end

# rubocop:enable Metrics/ClassLength
6 changes: 4 additions & 2 deletions app/views/locker_applications/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ Edit application
<% end %>
<%= render 'form', locker_application: @locker_application %>

<%= link_to 'Show', @locker_application %> |
<%= link_to 'Back', locker_applications_path %>
<% if @locker_application.complete %>
<%= link_to 'Show', @locker_application %> |
<%= link_to 'Back', locker_applications_path %>
<% end %>
2 changes: 2 additions & 0 deletions spec/features/locker_application_new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
click_button('Next')
end.to change(LockerApplication, :count)
expect(page).to have_current_path(edit_locker_application_path(id: LockerApplication.last.id), ignore_query: true)
# Since the application is still incomplete, we don't show the "successfully created" message yet
expect(page).not_to have_content('Application successfully created')
end

it 'can apply for a new locker' do
Expand Down
19 changes: 19 additions & 0 deletions spec/views/locker_applications/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
semester: 'MyString',
status_at_application: 'MyString',
department_at_application: 'MyString',
complete: true,
user:
))
end
Expand All @@ -42,6 +43,24 @@
end
end

it 'has a link to the show page' do
render
assert_select 'a', text: 'Show'
end

context 'when the application is not yet complete' do
before do
@locker_application = assign(:locker_application, LockerApplication.create!(
complete: false,
user:
))
end
it 'does not have a link to the show page' do
render
assert_select 'a', {count: 0, text: 'Show'}, 'DOM has no link called Show'
end
end

it 'limits the length of the department field to 70' do
render
assert_select '#locker_application_department_at_application[maxlength="70"]'
Expand Down

0 comments on commit 7aff857

Please sign in to comment.