remove auto enabling custom field for project when creating custom comment

This commit is contained in:
Ivan Kuchin
2026-02-23 12:31:53 +01:00
parent c39734c8d4
commit cb42aad76b
3 changed files with 1 additions and 34 deletions
-9
View File
@@ -37,19 +37,10 @@ class CustomComment < ApplicationRecord
validates :custom_field, presence: true, uniqueness: { scope: :customized }
validates :customized, presence: true
after_create :activate_custom_field_in_customized_project, if: -> { customized.is_a?(Project) }
private
# to not deal with it in Journals::CreateService::CustomComment#changes_sql
def normalize_newlines
self.text = text.gsub(/\r\n?/, "\n") if text
end
def activate_custom_field_in_customized_project
return if custom_field.is_for_all?
return if customized&.project_custom_fields&.include?(custom_field)
customized.project_custom_fields << custom_field
end
end
-24
View File
@@ -55,28 +55,4 @@ RSpec.describe CustomComment do
expect(comment.reload.text).to eq("Line 1\nLine 2\nLine 3\nLine 4")
end
end
describe "auto enabling custom field for project" do
let(:project) { create(:project) }
context "when custom field is not marked for all" do
let(:custom_field) { create(:project_custom_field) }
it "auto enables it for project" do
create(:custom_comment, custom_field:, customized: project)
expect(project.project_custom_fields).to eq([custom_field])
end
end
context "when field is marked for all" do
let(:custom_field) { create(:project_custom_field, :is_for_all) }
it "doesn't auto enable it for project" do
create(:custom_comment, custom_field:, customized: project)
expect(project.project_custom_fields).to eq([])
end
end
end
end
@@ -230,7 +230,7 @@ RSpec.describe Project, "acts_as_journalized" do
end
describe "custom comments" do
shared_let(:custom_field) { create(:string_project_custom_field, :has_comment) }
let!(:custom_field) { create(:string_project_custom_field, :has_comment, projects: [project]) }
let(:custom_comment_key) { "custom_comment_#{custom_field.id}" }
let(:custom_comment_text) { "some descriptive comment" }
let(:modified_custom_comment_text) { "a more descriptive comment" }