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.
149 lines
5.4 KiB
149 lines
5.4 KiB
#-- copyright
|
|
# OpenProject is a project management system.
|
|
#
|
|
# Copyright (C) 2012-2013 the OpenProject Team
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License version 3.
|
|
#
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
#++
|
|
|
|
require 'spec_helper'
|
|
|
|
describe WorkPackage do
|
|
|
|
let(:project) { FactoryGirl.create(:project) }
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
describe "validations" do
|
|
|
|
# validations
|
|
[:subject, :priority, :project, :type, :author, :status].each do |field|
|
|
it{ should validate_presence_of field}
|
|
end
|
|
|
|
it { should ensure_length_of(:subject).is_at_most 255 }
|
|
it { should ensure_inclusion_of(:done_ratio).in_range 0..100 }
|
|
it { should validate_numericality_of :estimated_hours}
|
|
|
|
it "validates, that start-date is before end-date" do
|
|
wp = FactoryGirl.build(:work_package, start_date: 1.day.from_now, due_date: 1.day.ago)
|
|
expect(wp).to have(1).errors_on(:due_date)
|
|
end
|
|
|
|
it "validates, that correct formats are properly parsed" do
|
|
wp = FactoryGirl.build(:work_package, start_date: "01/01/13", due_date: "31/01/13")
|
|
expect(wp).to have(:no).errors_on(:start_date)
|
|
expect(wp).to have(:no).errors_on(:due_date)
|
|
end
|
|
|
|
describe "hierarchical work_package-validations" do
|
|
# There are basically __no__ validations for hierarchies: The sole semantic here is, that the start-date of a parent
|
|
# is set to the earliest start-date of its children.
|
|
|
|
let(:early_date) {1.week.from_now.to_date}
|
|
let(:late_date) {2.weeks.from_now.to_date}
|
|
let(:parent) { FactoryGirl.create(:work_package, author: user, project: project, start_date: late_date)}
|
|
let(:child_1){ FactoryGirl.create(:work_package, author: user, project: project, parent: parent, start_date: late_date)}
|
|
let(:child_2){ FactoryGirl.create(:work_package, author: user, project: project, parent: parent, start_date: late_date)}
|
|
|
|
it "verify, that the start-date of a parent is set to the start-date of it's earliest child." do
|
|
child_1.start_date = early_date
|
|
expect(child_1).to be_valid # yes, I can move the child-start-date before the parent-start-date...
|
|
child_1.save
|
|
|
|
expect{
|
|
parent.reload
|
|
}.to change{parent.start_date}.from(late_date).to(early_date) # ... but this changes the parent's start_date to the child's start_date
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
describe "validations of related packages" do
|
|
let(:predecessor){ FactoryGirl.create(:work_package, author: user, project: project, start_date: "31/01/13")}
|
|
let(:successor) {FactoryGirl.create(:work_package, author: user, project: project, start_date: "31/01/13")}
|
|
|
|
it "validate, that the start date of a work-package is no sooner than the start_dates of preceding work_packages" do
|
|
relation = IssueRelation.new(:issue_from => predecessor, :issue_to => successor, :relation_type => IssueRelation::TYPE_PRECEDES)
|
|
relation.save!
|
|
|
|
|
|
successor.reload # TODO this is ugly: We should be able to test all this with stubbed objects and without hitting the db...
|
|
successor.start_date = "01/01/13"
|
|
|
|
expect(successor).not_to be_valid
|
|
expect(successor).to have(1).errors_on(:start_date)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
describe "validations of versions" do
|
|
|
|
it "validate, that versions of the project can be assigned to workpackages" do
|
|
wp = FactoryGirl.build(:work_package)
|
|
assignable_version = FactoryGirl.create(:version, project: wp.project)
|
|
|
|
wp.fixed_version = assignable_version
|
|
expect(wp).to be_valid
|
|
|
|
end
|
|
it "validate, that the fixed_version belongs to the project ticket lives in" do
|
|
other_project = FactoryGirl.create(:project)
|
|
non_assignable_version = FactoryGirl.create(:version, project: other_project)
|
|
|
|
wp = FactoryGirl.build(:work_package)
|
|
wp.fixed_version = non_assignable_version
|
|
|
|
expect(wp).not_to be_valid
|
|
expect(wp).to have(1).errors_on(:fixed_version_id)
|
|
end
|
|
|
|
it "validate, that closed or locked versions cannot be assigned" do
|
|
wp = FactoryGirl.build(:work_package)
|
|
non_assignable_version = FactoryGirl.create(:version, project: wp.project)
|
|
|
|
%w{locked closed}.each do |status|
|
|
non_assignable_version.update_attribute(:status, status)
|
|
|
|
wp.fixed_version = non_assignable_version
|
|
expect(wp).not_to be_valid
|
|
expect(wp).to have(1).errors_on(:fixed_version_id)
|
|
end
|
|
end
|
|
|
|
describe "validations of enabled types" do
|
|
let (:old_type) {FactoryGirl.create(:type, name: "old")}
|
|
|
|
let (:old_project) {FactoryGirl.create(:project, types: [old_type])}
|
|
let (:work_package) {FactoryGirl.create(:work_package, project: old_project, type: old_type)}
|
|
|
|
let (:new_type) {FactoryGirl.create(:type, name: "new")}
|
|
let (:new_project) {FactoryGirl.create(:project, :types => [new_type])}
|
|
|
|
|
|
it "validate, that the newly selected type is available for the project the wp lives in" do
|
|
# change type to a type of another project
|
|
|
|
work_package.type = new_type
|
|
|
|
expect(work_package).not_to be_valid
|
|
expect(work_package).to have(1).errors_on(:type_id)
|
|
end
|
|
|
|
it "validate, that the selected type is enabled for the project the wp was moved into" do
|
|
work_package.project = new_project
|
|
|
|
expect(work_package).not_to be_valid
|
|
expect(work_package).to have(1).errors_on(:type_id)
|
|
end
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
end |