This repository has been archived by the owner on Jun 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #527 from omu/add-available-course-models
Add available course models
- Loading branch information
Showing
17 changed files
with
197 additions
and
0 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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class AvailableCourse < ApplicationRecord | ||
# relations | ||
belongs_to :academic_term | ||
belongs_to :curriculum | ||
belongs_to :course | ||
has_many :groups, class_name: 'AvailableCourseGroup', dependent: :destroy | ||
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class AvailableCourseGroup < ApplicationRecord | ||
# relations | ||
belongs_to :available_course | ||
has_many :lecturers, class_name: 'AvailableCourseLecturer', foreign_key: :group_id, | ||
inverse_of: :group, dependent: :destroy | ||
|
||
# validations | ||
validates :name, presence: true, uniqueness: { scope: :available_course } | ||
validates :quota, numericality: { only_integer: true, greater_than_or_equal_to: 1 }, allow_blank: true | ||
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class AvailableCourseLecturer < ApplicationRecord | ||
# relations | ||
belongs_to :group, class_name: 'AvailableCourseGroup' | ||
belongs_to :lecturer, class_name: 'Employee' | ||
|
||
# validations | ||
validates :coordinator, presence: true, inclusion: { in: [true, false] } | ||
|
||
# scopes | ||
scope :coordinator, -> { where(coordinator: true) } | ||
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
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateAvailableCourses < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :available_courses do |t| | ||
t.references :academic_term | ||
t.references :curriculum | ||
t.references :course | ||
t.timestamps | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
db/migrate/20181112175328_create_available_course_groups.rb
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateAvailableCourseGroups < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :available_course_groups do |t| | ||
t.string :name, null: false, limit: 50 | ||
t.integer :quota | ||
t.references :available_course | ||
t.timestamps | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
db/migrate/20181112175343_create_available_course_lecturers.rb
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateAvailableCourseLecturers < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :available_course_lecturers do |t| | ||
t.boolean :coordinator, default: false, null: false | ||
t.references :group, foreign_key: { to_table: :available_course_groups } | ||
t.references :lecturer, foreign_key: { to_table: :employees } | ||
t.timestamps | ||
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
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 @@ | ||
ati_group_1: | ||
available_course: ati_fall_2017_2018 | ||
name: Group 1 | ||
quota: 10 |
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 @@ | ||
ati_group_1_lecturer_john: | ||
group: ati_group_1 | ||
lecturer: chief_john | ||
coordinator: true | ||
ati_group_1_lecturer_serhat: | ||
group: ati_group_1 | ||
lecturer: serhat_active | ||
coordinator: false |
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 @@ | ||
ati_fall_2017_2018: | ||
academic_term: fall_2017_2018 | ||
curriculum: one | ||
course: ati |
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,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class AvailableCourseGroupTest < ActiveSupport::TestCase | ||
# relations | ||
%i[ | ||
available_course | ||
lecturers | ||
].each do |property| | ||
test "a available_course_group can communicate with #{property}" do | ||
assert available_course_groups(:ati_group_1).send(property) | ||
end | ||
end | ||
|
||
# validations: presence | ||
test 'should not save available_course_group without name' do | ||
available_course_groups(:ati_group_1).name = nil | ||
assert_not available_course_groups(:ati_group_1).valid? | ||
assert_not_empty available_course_groups(:ati_group_1).errors[:name] | ||
end | ||
|
||
# validations: uniqueness | ||
test 'name should be unique' do | ||
fake = available_course_groups(:ati_group_1).dup | ||
assert_not fake.valid? | ||
assert_not_empty fake.errors[:name] | ||
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,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class AvailableCourseLecturerTest < ActiveSupport::TestCase | ||
# relations | ||
%i[ | ||
group | ||
lecturer | ||
].each do |property| | ||
test "a available_course_lecturer can communicate with #{property}" do | ||
assert available_course_lecturers(:ati_group_1_lecturer_john).send(property) | ||
end | ||
end | ||
|
||
# validations: presence | ||
test 'should not save available_course_group without coordinator info' do | ||
available_course_lecturers(:ati_group_1_lecturer_john).coordinator = nil | ||
assert_not available_course_lecturers(:ati_group_1_lecturer_john).valid? | ||
assert_not_empty available_course_lecturers(:ati_group_1_lecturer_john).errors[:coordinator] | ||
end | ||
|
||
# scopes | ||
test 'coordinator scope returns coordinator lecturers' do | ||
lecturers = available_course_groups(:ati_group_1).lecturers | ||
assert lecturers.coordinator.to_a.include?(available_course_lecturers(:ati_group_1_lecturer_john)) | ||
assert_not lecturers.coordinator.to_a.include?(available_course_lecturers(:ati_group_1_lecturer_serhat)) | ||
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class AvailableCourseTest < ActiveSupport::TestCase | ||
# relations | ||
%i[ | ||
academic_term | ||
curriculum | ||
course | ||
groups | ||
].each do |property| | ||
test "a available_course can communicate with #{property}" do | ||
assert available_courses(:ati_fall_2017_2018).send(property) | ||
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
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