From d4d8f8c94d97e398b5a52c593f258b79e4a79995 Mon Sep 17 00:00:00 2001 From: bivanalhar Date: Fri, 3 May 2024 12:08:43 +0800 Subject: [PATCH] test(duplication): add more test --- .../course/duplications_controller.rb | 2 +- .../course/duplications_controller_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controllers/course/duplications_controller.rb b/app/controllers/course/duplications_controller.rb index 814050f6920..f3c97ef094b 100644 --- a/app/controllers/course/duplications_controller.rb +++ b/app/controllers/course/duplications_controller.rb @@ -20,7 +20,7 @@ def authorize_duplication return if instance_params == current_tenant.id destination_tenant = Instance.find(instance_params) - + authorize!(:duplicate_across_instances, destination_tenant) end diff --git a/spec/controllers/course/duplications_controller_spec.rb b/spec/controllers/course/duplications_controller_spec.rb index a46a47a59d9..ec65655d1ee 100644 --- a/spec/controllers/course/duplications_controller_spec.rb +++ b/spec/controllers/course/duplications_controller_spec.rb @@ -4,6 +4,7 @@ RSpec.describe Course::DuplicationsController, type: :controller do let(:instance) { Instance.default } let(:destination_instance) { create(:instance) } + let(:destination_instance_admin) { create(:instance_user, :instructor, instance: destination_instance).user } with_tenant(:instance) do let(:course) { create(:course) } @@ -25,6 +26,21 @@ it { expect { subject }.to raise_exception(CanCan::AccessDenied) } end + context 'when course manager in a course which is instance normal wants to duplicate to other instance' do + let(:instance_normal_user) do + ActsAsTenant.without_tenant do + create(:instance_user, user: destination_instance_admin, instance: instance).user + end + end + let!(:instance_course_manager) { create(:course_manager, user: instance_normal_user, course: course).user } + before { sign_in(instance_course_manager) } + + it 'expects the duplication to be successful' do + subject + expect(response).to be_successful + end + end + context 'when admin user wants to duplicate course to another instance' do let(:admin) { create(:administrator) } let(:admin_course_user) { create(:course_manager, user: admin, course: course).user }