Skip to content

Commit

Permalink
Removed name from assessment yml (#1993)
Browse files Browse the repository at this point in the history
* Removed name from assessment yml

* Modified test after removing name from assessment yml

* Removed unnecessary test for wrong assessment name

* Removed yml name check in assessments_controller

---------

Co-authored-by: Nicholas Clark <[email protected]>
  • Loading branch information
najclark and Nicholas Clark authored Nov 29, 2023
1 parent 69230d9 commit 08e9710
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
14 changes: 1 addition & 13 deletions app/controllers/assessments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,7 @@ def install_assessment

# each assessment must have an associated yaml file,
# and it must have a name field that matches its filename
if File.exist?(File.join(dir_path, filename, "#{filename}.yml"))
props = YAML.safe_load(File.open(
File.join(dir_path, filename, "#{filename}.yml"), "r", &:read
))
unless props["general"] && (props["general"]["name"] == filename)
flash.now[:error] = flash.now[:error] ? "#{flash.now[:error]} <br>" : ""
flash.now[:error] += "An error occurred while trying to display an existing assessment " \
"from file directory #{filename}: Name in yaml (#{props['general']['name']}) " \
"doesn't match #{filename}"
flash.now[:html_safe] = true
next
end
else
unless File.exist?(File.join(dir_path, filename, "#{filename}.yml"))
flash.now[:error] = flash.now[:error] ? "#{flash.now[:error]} <br>" : ""
flash.now[:error] += "An error occurred while trying to display an existing assessment " \
"from file directory #{filename}: #{filename}.yml does not exist"
Expand Down
6 changes: 3 additions & 3 deletions app/models/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def serialize
s
end

GENERAL_SERIALIZABLE = Set.new %w[name display_name category_name description handin_filename
GENERAL_SERIALIZABLE = Set.new %w[display_name category_name description handin_filename
handin_directory has_svn has_lang max_grace_days handout
writeup max_submissions disable_handins max_size
version_threshold is_positive_grading embedded_quiz group_size
Expand All @@ -534,8 +534,8 @@ def serialize_general
end

def deserialize(s)
unless s["general"] && (s["general"]["name"] == name)
raise "Name in yaml (#{s['general']['name']}) doesn't match #{name}"
unless s["general"]
raise "General section missing in yaml"
end

if s["dates"] && s["dates"]["start_at"]
Expand Down
16 changes: 1 addition & 15 deletions spec/controllers/assessments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@
tar.seek("#{course_hash[:assessment].name}/#{course_hash[:assessment].name}.yml") do
|entry|
test = YAML.safe_load(entry.read)
expect(
test["general"]["name"]
).to eq(course_hash[:assessment].name)
expect(
test["general"]["display_name"]
).to eq(course_hash[:assessment].display_name)
Expand Down Expand Up @@ -150,18 +147,7 @@
expect(response).to have_http_status(302)
expect(flash[:success]).to be_present
end
it "handles broken yaml file" do
file = fixture_file_upload("assessments/homework02-yaml-name-field-wrong.tar")
post :importAsmtFromTar, params: { course_name: course_2_hash[:course].name,
name: course_2_hash[:assessment].name,
tarFile: file }
expect(response).to have_http_status(302)
expect(flash[:error]).to be_present
expect(flash[:error]).to match(/Error loading yaml/m)
end
it "handles any module name" do
# we now support any module name since we just overwrite the module name anyways,
# so this test is now successful
it "handles mismatched module name" do
file = fixture_file_upload("assessments/homework02-module-mismatch.tar")
post :importAsmtFromTar, params: { course_name: course_2_hash[:course].name,
name: course_2_hash[:assessment].name,
Expand Down

0 comments on commit 08e9710

Please sign in to comment.