-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don’t require multitenancy attribute in
get
(#1716)
Signed-off-by: Adam Tharani <adamtharani@me.com>
- Loading branch information
1 parent
fdea4ae
commit fa967ed
Showing
2 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
defmodule Ash.Test.MultitenancyTest do | ||
@moduledoc false | ||
use ExUnit.Case, async: true | ||
|
||
alias Ash.Test.Domain, as: Domain | ||
|
||
defmodule MultiTenant do | ||
use Ash.Resource, domain: Domain, data_layer: Ash.DataLayer.Ets | ||
|
||
multitenancy do | ||
strategy :attribute | ||
attribute :owner | ||
end | ||
|
||
attributes do | ||
attribute :id, :integer, primary_key?: true, allow_nil?: false, public?: true | ||
attribute :owner, :integer, primary_key?: true, allow_nil?: false, public?: true | ||
end | ||
|
||
actions do | ||
default_accept :* | ||
defaults [:read, :create] | ||
end | ||
end | ||
|
||
test "reading an object doesn't require multitenancy attribute in the primary key" do | ||
MultiTenant | ||
|> Ash.Changeset.for_create(:create, %{id: 1000, owner: 1}) | ||
|> Ash.create!(tenant: 1) | ||
|
||
MultiTenant | ||
|> Ash.get!(1000, tenant: 1) | ||
end | ||
|
||
defmodule NonMultiTenant do | ||
use Ash.Resource, domain: Domain, data_layer: Ash.DataLayer.Ets | ||
|
||
attributes do | ||
attribute :id, :integer, primary_key?: true, allow_nil?: false, public?: true | ||
attribute :owner, :integer, primary_key?: true, allow_nil?: false, public?: true | ||
end | ||
|
||
actions do | ||
default_accept :* | ||
defaults [:read, :create] | ||
end | ||
end | ||
|
||
test "reading an object without multitenancy requires attribute in the primary key" do | ||
NonMultiTenant | ||
|> Ash.Changeset.for_create(:create, %{id: 1000, owner: 1}) | ||
|> Ash.create!() | ||
|
||
ExUnit.Assertions.assert_raise(Ash.Error.Invalid, fn -> | ||
NonMultiTenant | ||
|> Ash.get!(1000) | ||
end) | ||
|
||
NonMultiTenant | ||
|> Ash.get!(%{id: 1000, owner: 1}) | ||
end | ||
end |