|
1 | 1 | defmodule AshPostgres.ReferencesTest do |
2 | 2 | use AshPostgres.RepoCase |
| 3 | + import ExUnit.CaptureIO |
3 | 4 |
|
4 | 5 | test "can't use match_type != :full when referencing an non-primary key index" do |
5 | 6 | Code.compiler_options(ignore_module_conflict: true) |
@@ -66,44 +67,47 @@ defmodule AshPostgres.ReferencesTest do |
66 | 67 | end |
67 | 68 | end |
68 | 69 |
|
69 | | - assert_raise Spark.Error.DslError, ~r/Unsupported match_type./, fn -> |
70 | | - defmodule UserThing do |
71 | | - @moduledoc false |
72 | | - use Ash.Resource, |
73 | | - domain: nil, |
74 | | - data_layer: AshPostgres.DataLayer |
75 | | - |
76 | | - attributes do |
77 | | - attribute(:id, :string, primary_key?: true, allow_nil?: false, public?: true) |
78 | | - attribute(:name, :string, public?: true) |
79 | | - attribute(:org_id, :uuid, public?: true) |
80 | | - attribute(:foo_id, :uuid, public?: true) |
81 | | - end |
| 70 | + {_, io} = |
| 71 | + with_io(:stderr, fn -> |
| 72 | + defmodule UserThing do |
| 73 | + @moduledoc false |
| 74 | + use Ash.Resource, |
| 75 | + domain: nil, |
| 76 | + data_layer: AshPostgres.DataLayer |
| 77 | + |
| 78 | + attributes do |
| 79 | + attribute(:id, :string, primary_key?: true, allow_nil?: false, public?: true) |
| 80 | + attribute(:name, :string, public?: true) |
| 81 | + attribute(:org_id, :uuid, public?: true) |
| 82 | + attribute(:foo_id, :uuid, public?: true) |
| 83 | + end |
82 | 84 |
|
83 | | - multitenancy do |
84 | | - strategy(:attribute) |
85 | | - attribute(:org_id) |
86 | | - end |
| 85 | + multitenancy do |
| 86 | + strategy(:attribute) |
| 87 | + attribute(:org_id) |
| 88 | + end |
87 | 89 |
|
88 | | - relationships do |
89 | | - belongs_to(:org, Org) |
90 | | - belongs_to(:user, User, destination_attribute: :secondary_id) |
91 | | - end |
| 90 | + relationships do |
| 91 | + belongs_to(:org, Org) |
| 92 | + belongs_to(:user, User, destination_attribute: :secondary_id) |
| 93 | + end |
92 | 94 |
|
93 | | - postgres do |
94 | | - table("user_things") |
95 | | - repo(AshPostgres.TestRepo) |
| 95 | + postgres do |
| 96 | + table("user_things") |
| 97 | + repo(AshPostgres.TestRepo) |
96 | 98 |
|
97 | | - references do |
98 | | - reference :user, match_with: [foo_id: :foo_id], match_type: :simple |
| 99 | + references do |
| 100 | + reference :user, match_with: [foo_id: :foo_id], match_type: :simple |
| 101 | + end |
99 | 102 | end |
100 | | - end |
101 | 103 |
|
102 | | - actions do |
103 | | - defaults([:create, :read, :update, :destroy]) |
| 104 | + actions do |
| 105 | + defaults([:create, :read, :update, :destroy]) |
| 106 | + end |
104 | 107 | end |
105 | | - end |
106 | | - end |
| 108 | + end) |
| 109 | + |
| 110 | + assert io =~ "Unsupported match_type" |
107 | 111 | end |
108 | 112 |
|
109 | 113 | test "named reference results in properly applied foreign_key_constraint/3 on the underlying changeset" do |
|
0 commit comments