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,29 +1,27 @@
# 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 current_user.add_role :canny_consent
redirect_to feedback_bugs_path redirect_to feedback_bugs_path
end end
end
def features def features; end
end def bugs; end
def bugs
end
private private
def feature_enabled? def feature_enabled?
redirect_to root_path if APP_CONFIG['canny'].nil? redirect_to root_path if APP_CONFIG["canny"].nil?
end end
def canny_consent_given? def canny_consent_given?

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,13 +5,13 @@ 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
@ -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

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")