Skip to content

Deletion Test Issue #58

Description

@njwest

Okay, this is a weird bug that I think is coming from my code, not the alog module.

I have some fairly standard Phoenix-style ExUnit tests that test the creation and deletion of certain resources that use the Alog module in their schema files.

I have resource one, SomeItem, with a deletion test that passes like so:

def some_item_fixture(attrs \\ %{}) do
  {:ok, %User{} = user} = SomeContext.create_user(@user_valid_attrs)

  {:ok, some_item} =
    attrs
    |> Enum.into(@valid_attrs)
    |> Map.put(:user_id, user.id)
    |> SomeContext.create_some_item()

  some_item
end

test "delete_some_item/1 deletes the some_item" do
  some_item = some_item_fixture()

  assert {:ok, %SomeItem{}} = SomeContext.delete_some_item(some_item) # calls SomeItem.delete(some_item)

  assert_raise Ecto.NoResultsError, fn -> SomeItem.get!(some_item.uuid) end
end

I have resource two, SecondItem, for which the deletion test does not pass:

def second_item_fixture(attrs \\ %{}) do
  {:ok, %SomePlace{} = some_place} = OtherContext.create_some_place(@valid_some_place_attrs)

  new_type_attrs =
    @valid_second_item_attrs
    |> Map.put(:some_place_id, some_place.id)

  {:ok, %SecondItem{} = second_item} = SomeContext.create_second_item(new_type_attrs)

  second_item
end

test "delete_second_item/1 deletes the second_item" do
  second_item = second_item_fixture()
  assert {:ok, %SecondItem{}} = SomeContext.delete_second_item(second_item) # calls SecondItem.delete(some_item)

  assert_raise Ecto.NoResultsError, fn -> SecondItem.get!(second_item.uuid) end
end

The delete_second_item test fails on the Ecto.NoResultsError, and when I assert that a regular get/1 returns nil, the get returns the entire %SecondItem{} struct with deleted: false

The schemas for both resources are nearly identical, using the same use ALog declaration at the beginning of each module, and when I run the same functions in order for the SecondItem above either in app or in iex, I get the expected result.

Any ideas/suggestions would be appreciated :P

Activity

  1. changed the title [-]Deletion Test Doesn't Always Work[/-] [+]Deletion Test Issue[/+] on Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions