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

View File

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

View File

@ -5,15 +5,15 @@ require "rails_helper"
describe FeedbackController, type: :controller do
before do
stub_const("APP_CONFIG", {
'hostname' => 'example.com',
'https' => true,
'items_per_page' => 5,
'canny' => {
'sso': 'sso',
'feature_board': 'feature',
'bug_board': 'bug'
}
})
"hostname" => "example.com",
"https" => true,
"items_per_page" => 5,
"canny" => {
sso: "sso",
feature_board: "feature",
bug_board: "bug"
}
})
end
describe "#consent" do
@ -28,7 +28,7 @@ describe FeedbackController, type: :controller do
end
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(response).to redirect_to(feedback_bugs_path)
end

View File

@ -5,24 +5,24 @@ require "rails_helper"
describe FeedbackHelper, type: :helper do
before do
stub_const("APP_CONFIG", {
'hostname' => 'example.com',
'https' => true,
'items_per_page' => 5,
'canny' => {
'sso': 'sso',
'feature_board': 'feature',
'bug_board': 'bug'
}
})
"hostname" => "example.com",
"https" => true,
"items_per_page" => 5,
"canny" => {
sso: "sso",
feature_board: "feature",
bug_board: "bug"
}
})
end
describe "#canny_token" 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)
}
end
it "should return a proper token" do
expect(helper.canny_token).to eq("eyJhbGciOiJIUzI1NiJ9.eyJhdmF0YXJVUkwiOiIvaW1hZ2VzL2xhcmdlL25vX2F2YXRhci5wbmciLCJuYW1lIjoiY2FubmVkX2xhdWdodGVyIiwiaWQiOjEwLCJlbWFpbCI6ImNhbkBkby5jb20ifQ.aRZn8kAezMJucYQV4RXiMPvhSRVR3wKp1ZQtcsIWaaE")