Skip to content
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

Merged
merged 1 commit into from
Dec 8, 2020

Conversation

MothOnMars
Copy link
Contributor

'lil more spec refactoring. This PR:

  • adds .rspec-local to .gitignore
  • moves some of the serialization specs out of the document specs and into the serializer spec
  • adds a few minor unit specs for the models
  • moves the "created"/"changed" spec to the request spec, to ensure future refactoring doesn't break that specific functionality

Copy link
Contributor Author

@MothOnMars MothOnMars left a 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.

Comment on lines +41 to +64
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
Copy link
Contributor Author

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.

Comment on lines -19 to -34
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('-')
)
Copy link
Contributor Author

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.

Comment on lines -43 to -67
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
Copy link
Contributor Author

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...

Comment on lines -69 to -80
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
Copy link
Contributor Author

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.

@MothOnMars MothOnMars merged commit 12d4f1e into GSA:master Dec 8, 2020
@MothOnMars MothOnMars deleted the serialization_1767 branch December 8, 2020 15:54
@MyNameIsMissing MyNameIsMissing mentioned this pull request Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants