1
0
Fork 0

FIX: registered topic field names not being cast properly in actions

Dieser Commit ist enthalten in:
Angus McLeod 2022-09-02 09:45:20 +02:00
Ursprung 47a1a3d730
Commit e5904846cf
3 geänderte Dateien mit 64 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -481,8 +481,8 @@ class CustomWizard::Action
registered = registered_fields.select { |f| f.name == name }.first registered = registered_fields.select { |f| f.name == name }.first
if registered.present? if registered.present?
klass = registered.klass klass = registered.klass.to_sym
type = registered.type type = registered.type.to_sym
end end
next if type === :json && json_attr.blank? next if type === :json && json_attr.blank?

Datei anzeigen

@ -21,6 +21,20 @@ describe CustomWizard::Action do
) )
} }
let(:create_topic) {
JSON.parse(
File.open(
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/actions/create_topic.json"
).read
)
}
let(:custom_field_json) {
JSON.parse(File.open(
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/custom_field/custom_fields.json"
).read)
}
before do before do
Group.refresh_automatic_group!(:trust_level_2) Group.refresh_automatic_group!(:trust_level_2)
CustomWizard::Template.save(wizard_template, skip_jobs: true) CustomWizard::Template.save(wizard_template, skip_jobs: true)
@ -107,6 +121,40 @@ describe CustomWizard::Action do
expect(topic_json_custom_field.exists?).to eq(true) expect(topic_json_custom_field.exists?).to eq(true)
expect(post_custom_field.exists?).to eq(true) expect(post_custom_field.exists?).to eq(true)
end end
it "adds registered custom fields" do
custom_field = custom_field_json['custom_fields'][0]
custom_field_name = custom_field["name"]
custom_field_value = "Custom value"
CustomWizard::CustomField.new(nil, custom_field).save
create_topic["custom_fields"] = [
{
"type": "association",
"pairs": [
{
"index": 0,
"key": custom_field_name,
"key_type": "custom_field",
"value": custom_field_value,
"value_type": "text",
"connector": "association"
}
]
}
]
wizard = CustomWizard::Wizard.new(@template, user)
action = CustomWizard::Action.new(
wizard: wizard,
action: create_topic.with_indifferent_access,
submission: wizard.current_submission
)
action.perform
expect(action.result.success?).to eq(true)
expect(TopicCustomField.exists?(name: custom_field_name, value: custom_field_value)).to eq(true)
end
end end
context 'sending a message' do context 'sending a message' do

14
spec/fixtures/actions/create_topic.json gevendort Normale Datei
Datei anzeigen

@ -0,0 +1,14 @@
{
"id": "create_topic_1",
"type": "create_topic",
"post_builder": true,
"post_template": "First post in the topic!",
"title": [
{
"type": "assignment",
"output_type": "text",
"output_connector": "set",
"output": "My new topic"
}
]
}