-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly carry over first primary key attribute type and constr…
…aints (#36) The main problem in 7e825a1 was using the `attributes` variable to detect the PK (which only contains attrs from `attributes_as_attributes`). This commit also fixes an issue on the generated `:has_many` relationsip when the resource is using a PK other than `:id`.
- Loading branch information
1 parent
7e825a1
commit 6d5cb7c
Showing
3 changed files
with
66 additions
and
17 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
46 changes: 46 additions & 0 deletions
46
test/ash_paper_trail/resource/transformers/create_version_resource_test.exs
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,46 @@ | ||
defmodule AshPaperTrail.Resource.Transformers.CreateVersionResourceTest do | ||
use ExUnit.Case | ||
|
||
defmodule Tag do | ||
use Ash.Resource, | ||
data_layer: Ash.DataLayer.Ets, | ||
extensions: [AshPaperTrail.Resource], | ||
validate_api_inclusion?: false | ||
|
||
ets do | ||
private? true | ||
end | ||
|
||
attributes do | ||
attribute :name, :string do | ||
allow_nil? false | ||
primary_key? true | ||
constraints max_length: 20 | ||
end | ||
end | ||
end | ||
|
||
defmodule Api do | ||
use Ash.Api, extensions: [AshPaperTrail.Api], validate_config_inclusion?: false | ||
|
||
resources do | ||
resource Tag | ||
resource Tag.Version | ||
end | ||
end | ||
|
||
describe "attribute :version_source_id" do | ||
setup do | ||
version_source_id = Ash.Resource.Info.attribute(Tag.Version, :version_source_id) | ||
[version_source_id: version_source_id] | ||
end | ||
|
||
test "uses resource primary key type", %{version_source_id: version_source_id} do | ||
assert version_source_id.type == Ash.Type.String | ||
end | ||
|
||
test "uses resource primary key constraints", %{version_source_id: version_source_id} do | ||
assert version_source_id.constraints == [allow_empty?: false, trim?: true, max_length: 20] | ||
end | ||
end | ||
end |