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
Write tests for index action
Aaron Contreras31d2e8cb3657
diff --git a/spec/controllers/shares_controller_spec.rb b/spec/controllers/shares_controller_spec.rbindex 1de2c46cd3d..0734128d978 100644--- a/spec/controllers/shares_controller_spec.rb+++ b/spec/controllers/shares_controller_spec.rb@@ -153,6 +153,93 @@ RSpec.describe SharesController doenddescribe "index" do+ let(:make_request) { get :index, params: { project_query_id: project_query.id }, format: :turbo_stream }++ before do+ # Spy the render call to assert the right+ # components to have rendered+ allow(controller).to receive(:render).and_call_original+ end++ context "when the strategy does not allow viewing or managing but enterprise check succeeds",+ with_ee: %i[work_package_sharing] do+ let(:strategy) { instance_double(SharingStrategies::ProjectQueryStrategy, viewable?: false, manageable?: false) }++ before do+ allow(SharingStrategies::ProjectQueryStrategy).to receive(:new).and_return(strategy)+ end++ it "responds with 403" do+ make_request+ expect(response).to have_http_status(:forbidden)+ end+ end++ context "when the strategy allows viewing but enterprise check fails" do+ let(:strategy) { instance_double(SharingStrategies::ProjectQueryStrategy, viewable?: true, manageable?: false) }++ before do+ allow(SharingStrategies::ProjectQueryStrategy).to receive(:new).and_return(strategy)+ end++ it "renders the upsale component" do+ make_request+ expect(response).to have_http_status(:ok)+ expect(controller).to have_received(:render).with(an_instance_of(Shares::ModalUpsaleComponent))+ end+ end++ context "when the strategy allows viewing and enterprise check passes",+ with_ee: %i[work_package_sharing] do+ before do+ # Since this goes through and renders, we only care about+ # stubbing permission related methods+ allow_any_instance_of(SharingStrategies::ProjectQueryStrategy)+ .to receive_messages(viewable?: true, manageable?: false)+ end++ it "succeeds" do+ make_request+ expect(response).to have_http_status(:ok)+ expect(controller).to have_received(:render).with(+ an_instance_of(Shares::ModalBodyComponent),+ layout: nil+ )+ end+ end++ context "when the strategy allows managing but enterprise check fails" do+ let(:strategy) { instance_double(SharingStrategies::ProjectQueryStrategy, viewable?: false, manageable?: true) }++ before do+ allow(SharingStrategies::ProjectQueryStrategy).to receive(:new).and_return(strategy)+ end++ it "renders the upsale component" do+ make_request+ expect(response).to have_http_status(:ok)+ expect(controller).to have_received(:render).with(an_instance_of(Shares::ModalUpsaleComponent))+ end+ end++ context "when the strategy allows managing and enterprise check passes",+ with_ee: %i[work_package_sharing] do+ before do+ # Since this goes through and renders, we only care about+ # stubbing permission related methods+ allow_any_instance_of(SharingStrategies::ProjectQueryStrategy)+ .to receive_messages(viewable?: true, manageable?: true)+ end++ it "succeeds" do+ make_request+ expect(response).to have_http_status(:ok)+ expect(controller).to have_received(:render).with(+ an_instance_of(Shares::ModalBodyComponent),+ layout: nil+ )+ end+ endenddescribe "create" do