Skip to content

Commit

Permalink
Indicate WP subject as non-writable when generated
Browse files Browse the repository at this point in the history
Automatic subject generation should prevent users from
editing the subject directly. Instead it can only be updated
automatically, when other fields change in that case.
  • Loading branch information
NobodysNightmare committed Jan 8, 2025
1 parent 4a96220 commit efa3f18
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit efa3f18

Please sign in to comment.