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

fix crash when labels are added concurrently #542

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading