forked from expertiza/reimplementation-back-end
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github workflows and fixing rspec model cases.
Removed Assignment as foreign key from questionnaire.
- Loading branch information
kmalick
committed
Dec 6, 2024
1 parent
13a0fdc
commit ba3eca3
Showing
27 changed files
with
376 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
service_name: travis-ci | ||
repo_token: cDmwC7VoKwQvWO7XsPBmE3hH7t1tFpLFn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:[email protected]: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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: ruby | ||
rvm: | ||
- 3.2.1 | ||
- jruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '[email protected]', 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: '[email protected]', 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: '[email protected]', password: '123456789', password_confirmation: '123456789') } | ||
|
||
describe 'validations' do | ||
it 'validates presence of name' do | ||
course.name = '' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '[email protected]', 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: '[email protected]', fullname: 'Test Instructor', | ||
Instructor.create(id: 1234, name: 'testinstructor', email: '[email protected]', 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 | ||
|
Oops, something went wrong.