From 635700a51e5bd322911f8c3e8453cee1f389cc10 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Sat, 25 Nov 2023 11:35:21 +0100 Subject: [PATCH] DEV: custom fields concern has be refactored https://github.com/discourse/discourse/commit/6aa69bdaeae33effec0acebceaf05f0944c68d77 --- lib/custom_wizard/custom_field.rb | 8 ++++---- spec/components/custom_wizard/custom_field_spec.rb | 4 ++-- spec/extensions/custom_field_extensions_spec.rb | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/custom_wizard/custom_field.rb b/lib/custom_wizard/custom_field.rb index e8c69c8e..234ef0c7 100644 --- a/lib/custom_wizard/custom_field.rb +++ b/lib/custom_wizard/custom_field.rb @@ -234,16 +234,16 @@ class ::CustomWizard::CustomField external = [] CLASSES.keys.each do |klass| - field_types = klass.to_s.classify.constantize.custom_field_types + meta_data = klass.to_s.classify.constantize.send('custom_field_meta_data') - if field_types.present? - field_types.each do |name, type| + if meta_data.present? + meta_data.each do |name, data| unless list.any? { |field| field.name === name } field = new( 'external', name: name, klass: klass, - type: type + type: data.type ) external.push(field) end diff --git a/spec/components/custom_wizard/custom_field_spec.rb b/spec/components/custom_wizard/custom_field_spec.rb index e25294a0..3edff439 100644 --- a/spec/components/custom_wizard/custom_field_spec.rb +++ b/spec/components/custom_wizard/custom_field_spec.rb @@ -260,11 +260,11 @@ describe CustomWizard::CustomField do expect(CustomWizard::CustomField.list_by(:serializers, ['post']).length).to eq(0) end - it "lists custom field records added by other plugins " do + it "custom field records added by other plugins " do expect(CustomWizard::CustomField.external_list.length).to be > 2 end - it "lists all custom field records" do + it "all custom field records" do expect(CustomWizard::CustomField.full_list.length).to be > 2 end end diff --git a/spec/extensions/custom_field_extensions_spec.rb b/spec/extensions/custom_field_extensions_spec.rb index e73099ca..1e7f1acc 100644 --- a/spec/extensions/custom_field_extensions_spec.rb +++ b/spec/extensions/custom_field_extensions_spec.rb @@ -21,7 +21,7 @@ describe "custom field extensions" do context "topic" do it "registers topic custom fields" do topic - expect(Topic.get_custom_field_type("topic_field_1")).to eq(:boolean) + expect(Topic.get_custom_field_descriptor("topic_field_1").type).to eq(:boolean) end it "adds topic custom fields to the topic_view serializer" do @@ -54,7 +54,7 @@ describe "custom field extensions" do context "post" do it "registers post custom fields" do post - expect(Post.get_custom_field_type("post_field_1")).to eq(:integer) + expect(Post.get_custom_field_descriptor("post_field_1").type).to eq(:integer) end it "adds post custom fields to the post serializer" do @@ -84,7 +84,7 @@ describe "custom field extensions" do context "category" do it "registers" do category - expect(Category.get_custom_field_type("category_field_1")).to eq(:json) + expect(Category.get_custom_field_descriptor("category_field_1").type).to eq(:json) end it "adds custom fields to the basic category serializer" do @@ -104,7 +104,7 @@ describe "custom field extensions" do context "group" do it "registers" do group - expect(Group.get_custom_field_type("group_field_1")).to eq(:string) + expect(Group.get_custom_field_descriptor("group_field_1").type).to eq(:string) end it "adds custom fields to the basic group serializer" do