-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actually create a
Source
for every “person”
- Loading branch information
1 parent
1a35461
commit 3322bad
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule Edges.Events.ActionTest do | ||
use ExUnit.Case | ||
|
||
alias Edges.Events.Action | ||
alias Edges.Events.Source | ||
alias Edges.Repo | ||
|
||
setup do | ||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Edges.Repo) | ||
|
||
{:ok, source} = | ||
%Source{} | ||
|> Source.changeset(%{person: "test source"}) | ||
|> Repo.insert() | ||
|
||
{:ok, existing_source: source} | ||
end | ||
|
||
describe "Action Creation" do | ||
test "creating for an existing person uses that source", %{existing_source: source} do | ||
person = source.person() | ||
source_id = source.id() | ||
|
||
{:ok, action} = | ||
%Action{} | ||
|> Action.changeset(%{action: "Favorited", resource_type: "Listing", resource_id: "42", person: person}) | ||
|> Repo.insert() | ||
|
||
assert ^source_id = action.source_id() | ||
end | ||
|
||
test "creating for a new person creates a new source", %{existing_source: source} do | ||
existing_id = source.id() | ||
|
||
{:ok, action} = | ||
%Action{} | ||
|> Action.changeset(%{action: "Favorites", resource_type: "Listing", resource_id: "42", person: "new guy"}) | ||
|> Repo.insert() | ||
|
||
refute existing_id == action.source_id() | ||
end | ||
end | ||
end |