af3e61fe75
* Add custom field improvements This PR does a few things to improve our support of custom fields 1. Adds custom fields added by other plugins to the list in admin/wizards/custom-fields and the custom field list in the mapper selector 2. Adds support for json custom fields in the wizard actions * Make eslint happy * Make prettier happy * Make rubocop happy * Make ember template lint happy * Don't assume we have the context in the selector * Ensure custom fields don't require optional attributes (with tests)
47 Zeilen
1,4 KiB
Ruby
47 Zeilen
1,4 KiB
Ruby
# frozen_string_literal: true
|
|
require_relative '../../../plugin_helper'
|
|
|
|
describe CustomWizard::AdminCustomFieldsController do
|
|
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
|
|
|
let(:custom_field_json) {
|
|
JSON.parse(File.open(
|
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/custom_field/custom_fields.json"
|
|
).read)
|
|
}
|
|
|
|
before do
|
|
custom_field_json['custom_fields'].each do |field_json|
|
|
CustomWizard::CustomField.new(nil, field_json).save
|
|
end
|
|
sign_in(admin_user)
|
|
end
|
|
|
|
it "returns the full list of custom fields" do
|
|
get "/admin/wizards/custom-fields.json"
|
|
expect(response.parsed_body.length).to eq(15)
|
|
end
|
|
|
|
it "saves custom fields" do
|
|
topic_field = CustomWizard::CustomField.find_by_name('topic_field_1')
|
|
topic_field_json = topic_field.as_json
|
|
topic_field_json['type'] = 'string'
|
|
|
|
put "/admin/wizards/custom-fields.json", params: {
|
|
custom_field: topic_field_json
|
|
}
|
|
expect(response.status).to eq(200)
|
|
expect(
|
|
CustomWizard::CustomField.find_by_name('topic_field_1').type
|
|
).to eq('string')
|
|
end
|
|
|
|
it "destroys custom fields" do
|
|
topic_field = custom_field_json['custom_fields'][0]
|
|
delete "/admin/wizards/custom-fields/#{topic_field["name"]}.json"
|
|
expect(response.status).to eq(200)
|
|
expect(
|
|
CustomWizard::CustomField.exists?('topic_field_1')
|
|
).to eq(false)
|
|
end
|
|
end
|