Skip to content

Commit

Permalink
fix crash when labels are added concurrently (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek authored Dec 31, 2024
1 parent ca36ed9 commit 8ded880
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/mindwendel/brainstormings/idea_idea_label.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Mindwendel.Brainstormings.IdeaIdeaLabel do
|> cast_assoc(:idea, required: true)
|> cast_assoc(:idea_label, required: true)
|> unique_constraint([:idea_id, :idea_label_id],
name: :idea_idea_labels_idea_id_idea_label_id_index
name: :idea_idea_labels_pkey
)
end

Expand All @@ -30,7 +30,7 @@ defmodule Mindwendel.Brainstormings.IdeaIdeaLabel do
|> cast(attrs, [:idea_id, :idea_label_id])
|> validate_required([:idea_id, :idea_label_id])
|> unique_constraint([:idea_id, :idea_label_id],
name: :idea_idea_labels_idea_id_idea_label_id_index
name: :idea_idea_labels_pkey
)
end
end
2 changes: 1 addition & 1 deletion test/mindwendel/idea_idea_label_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Mindwendel.IdeaIdeaLabelTest do
}
end

test "s", %{idea: idea} do
test "valid with idea and idea_label", %{idea: idea} do
idea_label = idea.brainstorming.labels |> Enum.at(0)

idea_idea_label_changeset =
Expand Down
13 changes: 2 additions & 11 deletions test/mindwendel/idea_labels_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,12 @@ defmodule Mindwendel.IdeaLabelsTest do
assert Repo.one(IdeaLabel) == idea_label
end

@tag :skip
test "does not add the same IdeaLabel twice to Idea", %{idea_label: idea_label, idea: idea} do
# Calling this method twice does not fail and does not create duplicates
{:ok, idea_idea_label_after_method_call_1} =
IdeaLabels.add_idea_label_to_idea(idea, idea_label.id)

{:ok, idea_idea_label_after_method_call_2} =
{:ok, _} =
IdeaLabels.add_idea_label_to_idea(idea, idea_label.id)

# There should still be only one IdeaIdeaLabel
assert Repo.count(IdeaIdeaLabel) == 1

assert Repo.count(IdeaLabel) == 1

assert idea_idea_label_after_method_call_1 == idea_idea_label_after_method_call_2
assert {:error, _changeset} = IdeaLabels.add_idea_label_to_idea(idea, idea_label.id)
end

@tag :skip
Expand Down

0 comments on commit 8ded880

Please sign in to comment.