Files
discourse/spec/support/shared_examples/custom_fields.rb
Loïc Guitaut 4f82ceaf39 DEV: Introduce core features system specs for plugins
This patch adds a new shared example to be used as a smoke test in
plugins and themes.

A `skip_examples` argument is available to easily opt-out from a
category of tests.

Example:
```rb
RSpec.describe "Testing core features", type: :system do
  it_behaves_like "having working core features", skip_examples: %i[search login]
end
```
2025-03-27 12:12:01 +01:00

28 lines
801 B
Ruby

# frozen_string_literal: true
RSpec.shared_examples_for "it has custom fields" do
let(:record) { described_class.new }
describe "Max number of custom fields" do
let(:custom_fields) { (1..101).to_a.product(["value"]).to_h }
before { record.custom_fields = custom_fields }
it "can't have more than 100 custom fields" do
expect(record).to be_invalid
expect(record.errors[:base]).to include(/Maximum number.*\(100\)/)
end
end
describe "Max length of a custom field" do
let(:bad_value) { "a" * 10_000_001 }
before { record.custom_fields[:my_custom_field] = bad_value }
it "can't have more than 10,000,000 characters" do
expect(record).to be_invalid
expect(record.errors[:base]).to include(/Maximum length.*\(10000000\)/)
end
end
end