Skip to content

Commit 9be17bc

Browse files
authored
Merge pull request #427 from openstax/cnxmod-tags
Handle cnxmod tags for Assignable exercises
2 parents c8bafaa + d298bb8 commit 9be17bc

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

app/routines/exercises/import/assessments.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ def exec(filename:, book_uuid:)
145145
Rails.logger.warn { "Row ##{row_number} has no associated page in the book" } \
146146
unless uuid_index.nil? && section_index.nil?
147147
else
148-
exercise.tags << "context-cnxmod:#{page_uuid}"
149-
exercise.tags << "assessment:#{row[pre_or_post_index].downcase == 'pre' ? 'preparedness' : 'practice'
148+
is_pre = row[pre_or_post_index].downcase == 'pre'
149+
exercise.tags << "context-cnxmod:#{page_uuid}" unless is_pre
150+
exercise.tags << "assessment:#{is_pre ? 'preparedness' : 'practice'
150151
}:https://openstax.org/orn/book:page/#{book_uuid}:#{page_uuid}" \
151152
unless pre_or_post_index.nil? || row[pre_or_post_index].blank?
152153
end

app/routines/exercises/tag/assessments.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ def exec(filename:, book_uuid:)
6262

6363
pre_section_tag = "assessment:preparedness:https://openstax.org/orn/book:page/#{book_uuid}:#{page_uuid}"
6464
post_section_tag = "assessment:practice:https://openstax.org/orn/book:page/#{book_uuid}:#{page_uuid}"
65+
cnxmod_tag = "context-cnxmod:#{page_uuid}"
6566

6667
row_number = row_index + 1
6768

6869
begin
69-
tag pre_and_post_section_exercises, [ pre_section_tag, post_section_tag ]
70+
tag pre_and_post_section_exercises, [ pre_section_tag, post_section_tag, cnxmod_tag ]
7071
tag pre_section_exercises, [ pre_section_tag ]
71-
tag post_section_exercises, [ post_section_tag ]
72+
tag post_section_exercises, [ post_section_tag, cnxmod_tag ]
7273
rescue StandardError => se
7374
Rails.logger.error { "Failed to import row ##{row_number} - #{se.message}" }
7475
failures[row_number] = se.to_s

spec/routines/exercises/import/assessments_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@
3535
expect(exercises[0].publication_group.nickname).to eq 'Q1'
3636
expect(Set.new exercises[0].tags.map(&:to_s)).to eq Set[
3737
'assessment:preparedness:https://openstax.org/orn/book:page/62a49025-8cd8-407c-9cfb-c7eba55cf1c6:97af6b57-0004-4218-99c1-f2cfedea8f30',
38-
'context-cnxmod:97af6b57-0004-4218-99c1-f2cfedea8f30',
39-
'book-slug:college-success-concise',
4038
'machine-teks:dacf53a6-2b09-49f1-9926-de4efe1049e0',
41-
'module-slug:college-success-concise:1-1-why-college',
4239
'teks:T1.1',
4340
]
4441
expect(exercises[0].questions.first.stems.first.content).to eq 'Some question?'

spec/routines/exercises/tag/assessments_spec.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,38 @@
66
let(:book_uuid) { SecureRandom.uuid }
77
let(:page_uuid) { 'a9ce0e38-4f52-4fe0-9433-d8df95f6e3b2' }
88

9-
let(:expected_pre_tag) { "assessment:preparedness:https://openstax.org/orn/book:page/#{book_uuid}:#{page_uuid}" }
10-
let(:expected_post_tag) { "assessment:practice:https://openstax.org/orn/book:page/#{book_uuid}:#{page_uuid}" }
9+
let(:expected_pre_tag) { "assessment:preparedness:https://openstax.org/orn/book:page/#{book_uuid}:#{page_uuid}" }
10+
let(:expected_post_tag) { "assessment:practice:https://openstax.org/orn/book:page/#{book_uuid}:#{page_uuid}" }
11+
let(:expected_cnxmod_tag) { "context-cnxmod:#{page_uuid}" }
1112

1213
let!(:exercises) { (1..9).map { |ii| FactoryBot.create(:publication, number: ii).publishable } }
1314

1415
# Disable set_slug_tags!
1516
before { allow_any_instance_of(Exercise).to receive(:set_slug_tags!) }
1617

1718
it 'tags exercises with the sample spreadsheet' do
18-
expect { described_class.call(filename: fixture_path, book_uuid: book_uuid) }.to change { ExerciseTag.count }.by(10)
19+
expect do
20+
described_class.call(filename: fixture_path, book_uuid: book_uuid)
21+
end.to change { ExerciseTag.count }.by(15)
1922

2023
exercises.each(&:reload)
2124

2225
exercises.each do |exercise|
2326
valid_tags = []
2427
valid_tags << expected_pre_tag if exercise.number <= 5
25-
valid_tags << expected_post_tag if exercise.number >= 5
28+
valid_tags << [expected_post_tag, expected_cnxmod_tag] if exercise.number >= 5
2629

2730
expect(exercise.tags).to satisfy do |tags|
28-
expect(tags.length).to eq exercise.number == 5 ? 2 : 1
31+
expect(tags.length).to eq exercise.number < 5 ? 1 : exercise.number == 5 ? 3 : 2
2932
tags.all { |tag| expect(valid_tags).to include tag.name }
3033
end
3134
end
3235
end
3336

3437
it 'skips exercises with no changes (idempotence)' do
35-
expect { described_class.call(filename: fixture_path, book_uuid: book_uuid) }.to change { ExerciseTag.count }.by(10)
38+
expect do
39+
described_class.call(filename: fixture_path, book_uuid: book_uuid)
40+
end.to change { ExerciseTag.count }.by(15)
3641

3742
expect { described_class.call(filename: fixture_path, book_uuid: book_uuid) }.not_to change { ExerciseTag.count }
3843
end

0 commit comments

Comments
 (0)