Skip to content

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

Switch to double quotes for files modified on this branch

Christophe Bliard188bae702d02
diff --git a/spec/models/work_package_spec.rb b/spec/models/work_package_spec.rb
index 0af23f558c4..fd27330defb 100644
--- a/spec/models/work_package_spec.rb
+++ b/spec/models/work_package_spec.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-require 'spec_helper'
+require "spec_helper"
RSpec.describe WorkPackage do
shared_let(:type) { create(:type_standard) }
@@ -54,23 +54,23 @@ RSpec.describe WorkPackage do
author_id: user.id,
status_id: status.id,
priority:,
- subject: 'test_create',
- description: 'WorkPackage#create',
- estimated_hours: '1:30' }
+ subject: "test_create",
+ description: "WorkPackage#create",
+ estimated_hours: "1:30" }
end
end
- describe 'associations' do
+ describe "associations" do
subject { work_package }
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:type) }
it { is_expected.to belong_to(:status) }
it { is_expected.to belong_to(:author) }
- it { is_expected.to belong_to(:assigned_to).class_name('Principal').optional }
- it { is_expected.to belong_to(:responsible).class_name('Principal').optional }
+ it { is_expected.to belong_to(:assigned_to).class_name("Principal").optional }
+ it { is_expected.to belong_to(:responsible).class_name("Principal").optional }
it { is_expected.to belong_to(:version).optional }
- it { is_expected.to belong_to(:priority).class_name('IssuePriority') }
+ it { is_expected.to belong_to(:priority).class_name("IssuePriority") }
it { is_expected.to belong_to(:category).optional }
it { is_expected.to have_many(:time_entries).dependent(:delete_all) }
it { is_expected.to have_many(:file_links).dependent(:delete_all).class_name("Storages::FileLink") }
@@ -78,28 +78,28 @@ RSpec.describe WorkPackage do
it { is_expected.to have_and_belong_to_many(:changesets) }
it { is_expected.to have_and_belong_to_many(:github_pull_requests) }
it { is_expected.to have_many(:members).dependent(:destroy) }
- it { is_expected.to have_many(:member_principals).through(:members).class_name('Principal').source(:principal) }
+ it { is_expected.to have_many(:member_principals).through(:members).class_name("Principal").source(:principal) }
it { is_expected.to have_many(:meeting_agenda_items) }
it { is_expected.to have_many(:meetings).through(:meeting_agenda_items).source(:meeting) }
end
- describe '.new' do
- context 'type' do
+ describe ".new" do
+ describe "type" do
let(:type2) { create(:type) }
before do
project.types << type2
end
- context 'no project chosen' do
- it 'has no type set if no project was chosen' do
+ context "when no project chosen" do
+ it "has no type set if no project was chosen" do
expect(described_class.new.type)
.to be_nil
end
end
- context 'project chosen' do
- it 'has the provided type if one is provided' do
+ context "when project chosen" do
+ it "has the provided type if one is provided" do
expect(described_class.new(project:, type: type2).type)
.to eql type2
end
@@ -107,14 +107,14 @@ RSpec.describe WorkPackage do
end
end
- describe 'create' do
- describe '#save' do
+ describe "create" do
+ describe "#save" do
subject { work_package.save }
it { is_expected.to be_truthy }
end
- describe '#estimated_hours' do
+ describe "#estimated_hours" do
before do
work_package.save!
work_package.reload
@@ -125,7 +125,7 @@ RSpec.describe WorkPackage do
it { is_expected.to eq(1.5) }
end
- describe 'minimal' do
+ describe "minimal" do
let(:work_package_minimal) do
described_class.new.tap do |w|
w.attributes = { project_id: project.id,
@@ -133,17 +133,17 @@ RSpec.describe WorkPackage do
author_id: user.id,
status_id: status.id,
priority:,
- subject: 'test_create' }
+ subject: "test_create" }
end
end
- context 'save' do
+ describe "save" do
subject { work_package_minimal.save }
it { is_expected.to be_truthy }
end
- context 'description' do
+ describe "description" do
before do
work_package_minimal.save!
work_package_minimal.reload
@@ -155,8 +155,8 @@ RSpec.describe WorkPackage do
end
end
- describe '#assigned_to' do
- context 'group_assignment' do
+ describe "#assigned_to" do
+ describe "group_assignment" do
let(:group) { create(:group) }
subject do
@@ -169,7 +169,7 @@ RSpec.describe WorkPackage do
end
end
- describe '#category' do
+ describe "#category" do
let(:user2) { create(:user, member_with_permissions: { project => %i[view_work_packages edit_work_packages] }) }
let(:category) do
create(:category,
@@ -187,7 +187,7 @@ RSpec.describe WorkPackage do
it { is_expected.to eq(category.assigned_to) }
end
- describe 'responsible' do
+ describe "responsible" do
let(:group) { create(:group) }
let!(:member) do
create(:member,
@@ -196,16 +196,16 @@ RSpec.describe WorkPackage do
roles: [create(:project_role)])
end
- context 'with group assigned' do
+ context "with group assigned" do
before { work_package.responsible = group }
- it 'is valid' do
+ it "is valid" do
expect(work_package).to be_valid
end
end
end
- describe '#assignable_versions' do
+ describe "#assignable_versions" do
let(:stub_version2) { build_stubbed(:version) }
def stub_shared_versions(v = nil)
@@ -220,7 +220,7 @@ RSpec.describe WorkPackage do
expect(stub_work_package.assignable_versions).to eq([stub_version])
end
- it 'returns the former version if the version changed' do
+ it "returns the former version if the version changed" do
stub_shared_versions
stub_work_package.version = stub_version2
@@ -232,7 +232,7 @@ RSpec.describe WorkPackage do
expect(stub_work_package.assignable_versions).to eq([stub_version])
end
- it 'returns the current version if the version did not change' do
+ it "returns the current version if the version did not change" do
stub_shared_versions
stub_work_package.version = stub_version
@@ -242,7 +242,7 @@ RSpec.describe WorkPackage do
expect(stub_work_package.assignable_versions).to eq([stub_version])
end
- context 'with many versions' do
+ context "with many versions" do
let!(:work_package) do
wp = create(:work_package,
project:,
@@ -254,38 +254,38 @@ RSpec.describe WorkPackage do
end
let!(:version_current) do
create(:version,
- status: 'closed',
+ status: "closed",
project:)
end
let!(:version_open) do
create(:version,
- status: 'open',
+ status: "open",
project:)
end
let!(:version_locked) do
create(:version,
- status: 'locked',
+ status: "locked",
project:)
end
let!(:version_closed) do
create(:version,
- status: 'closed',
+ status: "closed",
project:)
end
let!(:version_other_project) do
create(:version,
- status: 'open',
+ status: "open",
project: create(:project))
end
- it 'returns all open versions of the project' do
+ it "returns all open versions of the project" do
expect(work_package.assignable_versions)
.to contain_exactly(version_current, version_open)
end
end
end
- describe '#destroy' do
+ describe "#destroy" do
let!(:time_entry1) do
create(:time_entry,
project:,
@@ -301,34 +301,34 @@ RSpec.describe WorkPackage do
work_package.destroy
end
- describe 'work package' do
+ describe "work package" do
subject { described_class.find_by(id: work_package.id) }
it { is_expected.to be_nil }
end
- describe 'time entries' do
+ describe "time entries" do
subject { TimeEntry.find_by(work_package_id: work_package.id) }
it { is_expected.to be_nil }
end
end
- include_examples 'creates an audit trail on destroy' do
+ include_examples "creates an audit trail on destroy" do
subject { create(:work_package) }
end
- describe '#done_ratio' do
+ describe "#done_ratio" do
shared_let(:status_new) do
create(:status,
- name: 'New',
+ name: "New",
is_default: true,
is_closed: false,
default_done_ratio: 50)
end
shared_let(:status_assigned) do
create(:status,
- name: 'Assigned',
+ name: "Assigned",
is_default: true,
is_closed: false,
default_done_ratio: 0)
@@ -344,28 +344,28 @@ RSpec.describe WorkPackage do
done_ratio: 30)
end
- describe '#value' do
- context 'for work-based mode',
- with_settings: { work_package_done_ratio: 'field' } do
- it 'returns the value from work package field' do
+ describe "#value" do
+ context "for work-based mode",
+ with_settings: { work_package_done_ratio: "field" } do
+ it "returns the value from work package field" do
expect(work_package_new.done_ratio).to be_nil
expect(work_package_assigned.done_ratio).to eq(30)
end
end
- context 'for status-based mode',
- with_settings: { work_package_done_ratio: 'status' } do
- it 'uses the % Complete value from the work package status' do
+ context "for status-based mode",
+ with_settings: { work_package_done_ratio: "status" } do
+ it "uses the % Complete value from the work package status" do
expect(work_package_new.done_ratio).to eq(status_new.default_done_ratio)
expect(work_package_assigned.done_ratio).to eq(status_assigned.default_done_ratio)
end
end
end
- describe '#update_done_ratio_from_status' do
- context 'for work-based mode',
- with_settings: { work_package_done_ratio: 'field' } do
- it 'does not update the done ratio' do
+ describe "#update_done_ratio_from_status" do
+ context "for work-based mode",
+ with_settings: { work_package_done_ratio: "field" } do
+ it "does not update the done ratio" do
expect { work_package_new.update_done_ratio_from_status }
.not_to change { work_package_new[:done_ratio] }
expect { work_package_assigned.update_done_ratio_from_status }
@@ -373,9 +373,9 @@ RSpec.describe WorkPackage do
end
end
- context 'for status-based mode',
- with_settings: { work_package_done_ratio: 'status' } do
- it 'updates the done ratio without saving it' do
+ context "for status-based mode",
+ with_settings: { work_package_done_ratio: "status" } do
+ it "updates the done ratio without saving it" do
expect { work_package_new.update_done_ratio_from_status }
.to change { work_package_new[:done_ratio] }
.from(nil).to(50)
@@ -389,7 +389,7 @@ RSpec.describe WorkPackage do
end
end
- describe '#group_by' do
+ describe "#group_by" do
shared_let(:type2) { create(:type) }
shared_let(:priority2) { create(:priority) }
shared_let(:project) { create(:project, types: [type, type2]) }
@@ -422,72 +422,72 @@ RSpec.describe WorkPackage do
category: category2)
end
- shared_examples_for 'group by' do
- context 'size' do
+ shared_examples_for "group by" do
+ describe "size" do
subject { groups.size }
it { is_expected.to eq(2) }
end
- context 'total' do
- subject { groups.inject(0) { |sum, group| sum + group['total'].to_i } }
+ describe "total" do
+ subject { groups.inject(0) { |sum, group| sum + group["total"].to_i } }
it { is_expected.to eq(2) }
end
end
- context 'by type' do
+ describe "by type" do
let(:groups) { described_class.by_type(project) }
- it_behaves_like 'group by'
+ it_behaves_like "group by"
end
- context 'by version' do
+ describe "by version" do
let(:groups) { described_class.by_version(project) }
- it_behaves_like 'group by'
+ it_behaves_like "group by"
end
- context 'by priority' do
+ describe "by priority" do
let(:groups) { described_class.by_priority(project) }
- it_behaves_like 'group by'
+ it_behaves_like "group by"
end
- context 'by category' do
+ describe "by category" do
let(:groups) { described_class.by_category(project) }
- it_behaves_like 'group by'
+ it_behaves_like "group by"
end
- context 'by assigned to' do
+ describe "by assigned to" do
let(:groups) { described_class.by_assigned_to(project) }
- it_behaves_like 'group by'
+ it_behaves_like "group by"
end
- context 'by responsible' do
+ describe "by responsible" do
let(:groups) { described_class.by_responsible(project) }
- it_behaves_like 'group by'
+ it_behaves_like "group by"
end
- context 'by author' do
+ describe "by author" do
let(:groups) { described_class.by_author(project) }
- it_behaves_like 'group by'
+ it_behaves_like "group by"
end
- context 'by project' do
+ describe "by project" do
shared_let(:project2) { create(:project, parent: project) }
shared_let(:work_package3) { create(:work_package, project: project2) }
let(:groups) { described_class.by_author(project) }
- it_behaves_like 'group by'
+ it_behaves_like "group by"
end
end
- describe '#recently_updated' do
+ describe "#recently_updated" do
let!(:work_package1) { create(:work_package) }
let!(:work_package2) { create(:work_package) }
@@ -498,22 +498,22 @@ RSpec.describe WorkPackage do
end
end
- context 'limit' do
+ describe "limit" do
subject { described_class.recently_updated.limit(1).first }
it { is_expected.to eq(work_package2) }
end
end
- describe '#on_active_project' do
+ describe "#on_active_project" do
shared_let(:work_package) { create(:work_package, project:) }
subject { described_class.on_active_project.length }
- context 'one work package in active projects' do
+ context "with one work package in active projects" do
it { is_expected.to eq(1) }
- context 'and one work package in archived projects' do
+ context "and one work package in archived projects" do
shared_let(:work_package_in_archived_project) do
create(:work_package, project: project_archived)
end
@@ -523,15 +523,15 @@ RSpec.describe WorkPackage do
end
end
- describe '#with_author' do
+ describe "#with_author" do
shared_let(:work_package) { create(:work_package, project:, author: user1) }
subject { described_class.with_author(user1).length }
- context 'one work package in active projects' do
+ context "with one work package in active projects" do
it { is_expected.to eq(1) }
- context 'and one work package in archived projects' do
+ context "and one work package in archived projects" do
shared_let(:work_package_in_archived_project) do
create(:work_package, project: project_archived, author: user1)
end
@@ -541,75 +541,75 @@ RSpec.describe WorkPackage do
end
end
- describe '#add_time_entry' do
- it 'returns a new time entry' do
+ describe "#add_time_entry" do
+ it "returns a new time entry" do
expect(stub_work_package.add_time_entry).to be_a TimeEntry
end
- it 'alreadies have the project assigned' do
+ it "has already the project assigned" do
stub_work_package.project = stub_project
expect(stub_work_package.add_time_entry.project).to eq(stub_project)
end
- it 'alreadies have the work_package assigned' do
+ it "has already the work_package assigned" do
expect(stub_work_package.add_time_entry.work_package).to eq(stub_work_package)
end
- it 'returns an usaved entry' do
+ it "returns an unsaved entry" do
expect(stub_work_package.add_time_entry).to be_new_record
end
end
- describe '.allowed_target_project_on_move' do
+ describe ".allowed_target_project_on_move" do
let(:permissions) { [:move_work_packages] }
let(:user) do
create(:user, member_with_permissions: { project => permissions })
end
- context 'when having the move_work_packages permission' do
- it 'returns the project' do
+ context "when having the move_work_packages permission" do
+ it "returns the project" do
expect(described_class.allowed_target_projects_on_move(user))
.to contain_exactly(project)
end
end
- context 'when lacking the move_work_packages permission' do
+ context "when lacking the move_work_packages permission" do
let(:permissions) { [] }
- it 'does not return the project' do
+ it "does not return the project" do
expect(described_class.allowed_target_projects_on_move(user))
.to be_empty
end
end
end
- describe '.allowed_target_project_on_create' do
+ describe ".allowed_target_project_on_create" do
let(:permissions) { [:add_work_packages] }
let(:user) do
create(:user, member_with_permissions: { project => permissions })
end
- context 'when having the add_work_packages permission' do
- it 'returns the project' do
+ context "when having the add_work_packages permission" do
+ it "returns the project" do
expect(described_class.allowed_target_projects_on_create(user))
.to contain_exactly(project)
end
end
- context 'when lacking the add_work_packages permission' do
+ context "when lacking the add_work_packages permission" do
let(:permissions) { [] }
- it 'does not return the project' do
+ it "does not return the project" do
expect(described_class.allowed_target_projects_on_create(user))
.to be_empty
end
end
end
- describe '#duration' do
+ describe "#duration" do
context "when not setting a value" do
- it 'is nil' do
+ it "is nil" do
expect(work_package.duration).to be_nil
end
end
@@ -619,13 +619,13 @@ RSpec.describe WorkPackage do
work_package.duration = 5
end
- it 'is the value' do
+ it "is the value" do
expect(work_package.duration).to eq(5)
end
end
end
- describe 'changed_since' do
+ describe "changed_since" do
shared_let(:work_package) do
Timecop.travel(5.hours.ago) do
create(:work_package, project:)
@@ -634,35 +634,35 @@ RSpec.describe WorkPackage do
subject { described_class.changed_since(since) }
- describe 'null' do
+ describe "null" do
let(:since) { nil }
it { expect(subject).to contain_exactly(work_package) }
end
- describe 'now' do
+ describe "now" do
let(:since) { DateTime.now }
it { expect(subject).to be_empty }
end
- describe 'work package update' do
+ describe "work package update" do
let(:since) { work_package.reload.updated_at }
it { expect(subject).to contain_exactly(work_package) }
end
end
- describe '#ignore_non_working_days' do
- context 'for a new record' do
- it 'is false' do
+ describe "#ignore_non_working_days" do
+ context "for a new record" do
+ it "is false" do
expect(described_class.new.ignore_non_working_days)
.to be false
end
end
end
- context 'when destroying with agenda items' do
+ context "when destroying with agenda items" do
shared_let(:work_package) do
create(:work_package, project:, type:, status:, priority:)
end
@@ -672,9 +672,9 @@ RSpec.describe WorkPackage do
shared_let(:other_meeting) { other_agenda_item.meeting }
let(:latest_journals) do
Journal
- .select('DISTINCT ON (journable_id) *')
- .where(journable_type: 'Meeting', journable_id: meeting_agenda_items.pluck(:meeting_id))
- .order('journable_id, updated_at DESC')
+ .select("DISTINCT ON (journable_id) *")
+ .where(journable_type: "Meeting", journable_id: meeting_agenda_items.pluck(:meeting_id))
+ .order("journable_id, updated_at DESC")
end
subject { work_package.destroy }
@@ -684,18 +684,18 @@ RSpec.describe WorkPackage do
Meeting.find_each(&:save_journals)
end
- it 'dissociates the agenda items' do
+ it "dissociates the agenda items" do
expect { subject }
.to change { MeetingAgendaItem.find(meeting_agenda_items).pluck(:work_package_id) }
.from(Array.new(3, work_package.id))
.to(Array.new(3, nil))
end
- it 'does not affect other agenda items' do
+ it "does not affect other agenda items" do
expect { subject }.not_to change(other_agenda_item, :reload)
end
- it 'updates the agenda item journal' do
+ it "updates the agenda item journal" do
expect { subject }
.to change {
Journal::MeetingAgendaItemJournal
@@ -706,7 +706,7 @@ RSpec.describe WorkPackage do
.to(Array.new(3, nil))
end
- it 'does not affect the agenda item journal' do
+ it "does not affect the agenda item journal" do
expect { subject }
.not_to change {
Journal::MeetingAgendaItemJournal
@@ -716,32 +716,32 @@ RSpec.describe WorkPackage do
end
end
- describe '#remaining_hours' do
- it 'allows empty values' do
+ describe "#remaining_hours" do
+ it "allows empty values" do
expect(work_package.remaining_hours).to be_nil
expect(work_package).to be_valid
end
- it 'allows values greater than or equal to 0' do
- work_package.remaining_hours = '0'
+ it "allows values greater than or equal to 0" do
+ work_package.remaining_hours = "0"
expect(work_package).to be_valid
- work_package.remaining_hours = '1'
+ work_package.remaining_hours = "1"
expect(work_package).to be_valid
end
- it 'disallows negative values' do
- work_package.remaining_hours = '-1'
+ it "disallows negative values" do
+ work_package.remaining_hours = "-1"
expect(work_package).not_to be_valid
end
- it 'disallows string values, that are not numbers' do
- work_package.remaining_hours = 'abc'
+ it "disallows string values, that are not numbers" do
+ work_package.remaining_hours = "abc"
expect(work_package).not_to be_valid
end
- it 'allows non-integers' do
- work_package.remaining_hours = '1.3'
+ it "allows non-integers" do
+ work_package.remaining_hours = "1.3"
expect(work_package).to be_valid
end
end