0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00

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 CustomWizard::Engine.routes.draw do
get ':wizard_id' => 'wizard#index' get ':wizard_id' => 'wizard#index'
put ':wizard_id/skip' => 'wizard#skip' put ':wizard_id/skip' => 'wizard#skip'

Datei anzeigen

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

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::AdminApiController < CustomWizard::AdminController class CustomWizard::AdminApiController < CustomWizard::AdminController
skip_before_action :check_xhr, only: [:redirect] 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.set(params[:name], code: params[:code])
CustomWizard::Api::Authorization.get_token(params[:name]) 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 end
private private

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Api::Endpoint class CustomWizard::Api::Endpoint
include ActiveModel::SerializerSupport include ActiveModel::SerializerSupport
@ -9,7 +10,7 @@ class CustomWizard::Api::Endpoint
:content_type, :content_type,
:success_codes :success_codes
def initialize(api_name, data={}) def initialize(api_name, data = {})
@api_name = api_name @api_name = api_name
data.each do |k, v| data.each do |k, v|
@ -35,7 +36,7 @@ class CustomWizard::Api::Endpoint
self.get(api_name, endpoint_id) self.get(api_name, endpoint_id)
end end
def self.get(api_name, endpoint_id, opts={}) def self.get(api_name, endpoint_id, opts = {})
return nil if !endpoint_id return nil if !endpoint_id
if data = PluginStore.get("custom_wizard_api_#{api_name}", "endpoint_#{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 class CustomWizard::Api::LogEntry
include ActiveModel::SerializerSupport include ActiveModel::SerializerSupport
@ -12,7 +13,7 @@ class CustomWizard::Api::LogEntry
:name, :name,
:avatar_template :avatar_template
def initialize(api_name, data={}) def initialize(api_name, data = {})
@api_name = api_name @api_name = api_name
data.each do |k, v| data.each do |k, v|
@ -38,7 +39,7 @@ class CustomWizard::Api::LogEntry
self.get(api_name, log_id) self.get(api_name, log_id)
end end
def self.get(api_name, log_id, opts={}) def self.get(api_name, log_id, opts = {})
return nil if !log_id return nil if !log_id
if data = PluginStore.get("custom_wizard_api_#{api_name}", "log_#{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 class CustomWizard::Builder
attr_accessor :wizard, :updater, :submissions attr_accessor :wizard, :updater, :submissions
def initialize(wizard_id, user=nil) def initialize(wizard_id, user = nil)
template = CustomWizard::Template.find(wizard_id) template = CustomWizard::Template.find(wizard_id)
return nil if template.blank? return nil if template.blank?
@ -125,7 +126,7 @@ class CustomWizard::Builder
if final_step if final_step
if @wizard.id == @wizard.user.custom_fields['redirect_to_wizard'] 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) @wizard.user.save_custom_fields(true)
end end

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
class CustomWizard::Mapper class CustomWizard::Mapper
attr_accessor :inputs, :data, :user attr_accessor :inputs, :data, :user
@ -212,7 +213,7 @@ class CustomWizard::Mapper
end end
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? return string if string.blank?
if opts[:user] if opts[:user]

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -32,6 +32,6 @@ describe Jobs::SetAfterTimeWizard do
).to eq(3) ).to eq(3)
expect(messages.first.data).to eq("super_mega_fun_wizard") 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
end end

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative '../../../plugin_helper' require_relative '../../../plugin_helper'
describe CustomWizard::AdminManagerController do describe CustomWizard::AdminManagerController do
@ -53,7 +54,7 @@ describe CustomWizard::AdminManagerController do
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response.parsed_body['imported']).to match_array(templates) 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 end
it 'rejects a template with the same id as a saved template' do 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' require_relative '../../../plugin_helper'
describe CustomWizard::AdminSubmissionsController do describe CustomWizard::AdminSubmissionsController do
fab!(:admin_user) {Fabricate(:user, admin: true)} fab!(:admin_user) { Fabricate(:user, admin: true) }
fab!(:user1) {Fabricate(:user)} fab!(:user1) { Fabricate(:user) }
fab!(:user2) {Fabricate(:user)} fab!(:user2) { Fabricate(:user) }
let(:template) { let(:template) {
JSON.parse(File.open( JSON.parse(File.open(

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -24,6 +24,6 @@ describe CustomWizard::CustomFieldSerializer do
expect(json[:name]).to eq("topic_field_1") expect(json[:name]).to eq("topic_field_1")
expect(json[:klass]).to eq("topic") expect(json[:klass]).to eq("topic")
expect(json[:type]).to eq("boolean") 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
end end

Datei anzeigen

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