diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 04a3fb607..ea4c66e66 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -61,6 +61,10 @@ def logged_in? def accept_terms store_path + + # https://guides.rubyonrails.org/layouts_and_rendering.html#avoiding-double-render-errors + redirect_to redirect_path and return unless logged_in? + redirect_to terms_and_conditions_path if current_user.accepted_toc_at.blank? end diff --git a/app/controllers/member/details_controller.rb b/app/controllers/member/details_controller.rb index d620bdf3f..16e292251 100644 --- a/app/controllers/member/details_controller.rb +++ b/app/controllers/member/details_controller.rb @@ -7,6 +7,8 @@ class Member::DetailsController < ApplicationController def edit accept_terms + # https://apidock.com/rails/ActionController/Metal/performed%3F + return if performed? flash[notice] = I18n.t('notifications.signing_up') @member.newsletter ||= true diff --git a/spec/controllers/details_controller_spec.rb b/spec/controllers/details_controller_spec.rb new file mode 100644 index 000000000..b388e52c9 --- /dev/null +++ b/spec/controllers/details_controller_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +RSpec.describe Member::DetailsController, type: :controller do + describe "GET edit" do + context "When a user is not logged in" do + it "redirects to GitHub authentication" do + get :edit + expect(response).to redirect_to("/auth/github") + end + end + end +end