Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 20:02:54 +01:00
FIX: registered topic field names not being cast properly in actions
Dieser Commit ist enthalten in:
Ursprung
47a1a3d730
Commit
e5904846cf
3 geänderte Dateien mit 64 neuen und 2 gelöschten Zeilen
|
@ -481,8 +481,8 @@ class CustomWizard::Action
|
|||
|
||||
registered = registered_fields.select { |f| f.name == name }.first
|
||||
if registered.present?
|
||||
klass = registered.klass
|
||||
type = registered.type
|
||||
klass = registered.klass.to_sym
|
||||
type = registered.type.to_sym
|
||||
end
|
||||
|
||||
next if type === :json && json_attr.blank?
|
||||
|
|
|
@ -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
|
||||
Group.refresh_automatic_group!(:trust_level_2)
|
||||
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(post_custom_field.exists?).to eq(true)
|
||||
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
|
||||
|
||||
context 'sending a message' do
|
||||
|
|
14
spec/fixtures/actions/create_topic.json
gevendort
Normale Datei
14
spec/fixtures/actions/create_topic.json
gevendort
Normale Datei
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
Laden …
In neuem Issue referenzieren