Skip to content

Commit

Permalink
fix "except" option handling (#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
ademenev authored Dec 31, 2024
1 parent a9c11f7 commit 2b344e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ash/notifier/pub_sub/pub_sub.ex
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ defmodule Ash.Notifier.PubSub do

defp matches?(%{action: action}, %{name: action}), do: true

defp matches?(%{type: type, except: except}, %{type: type, action: action}) do
defp matches?(%{type: type, except: except}, %{type: type, name: action}) do
action not in except
end

Expand Down
11 changes: 11 additions & 0 deletions test/notifier/pubsub_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ defmodule Ash.Test.Notifier.PubSubTest do
publish :update, ["foo", :id], previous_values?: true
publish :update, ["bar", :name], event: "name_change", previous_values?: true
publish :update_pkey, ["foo", :_pkey], previous_values?: true

publish_all :update, ["baz", :id], event: "any_update", except: [:update_pkey]
publish_all :update, ["fiz", :id], event: "any_update", except: [:doesnotexist]
end

ets do
Expand Down Expand Up @@ -160,6 +163,10 @@ defmodule Ash.Test.Notifier.PubSubTest do
assert_receive {:broadcast, ^message, "name_change", %Ash.Notifier.Notification{}}
message = "post:bar:ted"
assert_receive {:broadcast, ^message, "name_change", %Ash.Notifier.Notification{}}
message = "post:baz:#{post.id}"
assert_receive {:broadcast, ^message, "any_update", %Ash.Notifier.Notification{}}
message = "post:fiz:#{post.id}"
assert_receive {:broadcast, ^message, "any_update", %Ash.Notifier.Notification{}}
end

test "publishing a message with a pkey matcher" do
Expand All @@ -179,6 +186,10 @@ defmodule Ash.Test.Notifier.PubSubTest do

message = "post:foo:#{new_id}"
assert_receive {:broadcast, ^message, "update_pkey", %Ash.Notifier.Notification{}}
message = "post:baz:#{new_id}"
refute_receive {:broadcast, ^message, "any_update", %Ash.Notifier.Notification{}}
message = "post:fiz:#{new_id}"
assert_receive {:broadcast, ^message, "any_update", %Ash.Notifier.Notification{}}
end

test "publishing a message with a different delimiter" do
Expand Down

0 comments on commit 2b344e1

Please sign in to comment.