Skip to content

Commit

Permalink
Fixes in auth spec description and courses tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anshganatra committed Dec 4, 2024
1 parent 5ac63c8 commit a490d8e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 66 deletions.
4 changes: 2 additions & 2 deletions spec/controllers/concerns/authorization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
# Tests for all_actions_allowed? method
##########################################
describe '#all_actions_allowed?' do
context 'when the user has the Administrator role' do
context 'when the user has the Super Administrator role' do
before do
allow(controller).to receive(:has_required_role?).with('Super Administrator').and_return(true)
end
Expand All @@ -136,7 +136,7 @@
end
end

context 'when the user does not have the Administrator role' do
context 'when the user does not have the Super Administrator role' do
before do
allow(controller).to receive(:has_required_role?).with('Super Administrator').and_return(false)
allow(controller).to receive(:action_allowed?).and_return(false)
Expand Down
86 changes: 22 additions & 64 deletions spec/requests/api/v1/courses_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
require 'swagger_helper'
require 'json_web_token'

RSpec.describe 'api/v1/courses', type: :request do
before(:all) do
# Create roles in hierarchy
@super_admin = Role.find_or_create_by(name: 'Super Administrator')
@admin = Role.find_or_create_by(name: 'Administrator', parent_id: @super_admin.id)
@instructor = Role.find_or_create_by(name: 'Instructor', parent_id: @admin.id)
@ta = Role.find_or_create_by(name: 'Teaching Assistant', parent_id: @instructor.id)
@student = Role.find_or_create_by(name: 'Student', parent_id: @ta.id)
end

let(:prof) { User.create(
name: "profa",
password_digest: "password",
role_id: @instructor.id,
full_name: "Prof A",
email: "[email protected]",
mru_directory_path: "/home/testuser",
) }

let(:token) { JsonWebToken.encode({id: prof.id}) }
let(:Authorization) { "Bearer #{token}" }


# GET /courses/{id}/add_ta/{ta_id}
path '/api/v1/courses/{id}/add_ta/{ta_id}' do
Expand Down Expand Up @@ -60,14 +82,6 @@
path '/api/v1/courses/{id}/tas' do
parameter name: 'id', in: :path, type: :string, description: 'id'
let(:institution) { Institution.create(name: "NC State") }
let(:prof) { User.create(
name: "profa",
password_digest: "password",
role_id: 4,
fullname: "Prof A",
email: "[email protected]",
mru_directory_path: "/home/testuser",
) }
let(:course) { Course.create(institution_id: institution.id, instructor_id: prof.id, directory_path: 'samplepath', name: 'OODD', info: 'blank') }
let(:id) { course.id }
get('view_tas course') do
Expand All @@ -90,14 +104,6 @@
parameter name: 'id', in: :path, type: :string, description: 'id'
parameter name: 'ta_id', in: :path, type: :string, description: 'ta_id'
let(:institution) { Institution.create(name: "NC State") }
let(:prof) { User.create(
name: "profa",
password_digest: "password",
role_id: 4,
fullname: "Prof A",
email: "[email protected]",
mru_directory_path: "/home/testuser",
) }
let(:course) { Course.create(institution_id: institution.id, instructor_id: prof.id, directory_path: 'samplepath', name: 'OODD', info: 'blank') }
let(:id) { course.id }
let(:ta) { User.create(
Expand Down Expand Up @@ -134,14 +140,6 @@
path '/api/v1/courses/{id}/copy' do
parameter name: 'id', in: :path, type: :string, description: 'id'
let(:institution) { Institution.create(name: "NC State") }
let(:prof) { User.create(
name: "profa",
password_digest: "password",
role_id: 4,
fullname: "Prof A",
email: "[email protected]",
mru_directory_path: "/home/testuser",
) }
let(:course) { Course.create(institution_id: institution.id, instructor_id: prof.id, directory_path: 'samplepath', name: 'OODD', info: 'blank') }
let(:id) { course.id }
get('copy course') do
Expand Down Expand Up @@ -192,14 +190,6 @@
}
response(201, 'successful') do
let(:institution) { Institution.create(name: "NC State") }
let(:prof) { User.create(
name: "profa",
password_digest: "password",
role_id: 4,
fullname: "Prof A",
email: "[email protected]",
mru_directory_path: "/home/testuser",
) }
let(:course) { { institution_id: institution.id, instructor_id: prof.id, directory_path: 'samplepath', name: 'OODD', info: 'blank' } }
after do |example|
example.metadata[:response][:content] = {
Expand All @@ -217,14 +207,6 @@
path '/api/v1/courses/{id}' do
parameter name: 'id', in: :path, type: :string, description: 'id'
let(:institution) { Institution.create(name: "NC State") }
let(:prof) { User.create(
name: "profa",
password_digest: "password",
role_id: 4,
fullname: "Prof A",
email: "[email protected]",
mru_directory_path: "/home/testuser",
) }
let(:course) { Course.create(institution_id: institution.id, instructor_id: prof.id, directory_path: 'samplepath', name: 'OODD', info: 'blank') }
let(:id) { course.id }
get('show course') do
Expand Down Expand Up @@ -257,14 +239,6 @@
required: %w[]
}
let(:institution) { Institution.create(name: "NC State") }
let(:prof) { User.create(
name: "profa",
password_digest: "password",
role_id: 4,
fullname: "Prof A",
email: "[email protected]",
mru_directory_path: "/home/testuser",
) }
let(:course) { Course.create(institution_id: institution.id, instructor_id: prof.id, directory_path: 'samplepath', name: 'OODD', info: 'blank') }
let(:id) { course.id }
response(200, 'successful') do
Expand Down Expand Up @@ -295,14 +269,6 @@
required: %w[]
}
let(:institution) { Institution.create(name: "NC State") }
let(:prof) { User.create(
name: "profa",
password_digest: "password",
role_id: 4,
fullname: "Prof A",
email: "[email protected]",
mru_directory_path: "/home/testuser",
) }
let(:course) { Course.create(institution_id: institution.id, instructor_id: prof.id, directory_path: 'samplepath', name: 'OODD', info: 'blank') }
let(:id) { course.id }
response(200, 'successful') do
Expand All @@ -321,14 +287,6 @@
delete('delete course') do
tags 'Courses'
let(:institution) { Institution.create(name: "NC State") }
let(:prof) { User.create(
name: "profa",
password_digest: "password",
role_id: 4,
fullname: "Prof A",
email: "[email protected]",
mru_directory_path: "/home/testuser",
) }
let(:course) { Course.create(institution_id: institution.id, instructor_id: prof.id, directory_path: 'samplepath', name: 'OODD', info: 'blank') }
let(:id) { course.id }
response(204, 'successful') do
Expand Down

0 comments on commit a490d8e

Please sign in to comment.