1
0
Fork 0

Apply rubcop and get tests pass (#76)

Dieser Commit ist enthalten in:
Angus McLeod 2021-03-11 17:30:15 +11:00 committet von GitHub
Ursprung 065bc17929
Commit 4edb40e526
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
91 geänderte Dateien mit 1070 neuen und 1006 gelöschten Zeilen

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
CustomWizard::Engine.routes.draw do
get ':wizard_id' => 'wizard#index'
put ':wizard_id/skip' => 'wizard#skip'

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::AdminController < ::Admin::AdminController
before_action :ensure_admin

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::AdminApiController < CustomWizard::AdminController
skip_before_action :check_xhr, only: [:redirect]
@ -85,7 +86,7 @@ class CustomWizard::AdminApiController < CustomWizard::AdminController
CustomWizard::Api::Authorization.set(params[:name], code: params[:code])
CustomWizard::Api::Authorization.get_token(params[:name])
return redirect_to path('/admin/wizards/apis/' + params[:name])
redirect_to path('/admin/wizards/apis/' + params[:name])
end
private

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
def index
render_json_dump(custom_field_list)

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::AdminLogsController < CustomWizard::AdminController
def index
render_serialized(

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::AdminManagerController < CustomWizard::AdminController
skip_before_action :check_xhr, only: [:export]
before_action :get_wizard_ids, except: [:import]

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::AdminSubmissionsController < CustomWizard::AdminController
skip_before_action :preload_json, :check_xhr, only: [:download]
before_action :find_wizard, except: [:index]

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::AdminWizardController < CustomWizard::AdminController
before_action :find_wizard, only: [:show, :remove]

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::StepsController < ::ApplicationController
before_action :ensure_logged_in
before_action :ensure_can_update

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::WizardController < ::ApplicationController
prepend_view_path(Rails.root.join('plugins', 'discourse-custom-wizard', 'views'))
layout 'wizard'

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class UpdateWatchCategoriesAction < ActiveRecord::Migration[6.0]
def change
watch_category_wizards = PluginStoreRow.where("

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
module CustomWizardCustomFieldPreloader
def preload_custom_fields(objects, fields)
if objects.present? && cw_fields_enabled?

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
module CustomWizardCustomFieldSerializer
def attributes(*args)
hash = super

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
module ExtraLocalesControllerCustomWizard
private def valid_bundle?(bundle)
super || begin

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
module InvitesControllerCustomWizard
def path(url)
if ::Wizard.user_requires_completion?(@user)

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
module CustomWizardUsersController
def account_created
if current_user.present? &&

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
module CustomWizardFieldExtension
attr_reader :raw,
:label,

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
module CustomWizardStepExtension
attr_accessor :title, :description, :key, :permitted, :permitted_message
end

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Jobs
class ClearAfterTimeWizard < ::Jobs::Base
sidekiq_options queue: 'critical'

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Jobs
class RefreshApiAccessToken < ::Jobs::Base
def execute(args)

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
module Jobs
class SetAfterTimeWizard < ::Jobs::Base
def execute(args)

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Action
attr_accessor :data,
:action,
@ -465,7 +466,6 @@ class CustomWizard::Action
name = keyArr.first
end
registered = registered_fields.select { |f| f[:name] == name }
if registered.first.present?
klass = registered.first[:klass]
@ -712,7 +712,7 @@ class CustomWizard::Action
if @log.any?
@log.each do |item|
log << "; #{item.to_s}"
log += "; #{item.to_s}"
end
end

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::ActionResult
attr_accessor :success, :handler, :output

Datei anzeigen

@ -1,10 +1,11 @@
# frozen_string_literal: true
class CustomWizard::Api
include ActiveModel::SerializerSupport
attr_accessor :name,
:title
def initialize(name, data={})
def initialize(name, data = {})
@name = name
data.each do |k, v|
self.send "#{k}=", v if self.respond_to?(k)

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'excon'
class CustomWizard::Api::Authorization
@ -19,7 +20,7 @@ class CustomWizard::Api::Authorization
:username,
:password
def initialize(api_name, data={})
def initialize(api_name, data = {})
@api_name = api_name
data.each do |k, v|
@ -106,18 +107,18 @@ class CustomWizard::Api::Authorization
connection = Excon.new(
authorization.token_url,
:headers => {
headers: {
"Content-Type" => "application/x-www-form-urlencoded"
},
:method => 'GET',
:query => URI.encode_www_form(body)
method: 'GET',
query: URI.encode_www_form(body)
)
begin
result = connection.request()
log_params = {time: Time.now, user_id: 0, status: 'SUCCESS', url: authorization.token_url, error: ""}
log_params = { time: Time.now, user_id: 0, status: 'SUCCESS', url: authorization.token_url, error: "" }
CustomWizard::Api::LogEntry.set(name, log_params)
rescue SystemCallError => e
log_params = {time: Time.now, user_id: 0, status: 'FAILURE', url: authorization.token_url, error: "Token refresh request failed: #{e.inspect}"}
log_params = { time: Time.now, user_id: 0, status: 'FAILURE', url: authorization.token_url, error: "Token refresh request failed: #{e.inspect}" }
CustomWizard::Api::LogEntry.set(name, log_params)
end

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Api::Endpoint
include ActiveModel::SerializerSupport
@ -9,7 +10,7 @@ class CustomWizard::Api::Endpoint
:content_type,
:success_codes
def initialize(api_name, data={})
def initialize(api_name, data = {})
@api_name = api_name
data.each do |k, v|
@ -35,7 +36,7 @@ class CustomWizard::Api::Endpoint
self.get(api_name, endpoint_id)
end
def self.get(api_name, endpoint_id, opts={})
def self.get(api_name, endpoint_id, opts = {})
return nil if !endpoint_id
if data = PluginStore.get("custom_wizard_api_#{api_name}", "endpoint_#{endpoint_id}")

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Api::LogEntry
include ActiveModel::SerializerSupport
@ -12,7 +13,7 @@ class CustomWizard::Api::LogEntry
:name,
:avatar_template
def initialize(api_name, data={})
def initialize(api_name, data = {})
@api_name = api_name
data.each do |k, v|
@ -38,7 +39,7 @@ class CustomWizard::Api::LogEntry
self.get(api_name, log_id)
end
def self.get(api_name, log_id, opts={})
def self.get(api_name, log_id, opts = {})
return nil if !log_id
if data = PluginStore.get("custom_wizard_api_#{api_name}", "log_#{log_id}")

Datei anzeigen

@ -1,7 +1,8 @@
# frozen_string_literal: true
class CustomWizard::Builder
attr_accessor :wizard, :updater, :submissions
def initialize(wizard_id, user=nil)
def initialize(wizard_id, user = nil)
template = CustomWizard::Template.find(wizard_id)
return nil if template.blank?
@ -125,7 +126,7 @@ class CustomWizard::Builder
if final_step
if @wizard.id == @wizard.user.custom_fields['redirect_to_wizard']
@wizard.user.custom_fields.delete('redirect_to_wizard');
@wizard.user.custom_fields.delete('redirect_to_wizard')
@wizard.user.save_custom_fields(true)
end

Datei anzeigen

@ -90,7 +90,6 @@ class ::CustomWizard::CustomField
add_error(I18n.t("#{i18n_key}.unsupported_type", type: value))
end
if attr == 'name'
unless value.is_a?(String)
add_error(I18n.t("#{i18n_key}.name_invalid", name: value))

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Field
def self.types
@types ||= {
@ -64,7 +65,7 @@ class CustomWizard::Field
@require_assets ||= {}
end
def self.register(type, plugin = nil, asset_paths = [], opts={})
def self.register(type, plugin = nil, asset_paths = [], opts = {})
if type
types[type.to_sym] ||= {}
types[type.to_sym] = opts[:type_opts] if opts[:type_opts].present?

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Log
include ActiveModel::Serialization

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Mapper
attr_accessor :inputs, :data, :user
@ -212,7 +213,7 @@ class CustomWizard::Mapper
end
end
def interpolate(string, opts={ user: true, wizard: true, value: true })
def interpolate(string, opts = { user: true, wizard: true, value: true })
return string if string.blank?
if opts[:user]

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::RealtimeValidation::Result
attr_accessor :type,
:items,

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::RealtimeValidation::SimilarTopics
attr_accessor :user

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::StepUpdater
include ActiveModel::Model

Datei anzeigen

@ -10,7 +10,7 @@ class CustomWizard::Template
@data = data
end
def save(opts={})
def save(opts = {})
@opts = opts
normalize_data
@ -27,7 +27,7 @@ class CustomWizard::Template
@data[:id]
end
def self.save(data, opts={})
def self.save(data, opts = {})
new(data).save(opts)
end

Datei anzeigen

@ -1,8 +1,9 @@
# frozen_string_literal: true
class CustomWizard::TemplateValidator
include HasErrors
include ActiveModel::Model
def initialize(data, opts={})
def initialize(data, opts = {})
@data = data
@opts = opts
end

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'addressable/uri'
class ::CustomWizard::UpdateValidator

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_dependency 'wizard/step'
require_dependency 'wizard/field'
require_dependency 'wizard/step_updater'
@ -29,7 +30,7 @@ class CustomWizard::Wizard
:user,
:first_step
def initialize(attrs = {}, user=nil)
def initialize(attrs = {}, user = nil)
@user = user
attrs = attrs.with_indifferent_access
@ -177,7 +178,7 @@ class CustomWizard::Wizard
def can_access?
return false unless user
return true if user.admin
return permitted? && (multiple_submissions || !completed?)
permitted? && (multiple_submissions || !completed?)
end
def reset

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
# name: discourse-custom-wizard
# about: Create custom wizards
# version: 0.7.0
@ -138,7 +139,7 @@ after_initialize do
@excluded_routes ||= SiteSetting.wizard_redirect_exclude_paths.split('|') + ['/w/']
url = request.referer || request.original_url
if request.format === 'text/html' && !@excluded_routes.any? {|str| /#{str}/ =~ url} && wizard_id
if request.format === 'text/html' && !@excluded_routes.any? { |str| /#{str}/ =~ url } && wizard_id
if request.referer !~ /\/w\// && request.referer !~ /\/invites\//
CustomWizard::Wizard.set_submission_redirect(current_user, wizard_id, request.referer)
end
@ -154,7 +155,7 @@ after_initialize do
add_to_serializer(:site, :complete_custom_wizard) do
if scope.user && requires_completion = CustomWizard::Wizard.prompt_completion(scope.user)
requires_completion.map {|w| { name: w[:name], url: "/w/#{w[:id]}"} }
requires_completion.map { |w| { name: w[:name], url: "/w/#{w[:id]}" } }
end
end

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Api::AuthorizationSerializer < ::ApplicationSerializer
attributes :auth_type,
:auth_url,

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Api::BasicEndpointSerializer < ::ApplicationSerializer
attributes :id,
:name

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Api::EndpointSerializer < ::ApplicationSerializer
attributes :id,
:name,

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Api::LogSerializer < ::ApplicationSerializer
attributes :log_id,
:time,

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::ApiSerializer < ::ApplicationSerializer
attributes :name,
:title,

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::BasicApiSerializer < ::ApplicationSerializer
attributes :name,
:title,

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::BasicWizardSerializer < ::ApplicationSerializer
attributes :id, :name
end

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::CustomFieldSerializer < ApplicationSerializer
attributes :id, :klass, :name, :type, :serializers
end

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::LogSerializer < ApplicationSerializer
attributes :message, :date
end

Datei anzeigen

@ -1,2 +1,3 @@
# frozen_string_literal: true
class ::CustomWizard::RealtimeValidation::SimilarTopicsSerializer < ::SimilarTopicSerializer
end

Datei anzeigen

@ -1,5 +1,3 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::Builder do

Datei anzeigen

@ -4,8 +4,8 @@ require_relative '../../plugin_helper.rb'
describe CustomWizard::Cache do
it "writes and reads values to the cache" do
CustomWizard::Cache.new('list').write([1,2,3])
expect(CustomWizard::Cache.new('list').read).to eq([1,2,3])
CustomWizard::Cache.new('list').write([1, 2, 3])
expect(CustomWizard::Cache.new('list').read).to eq([1, 2, 3])
end
it "deletes values from the cache" do
@ -15,7 +15,7 @@ describe CustomWizard::Cache do
describe "#wrap" do
before do
@raw = [1,2,3]
@raw = [1, 2, 3]
end
def list
@ -23,12 +23,12 @@ describe CustomWizard::Cache do
end
it "returns value from passed block" do
expect(list).to eq([1,2,3])
expect(list).to eq([1, 2, 3])
end
it "returns cached value" do
cached = list
@raw = [3,2,1]
@raw = [3, 2, 1]
expect(list).to eq(cached)
end
end

Datei anzeigen

@ -23,7 +23,7 @@ describe CustomWizard::CustomField do
plugin_name = '#{CustomWizard::CustomField::NAMESPACE}' AND
key = '#{custom_field.name}' AND
value::jsonb = '#{field_json.except('name').to_json}'::jsonb
", ).exists?
",).exists?
).to eq(true)
end
end
@ -44,7 +44,7 @@ describe CustomWizard::CustomField do
plugin_name = '#{CustomWizard::CustomField::NAMESPACE}' AND
key = '#{updated_field.name}' AND
value::jsonb = '#{updated_field_json.except('name').to_json}'::jsonb
", ).exists?
",).exists?
).to eq(true)
end

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::Field do

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::Log do

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::Mapper do
@ -86,6 +87,8 @@ describe CustomWizard::Mapper do
it "does not map when one of multiple conditions are not met" do
user1.email = "angus@other-email.com"
user1.save
expect(CustomWizard::Mapper.new(
inputs: inputs['conditional_multiple_pairs'],
data: data,

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::Template do

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::TemplateValidator do

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::UpdateValidator do

Datei anzeigen

@ -1,9 +1,10 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::Wizard do
fab!(:user) { Fabricate(:user) }
fab!(:trusted_user) { Fabricate(:user, trust_level: TrustLevel[3])}
fab!(:admin_user) { Fabricate(:user, admin: true)}
fab!(:trusted_user) { Fabricate(:user, trust_level: TrustLevel[3]) }
fab!(:admin_user) { Fabricate(:user, admin: true) }
let(:template_json) {
JSON.parse(File.open(

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../plugin_helper'
describe ExtraLocalesControllerCustomWizard, type: :request do

Datei anzeigen

@ -1,10 +1,10 @@
# frozen_string_literal: true
require_relative '../plugin_helper'
describe InvitesControllerCustomWizard, type: :request do
fab!(:topic) { Fabricate(:topic) }
let(:invite) do
Invite.invite_by_email("angus@email.com", topic.user, topic)
end
let(:invite) { Invite.generate(topic.user, email: "angus@mcleod.org", topic: topic) }
let(:template) do
JSON.parse(File.open(
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json"

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../plugin_helper'
describe CustomWizardUsersController, type: :request do

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../plugin_helper'
describe CustomWizardFieldExtension do

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../plugin_helper'
describe CustomWizardStepExtension do

Datei anzeigen

@ -32,6 +32,6 @@ describe Jobs::SetAfterTimeWizard do
).to eq(3)
expect(messages.first.data).to eq("super_mega_fun_wizard")
expect(messages.first.user_ids).to match_array([user1.id,user2.id,user3.id])
expect(messages.first.user_ids).to match_array([user1.id, user2.id, user3.id])
end
end

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../../plugin_helper'
describe CustomWizard::AdminCustomFieldsController do

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../../plugin_helper'
describe CustomWizard::AdminLogsController do

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../../plugin_helper'
describe CustomWizard::AdminManagerController do
@ -53,7 +54,7 @@ describe CustomWizard::AdminManagerController do
expect(response.status).to eq(200)
expect(response.parsed_body['imported']).to match_array(templates)
expect(CustomWizard::Template.list.map {|t| t.slice('id', 'name') }).to match_array(templates)
expect(CustomWizard::Template.list.map { |t| t.slice('id', 'name') }).to match_array(templates)
end
it 'rejects a template with the same id as a saved template' do

Datei anzeigen

@ -1,9 +1,10 @@
# frozen_string_literal: true
require_relative '../../../plugin_helper'
describe CustomWizard::AdminSubmissionsController do
fab!(:admin_user) {Fabricate(:user, admin: true)}
fab!(:user1) {Fabricate(:user)}
fab!(:user2) {Fabricate(:user)}
fab!(:admin_user) { Fabricate(:user, admin: true) }
fab!(:user1) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) }
let(:template) {
JSON.parse(File.open(

Datei anzeigen

@ -1,9 +1,10 @@
# frozen_string_literal: true
require_relative '../../../plugin_helper'
describe CustomWizard::AdminWizardController do
fab!(:admin_user) {Fabricate(:user, admin: true)}
fab!(:user1) {Fabricate(:user)}
fab!(:user2) {Fabricate(:user)}
fab!(:admin_user) { Fabricate(:user, admin: true) }
fab!(:user1) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) }
let(:template) {
JSON.parse(File.open(

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe ApplicationController do

Datei anzeigen

@ -92,4 +92,3 @@ describe "custom field extensions" do
end
end
end

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::StepsController do

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../plugin_helper'
describe CustomWizard::WizardController do

Datei anzeigen

@ -24,6 +24,6 @@ describe CustomWizard::CustomFieldSerializer do
expect(json[:name]).to eq("topic_field_1")
expect(json[:klass]).to eq("topic")
expect(json[:type]).to eq("boolean")
expect(json[:serializers]).to match_array(["topic_list_item","topic_view"])
expect(json[:serializers]).to match_array(["topic_list_item", "topic_view"])
end
end

Datei anzeigen

@ -32,7 +32,7 @@ describe CustomWizard::FieldSerializer do
scope: Guardian.new(user)
).as_json
expect(json_array[0][:format]).to eq("YYYY-MM-DD")
expect(json_array[5][:file_types]).to eq(".jpg,.png")
expect(json_array[4][:number]).to eq(5)
expect(json_array[3][:number]).to eq(4)
expect(json_array[6][:file_types]).to eq(".jpg,.png")
end
end