-
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.
- Loading branch information
1 parent
a7218e4
commit 5738565
Showing
2 changed files
with
98 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
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 |
---|---|---|
|
@@ -2,13 +2,15 @@ | |
|
||
require Rails.root.join('lib/tasks/load_gem_records_csv.rb') | ||
class LoadGemRecordsTest < ActiveSupport::TestCase | ||
setup do | ||
gem_load = LoadGemRecordsCSV.new | ||
gem_load.load_gem_records("test/fixtures/files/gem_records.csv") | ||
gem_load.load_committee_members("test/fixtures/files/committee_members.csv") | ||
end | ||
|
||
GEM_RECORDS_FILE = "test/fixtures/files/gem_records.csv" | ||
COMMITTEE_MEMBERS_FILE = "test/fixtures/files/committee_members.csv" | ||
|
||
should "parse csv" do | ||
gem_load = LoadGemRecordsCSV.new | ||
gem_load.load_gem_records(LoadGemRecordsTest::GEM_RECORDS_FILE) | ||
gem_load.load_committee_members(LoadGemRecordsTest::COMMITTEE_MEMBERS_FILE) | ||
|
||
assert_equal 3, GemRecord.count | ||
|
||
records = GemRecord.order(:seqgradevent) | ||
|
@@ -55,4 +57,76 @@ class LoadGemRecordsTest < ActiveSupport::TestCase | |
assert_equal 'Black', records[2].committee_members.last.last_name | ||
assert_equal 'Committee Member', records[2].committee_members.last.role | ||
end | ||
|
||
should "not delete existing GEM records when loading GEM records from CSV" do | ||
# create 5 GEM records | ||
create_list(:gem_record, 5) | ||
assert_equal 5, GemRecord.count | ||
|
||
# load 3 GEM records from CSV files | ||
gem_load = LoadGemRecordsCSV.new | ||
gem_load.load_gem_records(LoadGemRecordsTest::GEM_RECORDS_FILE) | ||
gem_load.load_committee_members(LoadGemRecordsTest::COMMITTEE_MEMBERS_FILE) | ||
|
||
# there should be 8 GEM records at this point | ||
assert_equal 8, GemRecord.count | ||
|
||
# load 3 GEM records from the exact same CSV files AGAIN | ||
gem_load = LoadGemRecordsCSV.new | ||
gem_load.load_gem_records(LoadGemRecordsTest::GEM_RECORDS_FILE) | ||
gem_load.load_committee_members(LoadGemRecordsTest::COMMITTEE_MEMBERS_FILE) | ||
|
||
# there should STILL be 8 GEM records at this point | ||
assert_equal 8, GemRecord.count | ||
end | ||
|
||
should "update existing and matching GEM records when loading GEM records from CSV" do | ||
# load 3 GEM records from CSV files | ||
gem_load = LoadGemRecordsCSV.new | ||
gem_load.load_gem_records(LoadGemRecordsTest::GEM_RECORDS_FILE) | ||
gem_load.load_committee_members(LoadGemRecordsTest::COMMITTEE_MEMBERS_FILE) | ||
|
||
# there should be 3 GEM records at this point | ||
assert_equal 3, GemRecord.count | ||
|
||
# load 3 GEM records from the exact same CSV files AGAIN | ||
gem_load = LoadGemRecordsCSV.new | ||
gem_load.load_gem_records(LoadGemRecordsTest::GEM_RECORDS_FILE) | ||
gem_load.load_committee_members(LoadGemRecordsTest::COMMITTEE_MEMBERS_FILE) | ||
|
||
# there should STILL be 3 GEM records at this point | ||
assert_equal 3, GemRecord.count | ||
|
||
|
||
records = GemRecord.order(:seqgradevent) | ||
|
||
# verify fields are correct | ||
assert_equal 1, records[0].seqgradevent | ||
assert_equal 'John Doe', records[0].studentname | ||
assert_equal 123456789, records[0].sisid | ||
assert_equal '[email protected]', records[0].emailaddress | ||
|
||
# change the fields | ||
records[0].studentname = 'does not matter' | ||
records[0].sisid = 'does not matter' | ||
records[0].emailaddress = 'does not matter' | ||
records[0].save! | ||
|
||
# RELOAD 3 GEM records from the exact same CSV files AGAIN | ||
gem_load = LoadGemRecordsCSV.new | ||
gem_load.load_gem_records(LoadGemRecordsTest::GEM_RECORDS_FILE) | ||
gem_load.load_committee_members(LoadGemRecordsTest::COMMITTEE_MEMBERS_FILE) | ||
|
||
records = GemRecord.order(:seqgradevent) | ||
|
||
# there should STILL be 3 GEM records at this point | ||
assert_equal 3, GemRecord.count | ||
|
||
# verify fields are updated from the CSV | ||
assert_equal 1, records[0].seqgradevent | ||
assert_equal 'John Doe', records[0].studentname | ||
assert_equal 123456789, records[0].sisid | ||
assert_equal '[email protected]', records[0].emailaddress | ||
|
||
end | ||
end |