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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Remove mocking from Cost WP Spec. It created permissions anyways
Klaus Zanders1072973519ed
diff --git a/modules/costs/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/modules/costs/spec/lib/api/v3/work_packages/work_package_representer_spec.rbindex 0f44943fe5f..0dc688c4dc8 100644--- a/modules/costs/spec/lib/api/v3/work_packages/work_package_representer_spec.rb+++ b/modules/costs/spec/lib/api/v3/work_packages/work_package_representer_spec.rb@@ -31,17 +31,17 @@ require 'spec_helper'RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doinclude API::V3::Utilities::PathHelper- let(:project) { create(:project) }- let(:role) do- create(:project_role,- permissions: %i[view_time_entries- view_cost_entries- view_cost_rates- view_work_packages])+ let(:additional_permissions) do+ %i[+ view_time_entries+ view_cost_entries+ view_cost_rates+ ]end++ let(:project) { create(:project) }let(:user) do- create(:user,- member_with_roles: { project => role })+ create(:user, member_with_permissions: { project => [:view_work_packages] + additional_permissions })endlet(:cost_entry_1) do@@ -130,22 +130,14 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendcontext 'no view_time_entries permission' do- before do- allow(user).to receive(:allowed_to?).and_return false- end+ let(:additional_permissions) { [] }it { is_expected.not_to have_json_path('spentTime') }endcontext 'only view_own_time_entries permission' do- let(:own_time_entries_role) do- create(:project_role, permissions: %i[view_own_time_entries- view_work_packages])- end-let(:user2) do- create(:user,- member_with_roles: { project => own_time_entries_role })+ create(:user, member_with_permissions: { project => %i[view_own_time_entries view_work_packages] })endlet!(:own_time_entry) do@@ -177,26 +169,12 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doenddescribe 'laborCosts' do- before do- allow(user).to receive(:allowed_to?).and_return false- end-before doallow(work_package).to receive(:labor_costs).and_return(6000.0)endcontext 'with the :view_hourly_rates and :view_time_entries permission' do- before do- allow(user)- .to receive(:allowed_to?)- .with(:view_time_entries, work_package.project)- .and_return true-- allow(user)- .to receive(:allowed_to?)- .with(:view_hourly_rates, work_package.project)- .and_return true- end+ let(:additional_permissions) { %i[view_hourly_rates view_time_entries] }it 'is expected to have a laborCosts attribute' doexpect(subject).to be_json_eql('6,000.00 EUR'.to_json).at_path('laborCosts')@@ -204,17 +182,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendcontext 'with the :view_own_hourly_rate and :view_own_time_entries permission' do- before do- allow(user)- .to receive(:allowed_to?)- .with(:view_own_time_entries, work_package.project)- .and_return true-- allow(user)- .to receive(:allowed_to?)- .with(:view_own_hourly_rate, work_package.project)- .and_return true- end+ let(:additional_permissions) { %i[view_own_hourly_rate view_own_time_entries] }it 'is expected to have a laborCosts attribute' doexpect(subject).to be_json_eql('6,000.00 EUR'.to_json).at_path('laborCosts')@@ -229,26 +197,12 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doenddescribe 'materialCosts' do- before do- allow(user).to receive(:allowed_to?).and_return false- end-before doallow(work_package).to receive(:material_costs).and_return(6000.0)endcontext 'with the :view_own_cost_entries and :view_cost_rates permission' do- before do- allow(user)- .to receive(:allowed_to?)- .with(:view_own_cost_entries, work_package.project)- .and_return true-- allow(user)- .to receive(:allowed_to?)- .with(:view_cost_rates, work_package.project)- .and_return true- end+ let(:additional_permissions) { %i[view_own_cost_entries view_cost_rates] }it 'is expected to have a materialCosts attribute' doexpect(subject).to be_json_eql('6,000.00 EUR'.to_json).at_path('materialCosts')@@ -256,17 +210,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendcontext 'with the :view_cost_entries and :view_cost_rates permission' do- before do- allow(user)- .to receive(:allowed_to?)- .with(:view_cost_entries, work_package.project)- .and_return true-- allow(user)- .to receive(:allowed_to?)- .with(:view_cost_rates, work_package.project)- .and_return true- end+ let(:additional_permissions) { %i[view_cost_entries view_cost_rates] }it 'is expected to have a materialCosts attribute' doexpect(subject).to be_json_eql('6,000.00 EUR'.to_json).at_path('materialCosts')@@ -274,6 +218,8 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendcontext 'without the user having permission' do+ let(:additional_permissions) { [] }+it 'has no attribute' doexpect(subject).not_to have_json_path('materialCosts')end@@ -281,26 +227,12 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doenddescribe 'overallCosts' do- before do- allow(user).to receive(:allowed_to?).and_return false- end-before doallow(work_package).to receive(:overall_costs).and_return(6000.0)endcontext 'with the :view_hourly_rates and :view_time_entries permission' do- before do- allow(user)- .to receive(:allowed_to?)- .with(:view_time_entries, work_package.project)- .and_return true-- allow(user)- .to receive(:allowed_to?)- .with(:view_hourly_rates, work_package.project)- .and_return true- end+ let(:additional_permissions) { %i[view_hourly_rates view_time_entries] }it 'is expected to have a overallCosts attribute' doexpect(subject).to be_json_eql('6,000.00 EUR'.to_json).at_path('overallCosts')@@ -308,17 +240,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendcontext 'with the :view_own_hourly_rate and :view_own_time_entries permission' do- before do- allow(user)- .to receive(:allowed_to?)- .with(:view_own_time_entries, work_package.project)- .and_return true-- allow(user)- .to receive(:allowed_to?)- .with(:view_own_hourly_rate, work_package.project)- .and_return true- end+ let(:additional_permissions) { %i[view_own_time_entries view_own_hourly_rate] }it 'is expected to have a overallCosts attribute' doexpect(subject).to be_json_eql('6,000.00 EUR'.to_json).at_path('overallCosts')@@ -326,17 +248,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendcontext 'with the :view_own_cost_entries and :view_cost_rates permission' do- before do- allow(user)- .to receive(:allowed_to?)- .with(:view_own_cost_entries, work_package.project)- .and_return true-- allow(user)- .to receive(:allowed_to?)- .with(:view_cost_rates, work_package.project)- .and_return true- end+ let(:additional_permissions) { %i[view_own_cost_entries view_cost_rates] }it 'is expected to have a overallCosts attribute' doexpect(subject).to be_json_eql('6,000.00 EUR'.to_json).at_path('overallCosts')@@ -344,17 +256,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendcontext 'with the :view_cost_entries and :view_cost_rates permission' do- before do- allow(user)- .to receive(:allowed_to?)- .with(:view_cost_entries, work_package.project)- .and_return true-- allow(user)- .to receive(:allowed_to?)- .with(:view_cost_rates, work_package.project)- .and_return true- end+ let(:additional_permissions) { %i[view_cost_entries view_cost_rates] }it 'is expected to have a overallCosts attribute' doexpect(subject).to be_json_eql('6,000.00 EUR'.to_json).at_path('overallCosts')@@ -362,6 +264,8 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendcontext 'without the user having permission' do+ let(:additional_permissions) { [] }+it 'has no attribute' doexpect(subject).not_to have_json_path('overallCosts')end@@ -381,22 +285,20 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doenddescribe 'timeEntries' do- it 'exists if user has view_time_entries permission' do- allow(user).to receive(:allowed_to?).and_return false- allow(user).to receive(:allowed_to?).with(:view_time_entries,- work_package.project)- .and_return true+ context 'with the :view_time_entries permission' do+ let(:additional_permissions) { %i[view_time_entries] }- expect(subject).to have_json_path('_links/timeEntries/href')+ it 'has timeEntries link' do+ expect(subject).to have_json_path('_links/timeEntries/href')+ endend- it 'has spentTime link when user only has view_own_time_entries permission' do- allow(user).to receive(:allowed_to?).and_return false- allow(user).to receive(:allowed_to?).with(:view_own_time_entries,- work_package.project)- .and_return true+ context 'with the :view_own_time_entries permission' do+ let(:additional_permissions) { %i[view_own_time_entries] }- expect(subject).to have_json_path('_links/timeEntries/href')+ it 'has timeEnries link' do+ expect(subject).to have_json_path('_links/timeEntries/href')+ endendendend