amnesia
amnesia copied to clipboard
Message does not get deleted
For some reason delete does not actually delete a message. Here is a relevant test. You can skip first three lines related to phoenix, it is related to the code writing to amnesia.
test "server receives message, stores it and replies with `received` status", %{socket: socket, user: user, chat: chat} do
{:ok, _, socket} = subscribe_and_join(socket, "chats:#{chat.id}", %{})
ref = push socket, "message", %{body: "the body", client_id: 1, created_at: :os.system_time(:seconds)}
assert_reply ref, :ok, %{client_id: 1, status: "received"}
[message] = Amnesia.transaction do
selection = Message.where chat_id == chat.id, select: [id, body, client_id, chat_id, created_at, status, user_id]
selection
|> Amnesia.Selection.values
end
chat_id = chat.id
user_id = user.id
assert [id, "the body", 1, ^chat_id, _, "received", ^user_id] = message
# Trying to delete here
status = Amnesia.transaction do
IO.inspect Message.last
Message.last |> Message.delete
end
IO.inspect status
# receiving ** (MatchError) no match of right hand side value: [[1, "the body", 1, 293, 1465198234, "received", 1514]]
[] = Amnesia.transaction do
selection = Message.where chat_id == chat.id, select: [id, body, client_id, chat_id, created_at, status, user_id]
selection
|> Amnesia.Selection.values
end
end
Is the Message of the type bag?
I believe if we need to delete items from a bag we need to use mnesia:delete_object
Try doing the following:
status = Amnesia.transaction do
IO.inspect Message.last
Message.last |> :mnesia.delete_object
end