Skip to content

Commit

Permalink
Allow for departments to be imported from Production (#1216)
Browse files Browse the repository at this point in the history
Will change the name to a department code
  • Loading branch information
carolyncole authored Jan 13, 2025
1 parent 76a6934 commit 68ae9fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/affiliation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ def self.load_from_file(file)
end
end
end

def self.find_fuzzy_by_name(name)
find_by(name: name) || Affiliation.where("name like '%#{name}%'").order(:code).first
end
end
3 changes: 2 additions & 1 deletion lib/tasks/import.rake
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ namespace :import do
puts "Skipping project #{project_id}. There are already #{existing_project.count} version of that project in the system"
else
data_user = parse_multiple(project_metadata, "dataUser")
departments = parse_multiple(project_metadata,"department")
department_names = parse_multiple(project_metadata,"department")
departments = department_names.map {|name| Affiliation.find_fuzzy_by_name(name)&.code || name }

storage_size_gb = project_metadata["quota"].to_i/1000000000.0
metadata = ProjectMetadata.new_from_hash({
Expand Down
14 changes: 14 additions & 0 deletions spec/models/affiliation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,18 @@
expect(Affiliation.count).to eq 5
end
end

describe "find_fuzzy_by_name" do
before do
Affiliation.create(name: "abc123 and other", code: "1")
Affiliation.create(name: "abc123", code: "2")
end

it "finds the exact match first" do
expect(Affiliation.find_fuzzy_by_name("abc123").code).to eq("2")
end
it "orders the fuzzy match by code" do
expect(Affiliation.find_fuzzy_by_name("abc12").code).to eq("1")
end
end
end

0 comments on commit 68ae9fc

Please sign in to comment.