Move consent POST-logic to separate action

This commit is contained in:
Andreas Nedbal 2022-01-22 22:37:01 +01:00 committed by Andreas Nedbal
parent 1933aaac7f
commit d56dfc02f9
4 changed files with 17 additions and 8 deletions

View File

@ -7,7 +7,9 @@ class FeedbackController < ApplicationController
def consent def consent
redirect_to feedback_bugs_path if current_user.has_role? :canny_consent redirect_to feedback_bugs_path if current_user.has_role? :canny_consent
end
def update
return unless params[:consent] == "true" return unless params[:consent] == "true"
current_user.add_role :canny_consent current_user.add_role :canny_consent

View File

@ -15,7 +15,7 @@
%a.text-muted{ href: "https://canny.io/privacy" } Canny's Privacy Policy %a.text-muted{ href: "https://canny.io/privacy" } Canny's Privacy Policy
%p %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 %p
Alternatively, you can send us bug reports and feature requests directly on GitHub. Alternatively, you can send us bug reports and feature requests directly on GitHub.

View File

@ -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/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 '/: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/bugs(/*any)', to: 'feedback#bugs', via: 'get', as: 'feedback_bugs'
match '/feedback/feature_requests(/*any)', to: 'feedback#features', via: 'get', as: 'feedback_features' match '/feedback/feature_requests(/*any)', to: 'feedback#features', via: 'get', as: 'feedback_features'

View File

@ -26,12 +26,6 @@ describe FeedbackController, type: :controller do
get :consent get :consent
expect(response).to render_template(:consent) expect(response).to render_template(:consent)
end 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 end
context "user signed in with consent" do context "user signed in with consent" do
@ -46,6 +40,18 @@ describe FeedbackController, type: :controller do
end end
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 describe "#features" do
subject { get :features } subject { get :features }