mirror of
https://github.com/discourse/discourse.git
synced 2025-06-12 08:23:44 +08:00

1. **Multiselect Support for Choice Fields** - Added a `multiselect` option to the choices field component - Updated Field model to accept arrays as values for choices fields 2. **Post Content Feature Filtering** - Added ability to filter posts based on content features: - Posts with images - Posts with links - Posts with code blocks - Posts with uploads 3. **Improved Group Filtering** - Renamed `restricted_user_group` to `restricted_groups` to allow filtering by multiple groups - Added `excluded_groups` to replace `ignore_group_members` which was complex for end users - Renamed `restricted_groups` to `restricted_inbox_groups` for more specific PM filtering and clarity. 4. **Public Topics Filter** - Added a "Public Topics" filter option that excludes all secure categories
123 lines
3.0 KiB
Ruby
123 lines
3.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe DiscourseAutomation::Field do
|
|
describe "post field" do
|
|
DiscourseAutomation::Scriptable.add("test_post_field") { field :foo, component: :post }
|
|
|
|
fab!(:automation) { Fabricate(:automation, script: "test_post_field") }
|
|
|
|
it "works with an empty value" do
|
|
field =
|
|
DiscourseAutomation::Field.create(automation: automation, component: "post", name: "foo")
|
|
expect(field).to be_valid
|
|
end
|
|
|
|
it "works with a text value" do
|
|
field =
|
|
DiscourseAutomation::Field.create(
|
|
automation: automation,
|
|
component: "post",
|
|
name: "foo",
|
|
metadata: {
|
|
value: "foo",
|
|
},
|
|
)
|
|
expect(field).to be_valid
|
|
end
|
|
|
|
it "doesn’t work with an object value" do
|
|
field =
|
|
DiscourseAutomation::Field.create(
|
|
automation: automation,
|
|
component: "post",
|
|
name: "foo",
|
|
metadata: {
|
|
value: {
|
|
x: 1,
|
|
},
|
|
},
|
|
)
|
|
expect(field).to_not be_valid
|
|
end
|
|
end
|
|
|
|
describe "period field" do
|
|
DiscourseAutomation::Scriptable.add("test_period_field") { field :foo, component: :period }
|
|
|
|
fab!(:automation) { Fabricate(:automation, script: "test_period_field") }
|
|
|
|
it "works with an object value" do
|
|
value = { interval: "2", frequency: "day" }
|
|
field =
|
|
DiscourseAutomation::Field.create(
|
|
automation: automation,
|
|
component: "period",
|
|
name: "foo",
|
|
metadata: {
|
|
value: value,
|
|
},
|
|
)
|
|
expect(field).to be_valid
|
|
end
|
|
end
|
|
|
|
describe "choices field" do
|
|
DiscourseAutomation::Scriptable.add("test_choices_field") { field :foo, component: :choices }
|
|
|
|
fab!(:automation) { Fabricate(:automation, script: "test_choices_field") }
|
|
|
|
it "works with a string value" do
|
|
field =
|
|
DiscourseAutomation::Field.create(
|
|
automation: automation,
|
|
component: "choices",
|
|
name: "foo",
|
|
metadata: {
|
|
value: "some text",
|
|
},
|
|
)
|
|
expect(field).to be_valid
|
|
end
|
|
|
|
it "works with an integer value" do
|
|
field =
|
|
DiscourseAutomation::Field.create(
|
|
automation: automation,
|
|
component: "choices",
|
|
name: "foo",
|
|
metadata: {
|
|
value: 21,
|
|
},
|
|
)
|
|
expect(field).to be_valid
|
|
end
|
|
|
|
it "does work with an array value" do
|
|
# this is legit for multiselect choices
|
|
field =
|
|
DiscourseAutomation::Field.create(
|
|
automation: automation,
|
|
component: "choices",
|
|
name: "foo",
|
|
metadata: {
|
|
value: [1, 2, 3],
|
|
},
|
|
)
|
|
expect(field).to be_valid
|
|
end
|
|
|
|
it "works with a nil value" do
|
|
field =
|
|
DiscourseAutomation::Field.create(
|
|
automation: automation,
|
|
component: "choices",
|
|
name: "foo",
|
|
metadata: {
|
|
value: nil,
|
|
},
|
|
)
|
|
expect(field).to be_valid
|
|
end
|
|
end
|
|
end
|