Skip to content

Commit

Permalink
test(duplication): add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
bivanalhar committed May 3, 2024
1 parent bf2dc45 commit d4d8f8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/course/duplications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/course/duplications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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 }
Expand Down

0 comments on commit d4d8f8c

Please sign in to comment.