I was playing around mix test with phx and noticed that the result the I am get from the database was different from what I have inserted.
I created the schema with:
mix phx.gen.html Commerce Product products name:string price:decimal description:text
He’res the trimmed down test of what I was working on
test "testing products" do
{:ok, product} =
%Product{
name: "Some product",
description: "Some product description",
price: Decimal.new(25.20)
} |> Repo.insert
inserted_product = Commerce.get_product!(product.id)
assert inserted_product.price == product.price
end
And here’s the result of the tests. Here you can see that upon retrieval of the value from the DB.
the inserted_product.price
has retrieved %Decimal{sign: 1, coef: 25, exp: 0}
while the inserted value is %Decimal{sign: 1, coef: 252, exp: -1}
test testing products (PhxCommerce.Acceptance.ProductsTest)
test/acceptance/products_test.exs:32
Assertion with == failed
code: inserted_product.price() == product.price()
left: %Decimal{sign: 1, coef: 25, exp: 0}
right: %Decimal{sign: 1, coef: 252, exp: -1}
stacktrace:
test/acceptance/products_test.exs:41: (test)
I am still working/researching on what could have caused the problem and would appreciate if you could point out what I have missed.