Skip to content

Commit

Permalink
we are now treating the explain as json, so lets actually test it as …
Browse files Browse the repository at this point in the history
…such!
  • Loading branch information
epugh committed Sep 6, 2023
1 parent fc92897 commit 39ff7e0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions app/views/api/v1/snapshots/_snapshot.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ if with_docs
json.docs do
snapshot.snapshot_queries.each do |snapshot_query|
docs = snapshot_query.snapshot_docs.map do |doc|
{
id: doc.doc_id,
explain: JSON.parse(doc.explain),
{
id: doc.doc_id,
explain: JSON.parse(doc.explain),
rated_only: doc.rated_only,
fields: doc.fields.blank? ? nil :JSON.parse(doc.fields)
fields: doc.fields.blank? ? nil : JSON.parse(doc.fields),
}
end

Expand Down
32 changes: 16 additions & 16 deletions test/controllers/api/v1/snapshots_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class SnapshotsControllerTest < ActionController::TestCase
name: 'New Snapshot',
docs: {
first_query.id => [
{ id: 'doc1', explain: '1' },
{ id: 'doc2', explain: '2' }
{ id: 'doc1', explain: 1 },
{ id: 'doc2', explain: 2 }
],
second_query.id => [
{ id: 'doc3', explain: '3' },
{ id: 'doc4', explain: '4' }
{ id: 'doc3', explain: 3 },
{ id: 'doc4', explain: 4 }
],
},
queries: {
Expand Down Expand Up @@ -79,8 +79,8 @@ class SnapshotsControllerTest < ActionController::TestCase
name: 'New Snapshot',
docs: {
first_query.id => [
{ id: 'doc1', explain: '1' },
{ id: 'doc2', explain: '2' }
{ id: 'doc1', explain: 1 },
{ id: 'doc2', explain: 2 }
],
# in Rails 4, we could do second_query.id => [] and getting the second_query in,
# but in Rails 5, the second_query doesn't show up because the array that is empty
Expand All @@ -107,8 +107,8 @@ class SnapshotsControllerTest < ActionController::TestCase

snapshot = response.parsed_body

assert_equal snapshot['name'], data[:snapshot][:name]
assert_equal snapshot['docs'].length, data[:snapshot][:docs].length
assert_equal data[:snapshot][:name], snapshot['name']
assert_equal data[:snapshot][:docs].length, snapshot['docs'].length

data_doc = data[:snapshot][:docs][first_query.id][0]
response_doc = snapshot['docs'][first_query.id.to_s][0]
Expand Down Expand Up @@ -148,12 +148,12 @@ class SnapshotsControllerTest < ActionController::TestCase
name: '',
docs: {
first_query.id => [
{ id: 'doc1', explain: '1' },
{ id: 'doc2', explain: '2' }
{ id: 'doc1', explain: 1 },
{ id: 'doc2', explain: 2 }
],
second_query.id => [
{ id: 'doc3', explain: '3' },
{ id: 'doc4', explain: '4' }
{ id: 'doc3', explain: 3 },
{ id: 'doc4', explain: 4 }
],
},
queries: {
Expand Down Expand Up @@ -181,12 +181,12 @@ class SnapshotsControllerTest < ActionController::TestCase
snapshot: {
docs: {
first_query.id => [
{ id: 'doc1', explain: '1' },
{ id: 'doc2', explain: '2' }
{ id: 'doc1', explain: 1 },
{ id: 'doc2', explain: 2 }
],
second_query.id => [
{ id: 'doc3', explain: '3' },
{ id: 'doc4', explain: '4' }
{ id: 'doc3', explain: 3 },
{ id: 'doc4', explain: 4 }
],
},
queries: {
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/snapshot_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ a_doc:
doc_id: "doc a"
position: 1
snapshot_query: :first_snapshot_query
explain: "Explain Me"
explain: '{"message": "Explain Me"}'

b_doc:
doc_id: "doc b"
position: 1
snapshot_query: :first_snapshot_query
explain: "Explain Me"
explain: '{"message": "Explain Me"}'

c_doc:
doc_id: "doc c"
position: 1
snapshot_query: :second_snapshot_query
explain: "Explain Me"
explain: '{"message": "Explain Me"}'

d_doc:
doc_id: "doc d"
position: 1
snapshot_query: :second_snapshot_query
explain: "Explain Me"
explain: '{"message": "Explain Me"}'

0 comments on commit 39ff7e0

Please sign in to comment.