diff --git a/app/controllers/feedback_controller.rb b/app/controllers/feedback_controller.rb index deca59d1..d00d91d4 100644 --- a/app/controllers/feedback_controller.rb +++ b/app/controllers/feedback_controller.rb @@ -7,7 +7,9 @@ class FeedbackController < ApplicationController def consent redirect_to feedback_bugs_path if current_user.has_role? :canny_consent + end + def update return unless params[:consent] == "true" current_user.add_role :canny_consent diff --git a/app/views/feedback/consent.haml b/app/views/feedback/consent.haml index 5e91de51..2d1f1379 100644 --- a/app/views/feedback/consent.haml +++ b/app/views/feedback/consent.haml @@ -15,7 +15,7 @@ %a.text-muted{ href: "https://canny.io/privacy" } Canny's Privacy Policy %p - = button_to "Consent and proceed", feedback_consent_path, class: "btn btn-primary", method: :post, params: { consent: true } + = button_to "Consent and proceed", feedback_consent_update_path, class: "btn btn-primary", method: :post, params: { consent: true } %p Alternatively, you can send us bug reports and feature requests directly on GitHub. diff --git a/config/routes.rb b/config/routes.rb index 17e915d1..d274489c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -144,7 +144,8 @@ Rails.application.routes.draw do match '/:username/lists(/p/:page)', to: 'user#lists', via: 'get', as: :show_user_lists, defaults: {page: 1} match '/:username/questions(/p/:page)', to: 'user#questions', via: 'get', as: :show_user_questions, defaults: {page: 1} - match '/feedback/consent', to: 'feedback#consent', via: ['get', 'post'], as: 'feedback_consent' + match '/feedback/consent', to: 'feedback#consent', via: 'get', as: 'feedback_consent' + match '/feedback/consent/update', to: 'feedback#update', via: 'post', as: 'feedback_consent_update' match '/feedback/bugs(/*any)', to: 'feedback#bugs', via: 'get', as: 'feedback_bugs' match '/feedback/feature_requests(/*any)', to: 'feedback#features', via: 'get', as: 'feedback_features' diff --git a/spec/controllers/feedback_controller_spec.rb b/spec/controllers/feedback_controller_spec.rb index eed7e80c..0f4ca420 100644 --- a/spec/controllers/feedback_controller_spec.rb +++ b/spec/controllers/feedback_controller_spec.rb @@ -26,12 +26,6 @@ describe FeedbackController, type: :controller do get :consent expect(response).to render_template(:consent) end - - it "sets the consent role" do - post :consent, params: { consent: "true" } - expect(user.has_role?(:canny_consent)).to eq(true) - expect(response).to redirect_to(feedback_bugs_path) - end end context "user signed in with consent" do @@ -46,6 +40,18 @@ describe FeedbackController, type: :controller do end end + describe "#update" do + let(:user) { FactoryBot.create(:user) } + + before(:each) { sign_in(user) } + + it "sets the consent role" do + post :update, params: { consent: "true" } + expect(user.has_role?(:canny_consent)).to eq(true) + expect(response).to redirect_to(feedback_bugs_path) + end + end + describe "#features" do subject { get :features }