-
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.
Allowing Affliations to be loaded from the department csv file (#1214)
- Loading branch information
1 parent
ad0da73
commit 80ca3fc
Showing
15 changed files
with
93 additions
and
24 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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
# frozen_string_literal: true | ||
class Affiliation | ||
def self.all | ||
data = [] | ||
data << { code: "23100", name: "Astrophysical Sciences" } | ||
data << { code: "HPC", name: "High Performance Computing" } | ||
data << { code: "RDSS", name: "Research Data and Scholarship Services" } | ||
data << { code: "PRDS", name: "Princeton Research Data Service" } | ||
data << { code: "PPPL", name: "Princeton Plasma Physics Laboratory" } | ||
data | ||
class Affiliation < ApplicationRecord | ||
# Affiliation file is loaded onto the servers via pransible into the shared folder | ||
def self.load_from_file(file) | ||
affiliations = CSV.read(file, headers: true, skip_lines: /^JT_CF.*/) | ||
affiliations.each do |data| | ||
code = data["Dept"] | ||
if Affiliation.where(code: ).count == 0 | ||
self.create(code: code, name: data["Department Descr"]) | ||
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
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 @@ | ||
class CreateAffiliations < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :affiliations do |t| | ||
t.string :code, null: false | ||
t.string :name, null: false | ||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
# frozen_string_literal: true | ||
namespace :load_affiliations do | ||
desc "Load in users from the registration list" | ||
task :from_file, [:department_file] => [:environment] do |_, args| | ||
Affiliation.load_from_file(args[:department_file]) | ||
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
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,7 @@ | ||
JT_CF_DEPT_TBL,2573,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, | ||
Dept,Eff Date,Status,Department Descr,SetID,Short Desc,Descr,Co,Location SetID,Location,Tax Loc,MgrID,Mgr Posn,Yr End Dt,Budget Lvl,GL-Expense,EEO4 Fcn,Ind Sector,Accnt_ins,SI_accdnt#,Hazard,Estab ID,RSK CD,Descr,Sub-Agency,PAR Line 2,PAR Line 3,PAR Line 4,PAR Line 5,PAR2 Descr,PAR3 Descr,PAR4 Descr,PAR5 Descr,Class Unit,Org. Unit,Work Sector,Agency Code,Indus Committee,NACE,FTE Edit,Can Grant,Use TL Distrib?,Use Budgets?,Use Encumb?,Use Distrib?,Budget Dept,Dist Optn,Stats Can Dept,Faculty Code,Manager,Acct Owner,Country Group,Bud. Only,RTBL Data,Sync ID,Sync Date Time | ||
55555,1/1/01,A,AST-Astrophysical Sciences,XXXX,55555,,,,,,,,0,A,,,,,,,,,,,,,,,,,,,,,,0,,,B,C,D,E,F,G,,H,,,,,,I,,9999,1/1/01 12:01 | ||
66666,1/1/01,A,HPC-High Performance Computing,XXXX,66666,,,,,,,,0,A,,,,,,,,,,,,,,,,,,,,,,0,,,B,C,D,E,F,G,,H,,,,,,I,,9999,1/1/01 12:01 | ||
77777,1/1/01,A,RDSS-Research Data and Scholarship Services,XXXX,77777,,,,,,,,0,A,,,,,,,,,,,,,,,,,,,,,,0,,,B,C,D,E,F,G,,H,,,,,,I,,9999,1/1/01 12:01 | ||
88888,1/1/01,A,PRDS-Princeton Research Data Service,XXXX,88888,,,,,,,,0,A,,,,,,,,,,,,,,,,,,,,,,0,,,B,C,D,E,F,G,,H,,,,,,I,,9999,1/1/01 12:01 | ||
99999,1/1/01,A,PPPL-Princeton Plasma Physics Laboratory,XXXX,99999,,,,,,,,0,A,,,,,,,,,,,,,,,,,,,,,,0,,,B,C,D,E,F,G,,H,,,,,,I,,9999,1/1/01 12:01 |
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,25 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe Affiliation, type: :model do | ||
describe "#load_from_file" do | ||
it "reads the departments from the file" do | ||
expect(Affiliation.count).to eq 0 | ||
Affiliation.load_from_file(Rails.root.join("spec", "fixtures", "departments.csv")) | ||
expect(Affiliation.count).to eq 5 | ||
expect(Affiliation.where(code: "55555").first.name).to eq("AST-Astrophysical Sciences") | ||
expect(Affiliation.where(code: "66666").first.name).to eq("HPC-High Performance Computing") | ||
expect(Affiliation.where(code: "77777").first.name).to eq("RDSS-Research Data and Scholarship Services") | ||
expect(Affiliation.where(code: "88888").first.name).to eq("PRDS-Princeton Research Data Service") | ||
expect(Affiliation.where(code: "99999").first.name).to eq("PPPL-Princeton Plasma Physics Laboratory") | ||
end | ||
|
||
it "only loads the departments once" do | ||
expect(Affiliation.count).to eq 0 | ||
Affiliation.load_from_file(Rails.root.join("spec", "fixtures", "departments.csv")) | ||
expect(Affiliation.count).to eq 5 | ||
Affiliation.load_from_file(Rails.root.join("spec", "fixtures", "departments.csv")) | ||
expect(Affiliation.count).to eq 5 | ||
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
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