kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
202 lines
7.0 KiB
202 lines
7.0 KiB
11 years ago
|
#-- copyright
|
||
11 years ago
|
# OpenProject Meeting Plugin
|
||
|
#
|
||
|
# Copyright (C) 2011-2014 the OpenProject Foundation (OPF)
|
||
11 years ago
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License version 3.
|
||
|
#
|
||
11 years ago
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
11 years ago
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
|
# See doc/COPYRIGHT.md for more details.
|
||
11 years ago
|
#++
|
||
|
|
||
13 years ago
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||
|
|
||
10 years ago
|
describe User, '#destroy', type: :model do
|
||
7 years ago
|
let(:user) { FactoryBot.create(:user) }
|
||
|
let(:user2) { FactoryBot.create(:user) }
|
||
13 years ago
|
let(:substitute_user) { DeletedUser.first }
|
||
|
let(:project) do
|
||
7 years ago
|
project = FactoryBot.create(:valid_project)
|
||
13 years ago
|
project
|
||
|
end
|
||
|
|
||
10 years ago
|
let(:meeting) {
|
||
7 years ago
|
FactoryBot.create(:meeting, project: project,
|
||
10 years ago
|
author: user2)
|
||
|
}
|
||
|
let(:participant) {
|
||
7 years ago
|
FactoryBot.create(:meeting_participant, user: user,
|
||
10 years ago
|
meeting: meeting,
|
||
|
invited: true,
|
||
|
attended: true)
|
||
|
}
|
||
13 years ago
|
|
||
|
before do
|
||
|
user
|
||
|
user2
|
||
|
end
|
||
|
|
||
10 years ago
|
shared_examples_for 'updated journalized associated object' do
|
||
13 years ago
|
before do
|
||
11 years ago
|
allow(User).to receive(:current).and_return(user2)
|
||
13 years ago
|
associations.each do |association|
|
||
10 years ago
|
associated_instance.send(association.to_s + '=', user2)
|
||
13 years ago
|
end
|
||
|
associated_instance.save!
|
||
|
|
||
11 years ago
|
allow(User).to receive(:current).and_return(user) # in order to have the content journal created by the user
|
||
13 years ago
|
associated_instance.reload
|
||
|
associations.each do |association|
|
||
10 years ago
|
associated_instance.send(association.to_s + '=', user)
|
||
13 years ago
|
end
|
||
|
associated_instance.save!
|
||
|
|
||
|
user.destroy
|
||
|
associated_instance.reload
|
||
|
end
|
||
|
|
||
11 years ago
|
it { expect(associated_class.find_by_id(associated_instance.id)).to eq(associated_instance) }
|
||
10 years ago
|
it 'should replace the user on all associations' do
|
||
13 years ago
|
associations.each do |association|
|
||
11 years ago
|
expect(associated_instance.send(association)).to eq(substitute_user)
|
||
13 years ago
|
end
|
||
|
end
|
||
11 years ago
|
it { expect(associated_instance.journals.first.user).to eq(user2) }
|
||
10 years ago
|
it 'should update first journal changes' do
|
||
13 years ago
|
associations.each do |association|
|
||
10 years ago
|
expect(associated_instance.journals.first.changed_data[(association.to_s + '_id').to_sym].last).to eq(user2.id)
|
||
13 years ago
|
end
|
||
|
end
|
||
11 years ago
|
it { expect(associated_instance.journals.last.user).to eq(substitute_user) }
|
||
10 years ago
|
it 'should update second journal changes' do
|
||
13 years ago
|
associations.each do |association|
|
||
10 years ago
|
expect(associated_instance.journals.last.changed_data[(association.to_s + '_id').to_sym].last).to eq(substitute_user.id)
|
||
13 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
shared_examples_for 'created journalized associated object' do
|
||
13 years ago
|
before do
|
||
11 years ago
|
allow(User).to receive(:current).and_return(user) # in order to have the content journal created by the user
|
||
13 years ago
|
associations.each do |association|
|
||
10 years ago
|
associated_instance.send(association.to_s + '=', user)
|
||
13 years ago
|
end
|
||
|
associated_instance.save!
|
||
|
|
||
11 years ago
|
allow(User).to receive(:current).and_return(user2)
|
||
13 years ago
|
associated_instance.reload
|
||
|
associations.each do |association|
|
||
10 years ago
|
associated_instance.send(association.to_s + '=', user2)
|
||
13 years ago
|
end
|
||
|
associated_instance.save!
|
||
|
|
||
|
user.destroy
|
||
|
associated_instance.reload
|
||
|
end
|
||
|
|
||
11 years ago
|
it { expect(associated_class.find_by_id(associated_instance.id)).to eq(associated_instance) }
|
||
10 years ago
|
it 'should keep the current user on all associations' do
|
||
13 years ago
|
associations.each do |association|
|
||
11 years ago
|
expect(associated_instance.send(association)).to eq(user2)
|
||
13 years ago
|
end
|
||
|
end
|
||
11 years ago
|
it { expect(associated_instance.journals.first.user).to eq(substitute_user) }
|
||
10 years ago
|
it 'should update the first journal' do
|
||
13 years ago
|
associations.each do |association|
|
||
10 years ago
|
expect(associated_instance.journals.first.changed_data[(association.to_s + '_id').to_sym].last).to eq(substitute_user.id)
|
||
13 years ago
|
end
|
||
|
end
|
||
11 years ago
|
it { expect(associated_instance.journals.last.user).to eq(user2) }
|
||
10 years ago
|
it 'should update the last journal' do
|
||
13 years ago
|
associations.each do |association|
|
||
10 years ago
|
expect(associated_instance.journals.last.changed_data[(association.to_s + '_id').to_sym].first).to eq(substitute_user.id)
|
||
|
expect(associated_instance.journals.last.changed_data[(association.to_s + '_id').to_sym].last).to eq(user2.id)
|
||
13 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
describe 'WHEN the user created a meeting' do
|
||
13 years ago
|
let(:associations) { [:author] }
|
||
7 years ago
|
let(:associated_instance) { FactoryBot.build(:meeting, project: project) }
|
||
13 years ago
|
let(:associated_class) { Meeting }
|
||
|
|
||
10 years ago
|
it_should_behave_like 'created journalized associated object'
|
||
13 years ago
|
end
|
||
|
|
||
10 years ago
|
describe 'WHEN the user updated a meeting' do
|
||
13 years ago
|
let(:associations) { [:author] }
|
||
7 years ago
|
let(:associated_instance) { FactoryBot.build(:meeting, project: project) }
|
||
13 years ago
|
let(:associated_class) { Meeting }
|
||
|
|
||
10 years ago
|
it_should_behave_like 'updated journalized associated object'
|
||
13 years ago
|
end
|
||
|
|
||
10 years ago
|
describe 'WHEN the user created a meeting agenda' do
|
||
13 years ago
|
let(:associations) { [:author] }
|
||
10 years ago
|
let(:associated_instance) {
|
||
7 years ago
|
FactoryBot.build(:meeting_agenda, meeting: meeting,
|
||
10 years ago
|
text: 'lorem')
|
||
|
}
|
||
13 years ago
|
let(:associated_class) { MeetingAgenda }
|
||
|
|
||
10 years ago
|
it_should_behave_like 'created journalized associated object'
|
||
13 years ago
|
end
|
||
|
|
||
10 years ago
|
describe 'WHEN the user updated a meeting agenda' do
|
||
13 years ago
|
let(:associations) { [:author] }
|
||
10 years ago
|
let(:associated_instance) {
|
||
7 years ago
|
FactoryBot.build(:meeting_agenda, meeting: meeting,
|
||
10 years ago
|
text: 'lorem')
|
||
|
}
|
||
13 years ago
|
let(:associated_class) { MeetingAgenda }
|
||
|
|
||
10 years ago
|
it_should_behave_like 'updated journalized associated object'
|
||
13 years ago
|
end
|
||
|
|
||
10 years ago
|
describe 'WHEN the user created a meeting minutes' do
|
||
13 years ago
|
let(:associations) { [:author] }
|
||
10 years ago
|
let(:associated_instance) {
|
||
7 years ago
|
FactoryBot.build(:meeting_minutes, meeting: meeting,
|
||
10 years ago
|
text: 'lorem')
|
||
|
}
|
||
13 years ago
|
let(:associated_class) { MeetingMinutes }
|
||
|
|
||
10 years ago
|
it_should_behave_like 'created journalized associated object'
|
||
13 years ago
|
end
|
||
|
|
||
10 years ago
|
describe 'WHEN the user updated a meeting minutes' do
|
||
13 years ago
|
let(:associations) { [:author] }
|
||
10 years ago
|
let(:associated_instance) {
|
||
7 years ago
|
FactoryBot.build(:meeting_minutes, meeting: meeting,
|
||
10 years ago
|
text: 'lorem')
|
||
|
}
|
||
13 years ago
|
let(:associated_class) { MeetingMinutes }
|
||
|
|
||
10 years ago
|
it_should_behave_like 'updated journalized associated object'
|
||
13 years ago
|
end
|
||
|
|
||
10 years ago
|
describe 'WHEN the user participated in a meeting' do
|
||
13 years ago
|
before do
|
||
|
participant
|
||
|
# user2 added to participants by beeing the author
|
||
|
|
||
|
user.destroy
|
||
|
meeting.reload
|
||
|
participant.reload
|
||
|
end
|
||
|
|
||
11 years ago
|
it { expect(meeting.participants.map(&:user)).to match_array([DeletedUser.first, user2]) }
|
||
|
it { expect(participant.invited).to be_truthy }
|
||
|
it { expect(participant.attended).to be_truthy }
|
||
13 years ago
|
end
|
||
|
end
|