Fix user is shown as deleted incorrectly

pull/1853/head
Mihail Maxacov 10 years ago
parent c604f17be8
commit e6bde3a7a2
  1. 3
      app/models/journal_manager.rb
  2. 48
      spec/models/journal_manager_spec.rb

@ -197,8 +197,7 @@ class JournalManager
end end
# change journal user # 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? journal.save if journal.data.changed?
end end

@ -100,4 +100,52 @@ describe JournalManager, :type => :model do
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
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 end

Loading…
Cancel
Save