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

Message does not get deleted #51

Open
almeynman opened this issue Jun 6, 2016 · 1 comment
Open

Message does not get deleted #51

almeynman opened this issue Jun 6, 2016 · 1 comment

Comments

@almeynman
Copy link

almeynman commented Jun 6, 2016

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
@jmerriweather
Copy link

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

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

No branches or pull requests

2 participants