From e6bde3a7a286d9f1175c04ee841c3769e488704b Mon Sep 17 00:00:00 2001 From: Mihail Maxacov <0xf013@gmail.com> Date: Wed, 3 Sep 2014 10:46:32 +0300 Subject: [PATCH] Fix user is shown as deleted incorrectly --- app/models/journal_manager.rb | 3 +- spec/models/journal_manager_spec.rb | 48 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/models/journal_manager.rb b/app/models/journal_manager.rb index 9f9bd685ac..00eede350b 100644 --- a/app/models/journal_manager.rb +++ b/app/models/journal_manager.rb @@ -197,8 +197,7 @@ class JournalManager end # change journal user - journal.user_id = substitute_id if journal.user_id = current_user_id - + journal.user_id = substitute_id if journal.user_id == current_user_id journal.save if journal.data.changed? end diff --git a/spec/models/journal_manager_spec.rb b/spec/models/journal_manager_spec.rb index 083aab3596..44e6fc171a 100644 --- a/spec/models/journal_manager_spec.rb +++ b/spec/models/journal_manager_spec.rb @@ -100,4 +100,52 @@ describe JournalManager, :type => :model do it { is_expected.to be_truthy } end end + + + describe "self.#update_user_references" do + + let!(:work_package) {FactoryGirl.create :work_package} + let!(:doomed_user) {work_package.author} + let!(:data1) { + FactoryGirl.build(:journal_work_package_journal, + subject: work_package.subject, + status_id: work_package.status_id, + type_id: work_package.type_id, + author_id: doomed_user.id, + project_id: work_package.project_id) + } + let!(:data2) { + FactoryGirl.build(:journal_work_package_journal, + subject: work_package.subject, + status_id: work_package.status_id, + type_id: work_package.type_id, + author_id: doomed_user.id, + project_id: work_package.project_id) + } + let!(:doomed_user_journal) { + FactoryGirl.create :work_package_journal, + notes: "1", + user: doomed_user, + journable_id: work_package.id, + data: data1 + } + let!(:some_other_journal) { + FactoryGirl.create :work_package_journal, + notes: "2", + journable_id: work_package.id, + data: data2 + } + + before do + doomed_user.destroy + end + + it "should mark the user's journal as deleted" do + expect(doomed_user_journal.reload.user.is_a?(DeletedUser)).to be_truthy + end + + it "should not mark an unrelated journal's user as deleted" do + expect(some_other_journal.reload.user.is_a?(DeletedUser)).to be_falsy + end + end end