Fix Ruby codestyle

This commit is contained in:
Andreas Nedbal 2022-01-22 08:16:55 +01:00 committed by Andreas Nedbal
parent af66e69ca5
commit 3711c676da
4 changed files with 53 additions and 53 deletions

View File

@ -1,32 +1,30 @@
# frozen_string_literal: true
class FeedbackController < ApplicationController class FeedbackController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :feature_enabled? before_action :feature_enabled?
before_action :canny_consent_given?, only: %w(features bugs) before_action :canny_consent_given?, only: %w[features bugs]
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
if params[:consent] === 'true' then return unless params[:consent] == "true"
current_user.add_role :canny_consent
redirect_to feedback_bugs_path
end
end
def features current_user.add_role :canny_consent
redirect_to feedback_bugs_path
end
end def features; end
def bugs def bugs; end
end private
private def feature_enabled?
redirect_to root_path if APP_CONFIG["canny"].nil?
end
def feature_enabled? def canny_consent_given?
redirect_to root_path if APP_CONFIG['canny'].nil? redirect_to feedback_consent_path unless current_user.has_role? :canny_consent
end end
def canny_consent_given?
redirect_to feedback_consent_path unless current_user.has_role? :canny_consent
end
end end

View File

@ -1,14 +1,16 @@
# frozen_string_literal: true
module FeedbackHelper module FeedbackHelper
def canny_token def canny_token
return if current_user.nil? return if current_user.nil?
userData = { user_data = {
avatarURL: current_user.profile_picture.url(:large), avatarURL: current_user.profile_picture.url(:large),
name: current_user.screen_name, name: current_user.screen_name,
id: current_user.id, id: current_user.id,
email: current_user.email email: current_user.email
} }
JWT.encode(userData, APP_CONFIG.dig("canny", "sso")) JWT.encode(user_data, APP_CONFIG.dig("canny", "sso"))
end end
end end

View File

@ -5,15 +5,15 @@ require "rails_helper"
describe FeedbackController, type: :controller do describe FeedbackController, type: :controller do
before do before do
stub_const("APP_CONFIG", { stub_const("APP_CONFIG", {
'hostname' => 'example.com', "hostname" => "example.com",
'https' => true, "https" => true,
'items_per_page' => 5, "items_per_page" => 5,
'canny' => { "canny" => {
'sso': 'sso', sso: "sso",
'feature_board': 'feature', feature_board: "feature",
'bug_board': 'bug' bug_board: "bug"
} }
}) })
end end
describe "#consent" do describe "#consent" do
@ -28,7 +28,7 @@ describe FeedbackController, type: :controller do
end end
it "sets the consent role" do it "sets the consent role" do
post :consent, params: { consent: 'true' } post :consent, params: { consent: "true" }
expect(user.has_role?(:canny_consent)).to eq(true) expect(user.has_role?(:canny_consent)).to eq(true)
expect(response).to redirect_to(feedback_bugs_path) expect(response).to redirect_to(feedback_bugs_path)
end end
@ -97,4 +97,4 @@ describe FeedbackController, type: :controller do
end end
end end
end end
end end

View File

@ -5,24 +5,24 @@ require "rails_helper"
describe FeedbackHelper, type: :helper do describe FeedbackHelper, type: :helper do
before do before do
stub_const("APP_CONFIG", { stub_const("APP_CONFIG", {
'hostname' => 'example.com', "hostname" => "example.com",
'https' => true, "https" => true,
'items_per_page' => 5, "items_per_page" => 5,
'canny' => { "canny" => {
'sso': 'sso', sso: "sso",
'feature_board': 'feature', feature_board: "feature",
'bug_board': 'bug' bug_board: "bug"
} }
}) })
end end
describe "#canny_token" do describe "#canny_token" do
context "user signed in" do context "user signed in" do
let(:user) { FactoryBot.create(:user, id: 10, screen_name: "canned_laughter", email: 'can@do.com') } let(:user) { FactoryBot.create(:user, id: 10, screen_name: "canned_laughter", email: "can@do.com") }
before(:each) { before(:each) do
sign_in(user) sign_in(user)
} end
it "should return a proper token" do it "should return a proper token" do
expect(helper.canny_token).to eq("eyJhbGciOiJIUzI1NiJ9.eyJhdmF0YXJVUkwiOiIvaW1hZ2VzL2xhcmdlL25vX2F2YXRhci5wbmciLCJuYW1lIjoiY2FubmVkX2xhdWdodGVyIiwiaWQiOjEwLCJlbWFpbCI6ImNhbkBkby5jb20ifQ.aRZn8kAezMJucYQV4RXiMPvhSRVR3wKp1ZQtcsIWaaE") expect(helper.canny_token).to eq("eyJhbGciOiJIUzI1NiJ9.eyJhdmF0YXJVUkwiOiIvaW1hZ2VzL2xhcmdlL25vX2F2YXRhci5wbmciLCJuYW1lIjoiY2FubmVkX2xhdWdodGVyIiwiaWQiOjEwLCJlbWFpbCI6ImNhbkBkby5jb20ifQ.aRZn8kAezMJucYQV4RXiMPvhSRVR3wKp1ZQtcsIWaaE")
@ -35,4 +35,4 @@ describe FeedbackHelper, type: :helper do
end end
end end
end end
end end