diff --git a/lib/api/v3/work_packages/schema/base_work_package_schema.rb b/lib/api/v3/work_packages/schema/base_work_package_schema.rb index d7b8bbb692da..fa1817762052 100644 --- a/lib/api/v3/work_packages/schema/base_work_package_schema.rb +++ b/lib/api/v3/work_packages/schema/base_work_package_schema.rb @@ -53,6 +53,7 @@ def available_custom_fields def writable?(property) property = property.to_s + return false if property == "subject" && type&.replacement_pattern_defined_for?(:subject) # Special case for milestones + date property property = "start_date" if property == "date" && milestone? diff --git a/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb b/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb index 92c2c88a88cf..d429d80fa309 100644 --- a/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb +++ b/spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb @@ -299,6 +299,16 @@ expect(subject).to be_writable(:priority) end end + + describe "subject" do + it { is_expected.to be_writable(:subject) } + + context "when the type has automatic subject generation enabled" do + let(:type) { build_stubbed(:type, patterns: { subject: { blueprint: "Hello world", enabled: true } }) } + + it { is_expected.not_to be_writable(:subject) } + end + end end describe "#assignable_custom_field_values" do diff --git a/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb b/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb index 41affd8de2b7..cd0cf54566ad 100644 --- a/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb +++ b/spec/lib/api/v3/work_packages/schema/typed_work_package_schema_spec.rb @@ -83,6 +83,18 @@ it "finish date is writable" do expect(subject).to be_writable(:due_date) end + + it "subject is writable" do + expect(subject).to be_writable(:subject) + end + + context "when the type has automatic subject generation enabled" do + let(:type) { create(:type, patterns: { subject: { blueprint: "Hello world", enabled: true } }) } + + it "subject is not writable" do + expect(subject).not_to be_writable(:subject) + end + end end describe "#milestone?" do