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

Clean up rubocop errors from work_package_representer_spec.rb

Dombi Attila7ba6e63917cf
diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
index a5632a3ddc0..5bf1c6c5764 100644
--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
@@ -28,7 +28,6 @@
require 'spec_helper'
-# rubocop:disable RSpec:MultipleMemoizedHelpers
describe ::API::V3::WorkPackages::WorkPackageRepresenter do
include ::API::V3::Utilities::PathHelper
@@ -118,7 +117,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:status) { build_stubbed(:status, updated_at: Time.zone.now) }
let(:available_custom_fields) { [] }
- before(:each) do
+ before do
login_as current_user
allow(current_user)
@@ -136,7 +135,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
include_context 'eager loaded work package representer'
- context 'generation' do
+ describe 'generation' do
subject(:generated) { representer.to_json }
it { is_expected.to include_json('WorkPackage'.to_json).at_path('_type') }
@@ -151,25 +150,25 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
describe 'scheduleManually' do
- context 'no value' do
+ context 'when no value' do
it 'renders as false (default value)' do
- is_expected.to be_json_eql(false.to_json).at_path('scheduleManually')
+ expect(subject).to be_json_eql(false.to_json).at_path('scheduleManually')
end
end
- context 'false' do
+ context 'when false' do
let(:schedule_manually) { false }
it 'renders as false' do
- is_expected.to be_json_eql(false.to_json).at_path('scheduleManually')
+ expect(subject).to be_json_eql(false.to_json).at_path('scheduleManually')
end
end
- context 'true' do
+ context 'when true' do
let(:schedule_manually) { true }
it 'renders as true' do
- is_expected.to be_json_eql(true.to_json).at_path('scheduleManually')
+ expect(subject).to be_json_eql(true.to_json).at_path('scheduleManually')
end
end
end
@@ -180,11 +179,11 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:json_path) { 'startDate' }
end
- context 'no start date' do
+ context 'when it\'s nil' do
let(:start_date) { nil }
it 'renders as null' do
- is_expected.to be_json_eql(nil.to_json).at_path('startDate')
+ expect(subject).to be_json_eql(nil.to_json).at_path('startDate')
end
end
@@ -192,7 +191,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:type_milestone) { true }
it 'has no startDate' do
- is_expected.to_not have_json_path('startDate')
+ expect(subject).not_to have_json_path('startDate')
end
end
end
@@ -204,11 +203,11 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:json_path) { 'dueDate' }
end
- context 'no finish date' do
+ context 'with no finish date' do
let(:due_date) { nil }
it 'renders as null' do
- is_expected.to be_json_eql(nil.to_json).at_path('dueDate')
+ expect(subject).to be_json_eql(nil.to_json).at_path('dueDate')
end
end
end
@@ -216,8 +215,8 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'with a milestone type' do
let(:type_milestone) { true }
- it 'has no startDate' do
- is_expected.to_not have_json_path('dueDate')
+ it 'with no startDate' do
+ expect(subject).not_to have_json_path('dueDate')
end
end
end
@@ -231,18 +230,18 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:json_path) { 'date' }
end
- context 'no finish date' do
+ context 'with no finish date' do
let(:due_date) { nil }
it 'renders as null' do
- is_expected.to be_json_eql(nil.to_json).at_path('date')
+ expect(subject).to be_json_eql(nil.to_json).at_path('date')
end
end
end
- context 'with a milestone type' do
- it 'has no date' do
- is_expected.to_not have_json_path('date')
+ context 'with not a milestone type' do
+ it 'with no date' do
+ expect(subject).not_to have_json_path('date')
end
end
end
@@ -253,11 +252,11 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:json_path) { 'derivedStartDate' }
end
- context 'no derived start date' do
+ context 'with no derived start date' do
let(:derived_start_date) { nil }
it 'renders as null' do
- is_expected
+ expect(subject)
.to be_json_eql(nil.to_json)
.at_path('derivedStartDate')
end
@@ -266,9 +265,9 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'when the work package has a milestone type' do
let(:type_milestone) { true }
- it 'has no derivedStartDate' do
- is_expected
- .to_not have_json_path('derivedStartDate')
+ it 'with no derivedStartDate' do
+ expect(subject)
+ .not_to have_json_path('derivedStartDate')
end
end
end
@@ -279,11 +278,11 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:json_path) { 'derivedDueDate' }
end
- context 'no derived due date' do
+ context 'with no derived due date' do
let(:derived_due_date) { nil }
it 'renders as null' do
- is_expected
+ expect(subject)
.to be_json_eql(nil.to_json)
.at_path('derivedDueDate')
end
@@ -292,9 +291,9 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'when the work package has a milestone type' do
let(:type_milestone) { true }
- it 'has no derivedDueDate' do
- is_expected
- .to_not have_json_path('derivedDueDate')
+ it 'with no derivedDueDate' do
+ expect(subject)
+ .not_to have_json_path('derivedDueDate')
end
end
end
@@ -304,25 +303,25 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
it { is_expected.to be_json_eql('P6D'.to_json).at_path('duration') }
- context 'no duration' do
+ context 'with no duration' do
let(:duration) { nil }
it 'renders as null' do
- is_expected.to be_json_eql(nil.to_json).at_path('duration')
+ expect(subject).to be_json_eql(nil.to_json).at_path('duration')
end
end
context 'when the work_package is a milestone' do
let(:type_milestone) { true }
- it 'has no duration' do
- is_expected.to_not have_json_path('duration')
+ it 'with no duration' do
+ expect(subject).not_to have_json_path('duration')
end
end
context 'when the feature flag is off', with_flag: { work_packages_duration_field_active: false } do
- it 'has no duration' do
- is_expected.to_not have_json_path('duration')
+ it 'with no duration' do
+ expect(subject).not_to have_json_path('duration')
end
end
end
@@ -342,7 +341,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'when the feature flag is off', with_flag: { work_packages_duration_field_active: false } do
it 'has no ignoreNonWorkingDays' do
- is_expected.to_not have_json_path('ignoreNonWorkingDays')
+ expect(subject).not_to have_json_path('ignoreNonWorkingDays')
end
end
end
@@ -372,26 +371,27 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
describe 'readonly' do
- context 'no status' do
+ context 'with no status' do
let(:status) { nil }
+
it 'renders nothing' do
- is_expected.not_to have_json_path('readonly')
+ expect(subject).not_to have_json_path('readonly')
end
end
- context 'false', with_ee: %i[readonly_work_packages] do
+ context 'when false', with_ee: %i[readonly_work_packages] do
let(:status) { build_stubbed :status, is_readonly: false }
it 'renders as false' do
- is_expected.to be_json_eql(false.to_json).at_path('readonly')
+ expect(subject).to be_json_eql(false.to_json).at_path('readonly')
end
end
- context 'true', with_ee: %i[readonly_work_packages] do
+ context 'when true', with_ee: %i[readonly_work_packages] do
let(:status) { build_stubbed :status, is_readonly: true }
it 'renders as true' do
- is_expected.to be_json_eql(true.to_json).at_path('readonly')
+ expect(subject).to be_json_eql(true.to_json).at_path('readonly')
end
end
end
@@ -409,35 +409,38 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
it { is_expected.to be_json_eql('PT3H45M'.to_json).at_path('derivedEstimatedTime') }
end
- describe 'spentTime' do
+ # rubocop:disable RSpec:MultipleMemoizedHelpers
+ xdescribe 'spentTime' do
# spentTime is completely overwritten by costs
# TODO: move specs from costs to here
end
+ # rubocop:enable RSpec:MultipleMemoizedHelpers
describe 'percentageDone' do
describe 'work package done ratio setting behavior' do
- context 'setting enabled' do
+ context 'when setting enabled' do
it { expect(parse_json(subject)['percentageDone']).to eq(50) }
end
- context 'setting disabled' do
+ context 'when setting disabled' do
before do
allow(Setting)
.to receive(:work_package_done_ratio)
.and_return('disabled')
end
- it { is_expected.to_not have_json_path('percentageDone') }
+ it { is_expected.not_to have_json_path('percentageDone') }
end
end
end
describe 'custom fields' do
let(:available_custom_fields) { [build_stubbed(:int_wp_custom_field)] }
+
it 'uses a CustomFieldInjector' do
- expect(::API::V3::Utilities::CustomFieldInjector).to receive(:create_value_representer)
- .and_call_original
+ allow(::API::V3::Utilities::CustomFieldInjector).to receive(:create_value_representer).and_call_original
representer.to_json
+ expect(::API::V3::Utilities::CustomFieldInjector).to have_received(:create_value_representer)
end
end
@@ -456,7 +459,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'is a post link' do
- is_expected.to be_json_eql('post'.to_json).at_path('_links/update/method')
+ expect(subject).to be_json_eql('post'.to_json).at_path('_links/update/method')
end
end
@@ -467,11 +470,11 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'is a patch link' do
- is_expected.to be_json_eql('patch'.to_json).at_path('_links/updateImmediately/method')
+ expect(subject).to be_json_eql('patch'.to_json).at_path('_links/updateImmediately/method')
end
end
- context 'user is not allowed to edit work packages' do
+ context 'when user is not allowed to edit work packages' do
let(:permissions) { all_permissions - [:edit_work_packages] }
it_behaves_like 'has no link' do
@@ -483,7 +486,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'user is lacks edit permission but has assign_versions' do
+ context 'when user is lacks edit permission but has assign_versions' do
let(:permissions) { all_permissions - [:edit_work_packages] + [:assign_versions] }
it_behaves_like 'has an untitled link' do
@@ -523,7 +526,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
describe 'assignee' do
- context 'is user' do
+ context 'as a user' do
let(:assignee) { build_stubbed(:user) }
it_behaves_like 'has a titled link' do
@@ -533,7 +536,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'is group' do
+ context 'as a group' do
let(:assignee) { build_stubbed(:group) }
it_behaves_like 'has a titled link' do
@@ -543,7 +546,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'is placeholder user' do
+ context 'as a placeholder user' do
let(:assignee) { build_stubbed(:placeholder_user) }
it_behaves_like 'has a titled link' do
@@ -553,7 +556,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'is deleted user' do
+ context 'as a deleted user' do
let(:assignee) { build_stubbed(:deleted_user) }
it_behaves_like 'has a titled link' do
@@ -563,7 +566,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'is not set' do
+ context 'as not set' do
it_behaves_like 'has an empty link' do
let(:link) { 'assignee' }
end
@@ -571,7 +574,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
describe 'responsible' do
- context 'is user' do
+ context 'as a user' do
let(:responsible) { build_stubbed(:user) }
it_behaves_like 'has a titled link' do
@@ -581,7 +584,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'is group' do
+ context 'as a group' do
let(:responsible) { build_stubbed(:group) }
it_behaves_like 'has a titled link' do
@@ -591,7 +594,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'is placeholder user' do
+ context 'as a placeholder user' do
let(:responsible) { build_stubbed(:placeholder_user) }
it_behaves_like 'has a titled link' do
@@ -601,7 +604,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'is deleted user' do
+ context 'as a deleted user' do
let(:responsible) { build_stubbed(:deleted_user) }
it_behaves_like 'has a titled link' do
@@ -611,7 +614,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'is not set' do
+ context 'as not set' do
it_behaves_like 'has an empty link' do
let(:link) { 'responsible' }
end
@@ -631,13 +634,13 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:embedded_path) { '_embedded/version' }
let(:href_path) { '_links/version/href' }
- context 'no version set' do
+ context 'when no version set' do
it_behaves_like 'has an empty link' do
let(:link) { 'version' }
end
end
- context 'version set' do
+ context 'when version is set' do
let!(:version) { create :version, project: }
before do
@@ -651,8 +654,8 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'has the version embedded' do
- is_expected.to be_json_eql('Version'.to_json).at_path("#{embedded_path}/_type")
- is_expected.to be_json_eql(version.name.to_json).at_path("#{embedded_path}/name")
+ expect(subject).to be_json_eql('Version'.to_json).at_path("#{embedded_path}/_type")
+ expect(subject).to be_json_eql(version.name.to_json).at_path("#{embedded_path}/name")
end
end
end
@@ -668,8 +671,8 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'has the project embedded' do
- is_expected.to be_json_eql('Project'.to_json).at_path("#{embedded_path}/_type")
- is_expected.to be_json_eql(project.name.to_json).at_path("#{embedded_path}/name")
+ expect(subject).to be_json_eql('Project'.to_json).at_path("#{embedded_path}/_type")
+ expect(subject).to be_json_eql(project.name.to_json).at_path("#{embedded_path}/name")
end
end
@@ -677,13 +680,13 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:embedded_path) { '_embedded/category' }
let(:href_path) { '_links/category/href' }
- context 'no category set' do
+ context 'when no category set' do
it_behaves_like 'has an empty link' do
let(:link) { 'category' }
end
end
- context 'category set' do
+ context 'when category is set' do
let!(:category) { build_stubbed :category }
before do
@@ -697,9 +700,9 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'has the category embedded' do
- is_expected.to have_json_type(Hash).at_path('_embedded/category')
- is_expected.to be_json_eql('Category'.to_json).at_path("#{embedded_path}/_type")
- is_expected.to be_json_eql(category.name.to_json).at_path("#{embedded_path}/name")
+ expect(subject).to have_json_type(Hash).at_path('_embedded/category')
+ expect(subject).to be_json_eql('Category'.to_json).at_path("#{embedded_path}/_type")
+ expect(subject).to be_json_eql(category.name.to_json).at_path("#{embedded_path}/name")
end
end
end
@@ -712,8 +715,8 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'has the priority embedded' do
- is_expected.to be_json_eql('Priority'.to_json).at_path('_embedded/priority/_type')
- is_expected.to be_json_eql(priority.name.to_json).at_path('_embedded/priority/name')
+ expect(subject).to be_json_eql('Priority'.to_json).at_path('_embedded/priority/_type')
+ expect(subject).to be_json_eql(priority.name.to_json).at_path('_embedded/priority/name')
end
end
@@ -728,7 +731,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'has the budget embedded' do
- is_expected
+ expect(subject)
.to be_json_eql(budget.subject.to_json)
.at_path('_embedded/budget/subject')
end
@@ -736,12 +739,12 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'with the user lacking the view_budgets permission' do
it 'has no link to the budget' do
- is_expected
+ expect(subject)
.not_to have_json_path('_links/budget')
end
it 'has no budget embedded' do
- is_expected
+ expect(subject)
.not_to have_json_path('_embedded/budget')
end
end
@@ -763,7 +766,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'embeds the attachments as collection' do
- is_expected.to be_json_eql('Collection'.to_json).at_path('_embedded/attachments/_type')
+ expect(subject).to be_json_eql('Collection'.to_json).at_path('_embedded/attachments/_type')
end
it_behaves_like 'has an untitled link' do
@@ -782,10 +785,10 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'addAttachments is a post link' do
- is_expected.to be_json_eql('post'.to_json).at_path('_links/addAttachment/method')
+ expect(subject).to be_json_eql('post'.to_json).at_path('_links/addAttachment/method')
end
- context 'user is not allowed to edit work packages' do
+ context 'when user is not allowed to edit work packages' do
let(:permissions) { all_permissions - %i[edit_work_packages] }
it_behaves_like 'has no link' do
@@ -807,7 +810,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:method) { 'post' }
end
- context 'if user has no permission to view file links' do
+ context 'when user has no permission to view file links' do
let(:permissions) { all_permissions - %i[view_file_links] }
it_behaves_like 'has no link' do
@@ -817,13 +820,13 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
context 'when the user is not watching the work package' do
- it 'should have a link to watch' do
+ it 'has a link to watch' do
expect(subject)
.to be_json_eql(api_v3_paths.work_package_watchers(work_package.id).to_json)
.at_path('_links/watch/href')
end
- it 'should not have a link to unwatch' do
+ it 'does not have a link to unwatch' do
expect(subject).not_to have_json_path('_links/unwatch/href')
end
end
@@ -837,19 +840,19 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
.and_return(watchers)
end
- it 'should have a link to unwatch' do
+ it 'has a link to unwatch' do
expect(subject)
.to be_json_eql(api_v3_paths.watcher(current_user.id, work_package.id).to_json)
.at_path('_links/unwatch/href')
end
- it 'should not have a link to watch' do
+ it 'does not have a link to watch' do
expect(subject).not_to have_json_path('_links/watch/href')
end
end
context 'when the user has permission to add comments' do
- it 'should have a link to add comment' do
+ it 'has a link to add comment' do
expect(subject).to have_json_path('_links/addComment')
end
end
@@ -857,20 +860,20 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'when the user does not have the permission to add comments' do
let(:permissions) { all_permissions - [:add_work_package_notes] }
- it 'should not have a link to add comment' do
+ it 'does not have a link to add comment' do
expect(subject).not_to have_json_path('_links/addComment/href')
end
end
context 'when the user has the permission to add and remove watchers' do
- it 'should have a link to add watcher' do
+ it 'has a link to add watcher' do
expect(subject).to be_json_eql(
api_v3_paths.work_package_watchers(work_package.id).to_json
)
.at_path('_links/addWatcher/href')
end
- it 'should have a link to remove watcher' do
+ it 'has a link to remove watcher' do
expect(subject).to be_json_eql(
api_v3_paths.watcher('{user_id}', work_package.id).to_json
)
@@ -881,7 +884,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'when the user does not have the permission to add watchers' do
let(:permissions) { all_permissions - [:add_work_package_watchers] }
- it 'should not have a link to add watcher' do
+ it 'does not have a link to add watcher' do
expect(subject).not_to have_json_path('_links/addWatcher/href')
end
end
@@ -889,7 +892,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'when the user does not have the permission to remove watchers' do
let(:permissions) { all_permissions - [:delete_work_package_watchers] }
- it 'should not have a link to remove watcher' do
+ it 'does not have a link to remove watcher' do
expect(subject).not_to have_json_path('_links/removeWatcher/href')
end
end
@@ -918,7 +921,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
context 'when the user has the permission to manage relations' do
- it 'should have a link to add relation' do
+ it 'has a link to add relation' do
expect(subject).to have_json_path('_links/addRelation/href')
end
end
@@ -926,14 +929,14 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'when the user does not have the permission to manage relations' do
let(:permissions) { all_permissions - [:manage_work_package_relations] }
- it 'should not have a link to add relation' do
+ it 'does not have a link to add relation' do
expect(subject).not_to have_json_path('_links/addRelation/href')
end
end
end
context 'when the user has the permission to add work packages' do
- it 'should have a link to add child' do
+ it 'has a link to add child' do
expect(subject).to be_json_eql("/api/v3/projects/#{project.identifier}/work_packages".to_json)
.at_path('_links/addChild/href')
end
@@ -942,12 +945,12 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'when the user does not have the permission to add work packages' do
let(:permissions) { all_permissions - [:add_work_packages] }
- it 'should not have a link to add child' do
+ it 'does not have a link to add child' do
expect(subject).not_to have_json_path('_links/addChild/href')
end
end
- context 'timeEntries' do
+ describe 'timeEntries' do
context 'when the user has the permission to view time entries' do
it_behaves_like 'has a titled link' do
let(:link) { 'timeEntries' }
@@ -962,7 +965,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'when the user does not have the permission to view time entries' do
let(:permissions) { all_permissions - [:view_time_entries] }
- it 'should not have a link to timeEntries' do
+ it 'does not have a link to timeEntries' do
expect(subject).not_to have_json_path('_links/timeEntries/href')
end
end
@@ -994,13 +997,13 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'no parent' do
+ context 'with no parent' do
it_behaves_like 'has an empty link' do
let(:link) { 'parent' }
end
end
- context 'parent is visible' do
+ context 'when parent is visible' do
let(:parent) { visible_parent }
it_behaves_like 'has a titled link' do
@@ -1010,7 +1013,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'parent not visible' do
+ context 'when parent not visible' do
let(:parent) { invisible_parent }
it_behaves_like 'has an empty link' do
@@ -1019,7 +1022,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
- context 'ancestors' do
+ describe 'ancestors' do
let(:root) { build_stubbed(:work_package, project:) }
let(:intermediate) do
build_stubbed(:work_package, parent: root, project:)
@@ -1027,7 +1030,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'when ancestors are visible' do
before do
- expect(work_package).to receive(:visible_ancestors)
+ allow(work_package).to receive(:visible_ancestors)
.and_return([root, intermediate])
end
@@ -1037,22 +1040,24 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
.to eq(root.subject)
expect(parse_json(subject)['_links']['ancestors'][1]['title'])
.to eq(intermediate.subject)
+ expect(work_package).to have_received(:visible_ancestors)
end
end
context 'when ancestors are invisible' do
before do
- expect(work_package).to receive(:visible_ancestors)
+ allow(work_package).to receive(:visible_ancestors)
.and_return([])
end
it 'renders empty ancestors' do
expect(subject).to have_json_size(0).at_path('_links/ancestors')
+ expect(work_package).to have_received(:visible_ancestors)
end
end
end
- context 'children' do
+ describe 'children' do
let(:work_package) { create(:work_package, project:) }
let!(:forbidden_work_package) do
create(:work_package,
@@ -1128,6 +1133,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
context 'with feeds disabled', with_settings: { feeds_enabled?: false } do
let(:permissions) { all_permissions + [:export_work_packages] }
+
it_behaves_like 'has no link' do
let(:link) { 'atom' }
end
@@ -1162,6 +1168,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
let(:link) { 'formConfiguration' }
end
end
+
context 'when admin' do
let(:current_user) { build_stubbed :admin }
@@ -1189,7 +1196,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
}
]
- is_expected
+ expect(subject)
.to be_json_eql(expected.to_json)
.at_path('_links/customActions')
end
@@ -1207,13 +1214,13 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
it { is_expected.to be_json_eql(status.name.to_json).at_path('_embedded/status/name') }
it {
- is_expected.to be_json_eql(status.is_closed.to_json).at_path('_embedded/status/isClosed')
+ expect(subject).to be_json_eql(status.is_closed.to_json).at_path('_embedded/status/isClosed')
}
end
describe 'activities' do
it 'is not embedded' do
- is_expected.not_to have_json_path('_embedded/activities')
+ expect(subject).not_to have_json_path('_embedded/activities')
end
end
@@ -1224,7 +1231,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
before do
- scope = instance_double('ActiveRecord::Relation')
+ scope = instance_double(ActiveRecord::Relation)
allow(work_package)
.to receive(:visible_relations)
@@ -1236,23 +1243,23 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'embeds a collection' do
- is_expected
+ expect(subject)
.to be_json_eql('Collection'.to_json)
.at_path('_embedded/relations/_type')
end
it 'embeds with an href containing the work_package' do
- is_expected
+ expect(subject)
.to be_json_eql(api_v3_paths.work_package_relations(work_package.id).to_json)
.at_path('_embedded/relations/_links/self/href')
end
it 'embeds the visible relations' do
- is_expected
+ expect(subject)
.to be_json_eql(1.to_json)
.at_path('_embedded/relations/total')
- is_expected
+ expect(subject)
.to be_json_eql(api_v3_paths.relation(relation.id).to_json)
.at_path('_embedded/relations/_embedded/elements/0/_links/self/href')
end
@@ -1267,23 +1274,23 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'embeds a collection' do
- is_expected
+ expect(subject)
.to be_json_eql('Collection'.to_json)
.at_path('_embedded/fileLinks/_type')
end
it 'embeds with an href containing the work_package' do
- is_expected
+ expect(subject)
.to be_json_eql(api_v3_paths.file_links(work_package.id).to_json)
.at_path('_embedded/fileLinks/_links/self/href')
end
it 'embeds the visible file links' do
- is_expected
+ expect(subject)
.to be_json_eql(1.to_json)
.at_path('_embedded/fileLinks/total')
- is_expected
+ expect(subject)
.to be_json_eql(api_v3_paths.file_link(file_link.id).to_json)
.at_path('_embedded/fileLinks/_embedded/elements/0/_links/self/href')
end
@@ -1298,7 +1305,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
.to receive(:custom_actions)
.and_return([unassign_action])
- is_expected
+ expect(subject)
.to be_json_eql('Unassign'.to_json)
.at_path('_embedded/customActions/0/name')
end
@@ -1310,12 +1317,16 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
allow(OpenProject::Cache)
.to receive(:fetch)
.and_return({ _links: {} }.to_json)
- expect(OpenProject::Cache)
- .to receive(:fetch)
- .with(representer.json_cache_key)
- .and_call_original
+
+ allow(OpenProject::Cache)
+ .to receive(:fetch)
+ .with(representer.json_cache_key)
+ .and_call_original
representer.to_json
+
+ expect(OpenProject::Cache)
+ .to have_received(:fetch).with(representer.json_cache_key)
end
describe '#json_cache_key' do
@@ -1328,7 +1339,6 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
work_package.assigned_to = assigned_to
work_package.responsible = responsible
end
- let!(:former_cache_key) { representer.json_cache_key }
it 'includes the name of the representer class' do
expect(representer.json_cache_key)
@@ -1336,43 +1346,42 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
it 'changes when the locale changes' do
- I18n.with_locale(:fr) do
- expect(representer.json_cache_key)
- .not_to eql former_cache_key
- end
+ expect(
+ I18n.with_locale(:fr) { representer.json_cache_key }
+ ).not_to eq(representer.json_cache_key)
end
it 'changes when the feeds_enabled? setting is switched' do
- allow(Setting)
- .to receive(:feeds_enabled?)
- .and_return(!Setting.feeds_enabled?)
-
- expect(representer.json_cache_key)
- .not_to eql former_cache_key
+ expect do
+ allow(Setting)
+ .to receive(:feeds_enabled?)
+ .and_return(!Setting.feeds_enabled?)
+ end.to change(representer, :json_cache_key)
end
it 'changes when the work_package_done_ratio setting is changes' do
- allow(Setting)
- .to receive(:work_package_done_ratio)
- .and_return('status')
-
- expect(representer.json_cache_key)
- .not_to eql former_cache_key
+ expect do
+ allow(Setting)
+ .to receive(:work_package_done_ratio)
+ .and_return('status')
+ end.to change(representer, :json_cache_key)
end
it 'changes when the work_package is updated' do
- work_package.updated_at = 20.seconds.from_now
-
- expect(representer.json_cache_key)
- .not_to eql former_cache_key
+ expect do
+ work_package.updated_at = 20.seconds.from_now
+ end.to change(representer, :json_cache_key)
end
it 'factors in the eager loaded cache_checksum' do
- expect(work_package)
+ allow(work_package)
.to receive(:cache_checksum)
.and_return(srand)
representer.json_cache_key
+
+ expect(work_package)
+ .to have_received(:cache_checksum)
end
end
end
@@ -1398,4 +1407,3 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
end
-# rubocop:enable RSpec:MultipleMemoizedHelpers