Skip to content

Commit 369d659

Browse files
authored
Merge pull request #7534 from donny-wong/v2.7.1
V2.7.1
2 parents 77ccce7 + 32fe454 commit 369d659

File tree

6 files changed

+72
-6
lines changed

6 files changed

+72
-6
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [v2.7.1]
4+
5+
### 🐛 Bug fixes
6+
7+
- Fix bugs when assigning sections to starter file groups across multiple assignments (#7523)
8+
39
## [v2.7.0]
410

511
### 🚨 Breaking changes

app/MARKUS_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION=v2.7.0,PATCH_LEVEL=DEV
1+
VERSION=v2.7.1,PATCH_LEVEL=DEV

app/controllers/assignments_controller.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,26 @@ def populate_starter_file_manager
438438
use_rename: g.use_rename,
439439
files: starter_file_group_file_data(g) }
440440
end
441+
sections = current_course.sections.pluck(:id, :name)
441442
section_data = current_course.sections
442-
.left_outer_joins(:starter_file_groups)
443-
.order(:id)
443+
.joins(:starter_file_groups)
444+
.where('starter_file_groups.assessment_id': assignment.id)
444445
.pluck_to_hash('sections.id as section_id',
445446
'sections.name as section_name',
446447
'starter_file_groups.id as group_id',
447448
'starter_file_groups.name as group_name')
449+
section_data_ids = section_data.pluck(:section_id)
450+
sections.each do |id, name|
451+
unless section_data_ids.include? id
452+
section_data << {
453+
section_id: id,
454+
section_name: name,
455+
group_id: nil,
456+
group_name: nil
457+
}
458+
end
459+
end
460+
section_data.sort_by! { |x| x[:section_id] }
448461
data = { files: file_data,
449462
sections: section_data,
450463
available_after_due: assignment.starter_files_after_due,

app/models/section.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ def starter_file_group_for(assessment)
2424
end
2525

2626
def update_starter_file_group(assessment_id, starter_file_group_id)
27-
return if starter_file_groups.where(assessment_id: assessment_id).first&.id == starter_file_group_id
27+
starter_files_groups_for_assignment = starter_file_groups.where(assessment_id: assessment_id)
28+
return if starter_files_groups_for_assignment.first&.id == starter_file_group_id
2829

2930
# delete all old section starter file groups
30-
section_starter_file_groups.where.not(starter_file_group_id: starter_file_group_id).find_each(&:destroy)
31+
section_starter_file_groups.where(starter_file_group_id: starter_files_groups_for_assignment).find_each(&:destroy)
3132

3233
unless starter_file_group_id.nil?
3334
SectionStarterFileGroup.find_or_create_by(section_id: self.id, starter_file_group_id: starter_file_group_id)

spec/controllers/assignments_controller_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,13 +1033,38 @@
10331033
let(:params) { { course_id: assignment.course.id, id: ssfg.starter_file_group.assignment.id } }
10341034

10351035
it 'should contain the right values' do
1036+
expect(response.parsed_body['sections'].size).to eq 1
10361037
file_data = response.parsed_body['sections'].first
10371038
expected = { section_id: section.id,
10381039
section_name: section.name,
10391040
group_id: starter_file_group.id,
10401041
group_name: starter_file_group.name }
10411042
expect(file_data).to eq(expected.transform_keys(&:to_s))
10421043
end
1044+
1045+
context 'when there is another assignment with sections' do
1046+
let(:a2) { create(:assignment) }
1047+
let(:other_starter_file_group) { create(:starter_file_group, assignment: a2) }
1048+
let(:ssfg2) do
1049+
create(:section_starter_file_group, starter_file_group: other_starter_file_group, section: section)
1050+
end
1051+
let(:params) do
1052+
# Ensure creation of both assignments and starter file groups
1053+
ssfg
1054+
ssfg2
1055+
{ course_id: assignment.course.id, id: ssfg.starter_file_group.assignment.id }
1056+
end
1057+
1058+
it 'should only contain the section data for the requested assignment' do
1059+
expect(response.parsed_body['sections'].size).to eq 1
1060+
file_data = response.parsed_body['sections'].first
1061+
expected = { section_id: section.id,
1062+
section_name: section.name,
1063+
group_id: starter_file_group.id,
1064+
group_name: starter_file_group.name }
1065+
expect(file_data).to eq(expected.transform_keys(&:to_s))
1066+
end
1067+
end
10431068
end
10441069
end
10451070

spec/models/section_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
end
103103
end
104104

105-
context 'when a starter file group is already assigned' do
105+
context 'when a starter file group is already assigned for that assignment' do
106106
let(:section) { sections.second }
107107

108108
before { section.update_starter_file_group(assignment.id, starter_file_groups.first.id) }
@@ -117,5 +117,26 @@
117117
expect(ids).not_to include starter_file_groups.second.id
118118
end
119119
end
120+
121+
context 'when a starter file group is assigned for a different assignment' do
122+
let(:assignment2) { create(:assignment) }
123+
let!(:starter_file_groups2) { create_list(:starter_file_group_with_entries, 2, assignment: assignment2) }
124+
let(:section) { sections.second }
125+
126+
before do
127+
create(:section_starter_file_group, starter_file_group: starter_file_groups2.second, section: section)
128+
section.update_starter_file_group(assignment.id, starter_file_groups.first.id)
129+
end
130+
131+
it 'should assign the new starter file group' do
132+
ids = section.reload.section_starter_file_groups.pluck(:starter_file_group_id)
133+
expect(ids).to include starter_file_groups.first.id
134+
end
135+
136+
it 'should not remove the starter file group for the other assignment' do
137+
ids = section.reload.section_starter_file_groups.pluck(:starter_file_group_id)
138+
expect(ids).to include starter_file_groups2.second.id
139+
end
140+
end
120141
end
121142
end

0 commit comments

Comments
 (0)