-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use ecto schema assocs to determine if the viaRelationship is a …
…reverse. (#244) * fix: Use Ecto relationship keys to look up and lock viaRelationship * assets
- Loading branch information
Showing
19 changed files
with
167 additions
and
26 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
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
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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,70 @@ | ||
defmodule ExTeal.Fields.BelongsToTest do | ||
use TestExTeal.ConnCase | ||
alias ExTeal.Fields.BelongsTo | ||
alias TestExTeal.{Post, User} | ||
|
||
describe "apply_options_for/4" do | ||
@tag manifest: TestExTeal.DefaultManifest | ||
test "sets related values for an existing belongs to relationship" do | ||
user = insert(:user) | ||
post = insert(:post, user: user) | ||
f = BelongsTo.make(:user, User) | ||
conn = build_conn(:get, "/posts", %{}) | ||
|
||
f = BelongsTo.apply_options_for(f, post, conn, nil) | ||
|
||
assert f.options == %{ | ||
belongs_to_id: user.id, | ||
belongs_to_key: :user_id, | ||
belongs_to_relationship: "users", | ||
reverse: false | ||
} | ||
end | ||
|
||
@tag manifest: TestExTeal.DefaultManifest | ||
test "sets reverse to true when via relationship values are passed" do | ||
post = %Post{} | ||
user = insert(:user) | ||
f = BelongsTo.make(:user, User) | ||
|
||
conn = | ||
build_conn(:get, "/resources/posts/creation-fields", %{ | ||
"viaResource" => "users", | ||
"viaResourceId" => "#{user.id}", | ||
"viaRelationship" => "posts" | ||
}) | ||
|
||
f = BelongsTo.apply_options_for(f, post, conn, nil) | ||
|
||
assert f.options == %{ | ||
belongs_to_id: nil, | ||
belongs_to_key: :user_id, | ||
belongs_to_relationship: "users", | ||
reverse: true | ||
} | ||
end | ||
|
||
@tag manifest: TestExTeal.DefaultManifest | ||
test "sets reverse to false when via relationship doesn't correspond" do | ||
post = %Post{} | ||
user = insert(:user) | ||
f = BelongsTo.make(:editor, User) | ||
|
||
conn = | ||
build_conn(:get, "/resources/posts/creation-fields", %{ | ||
"viaResource" => "users", | ||
"viaResourceId" => "#{user.id}", | ||
"viaRelationship" => "posts" | ||
}) | ||
|
||
f = BelongsTo.apply_options_for(f, post, conn, nil) | ||
|
||
assert f.options == %{ | ||
belongs_to_id: nil, | ||
belongs_to_key: :editor_id, | ||
belongs_to_relationship: "users", | ||
reverse: false | ||
} | ||
end | ||
end | ||
end |
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
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
Oops, something went wrong.