I cannot figure out why this test is failing. It fails on assert result_one == result_two
. The hardcoded string sigil query returns a list of length 1, the interpolated query returns an empty list.
The Jason.encode
’d struct is apparently the same as the hardcoded string sigil.
The schema of Job
isn’t that important, just that custom_fields
is a jsonb
column.
test "json" do
intern = %{"Employment Type" => "Intern"}
insert(:job, custom_fields: intern)
intern_json = Jason.encode!(intern)
assert intern_json === ~s|{"Employment Type":"Intern"}| # This passes fine
query =
from j in Job,
as: :job,
where: fragment("custom_fields @> ?", ^intern_json),
select: j.id
query_two =
from j in Job,
where: fragment("custom_fields @> ?", ~s|{"Employment Type":"Intern"}|),
select: j.id
result_one = Repo.all(query)
result_two = Repo.all(query_two)
assert result_one == result_two # Failure here
end
Result:
Assertion with == failed
code: assert result_one == result_two
left: []
right: ["job_id0"]
Thanks for all the help