View Source Multiverses.Presence (multiverses_pubsub v0.5.0)
using-multiverses-with-phoenix-presence
Using Multiverses with Phoenix Presence
Since Phoenix Presence is a behaviour module that autogenerates functions for
you with its using
directive, it is inappropriate to use Multiverses to
override Phoenix Presence. Instead, you will have to override the autogenerated
module instead. Presuming that you have created a Presence module like so:
defmodule MyApp.Presence do
use Phoenix.Presence, otp_app: <my_otp_app>,
pubsub_server: <my_pubsub_server>
end
In your test_helpers.exs
file (or in a support directory), build the replacement presence module.
require Multiverses.Presence
Multiverses.Presence.clone(MyApp.Presence, as: MyApp.Multiverse.Presence)
Now set up your configuration:
in-config-exs
in config.exs
config :my_app, MyApp.Presence, MyApp.Presence
in-test-exs
in test.exs
config :my_app, MyApp.Presence, MyApp.Multiverse.Presence
in-modules-that-use-presence
in modules that use presence
defmodule MyApp.UsesPresence do
@my_app_presence Application.compile_env!(:my_app, MyApp.Presence)
#...
end
in-your-test-module
in your test module
defmodule MyAppTest.UsesPresenceTest do
use ExUnit.Case, async: true
setup do
Multiverses.shard(PubSub)
end
end
important-note
Important Note:
The Presence struct will have a :topic
key whose value includes the
universe postfix. If you're matching against this key, be sure to change
your match to be "topic" <> _
instead of "topic"