Skip to content

Instantly share code, notes, and snippets.

defmodule Votio.TopicChannelTest do
use Votio.ChannelCase
alias Votio.TopicChannel
alias Votio.Topic
alias Votio.TopicView
import Votio.Factory
@valid_attrs %{"message" => %{"categories" => %{"yep" => 0, "nope" => 0}, "title" => "some content"}}
@changeset_data %{"categories" => %{"yep" => 0, "nope" => 0}, "title" => "some content"}
defmodule Votio.TopicChannelTest do
use Votio.ChannelCase
alias Votio.TopicChannel
alias Votio.Topic
alias Votio.TopicView
import Votio.Factory
@valid_attrs %{"message" => %{"categories" => %{"yep" => 0, "nope" => 0}, "title" => "some content"}}
@updated_vote update_in @valid_attrs, ["message", "categories", "yep"], &(&1 + 1)
defmodule Votio.Topic do
use Votio.Web, :model
schema "topics" do
field :title, :string
field :categories, :map
field :voted_by, {:array, :id}
timestamps
defmodule Votio.TopicChannelTest do
use Votio.ChannelCase
alias Votio.TopicChannel
import Votio.Factory
setup do
user = create(:user)
{:ok, jwt, full_claims} = Guardian.encode_and_sign(user)
{:ok, _, socket} =
defmodule Votio.TopicChannel do
use Votio.Web, :channel
use Guardian.Channel
def join("topics:lobby", %{claims: claim, resource: resource}, socket) do
{:ok, %{ message: "Joined"}, socket}
end
def join("topics:lobby", _, socket) do
{:error, %{error: "authentication required"}}
defmodule Votio.TopicTest do
use Votio.ModelCase
import Votio.TestHelpers, only: [insert_topic: 1]
alias Votio.Topic
@valid_attrs %{categories: %{option1: 0, option2: 0}, title: "some content"}
@invalid_attrs1 %{}
@invalid_attrs2 %{title: "nope", categories: %{scotch: 0, beer: 0}}
defmodule Votio.TopicTest do
use Votio.ModelCase
import Votio.TestHelpers, only: [insert_topic: 1]
alias Votio.Topic
@valid_attrs %{categories: %{option1: 0, option2: 0}, title: "some content"}
@invalid_attrs1 %{}
@invalid_attrs2 %{title: "nope", categories: %{scotch: 0, beer: 0}}
defmodule Votio.TopicTest do
use Votio.ModelCase
import Votio.TestHelpers, only: [insert_topic: 1]
alias Votio.Topic
@valid_attrs %{categories: %{option1: 0, option2: 0}, title: "some content"}
@invalid_attrs1 %{}
@invalid_attrs2 %{title: "nope"}
defmodule Votio.Topic do
use Votio.Web, :model
schema "topics" do
field :title, :string
field :categories, :map
field :voted_by, {:array, :id}
timestamps
def validate_categories(%{model: %{categories: nil}} = changeset), do: add_error(changeset, :categories, "must have at least two categories")
def validate_categories(%{model: %{categories: categories}} = changeset) when map_size(categories) < 2 do
add_error(changeset, :categories, "must have at least two categories")
end
def validate_categories(changeset), do: changeset