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
[#52284] CostReportsController#destroy - wrong method name was renamed allowed_in_report -> allowed_in_report?
Aleksey Kurepin0620ddd1fe74
diff --git a/modules/reporting/app/controllers/cost_reports_controller.rb b/modules/reporting/app/controllers/cost_reports_controller.rbindex f6afb7d2c62..e8e8c28b99e 100644--- a/modules/reporting/app/controllers/cost_reports_controller.rb+++ b/modules/reporting/app/controllers/cost_reports_controller.rb@@ -148,7 +148,7 @@ class CostReportsController < ApplicationController# RecordNotFound if the query at :id does not existdef destroyif @query- @query.destroy if allowed_in_report(:destroy, @query)+ @query.destroy if allowed_in_report?(:destroy, @query)elseraise ActiveRecord::RecordNotFoundenddiff --git a/modules/reporting/spec/controllers/cost_reports_controller_spec.rb b/modules/reporting/spec/controllers/cost_reports_controller_spec.rbindex e60ba546b75..8e772b2942c 100644--- a/modules/reporting/spec/controllers/cost_reports_controller_spec.rb+++ b/modules/reporting/spec/controllers/cost_reports_controller_spec.rb@@ -26,7 +26,7 @@# See COPYRIGHT and LICENSE files for more details.#++-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')+require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")RSpec.describe CostReportsController doinclude OpenProject::Reporting::PluginSpecHelper@@ -34,20 +34,74 @@ RSpec.describe CostReportsController dolet(:user) { build(:user) }let(:project) { build(:valid_project) }+ before do+ allow(User).to receive(:current).and_return(user)+ end+describe "GET show" dobefore dois_member project, user, [:view_cost_entries]- allow(User).to receive(:current).and_return(user)end- describe "WHEN providing invalid units- WHEN having the view_cost_entries permission" do+ context 'with invalid units' do+ context 'with :view_cost_entries permission' do+ before do+ get :show, params: { id: 1, unit: -1 }+ end++ it 'returns 404 Not found' do+ expect(response).to have_http_status(:not_found)+ end+ end+ end+ end++ describe 'DELETE destroy' do+ let(:user) { build(:admin) }+ let(:cost_query) { create(:public_cost_query, user:, project:) }++ context 'with valid params' dobefore do- get :show, params: { id: 1, unit: -1 }+ delete :destroy, params: { id: cost_query.id, project_id: project.identifier }+ end++ it 'destroyed' do+ expect(CostQuery.count).to be_zero+ end++ it 'redirected' do+ expect(response).to have_http_status(:redirect)+ end+ end++ context 'with invalid params' do+ before do+ create(:public_cost_query, user:, project:)+ delete :destroy, params: { id: -1, project_id: -1 }+ end++ it 'not destroyed' do+ expect(CostQuery.count).not_to be_zero+ end++ it 'returns 404 Not found' do+ expect(response).to have_http_status(:not_found)+ end+ end++ context 'with non-admin user' do+ let(:user) { build(:user) }++ before do+ delete :destroy, params: { id: cost_query.id, project_id: project.identifier }+ end++ it 'not destroyed' do+ expect(CostQuery.count).not_to be_zeroend- it "responds with a 404 error" do- expect(response.code).to eql("404")+ it 'returns 403 Forbidden' do+ expect(response).to have_http_status(:forbidden)endendend