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

Deletion Test Issue #58

Open
njwest opened this issue Jun 5, 2019 · 0 comments
Open

Deletion Test Issue #58

njwest opened this issue Jun 5, 2019 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@njwest
Copy link

njwest commented Jun 5, 2019

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

@njwest njwest changed the title Deletion Test Doesn't Always Work Deletion Test Issue Jun 5, 2019
@iteles iteles added the help wanted Extra attention is needed label Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants