Skip to content

Commit

Permalink
Parse HTML as HTML so we can see the special characters
Browse files Browse the repository at this point in the history
refs QUIZ-2778

Test plan
- Test under quiz_api

Change-Id: I56653b47ba5aecdc92ea5723af38db759bffaa65
Reviewed-on: https://gerrit.instructure.com/124247
Tested-by: Jenkins
Reviewed-by: Hannah Bottalla <[email protected]>
QA-Review: Deepeeca Soundarrajan <[email protected]>
Product-Review: Dan Minkevitch <[email protected]>
  • Loading branch information
Ardena committed Aug 29, 2017
1 parent 0943cb7 commit c8ec443
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lib/qti/models/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def self.from_path!(path, package_root = nil)
new(path: path, package_root: package_root)
end

def initialize(path:, package_root: nil)
def initialize(path:, package_root: nil, html: false)
@path = path
set_package_root(package_root || File.dirname(path))
@doc = parse_xml(File.read(path))
@doc = html ? parse_html(File.read(path)) : parse_xml(File.read(path))
raise ArgumentError unless @doc
end

Expand All @@ -79,6 +79,10 @@ def parse_xml(xml_string)
Nokogiri.XML(xml_string, @path.to_s, &:noblanks)
end

def parse_html(html_string)
Nokogiri.HTML(html_string, @path.to_s, &:noblanks)
end

def remap_href_path(href)
return nil unless href
path = File.join(File.dirname(@path), href)
Expand Down
2 changes: 1 addition & 1 deletion lib/qti/v2/models/assessment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def stimulus_ref(ref)
end

def create_stimulus(stimulus_ref)
Qti::V2::Models::StimulusItem.from_path!(stimulus_ref, @package_root)
Qti::V2::Models::StimulusItem.new(path: stimulus_ref, package_root: @package_root, html: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion qti.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = 'qti'
spec.version = '0.8.0'
spec.version = '0.8.1'
spec.authors = ['Hannah Bottalla', 'Robinson Rodríguez']
spec.email = ['[email protected]', '[email protected]', '[email protected]']
spec.summary = %q(QTI 1.2 and 2.1 import and export models)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/qti/v2/models/assessment_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
it 'creates a stimulus from a given file' do
stimulus_path = File.join(fixtures_path, 'no_assessment_XML', 'passages', '0cfd5cf7-2c91-4b35-a57a-9f5d1709f68f.html')
stimulus = loaded_class.create_stimulus(stimulus_path)
expect(stimulus.title).to eq 'El equipo de hockey te necesita!'
expect(stimulus.title).to eq '¡El equipo de hockey te necesita!'
end
end
end
5 changes: 3 additions & 2 deletions spec/lib/qti/v2/models/stimulus_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
let(:file_path) { File.join('spec', 'fixtures', 'no_assessment_XML', 'imsmanifest.xml') }
let(:test_object) { Qti::V2::Models::NonAssessmentTest.from_path!(file_path) }
let(:stimulus_ref) { test_object.stimulus_ref(test_object.assessment_items[1]) }
let(:loaded_class) { described_class.from_path!(stimulus_ref) }
let(:loaded_class) { described_class.new(path: stimulus_ref, html: true) }

it 'loads a stimulus ref' do
expect do
Expand All @@ -13,12 +13,13 @@
end

it 'has the title' do
expect(loaded_class.title).to eq 'El equipo de hockey te necesita!'
expect(loaded_class.title).to eq '¡El equipo de hockey te necesita!'
end

it 'has sanitized item_body' do
expect(loaded_class.body).to include '<div'
expect(loaded_class.body).to include 'Listen to the audio passage.'
expect(loaded_class.body).to include '¡'
end

it 'has the identifier used to identify it in manifest file' do
Expand Down

0 comments on commit c8ec443

Please sign in to comment.