OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Ensure unchangeable reminder attributes are protected
Kabiru Mwenjac72487d26e7b
diff --git a/app/contracts/reminders/update_contract.rb b/app/contracts/reminders/update_contract.rbindex e09a94cdc81..de462cfec17 100644--- a/app/contracts/reminders/update_contract.rb+++ b/app/contracts/reminders/update_contract.rb@@ -34,7 +34,7 @@ module Remindersdef unchangeable_attributesif model.remindable_changed? || model.creator_id_changed?- errors.add(:base, :unchangeable_attributes)+ errors.add(:base, :unchangeable)endendenddiff --git a/spec/contracts/reminders/update_contract_spec.rb b/spec/contracts/reminders/update_contract_spec.rbindex 1feb81a88fd..3f58ed19b0d 100644--- a/spec/contracts/reminders/update_contract_spec.rb+++ b/spec/contracts/reminders/update_contract_spec.rb@@ -50,7 +50,7 @@ RSpec.describe Reminders::UpdateContract doreminder.remindable = build_stubbed(:work_package)end- it_behaves_like "contract is invalid", base: :unchangeable_attributes+ it_behaves_like "contract is invalid", base: :unchangeableendcontext "when creator_id changed" do@@ -60,7 +60,7 @@ RSpec.describe Reminders::UpdateContract doallow(User).to receive(:exists?).with(new_creator.id).and_return(true)end- it_behaves_like "contract is invalid", base: :unchangeable_attributes+ it_behaves_like "contract is invalid", base: :unchangeableendenddiff --git a/spec/services/reminders/update_service_spec.rb b/spec/services/reminders/update_service_spec.rbindex b3cc66b9785..1f4822a6f1d 100644--- a/spec/services/reminders/update_service_spec.rb+++ b/spec/services/reminders/update_service_spec.rb@@ -99,4 +99,38 @@ RSpec.describe Reminders::UpdateService doendendend++ describe "unchangeable attributes" do+ let(:original_creator) { create(:user) }+ let(:original_remindable) { create(:work_package) }+ let(:model_instance) { create(:reminder, creator: original_creator, remindable: original_remindable) }++ context "when attempting to update the creator" do+ subject { described_class.new(user: model_instance.creator, model: model_instance).call(creator: another_user) }++ let(:another_user) { create(:user) }++ it "does not update the creator", :aggregate_failures do+ update_svc = subject++ expect(update_svc).to be_a_failure+ expect(update_svc.result.reload.creator).to eq(original_creator)+ expect(update_svc.message).to eq("Creator is invalid. may not be accessed. cannot be changed.")+ end+ end++ context "when attempting to update the remindable" do+ subject { described_class.new(user: model_instance.creator, model: model_instance).call(remindable: another_remindable) }++ let(:another_remindable) { create(:work_package) }++ it "does not update the remindable", :aggregate_failures do+ update_svc = subject++ expect(update_svc).to be_a_failure+ expect(update_svc.result.reload.remindable).to eq(original_remindable)+ expect(update_svc.message).to include("cannot be changed.")+ end+ end+ endend