Skip to content

Commit e590484

Browse files
committed
FIX: registered topic field names not being cast properly in actions
1 parent 47a1a3d commit e590484

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

lib/custom_wizard/action.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ def add_custom_fields(params = {})
481481

482482
registered = registered_fields.select { |f| f.name == name }.first
483483
if registered.present?
484-
klass = registered.klass
485-
type = registered.type
484+
klass = registered.klass.to_sym
485+
type = registered.type.to_sym
486486
end
487487

488488
next if type === :json && json_attr.blank?

spec/components/custom_wizard/action_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
)
2222
}
2323

24+
let(:create_topic) {
25+
JSON.parse(
26+
File.open(
27+
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/actions/create_topic.json"
28+
).read
29+
)
30+
}
31+
32+
let(:custom_field_json) {
33+
JSON.parse(File.open(
34+
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/custom_field/custom_fields.json"
35+
).read)
36+
}
37+
2438
before do
2539
Group.refresh_automatic_group!(:trust_level_2)
2640
CustomWizard::Template.save(wizard_template, skip_jobs: true)
@@ -107,6 +121,40 @@
107121
expect(topic_json_custom_field.exists?).to eq(true)
108122
expect(post_custom_field.exists?).to eq(true)
109123
end
124+
125+
it "adds registered custom fields" do
126+
custom_field = custom_field_json['custom_fields'][0]
127+
custom_field_name = custom_field["name"]
128+
custom_field_value = "Custom value"
129+
130+
CustomWizard::CustomField.new(nil, custom_field).save
131+
create_topic["custom_fields"] = [
132+
{
133+
"type": "association",
134+
"pairs": [
135+
{
136+
"index": 0,
137+
"key": custom_field_name,
138+
"key_type": "custom_field",
139+
"value": custom_field_value,
140+
"value_type": "text",
141+
"connector": "association"
142+
}
143+
]
144+
}
145+
]
146+
147+
wizard = CustomWizard::Wizard.new(@template, user)
148+
action = CustomWizard::Action.new(
149+
wizard: wizard,
150+
action: create_topic.with_indifferent_access,
151+
submission: wizard.current_submission
152+
)
153+
action.perform
154+
155+
expect(action.result.success?).to eq(true)
156+
expect(TopicCustomField.exists?(name: custom_field_name, value: custom_field_value)).to eq(true)
157+
end
110158
end
111159

112160
context 'sending a message' do
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": "create_topic_1",
3+
"type": "create_topic",
4+
"post_builder": true,
5+
"post_template": "First post in the topic!",
6+
"title": [
7+
{
8+
"type": "assignment",
9+
"output_type": "text",
10+
"output_connector": "set",
11+
"output": "My new topic"
12+
}
13+
]
14+
}

0 commit comments

Comments
 (0)