diff --git a/app/models/custom_comment.rb b/app/models/custom_comment.rb index 469a73b29b4..80ef1861541 100644 --- a/app/models/custom_comment.rb +++ b/app/models/custom_comment.rb @@ -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 diff --git a/spec/models/custom_comment_spec.rb b/spec/models/custom_comment_spec.rb index c96b1397bc6..59ba738c102 100644 --- a/spec/models/custom_comment_spec.rb +++ b/spec/models/custom_comment_spec.rb @@ -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 diff --git a/spec/models/projects/project_acts_as_journalized_spec.rb b/spec/models/projects/project_acts_as_journalized_spec.rb index b34c78a06d4..92b361ad06d 100644 --- a/spec/models/projects/project_acts_as_journalized_spec.rb +++ b/spec/models/projects/project_acts_as_journalized_spec.rb @@ -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" }