This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Votio.Topic do | |
use Votio.Web, :model | |
schema "topics" do | |
field :title, :string | |
field :categories, :map | |
field :voted_by, {:array, :id} | |
timestamps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Votio.Topic do | |
use Votio.Web, :model | |
schema "topics" do | |
field :title, :string | |
field :categories, :map | |
field :voted_by, {:array, :id} | |
timestamps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |