diff --git a/app/controllers/locker_applications_controller.rb b/app/controllers/locker_applications_controller.rb index d3c42b8..42ab51f 100644 --- a/app/controllers/locker_applications_controller.rb +++ b/app/controllers/locker_applications_controller.rb @@ -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 @@ -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' } } @@ -152,6 +152,12 @@ def archived_param ActiveModel::Type::Boolean.new.cast(params[:archived]) end + + def creation_notice + return unless @locker_application.complete + + { message: 'Application successfully created', type: 'success' } + end end # rubocop:enable Metrics/ClassLength diff --git a/app/views/locker_applications/edit.html.erb b/app/views/locker_applications/edit.html.erb index f893ffc..15ef7c9 100644 --- a/app/views/locker_applications/edit.html.erb +++ b/app/views/locker_applications/edit.html.erb @@ -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 %> diff --git a/spec/features/locker_application_new_spec.rb b/spec/features/locker_application_new_spec.rb index 314afb2..69efe8a 100644 --- a/spec/features/locker_application_new_spec.rb +++ b/spec/features/locker_application_new_spec.rb @@ -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 diff --git a/spec/views/locker_applications/edit.html.erb_spec.rb b/spec/views/locker_applications/edit.html.erb_spec.rb index b9a135f..5a7c213 100644 --- a/spec/views/locker_applications/edit.html.erb_spec.rb +++ b/spec/views/locker_applications/edit.html.erb_spec.rb @@ -18,6 +18,7 @@ semester: 'MyString', status_at_application: 'MyString', department_at_application: 'MyString', + complete: true, user: )) end @@ -42,6 +43,25 @@ 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"]'