diff --git a/app/controllers/admin/education/cohorts_controller.rb b/app/controllers/admin/education/cohorts_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..c32d9edf9cb122816d2d85191765d2ca214ba597 --- /dev/null +++ b/app/controllers/admin/education/cohorts_controller.rb @@ -0,0 +1,59 @@ +class Admin::Education::CohortsController < Admin::Education::ApplicationController + load_and_authorize_resource class: Education::Cohort, + through: :current_university, + through_association: :education_cohorts + + def index + breadcrumb + end + + def show + breadcrumb + end + + def new + breadcrumb + end + + def edit + breadcrumb + end + + def create + @cohort.university = current_university + if @cohort.save + redirect_to [:admin, @cohort], + notice: t('admin.successfully_created_html', model: @cohort.to_s) + else + breadcrumb + render :new, status: :unprocessable_entity + end + end + + def update + if @cohort.update(cohort_params) + redirect_to [:admin, @cohort], + notice: t('admin.successfully_updated_html', model: @cohort.to_s) + else + render :edit, status: :unprocessable_entity + end + end + + def destroy + @cohort.destroy + redirect_to education_cohorts_url, + notice: t('admin.successfully_destroyed_html', model: @cohort.to_s) + end + + protected + + def breadcrumb + super + add_breadcrumb Education::cohort.model_name.human(count: 2), admin_education_cohorts_path + breadcrumb_for @cohort + end + + def cohort_params + params.require(:education_cohort).permit(:university_id, :program_id, :academic_year_id, :name) + end +end diff --git a/app/controllers/extranet/cohorts_controller.rb b/app/controllers/extranet/cohorts_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..e5eaf425d46a911cc0067782d927fd5ae6456cfb --- /dev/null +++ b/app/controllers/extranet/cohorts_controller.rb @@ -0,0 +1,12 @@ +class Extranet::CohortsController < ApplicationController + load_and_authorize_resource class: Education::Cohort, + through: :current_university, + through_association: :education_cohorts + + def index + @cohorts = @cohorts.ordered.page(params[:page]) + end + + def show + end +end diff --git a/app/models/education/academic_year.rb b/app/models/education/academic_year.rb index efbe632f93af0eabcf3ade9506b4addb7b16c988..fbacbef0f7004e8005e2e5482b1a2f22d87a622f 100644 --- a/app/models/education/academic_year.rb +++ b/app/models/education/academic_year.rb @@ -19,7 +19,9 @@ class Education::AcademicYear < ApplicationRecord include WithUniversity - scope :ordered, -> { order(year: :desc) } + has_many :cohorts, class_name: 'Education::Cohort' + + scope :ordered, -> { order(year: :desc) } def to_s "#{year}" diff --git a/app/models/education/cohort.rb b/app/models/education/cohort.rb new file mode 100644 index 0000000000000000000000000000000000000000..56885e89522c2d2535b003cfdf023172fcc7cc32 --- /dev/null +++ b/app/models/education/cohort.rb @@ -0,0 +1,39 @@ +# == Schema Information +# +# Table name: education_cohorts +# +# id :uuid not null, primary key +# name :string +# created_at :datetime not null +# updated_at :datetime not null +# academic_year_id :uuid not null, indexed +# program_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_education_cohorts_on_academic_year_id (academic_year_id) +# index_education_cohorts_on_program_id (program_id) +# index_education_cohorts_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_0f4a4f43d9 (university_id => universities.id) +# fk_rails_72528c3d76 (program_id => education_programs.id) +# fk_rails_c2d725cabd (academic_year_id => education_academic_years.id) +# +class Education::Cohort < ApplicationRecord + include WithUniversity + belongs_to :program, class_name: 'Education::Program' + belongs_to :academic_year, class_name: 'Education::AcademicYear' + has_and_belongs_to_many :people, + class_name: 'University::Person', + foreign_key: 'education_cohort_id', + association_foreign_key: 'university_person_id' + + scope :ordered, -> { order(:name) } + + def to_s + "#{program} #{academic_year}" + end +end diff --git a/app/models/university/person/alumnus/import.rb b/app/models/university/person/alumnus/import.rb index 935d6249966a29ccfd14684e5bd328fef882b95d..fd08abff9fbd1d0acfbf1bbe863678408874e522 100644 --- a/app/models/university/person/alumnus/import.rb +++ b/app/models/university/person/alumnus/import.rb @@ -1,3 +1,23 @@ +# == Schema Information +# +# Table name: university_person_alumnus_imports +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null, indexed +# user_id :uuid not null, indexed +# +# Indexes +# +# index_university_person_alumnus_imports_on_university_id (university_id) +# index_university_person_alumnus_imports_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_3ff74ac195 (user_id => users.id) +# fk_rails_d14eb003f9 (university_id => universities.id) +# class University::Person::Alumnus::Import < ApplicationRecord include WithUniversity include Importable @@ -33,19 +53,24 @@ class University::Person::Alumnus::Import < ApplicationRecord program = university.education_programs .find_by(id: row['program']) next if program.nil? - year = university.academic_years - .where(year: row['year']) - .first_or_create + academic_year = university.academic_years + .where(year: row['year']) + .first_or_create + + cohort = university.education_cohorts + .where(program: program, academic_year: academic_year) + .first_or_create first_name = clean_encoding row['first_name'] last_name = clean_encoding row['last_name'] + email = row['mail'] url = clean_encoding row['url'] - if row['mail'].blank? + if email.blank? person = university.people .where(first_name: first_name, last_name: last_name) .first_or_create else person = university.people - .where(email: row['mail']) + .where(email: email) .first_or_create person.first_name = first_name person.last_name = last_name @@ -55,7 +80,7 @@ class University::Person::Alumnus::Import < ApplicationRecord person.url = url person.slug = person.to_s.parameterize person.save - # byebug + cohort.people << person unless person.in?(cohort.people) end end diff --git a/app/models/university/person/with_education.rb b/app/models/university/person/with_education.rb index 1074dea4c1897fc9f03117426452d242cd7ded06..a72fbde6bb02579ffd06675d9597ee2b9b9fa596 100644 --- a/app/models/university/person/with_education.rb +++ b/app/models/university/person/with_education.rb @@ -11,6 +11,9 @@ module University::Person::WithEducation through: :involvements_as_teacher, source: :target, source_type: "Education::Program" + + has_and_belongs_to_many :cohorts, + class_name: 'Education::Cohort' end def education_programs_as_administrator diff --git a/app/models/university/with_education.rb b/app/models/university/with_education.rb index c7448f3d3f092ef36ae9490130ca656f069663cf..eab20006b33a912ae68713ef3a0d3892eb1fa1c8 100644 --- a/app/models/university/with_education.rb +++ b/app/models/university/with_education.rb @@ -2,6 +2,7 @@ module University::WithEducation extend ActiveSupport::Concern included do + has_many :education_cohorts, class_name: 'Education::Cohort', dependent: :destroy has_many :education_programs, class_name: 'Education::Program', dependent: :destroy has_many :education_schools, class_name: 'Education::School', dependent: :destroy has_many :academic_years, class_name: 'Education::AcademicYear', dependent: :destroy diff --git a/app/views/admin/education/cohorts/_education_cohort.json.jbuilder b/app/views/admin/education/cohorts/_education_cohort.json.jbuilder new file mode 100644 index 0000000000000000000000000000000000000000..ace1ee5325090fb5a9e73f3e39bd47649b3f2664 --- /dev/null +++ b/app/views/admin/education/cohorts/_education_cohort.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! education_cohort, :id, :university_id, :program_id, :academic_year_id, :name, :created_at, :updated_at +json.url education_cohort_url(education_cohort, format: :json) diff --git a/app/views/admin/education/cohorts/_form.html.erb b/app/views/admin/education/cohorts/_form.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..c2ed9f568c4c8921e94b008ef4dedf0c803d7fb7 --- /dev/null +++ b/app/views/admin/education/cohorts/_form.html.erb @@ -0,0 +1,16 @@ + +<%= simple_form_for(@education_cohort) do |f| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + + <div class="form-inputs"> + <%= f.association :university %> + <%= f.association :program %> + <%= f.association :academic_year %> + <%= f.input :name %> + </div> + + <div class="form-actions"> + <%= f.button :submit %> + </div> +<% end %> diff --git a/app/views/admin/education/cohorts/edit.html.erb b/app/views/admin/education/cohorts/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..8bbbfe709d3ef787e5406d1db79ea8d70b31cd91 --- /dev/null +++ b/app/views/admin/education/cohorts/edit.html.erb @@ -0,0 +1,6 @@ +<h1>Editing Education Cohort</h1> + +<%= render 'form', education_cohort: @education_cohort %> + +<%= link_to 'Show', @education_cohort %> | +<%= link_to 'Back', education_cohorts_path %> diff --git a/app/views/admin/education/cohorts/index.html.erb b/app/views/admin/education/cohorts/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..58267d3e37dd85cf37bd7658da0dcd0442435af2 --- /dev/null +++ b/app/views/admin/education/cohorts/index.html.erb @@ -0,0 +1,33 @@ +<p id="notice"><%= notice %></p> + +<h1>Education Cohorts</h1> + +<table> + <thead> + <tr> + <th>University</th> + <th>Program</th> + <th>Academic year</th> + <th>Name</th> + <th colspan="3"></th> + </tr> + </thead> + + <tbody> + <% @education_cohorts.each do |education_cohort| %> + <tr> + <td><%= education_cohort.university_id %></td> + <td><%= education_cohort.program_id %></td> + <td><%= education_cohort.academic_year_id %></td> + <td><%= education_cohort.name %></td> + <td><%= link_to 'Show', education_cohort %></td> + <td><%= link_to 'Edit', edit_education_cohort_path(education_cohort) %></td> + <td><%= link_to 'Destroy', education_cohort, method: :delete, data: { confirm: 'Are you sure?' } %></td> + </tr> + <% end %> + </tbody> +</table> + +<br> + +<%= link_to 'New Education Cohort', new_education_cohort_path %> diff --git a/app/views/admin/education/cohorts/index.json.jbuilder b/app/views/admin/education/cohorts/index.json.jbuilder new file mode 100644 index 0000000000000000000000000000000000000000..757fffcecb4ddaefa32c834aa44f4632f7b7bf90 --- /dev/null +++ b/app/views/admin/education/cohorts/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @education_cohorts, partial: "education_cohorts/education_cohort", as: :education_cohort diff --git a/app/views/admin/education/cohorts/new.html.erb b/app/views/admin/education/cohorts/new.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..7ac730f56df5d2ff85434b24e392f444c24d1918 --- /dev/null +++ b/app/views/admin/education/cohorts/new.html.erb @@ -0,0 +1,5 @@ +<h1>New Education Cohort</h1> + +<%= render 'form', education_cohort: @education_cohort %> + +<%= link_to 'Back', education_cohorts_path %> diff --git a/app/views/admin/education/cohorts/show.html.erb b/app/views/admin/education/cohorts/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e28142b11e21ae5eecba90ff87c32320035a3ad6 --- /dev/null +++ b/app/views/admin/education/cohorts/show.html.erb @@ -0,0 +1,24 @@ +<p id="notice"><%= notice %></p> + +<p> + <strong>University:</strong> + <%= @education_cohort.university_id %> +</p> + +<p> + <strong>Program:</strong> + <%= @education_cohort.program_id %> +</p> + +<p> + <strong>Academic year:</strong> + <%= @education_cohort.academic_year_id %> +</p> + +<p> + <strong>Name:</strong> + <%= @education_cohort.name %> +</p> + +<%= link_to 'Edit', edit_education_cohort_path(@education_cohort) %> | +<%= link_to 'Back', education_cohorts_path %> diff --git a/app/views/admin/education/cohorts/show.json.jbuilder b/app/views/admin/education/cohorts/show.json.jbuilder new file mode 100644 index 0000000000000000000000000000000000000000..8729cfa0b92b796974b2cdad4905634df0fdcd12 --- /dev/null +++ b/app/views/admin/education/cohorts/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "education_cohorts/education_cohort", education_cohort: @education_cohort diff --git a/app/views/extranet/academic_years/index.html.erb b/app/views/extranet/academic_years/index.html.erb index 6bb47711d1cc0040225ab2eddda52fe7784401f6..e5c3cd21229dd1c483b83cdd5686acfc89997388 100644 --- a/app/views/extranet/academic_years/index.html.erb +++ b/app/views/extranet/academic_years/index.html.erb @@ -11,7 +11,7 @@ <tbody> <% @academic_years.each do |year| %> <tr> - <td><%= year.year %></td> + <td><%= link_to year, year %></td> <td></td> </tr> <% end %> diff --git a/app/views/extranet/academic_years/show.html.erb b/app/views/extranet/academic_years/show.html.erb index 4c9b91dbfb52a216446f1c04b1897bfe42c9fd1c..07d6cf7dd467b0ed61e20636428889ce55024359 100644 --- a/app/views/extranet/academic_years/show.html.erb +++ b/app/views/extranet/academic_years/show.html.erb @@ -1,14 +1,7 @@ -<p id="notice"><%= notice %></p> +<% content_for :title, @academic_year %> -<p> - <strong>University:</strong> - <%= @education_academic_year.university_id %> -</p> +<h1><%= @academic_year %></h1> -<p> - <strong>Year:</strong> - <%= @education_academic_year.year %> -</p> - -<%= link_to 'Edit', edit_education_academic_year_path(@education_academic_year) %> | -<%= link_to 'Back', education_academic_years_path %> +<% @academic_year.cohorts.each do |cohort| %> + <%= link_to cohort, cohort %> +<% end %> diff --git a/app/views/extranet/cohorts/index.html.erb b/app/views/extranet/cohorts/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..5341018f4f63010fdaba38e873ec34a16caf646b --- /dev/null +++ b/app/views/extranet/cohorts/index.html.erb @@ -0,0 +1,19 @@ +<% content_for :title, Education::Cohort.model_name.human(count: 2) %> + +<table class="<%= table_classes %>"> + <thead> + <tr> + <th>Name</th> + <th></th> + </tr> + </thead> + + <tbody> + <% @cohorts.each do |cohort| %> + <tr> + <td><%= link_to cohort, cohort %></td> + <td></td> + </tr> + <% end %> + </tbody> +</table> diff --git a/app/views/extranet/cohorts/show.html.erb b/app/views/extranet/cohorts/show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..80c570517c0ef4f4bc151bdf02748440a1696fc5 --- /dev/null +++ b/app/views/extranet/cohorts/show.html.erb @@ -0,0 +1,7 @@ +<% content_for :title, @cohort %> + +<h1><%= @cohort %></h1> +<p><%= @cohort.people.count %></p> +<% @cohort.people.each do |person| %> + <%= link_to person, person %> +<% end %> diff --git a/config/navigation.rb b/config/navigation.rb index 00752306f546a1569ec97f3e612d6a0f014cf6da..39f93342cace8caa601aed22da5f0324b024415a 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -4,8 +4,17 @@ SimpleNavigation::Configuration.run do |navigation| navigation.highlight_on_subpath = true navigation.selected_class = 'active' navigation.items do |primary| - primary.item :home, t('extranet.home'), root_path - primary.item :years, Education::AcademicYear.model_name.human(count: 2), academic_years_path - primary.item :organizations, University::Organization.model_name.human(count: 2), organizations_path + primary.item :home, + t('extranet.home'), + root_path + primary.item :years, + Education::AcademicYear.model_name.human(count: 2), + education_academic_years_path + primary.item :organizations, + University::Organization.model_name.human(count: 2), + university_organizations_path + primary.item :cohorts, + Education::Cohort.model_name.human(count: 2), + education_cohorts_path end end diff --git a/config/routes.rb b/config/routes.rb index 03d12edd360278aaaf6706abfd504cc82a4e482c..7bf2ee0b0c0d5c65699cb0a2059c705454874c5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,4 @@ Rails.application.routes.draw do - namespace :university do - namespace :person do - namespace :alumnus do - resources :imports - end - end - end - resources :university_person_alumnus_imports authenticated :user, -> user { user.server_admin? } do match "/delayed_job" => DelayedJobWeb, :anchor => false, :via => [:get, :post] end diff --git a/config/routes/admin/education.rb b/config/routes/admin/education.rb index 9ef1f7832bbd33b22743d3c862af8178d96d0794..f4ae939d306a4de9b3b1eb6a8d3577fc10e9ec41 100644 --- a/config/routes/admin/education.rb +++ b/config/routes/admin/education.rb @@ -31,4 +31,6 @@ namespace :education do get :children end end + resources :academic_years + resources :cohorts end diff --git a/config/routes/extranet.rb b/config/routes/extranet.rb index e23246ed59008752fd1068fbcec6e73485d696d5..1fd34eb0fdf8a97c6a0d1bbd9883376f80251459 100644 --- a/config/routes/extranet.rb +++ b/config/routes/extranet.rb @@ -1,4 +1,8 @@ -get 'organizations' => 'extranet/organizations#index', as: :organizations +get 'cohorts' => 'extranet/cohorts#index', as: :education_cohorts +get 'cohorts/:id' => 'extranet/cohorts#show', as: :education_cohort +get 'organizations' => 'extranet/organizations#index', as: :university_organizations get 'organization/:id' => 'extranet/organizations#show', as: :university_organization -get 'years' => 'extranet/academic_years#index', as: :academic_years -get 'years/:id' => 'extranet/academic_years#show', as: :academic_year +get 'persons' => 'extranet/persons#index', as: :university_persons +get 'persons/:id' => 'extranet/persons#show', as: :university_person +get 'years' => 'extranet/academic_years#index', as: :education_academic_years +get 'years/:id' => 'extranet/academic_years#show', as: :education_academic_year diff --git a/db/migrate/20220317150614_create_education_cohorts.rb b/db/migrate/20220317150614_create_education_cohorts.rb new file mode 100644 index 0000000000000000000000000000000000000000..8794f5222f45aa882583466fb7947be7de93b112 --- /dev/null +++ b/db/migrate/20220317150614_create_education_cohorts.rb @@ -0,0 +1,12 @@ +class CreateEducationCohorts < ActiveRecord::Migration[6.1] + def change + create_table :education_cohorts, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :program, null: false, foreign_key: {to_table: :education_programs}, type: :uuid + t.references :academic_year, null: false, foreign_key: {to_table: :education_academic_years}, type: :uuid + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20220317151819_create_join_table_education_cohort_university_person.rb b/db/migrate/20220317151819_create_join_table_education_cohort_university_person.rb new file mode 100644 index 0000000000000000000000000000000000000000..1abfa95fca4f39bd95c21e8d52567f2401a6457f --- /dev/null +++ b/db/migrate/20220317151819_create_join_table_education_cohort_university_person.rb @@ -0,0 +1,8 @@ +class CreateJoinTableEducationCohortUniversityPerson < ActiveRecord::Migration[6.1] + def change + create_join_table :education_cohorts, :university_people, column_options: {type: :uuid} do |t| + t.index [:education_cohort_id, :university_person_id], name: 'index_cohort_person' + t.index [:university_person_id, :education_cohort_id], name: 'index_person_cohort' + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4e642214aa015b7ce23a3e962fd677783c71bb2c..0fff29eb6e0ffa16c51da84c377ff70a818c9a94 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_03_16_155340) do +ActiveRecord::Schema.define(version: 2022_03_17_151819) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -392,6 +392,25 @@ ActiveRecord::Schema.define(version: 2022_03_16_155340) do t.index ["university_id"], name: "index_education_academic_years_on_university_id" end + create_table "education_cohorts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "program_id", null: false + t.uuid "academic_year_id", null: false + t.string "name" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["academic_year_id"], name: "index_education_cohorts_on_academic_year_id" + t.index ["program_id"], name: "index_education_cohorts_on_program_id" + t.index ["university_id"], name: "index_education_cohorts_on_university_id" + end + + create_table "education_cohorts_university_people", id: false, force: :cascade do |t| + t.uuid "education_cohort_id", null: false + t.uuid "university_person_id", null: false + t.index ["education_cohort_id", "university_person_id"], name: "index_cohort_person" + t.index ["university_person_id", "education_cohort_id"], name: "index_person_cohort" + end + create_table "education_programs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" @@ -775,6 +794,9 @@ ActiveRecord::Schema.define(version: 2022_03_16_155340) do add_foreign_key "communication_website_posts", "university_people", column: "author_id" add_foreign_key "communication_websites", "universities" add_foreign_key "education_academic_years", "universities" + add_foreign_key "education_cohorts", "education_academic_years", column: "academic_year_id" + add_foreign_key "education_cohorts", "education_programs", column: "program_id" + add_foreign_key "education_cohorts", "universities" add_foreign_key "education_programs", "education_programs", column: "parent_id" add_foreign_key "education_programs", "universities" add_foreign_key "education_schools", "universities" diff --git a/test/controllers/education/cohorts_controller_test.rb b/test/controllers/education/cohorts_controller_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..e8e527ad1bbef72912c6509b815a3c842c169ab5 --- /dev/null +++ b/test/controllers/education/cohorts_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class Education::CohortsControllerTest < ActionDispatch::IntegrationTest + setup do + @education_cohort = education_cohorts(:one) + end + + test "should get index" do + get education_cohorts_url + assert_response :success + end + + test "should get new" do + get new_education_cohort_url + assert_response :success + end + + test "should create education_cohort" do + assert_difference('Education::Cohort.count') do + post education_cohorts_url, params: { education_cohort: { academic_year_id: @education_cohort.academic_year_id, name: @education_cohort.name, program_id: @education_cohort.program_id, university_id: @education_cohort.university_id } } + end + + assert_redirected_to education_cohort_url(Education::Cohort.last) + end + + test "should show education_cohort" do + get education_cohort_url(@education_cohort) + assert_response :success + end + + test "should get edit" do + get edit_education_cohort_url(@education_cohort) + assert_response :success + end + + test "should update education_cohort" do + patch education_cohort_url(@education_cohort), params: { education_cohort: { academic_year_id: @education_cohort.academic_year_id, name: @education_cohort.name, program_id: @education_cohort.program_id, university_id: @education_cohort.university_id } } + assert_redirected_to education_cohort_url(@education_cohort) + end + + test "should destroy education_cohort" do + assert_difference('Education::Cohort.count', -1) do + delete education_cohort_url(@education_cohort) + end + + assert_redirected_to education_cohorts_url + end +end diff --git a/test/fixtures/education/cohorts.yml b/test/fixtures/education/cohorts.yml new file mode 100644 index 0000000000000000000000000000000000000000..48a543db806f22f20ffa9dc40bd512758f52a9e5 --- /dev/null +++ b/test/fixtures/education/cohorts.yml @@ -0,0 +1,36 @@ +# == Schema Information +# +# Table name: education_cohorts +# +# id :uuid not null, primary key +# name :string +# created_at :datetime not null +# updated_at :datetime not null +# academic_year_id :uuid not null, indexed +# program_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_education_cohorts_on_academic_year_id (academic_year_id) +# index_education_cohorts_on_program_id (program_id) +# index_education_cohorts_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_0f4a4f43d9 (university_id => universities.id) +# fk_rails_72528c3d76 (program_id => education_programs.id) +# fk_rails_c2d725cabd (academic_year_id => education_academic_years.id) +# + +one: + university: one + program: one + academic_year: one + name: MyString + +two: + university: two + program: two + academic_year: two + name: MyString diff --git a/test/fixtures/university/person/alumnus/imports.yml b/test/fixtures/university/person/alumnus/imports.yml index b712a4f085ce90979c3d55bd7882a7444d713141..f8533f0e62b8768e40b987dc28aad4f609d1950a 100644 --- a/test/fixtures/university/person/alumnus/imports.yml +++ b/test/fixtures/university/person/alumnus/imports.yml @@ -1,4 +1,23 @@ -# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html +# == Schema Information +# +# Table name: university_person_alumnus_imports +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null, indexed +# user_id :uuid not null, indexed +# +# Indexes +# +# index_university_person_alumnus_imports_on_university_id (university_id) +# index_university_person_alumnus_imports_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_3ff74ac195 (user_id => users.id) +# fk_rails_d14eb003f9 (university_id => universities.id) +# one: university: one diff --git a/test/models/education/cohort_test.rb b/test/models/education/cohort_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..2bb945a4269462f09d294da1e8c6b96f50241a05 --- /dev/null +++ b/test/models/education/cohort_test.rb @@ -0,0 +1,31 @@ +# == Schema Information +# +# Table name: education_cohorts +# +# id :uuid not null, primary key +# name :string +# created_at :datetime not null +# updated_at :datetime not null +# academic_year_id :uuid not null, indexed +# program_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# index_education_cohorts_on_academic_year_id (academic_year_id) +# index_education_cohorts_on_program_id (program_id) +# index_education_cohorts_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_0f4a4f43d9 (university_id => universities.id) +# fk_rails_72528c3d76 (program_id => education_programs.id) +# fk_rails_c2d725cabd (academic_year_id => education_academic_years.id) +# +require "test_helper" + +class Education::CohortTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/university/person/alumnus/import_test.rb b/test/models/university/person/alumnus/import_test.rb index 980cdf30ab5264c860fa05921360e8c4506217fc..e8757e980ee1e9afff1818e585439882863a3246 100644 --- a/test/models/university/person/alumnus/import_test.rb +++ b/test/models/university/person/alumnus/import_test.rb @@ -1,3 +1,23 @@ +# == Schema Information +# +# Table name: university_person_alumnus_imports +# +# id :uuid not null, primary key +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null, indexed +# user_id :uuid not null, indexed +# +# Indexes +# +# index_university_person_alumnus_imports_on_university_id (university_id) +# index_university_person_alumnus_imports_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_3ff74ac195 (user_id => users.id) +# fk_rails_d14eb003f9 (university_id => universities.id) +# require "test_helper" class University::Person::Alumnus::ImportTest < ActiveSupport::TestCase diff --git a/test/system/education/cohorts_test.rb b/test/system/education/cohorts_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..2ed293473e1a44cbffdddfd1b614b8848a703711 --- /dev/null +++ b/test/system/education/cohorts_test.rb @@ -0,0 +1,49 @@ +require "application_system_test_case" + +class Education::CohortsTest < ApplicationSystemTestCase + setup do + @education_cohort = education_cohorts(:one) + end + + test "visiting the index" do + visit education_cohorts_url + assert_selector "h1", text: "Education/Cohorts" + end + + test "creating a Cohort" do + visit education_cohorts_url + click_on "New Education/Cohort" + + fill_in "Academic year", with: @education_cohort.academic_year_id + fill_in "Name", with: @education_cohort.name + fill_in "Program", with: @education_cohort.program_id + fill_in "University", with: @education_cohort.university_id + click_on "Create Cohort" + + assert_text "Cohort was successfully created" + click_on "Back" + end + + test "updating a Cohort" do + visit education_cohorts_url + click_on "Edit", match: :first + + fill_in "Academic year", with: @education_cohort.academic_year_id + fill_in "Name", with: @education_cohort.name + fill_in "Program", with: @education_cohort.program_id + fill_in "University", with: @education_cohort.university_id + click_on "Update Cohort" + + assert_text "Cohort was successfully updated" + click_on "Back" + end + + test "destroying a Cohort" do + visit education_cohorts_url + page.accept_confirm do + click_on "Destroy", match: :first + end + + assert_text "Cohort was successfully destroyed" + end +end