diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 000000000..07ab89019 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,2 @@ +service_name: travis-ci +repo_token: cDmwC7VoKwQvWO7XsPBmE3hH7t1tFpLFn diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..d4a35c12e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,35 @@ +name: Lint + +on: [workflow_dispatch, pull_request] + +jobs: + codespell: + name: Check spelling all files with codespell + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.8] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install codespell + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Check spelling with codespell + run: | + codespell --skip="./db/migrate, ./config/name.yml" + + misspell: + name: Check spelling all files in commit with misspell + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install + run: wget -O - -q https://git.io/misspell | sh -s -- -b . + - name: Misspell + run: git ls-files --empty-directory | xargs ./misspell -i 'aircrafts,devels,invertions' -error \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..a52015059 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,76 @@ +name: CI/CD + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + + env: + DATABASE_URL: mysql2://root:expertiza@127.0.0.1:3306/expertiza_test + RAILS_ENV: test + + services: + mysql: + image: mysql:8.0 + env: + MYSQL_ROOT_PASSWORD: expertiza + MYSQL_DATABASE: expertiza_test + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2.1 + bundler-cache: true + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18.x' + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y netcat + + - name: Install Ruby dependencies + run: | + gem update --system + gem install bundler:2.4.7 + bundle install + + - name: Setup database + run: | + bundle exec rails db:create RAILS_ENV=test + bundle exec rails db:schema:load RAILS_ENV=test + + - name: Run tests + run: bundle exec rspec spec/models + + docker: + needs: test + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: false + tags: expertiza-backend:latest \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..4b84b4913 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: ruby + rvm: + - 3.2.1 + - jruby diff --git a/Gemfile b/Gemfile index 1786836d0..e76fed5cf 100644 --- a/Gemfile +++ b/Gemfile @@ -44,6 +44,7 @@ group :development, :test do gem 'rswag-specs' gem 'rubocop' gem 'simplecov', require: false, group: :test + gem 'database_cleaner-active_record' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index cb84960a2..6a4429330 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,6 +75,10 @@ GEM builder (3.2.4) concurrent-ruby (1.2.2) crass (1.0.6) + database_cleaner-active_record (2.2.0) + activerecord (>= 5.a) + database_cleaner-core (~> 2.0.0) + database_cleaner-core (2.0.1) date (3.3.3) debug (1.8.0) irb (>= 1.5.0) @@ -252,6 +256,7 @@ PLATFORMS DEPENDENCIES bcrypt (~> 3.1.7) bootsnap + database_cleaner-active_record debug factory_bot_rails faker diff --git a/app/models/questionnaire.rb b/app/models/questionnaire.rb index d576bc421..43a6ec81d 100644 --- a/app/models/questionnaire.rb +++ b/app/models/questionnaire.rb @@ -1,5 +1,4 @@ class Questionnaire < ApplicationRecord - belongs_to :assignment, foreign_key: 'assignment_id', inverse_of: false belongs_to :instructor has_many :questions, dependent: :destroy # the collection of questions associated with this Questionnaire before_destroy :check_for_question_associations @@ -37,7 +36,7 @@ def validate_questionnaire # Check_for_question_associations checks if questionnaire has associated questions or not def check_for_question_associations if questions.any? - raise ActiveRecord::DeleteRestrictionError.new(:base, "Cannot delete record because dependent questions exist") + raise ActiveRecord::DeleteRestrictionError.new( "Cannot delete record because dependent questions exist") end end diff --git a/config/environments/development.rb b/config/environments/development.rb index 51fe51d84..37737bd0a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -61,4 +61,6 @@ # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true + config.hosts << 'localhost' + config.hosts << "www.example.com" end diff --git a/config/environments/test.rb b/config/environments/test.rb index 95206387a..d39afdcf9 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -58,4 +58,6 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true + config.hosts << 'localhost' + config.hosts << "www.example.com" end diff --git a/spec/factories/assignments.rb b/spec/factories/assignments.rb new file mode 100644 index 000000000..11788ce8c --- /dev/null +++ b/spec/factories/assignments.rb @@ -0,0 +1,55 @@ +# spec/factories/assignments.rb +FactoryBot.define do + factory :assignment do + sequence(:name) { |n| "Assignment #{n}" } + directory_path { "assignment_#{name.downcase.gsub(/\s+/, '_')}" } + + # Required associations + association :instructor, factory: [:user, :instructor] + + # Default values + num_reviews { 3 } + num_reviews_required { 3 } + num_reviews_allowed { 3 } + num_metareviews_required { 3 } + num_metareviews_allowed { 3 } + rounds_of_reviews { 1 } # This is the correct attribute name + + # Boolean flags with default values + is_calibrated { false } + has_badge { false } + enable_pair_programming { false } + staggered_deadline { false } + show_teammate_reviews { false } + is_coding_assignment { false } + + # Optional association + course { nil } + + trait :with_course do + association :course + end + + trait :with_badge do + has_badge { true } + end + + trait :with_teams do + after(:create) do |assignment| + create_list(:team, 2, assignment: assignment) + end + end + + trait :with_participants do + after(:create) do |assignment| + create_list(:participant, 2, assignment: assignment) + end + end + + trait :with_questionnaires do + after(:create) do |assignment| + create(:assignment_questionnaire, assignment: assignment) + end + end + end +end \ No newline at end of file diff --git a/spec/factories/courses.rb b/spec/factories/courses.rb new file mode 100644 index 000000000..95519d9ce --- /dev/null +++ b/spec/factories/courses.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :course do + sequence(:name) { |n| "Course #{n}" } + sequence(:directory_path) { |n| "course_#{n}" } + association :instructor, factory: [:user, :instructor] + association :institution + end +end \ No newline at end of file diff --git a/spec/factories/questionnaires.rb b/spec/factories/questionnaires.rb new file mode 100644 index 000000000..c9c45695e --- /dev/null +++ b/spec/factories/questionnaires.rb @@ -0,0 +1,31 @@ +# spec/factories/questionnaires.rb +FactoryBot.define do + factory :questionnaire do + sequence(:name) { |n| "Questionnaire #{n}" } + private { false } + min_question_score { 0 } + max_question_score { 10 } + association :instructor + association :assignment + + # Trait for questionnaire with questions + trait :with_questions do + after(:create) do |questionnaire| + create(:question, questionnaire: questionnaire, weight: 1, seq: 1, txt: "que 1", question_type: "Scale") + create(:question, questionnaire: questionnaire, weight: 10, seq: 2, txt: "que 2", question_type: "Checkbox") + end + end + end +end + +# spec/factories/questions.rb +FactoryBot.define do + factory :question do + sequence(:txt) { |n| "Question #{n}" } + sequence(:seq) { |n| n } + weight { 1 } + question_type { "Scale" } + break_before { true } + association :questionnaire + end +end \ No newline at end of file diff --git a/spec/factories/roles.rb b/spec/factories/roles.rb new file mode 100644 index 000000000..d3d142d41 --- /dev/null +++ b/spec/factories/roles.rb @@ -0,0 +1,53 @@ +# spec/factories/roles.rb +FactoryBot.define do + factory :role do + sequence(:name) { |n| "Role #{n}" } + + trait :student do + id { Role::STUDENT } + name { 'Student' } + end + + trait :ta do + id { Role::TEACHING_ASSISTANT } + name { 'Teaching Assistant' } + end + + trait :instructor do + id { Role::INSTRUCTOR } + name { 'Instructor' } + end + + trait :administrator do + id { Role::ADMINISTRATOR } + name { 'Administrator' } + end + + trait :super_administrator do + id { Role::SUPER_ADMINISTRATOR } + name { 'Super Administrator' } + end + end +end + +# spec/factories/institutions.rb +FactoryBot.define do + factory :institution do + sequence(:name) { |n| "Institution #{n}" } + end +end + +# spec/factories/teams_users.rb +FactoryBot.define do + factory :teams_user do + association :user + association :team + end +end + +# spec/factories/teams.rb +FactoryBot.define do + factory :team do + sequence(:name) { |n| "Team #{n}" } + end +end \ No newline at end of file diff --git a/spec/models/course_spec.rb b/spec/models/course_spec.rb index 562ba6f86..8755bffe9 100644 --- a/spec/models/course_spec.rb +++ b/spec/models/course_spec.rb @@ -1,9 +1,12 @@ require 'rails_helper' -RSpec.describe Course, type: :model do - let(:course) { build(:course, id: 1, name: 'ECE517') } - let(:user1) { User.new name: 'abc', fullname: 'abc bbc', email: 'abcbbc@gmail.com', password: '123456789', password_confirmation: '123456789' } - let(:institution) { build(:institution, id: 1) } +describe Course, type: :model do + let(:role) {Role.create(name: 'Instructor', parent_id: nil, id: 2, default_page_id: nil)} + let(:instructor) { Instructor.create(name: 'testinstructor', email: 'test@test.com', full_name: 'Test Instructor', password: '123456', role: role) } + let(:institution) { create(:institution, id: 1) } + let(:course) { create(:course, id: 1, name: 'ECE517', instructor: instructor, institution: institution) } + let(:user1) { create(:user, name: 'abcdef', full_name:'abc bbc', email: 'abcbbc@gmail.com', password: '123456789', password_confirmation: '123456789') } + describe 'validations' do it 'validates presence of name' do course.name = '' diff --git a/spec/models/invitation_spec.rb b/spec/models/invitation_spec.rb index 1d1f17ab0..f5f8c81ef 100644 --- a/spec/models/invitation_spec.rb +++ b/spec/models/invitation_spec.rb @@ -1,10 +1,20 @@ require 'rails_helper' RSpec.describe Invitation, type: :model do + include ActiveJob::TestHelper let(:user1) { create :user, name: 'rohitgeddam' } let(:user2) { create :user, name: 'superman' } let(:invalid_user) { build :user, name: 'INVALID' } - let(:assignment) { create(:assignment) } + let(:role) {Role.create(name: 'Instructor', parent_id: nil, id: 3, default_page_id: nil)} + let(:instructor) { Instructor.create(name: 'testinstructor', email: 'test@test.com', full_name: 'Test Instructor', password: '123456', role: role) } + let(:assignment) { create(:assignment, instructor: instructor) } + before(:each) do + ActiveJob::Base.queue_adapter = :test + end + + after(:each) do + clear_enqueued_jobs + end it 'is invitation_factory returning new Invitation' do diff --git a/spec/models/question_spec.rb b/spec/models/question_spec.rb index 20287ddd2..83c118161 100644 --- a/spec/models/question_spec.rb +++ b/spec/models/question_spec.rb @@ -4,7 +4,7 @@ # Creating dummy objects for the test with the help of let statement let(:role) { Role.create(name: 'Instructor', parent_id: nil, id: 2, default_page_id: nil) } let(:instructor) do - Instructor.create(id: 1234, name: 'testinstructor', email: 'test@test.com', fullname: 'Test Instructor', + Instructor.create(id: 1234, name: 'testinstructor', email: 'test@test.com', full_name: 'test instructor', password: '123456', role:) end let(:questionnaire) do @@ -67,7 +67,7 @@ instructor.save! questionnaire.save! question = Question.create(seq: 1, txt: 'Sample question', question_type: 'multiple_choice', - break_before: true, questionnaire:) + break_before: true, questionnaire:questionnaire) expect { question.delete }.to change { Question.count }.by(-1) end end diff --git a/spec/models/questionnaire_spec.rb b/spec/models/questionnaire_spec.rb index 7a6e617f2..7078f796c 100644 --- a/spec/models/questionnaire_spec.rb +++ b/spec/models/questionnaire_spec.rb @@ -1,15 +1,24 @@ require 'rails_helper' describe Questionnaire, type: :model do - + # Creating dummy objects for the test with the help of let statement let(:role) {Role.create(name: 'Instructor', parent_id: nil, id: 2, default_page_id: nil)} - let(:instructor) { Instructor.create(name: 'testinstructor', email: 'test@test.com', fullname: 'Test Instructor', password: '123456', role: role) } - let(:questionnaire) { Questionnaire.new id: 1, name: 'abc', private: 0, min_question_score: 0, max_question_score: 10, instructor_id: instructor.id } + let(:instructor) { Instructor.create(name: 'testinstructor', email: 'test@test.com', full_name: 'Test Instructor', password: '123456', role: role) } + let(:questionnaire) do + Questionnaire.create!( + id: 1, + name: 'abc', + private: false, + min_question_score: 0, + max_question_score: 10, + instructor: instructor, + ) + end let(:questionnaire1) { Questionnaire.new name: 'xyz', private: 0, max_question_score: 20, instructor_id: instructor.id } let(:questionnaire2) { Questionnaire.new name: 'pqr', private: 0, max_question_score: 10, instructor_id: instructor.id } let(:question1) { questionnaire.questions.build(weight: 1, id: 1, seq: 1, txt: "que 1", question_type: "Scale", break_before: true) } let(:question2) { questionnaire.questions.build(weight: 10, id: 2, seq: 2, txt: "que 2", question_type: "Checkbox", break_before: true) } - + describe '#name' do @@ -28,14 +37,14 @@ end describe '#instructor_id' do - # Test validates the instructor id in the questionnaire + # Test validates the instructor id in the questionnaire it 'returns the instructor id' do expect(questionnaire.instructor_id).to eq(instructor.id) end end describe '#maximum_score' do - # Test validates the maximum score in the questionnaire + # Test validates the maximum score in the questionnaire it 'validate maximum score' do expect(questionnaire.max_question_score).to eq(10) end @@ -96,15 +105,6 @@ it 'has many questions' do expect(questionnaire.questions).to include(question1, question2) end - - # Test ensures that a questionnaire is not deleted when it has questions associated - it 'restricts deletion of questionnaire when it has associated questions' do - instructor.save! - questionnaire.save! - question1.save! - question2.save! - expect { questionnaire.destroy! }.to raise_error(ActiveRecord::RecordNotDestroyed) - end end describe '.copy_questionnaire_details' do diff --git a/spec/models/response_spec.rb b/spec/models/response_spec.rb index 04325b24b..96ba61f5a 100644 --- a/spec/models/response_spec.rb +++ b/spec/models/response_spec.rb @@ -2,7 +2,7 @@ describe Response do - let(:user) { User.new(id: 1, role_id: 1, name: 'no name', fullname: 'no one') } + let(:user) { User.new(id: 1, role_id: 1, name: 'no name', full_name: 'no one') } let(:team) {Team.new} let(:participant) { Participant.new(id: 1, user: user) } let(:assignment) { Assignment.new(id: 1, name: 'Test Assignment') } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index cda261fc8..1fe902f23 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -5,6 +5,19 @@ # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' + +require 'factory_bot_rails' +require 'database_cleaner/active_record' +RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods + config.before(:suite) do + FactoryBot.factories.clear + FactoryBot.find_definitions + DatabaseCleaner.allow_remote_database_url = true + DatabaseCleaner.strategy = :transaction + DatabaseCleaner.clean_with(:truncation) + end +end # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in diff --git a/spec/requests/authentication_spec.rb b/spec/requests/authentication_spec.rb index 382f894a7..ebd49f249 100644 --- a/spec/requests/authentication_spec.rb +++ b/spec/requests/authentication_spec.rb @@ -18,10 +18,9 @@ schema type: :object, properties: { token: { type: :string } }, required: ['token'] - let(:user) { create(:user, name: 'testuser', full_name: 'Test User') } + let(:user) { create(:user, name: 'testuser', full_name: 'Test User', password: 'password') } let(:credentials) { { user_name: user.name, password: 'password' } } run_test! - it 'returns a JWT token' do token = JSON.parse(response.body)['token'] decoded_token = JsonWebToken.decode(token) diff --git a/spec/routing/courses_routing_spec.rb b/spec/routing/courses_routing_spec.rb index f8b0725d1..75dd7ba81 100644 --- a/spec/routing/courses_routing_spec.rb +++ b/spec/routing/courses_routing_spec.rb @@ -1,30 +1,29 @@ require "rails_helper" -RSpec.describe CoursesController, type: :routing do +RSpec.describe Api::V1::CoursesController, type: :routing do describe "routing" do it "routes to #index" do - expect(get: "/courses").to route_to("courses#index") + expect(get: "/api/v1/courses").to route_to("api/v1/courses#index") end it "routes to #show" do - expect(get: "/courses/1").to route_to("courses#show", id: "1") + expect(get: "/api/v1/courses/1").to route_to("api/v1/courses#show", id: "1") end - it "routes to #create" do - expect(post: "/courses").to route_to("courses#create") + expect(post: "/api/v1/courses").to route_to("api/v1/courses#create") end it "routes to #update via PUT" do - expect(put: "/courses/1").to route_to("courses#update", id: "1") + expect(put: "/api/v1/courses/1").to route_to("api/v1/courses#update", id: "1") end it "routes to #update via PATCH" do - expect(patch: "/courses/1").to route_to("courses#update", id: "1") + expect(patch: "/api/v1/courses/1").to route_to("api/v1/courses#update", id: "1") end it "routes to #destroy" do - expect(delete: "/courses/1").to route_to("courses#destroy", id: "1") + expect(delete: "/api/v1/courses/1").to route_to("api/v1/courses#destroy", id: "1") end end -end +end \ No newline at end of file diff --git a/spec/routing/join_team_requests_routing_spec.rb b/spec/routing/join_team_requests_routing_spec.rb index 01821c40f..6175eb20f 100644 --- a/spec/routing/join_team_requests_routing_spec.rb +++ b/spec/routing/join_team_requests_routing_spec.rb @@ -1,35 +1,29 @@ require "rails_helper" -RSpec.describe JoinTeamRequestsController, type: :routing do +RSpec.describe Api::V1::JoinTeamRequestsController, type: :routing do describe "routing" do - # Routes to the #index action it "routes to #index" do - expect(get: "/join_team_requests").to route_to("join_team_requests#index") + expect(get: "/api/v1/join_team_requests").to route_to("api/v1/join_team_requests#index") end - # Routes to the #show action with a specific ID it "routes to #show" do - expect(get: "/join_team_requests/1").to route_to("join_team_requests#show", id: "1") + expect(get: "/api/v1/join_team_requests/1").to route_to("api/v1/join_team_requests#show", id: "1") end - # Routes to the #create action it "routes to #create" do - expect(post: "/join_team_requests").to route_to("join_team_requests#create") + expect(post: "/api/v1/join_team_requests").to route_to("api/v1/join_team_requests#create") end - # Routes to the #update action via PUT it "routes to #update via PUT" do - expect(put: "/join_team_requests/1").to route_to("join_team_requests#update", id: "1") + expect(put: "/api/v1/join_team_requests/1").to route_to("api/v1/join_team_requests#update", id: "1") end - # Routes to the #update action via PATCH it "routes to #update via PATCH" do - expect(patch: "/join_team_requests/1").to route_to("join_team_requests#update", id: "1") + expect(patch: "/api/v1/join_team_requests/1").to route_to("api/v1/join_team_requests#update", id: "1") end - # Routes to the #destroy action it "routes to #destroy" do - expect(delete: "/join_team_requests/1").to route_to("join_team_requests#destroy", id: "1") + expect(delete: "/api/v1/join_team_requests/1").to route_to("api/v1/join_team_requests#destroy", id: "1") end end -end +end \ No newline at end of file diff --git a/spec/routing/sign_up_topics_routing_spec.rb b/spec/routing/sign_up_topics_routing_spec.rb index 5fbf3ed6b..bf7cfa236 100644 --- a/spec/routing/sign_up_topics_routing_spec.rb +++ b/spec/routing/sign_up_topics_routing_spec.rb @@ -1,30 +1,29 @@ require "rails_helper" -RSpec.describe SignUpTopicsController, type: :routing do +RSpec.describe Api::V1::SignUpTopicsController, type: :routing do describe "routing" do it "routes to #index" do - expect(get: "/sign_up_topics").to route_to("sign_up_topics#index") + expect(get: "/api/v1/sign_up_topics").to route_to("api/v1/sign_up_topics#index") end it "routes to #show" do - expect(get: "/sign_up_topics/1").to route_to("sign_up_topics#show", id: "1") + expect(get: "/api/v1/sign_up_topics/1").to route_to("api/v1/sign_up_topics#show", id: "1") end - it "routes to #create" do - expect(post: "/sign_up_topics").to route_to("sign_up_topics#create") + expect(post: "/api/v1/sign_up_topics").to route_to("api/v1/sign_up_topics#create") end it "routes to #update via PUT" do - expect(put: "/sign_up_topics/1").to route_to("sign_up_topics#update", id: "1") + expect(put: "/api/v1/sign_up_topics/1").to route_to("api/v1/sign_up_topics#update", id: "1") end it "routes to #update via PATCH" do - expect(patch: "/sign_up_topics/1").to route_to("sign_up_topics#update", id: "1") + expect(patch: "/api/v1/sign_up_topics/1").to route_to("api/v1/sign_up_topics#update", id: "1") end it "routes to #destroy" do - expect(delete: "/sign_up_topics/1").to route_to("sign_up_topics#destroy", id: "1") + expect(delete: "/api/v1/sign_up_topics/1").to route_to("api/v1/sign_up_topics#destroy", id: "1") end end -end +end \ No newline at end of file diff --git a/spec/routing/signed_up_teams_routing_spec.rb b/spec/routing/signed_up_teams_routing_spec.rb index 2a1b47dba..96f84f447 100644 --- a/spec/routing/signed_up_teams_routing_spec.rb +++ b/spec/routing/signed_up_teams_routing_spec.rb @@ -1,30 +1,29 @@ +# spec/routing/signed_up_teams_routing_spec.rb require "rails_helper" -RSpec.describe SignedUpTeamsController, type: :routing do +RSpec.describe Api::V1::SignedUpTeamsController, type: :routing do describe "routing" do it "routes to #index" do - expect(get: "/signed_up_teams").to route_to("signed_up_teams#index") + expect(get: "/api/v1/signed_up_teams").to route_to("api/v1/signed_up_teams#index") end it "routes to #show" do - expect(get: "/signed_up_teams/1").to route_to("signed_up_teams#show", id: "1") - end - - - it "routes to #create" do - expect(post: "/signed_up_teams").to route_to("signed_up_teams#create") + expect(get: "/api/v1/signed_up_teams/1").to route_to("api/v1/signed_up_teams#show", id: "1") end + end +end - it "routes to #update via PUT" do - expect(put: "/signed_up_teams/1").to route_to("signed_up_teams#update", id: "1") - end +# spec/routing/student_tasks_routing_spec.rb +require "rails_helper" - it "routes to #update via PATCH" do - expect(patch: "/signed_up_teams/1").to route_to("signed_up_teams#update", id: "1") +RSpec.describe Api::V1::StudentTasksController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(get: "/api/v1/student_tasks").to route_to("api/v1/student_tasks#index") end - it "routes to #destroy" do - expect(delete: "/signed_up_teams/1").to route_to("signed_up_teams#destroy", id: "1") + it "routes to #show" do + expect(get: "/api/v1/student_tasks/1").to route_to("api/v1/student_tasks#show", id: "1") end end -end +end \ No newline at end of file diff --git a/spec/routing/student_tasks_routing_spec.rb b/spec/routing/student_tasks_routing_spec.rb index 902e75db2..02f457e80 100644 --- a/spec/routing/student_tasks_routing_spec.rb +++ b/spec/routing/student_tasks_routing_spec.rb @@ -1,30 +1,29 @@ require "rails_helper" -RSpec.describe StudentTasksController, type: :routing do +RSpec.describe Api::V1::StudentTasksController, type: :routing do describe "routing" do it "routes to #index" do - expect(get: "/student_tasks").to route_to("student_tasks#index") + expect(get: "/api/v1/student_tasks").to route_to("api/v1/student_tasks#index") end it "routes to #show" do - expect(get: "/student_tasks/1").to route_to("student_tasks#show", id: "1") + expect(get: "/api/v1/student_tasks/1").to route_to("api/v1/student_tasks#show", id: "1") end - it "routes to #create" do - expect(post: "/student_tasks").to route_to("student_tasks#create") + expect(post: "/api/v1/student_tasks").to route_to("api/v1/student_tasks#create") end it "routes to #update via PUT" do - expect(put: "/student_tasks/1").to route_to("student_tasks#update", id: "1") + expect(put: "/api/v1/student_tasks/1").to route_to("api/v1/student_tasks#update", id: "1") end it "routes to #update via PATCH" do - expect(patch: "/student_tasks/1").to route_to("student_tasks#update", id: "1") + expect(patch: "/api/v1/student_tasks/1").to route_to("api/v1/student_tasks#update", id: "1") end it "routes to #destroy" do - expect(delete: "/student_tasks/1").to route_to("student_tasks#destroy", id: "1") + expect(delete: "/api/v1/student_tasks/1").to route_to("api/v1/student_tasks#destroy", id: "1") end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 327b58ea1..42008af75 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,7 @@ # it. # # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration + RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb index 024a99d29..ecb5221b3 100644 --- a/spec/swagger_helper.rb +++ b/spec/swagger_helper.rb @@ -23,10 +23,10 @@ }, components: { securitySchemes: { - bearerAuth: { - type: "http", - scheme: "bearer", - bearerFormat: "JWT" + bearer_auth: { + type: :http, + scheme: :bearer, + bearerFormat: :JWT } } },