-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SRCH-1767 refactor serialization specs #132
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some explanatory comments.
context 'when language fields contain HTML/CSS' do | ||
let(:html) do | ||
<<~HTML | ||
<div style="height: 100px; width: 100px;"></div> | ||
<p>hello & goodbye!</p> | ||
HTML | ||
end | ||
|
||
let(:original_hash) do | ||
ActiveSupport::HashWithIndifferentAccess.new( | ||
title: '<b><a href="http://foo.com/">foo</a></b><img src="bar.jpg">', | ||
description: html, | ||
content: "this <b>is</b> <a href='http://gov.gov/url.html'>html</a>" | ||
) | ||
end | ||
|
||
it 'sanitizes the language fields' do | ||
expect(serialize_hash).to match(hash_including( | ||
title_en: 'foo', | ||
description_en: 'hello & goodbye!', | ||
content_en: 'this is html' | ||
)) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved these specs out of the document specs:
https://github.com/GSA/i14y/pull/132/files#diff-ace14829a1667febf42459b631d07157bddc6e47d372750a17d6147b16221ceeL43
The functionality is implemented in the Serde
module (the Document serializer), so it makes sense to move the unit specs there, and it allows me to remove the Document specs based on the soon-to-be-removed Document.create
method.
before(:all) do | ||
handle = 'test_index' | ||
Elasticsearch::Persistence.client.indices.delete( | ||
index: [Document.index_namespace(handle), '*'].join('-') | ||
) | ||
es_documents_index_name = [Document.index_namespace(handle), 'v1'].join('-') | ||
Document.create_index!(index: es_documents_index_name) | ||
Elasticsearch::Persistence.client.indices.put_alias index: es_documents_index_name, | ||
name: Document.index_namespace(handle) | ||
Document.index_name = Document.index_namespace(handle) | ||
end | ||
|
||
after(:all) do | ||
Elasticsearch::Persistence.client.indices.delete( | ||
index: [Document.index_namespace('test_index'), '*'].join('-') | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These before
/after
blocks were there to support the .create
specs, which have now been moved to the Serde specs.
context 'when language fields contain HTML/CSS and HTML entities' do | ||
let(:html) do | ||
<<~HTML | ||
<div style="height: 100px; width: 100px;"></div> | ||
<p>hello & goodbye!</p> | ||
HTML | ||
end | ||
|
||
before do | ||
Document.create(_id: 'a123', | ||
language: 'en', | ||
title: '<b><a href="http://foo.com/">foo</a></b><img src="bar.jpg">', | ||
description: html, | ||
created: DateTime.now, | ||
path: 'http://www.agency.gov/page1.html', | ||
content: "this <b>is</b> <a href='http://gov.gov/url.html'>html</a>") | ||
end | ||
|
||
it 'sanitizes the language fields' do | ||
document = Document.find 'a123' | ||
expect(document.title).to eq('foo') | ||
expect(document.description).to eq('hello & goodbye!') | ||
expect(document.content).to eq('this is html') | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These specs have been moved to serde_spec.rb
, where they belong...
context 'when a created value is provided but not changed' do | ||
let(:params_without_changed) do | ||
valid_params.merge(created: DateTime.now, changed: '') | ||
end | ||
|
||
before { Document.create(params_without_changed) } | ||
|
||
it 'sets "changed" to be the same as "created"' do | ||
Document.create(params_without_changed) | ||
document = Document.find('a123') | ||
expect(document.changed).to eq document.created | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and these specs have been added to the integration spec for document creation. There are a few ways to pet this particular cat, so it felt safest to move the spec to the integration level to cover us no matter how it's implemented.
'lil more spec refactoring. This PR:
.rspec-local
to.gitignore