-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Failing test for module calculation inside expression one (#456)
- Loading branch information
Showing
7 changed files
with
328 additions
and
1 deletion.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
priv/resource_snapshots/test_repo/comedians/20241217232254.json
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,59 @@ | ||
{ | ||
"attributes": [ | ||
{ | ||
"allow_nil?": false, | ||
"default": "fragment(\"gen_random_uuid()\")", | ||
"generated?": false, | ||
"primary_key?": true, | ||
"references": null, | ||
"size": null, | ||
"source": "id", | ||
"type": "uuid" | ||
}, | ||
{ | ||
"allow_nil?": true, | ||
"default": "nil", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "name", | ||
"type": "text" | ||
}, | ||
{ | ||
"allow_nil?": false, | ||
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "inserted_at", | ||
"type": "utc_datetime_usec" | ||
}, | ||
{ | ||
"allow_nil?": false, | ||
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "updated_at", | ||
"type": "utc_datetime_usec" | ||
} | ||
], | ||
"base_filter": null, | ||
"check_constraints": [], | ||
"custom_indexes": [], | ||
"custom_statements": [], | ||
"has_create_action": false, | ||
"hash": "A376A922D4610DEAD0294DD863E8E2FF72FEC6316AC6B809C3DFC17B29094EBA", | ||
"identities": [], | ||
"multitenancy": { | ||
"attribute": null, | ||
"global": null, | ||
"strategy": null | ||
}, | ||
"repo": "Elixir.AshPostgres.TestRepo", | ||
"schema": null, | ||
"table": "comedians" | ||
} |
98 changes: 98 additions & 0 deletions
98
priv/resource_snapshots/test_repo/jokes/20241217232254.json
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,98 @@ | ||
{ | ||
"attributes": [ | ||
{ | ||
"allow_nil?": false, | ||
"default": "fragment(\"gen_random_uuid()\")", | ||
"generated?": false, | ||
"primary_key?": true, | ||
"references": null, | ||
"size": null, | ||
"source": "id", | ||
"type": "uuid" | ||
}, | ||
{ | ||
"allow_nil?": true, | ||
"default": "nil", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "text", | ||
"type": "text" | ||
}, | ||
{ | ||
"allow_nil?": true, | ||
"default": "false", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "is_good", | ||
"type": "boolean" | ||
}, | ||
{ | ||
"allow_nil?": false, | ||
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "inserted_at", | ||
"type": "utc_datetime_usec" | ||
}, | ||
{ | ||
"allow_nil?": false, | ||
"default": "fragment(\"(now() AT TIME ZONE 'utc')\")", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": null, | ||
"size": null, | ||
"source": "updated_at", | ||
"type": "utc_datetime_usec" | ||
}, | ||
{ | ||
"allow_nil?": true, | ||
"default": "nil", | ||
"generated?": false, | ||
"primary_key?": false, | ||
"references": { | ||
"deferrable": false, | ||
"destination_attribute": "id", | ||
"destination_attribute_default": null, | ||
"destination_attribute_generated": null, | ||
"index?": false, | ||
"match_type": null, | ||
"match_with": null, | ||
"multitenancy": { | ||
"attribute": null, | ||
"global": null, | ||
"strategy": null | ||
}, | ||
"name": "jokes_comedian_id_fkey", | ||
"on_delete": null, | ||
"on_update": null, | ||
"primary_key?": true, | ||
"schema": "public", | ||
"table": "comedians" | ||
}, | ||
"size": null, | ||
"source": "comedian_id", | ||
"type": "uuid" | ||
} | ||
], | ||
"base_filter": null, | ||
"check_constraints": [], | ||
"custom_indexes": [], | ||
"custom_statements": [], | ||
"has_create_action": false, | ||
"hash": "CFDCBDBAC925B20A1EA8EB4B3C37ACF1FD915FA21F6B07DE4D066AA167B9EEF5", | ||
"identities": [], | ||
"multitenancy": { | ||
"attribute": null, | ||
"global": null, | ||
"strategy": null | ||
}, | ||
"repo": "Elixir.AshPostgres.TestRepo", | ||
"schema": null, | ||
"table": "jokes" | ||
} |
77 changes: 77 additions & 0 deletions
77
priv/test_repo/migrations/20241217232254_migrate_resources45.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,77 @@ | ||
defmodule AshPostgres.TestRepo.Migrations.MigrateResources45 do | ||
@moduledoc """ | ||
Updates resources based on their most recent snapshots. | ||
This file was autogenerated with `mix ash_postgres.generate_migrations` | ||
""" | ||
|
||
use Ecto.Migration | ||
|
||
def up do | ||
create table(:jokes, primary_key: false) do | ||
add(:id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true) | ||
add(:text, :text) | ||
add(:is_good, :boolean, default: false) | ||
|
||
add(:inserted_at, :utc_datetime_usec, | ||
null: false, | ||
default: fragment("(now() AT TIME ZONE 'utc')") | ||
) | ||
|
||
add(:updated_at, :utc_datetime_usec, | ||
null: false, | ||
default: fragment("(now() AT TIME ZONE 'utc')") | ||
) | ||
|
||
add(:comedian_id, :uuid) | ||
end | ||
|
||
create table(:comedians, primary_key: false) do | ||
add(:id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true) | ||
end | ||
|
||
alter table(:jokes) do | ||
modify( | ||
:comedian_id, | ||
references(:comedians, | ||
column: :id, | ||
name: "jokes_comedian_id_fkey", | ||
type: :uuid, | ||
prefix: "public" | ||
) | ||
) | ||
end | ||
|
||
alter table(:comedians) do | ||
add(:name, :text) | ||
|
||
add(:inserted_at, :utc_datetime_usec, | ||
null: false, | ||
default: fragment("(now() AT TIME ZONE 'utc')") | ||
) | ||
|
||
add(:updated_at, :utc_datetime_usec, | ||
null: false, | ||
default: fragment("(now() AT TIME ZONE 'utc')") | ||
) | ||
end | ||
end | ||
|
||
def down do | ||
alter table(:comedians) do | ||
remove(:updated_at) | ||
remove(:inserted_at) | ||
remove(:name) | ||
end | ||
|
||
drop(constraint(:jokes, "jokes_comedian_id_fkey")) | ||
|
||
alter table(:jokes) do | ||
modify(:comedian_id, :uuid) | ||
end | ||
|
||
drop(table(:comedians)) | ||
|
||
drop(table(:jokes)) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
defmodule AshPostgres.Test.Comedian do | ||
@moduledoc false | ||
use Ash.Resource, | ||
domain: AshPostgres.Test.Domain, | ||
data_layer: AshPostgres.DataLayer, | ||
authorizers: [Ash.Policy.Authorizer] | ||
|
||
attributes do | ||
uuid_primary_key(:id) | ||
attribute(:name, :string, public?: true) | ||
create_timestamp(:inserted_at, public?: true) | ||
update_timestamp(:updated_at, public?: true) | ||
end | ||
|
||
relationships do | ||
has_many(:jokes, AshPostgres.Test.Joke, public?: true) | ||
end | ||
|
||
calculations do | ||
calculate(:has_jokes_mod, :boolean, AshPostgres.Test.Comedian.HasJokes) | ||
calculate(:has_jokes_expr, :boolean, expr(has_jokes_mod == true)) | ||
end | ||
|
||
actions do | ||
defaults([:read]) | ||
|
||
create :create do | ||
primary?(true) | ||
accept([:name]) | ||
end | ||
end | ||
|
||
code_interface do | ||
define(:create) | ||
end | ||
|
||
postgres do | ||
table("comedians") | ||
repo(AshPostgres.TestRepo) | ||
end | ||
end | ||
|
||
defmodule AshPostgres.Test.Comedian.HasJokes do | ||
Check warning on line 43 in test/support/resources/comedian.ex GitHub Actions / ash-ci (15) / mix credo --strict
Check warning on line 43 in test/support/resources/comedian.ex GitHub Actions / ash-ci (14) / mix credo --strict
Check warning on line 43 in test/support/resources/comedian.ex GitHub Actions / ash-ci (16) / mix credo --strict
|
||
use Ash.Resource.Calculation | ||
|
||
@impl true | ||
def load(_, _, _) do | ||
[:jokes] | ||
end | ||
|
||
@impl true | ||
def calculate(comedians, _, _) do | ||
Enum.map(comedians, fn %{jokes: jokes} -> | ||
Enum.any?(jokes) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule AshPostgres.Test.Joke do | ||
@moduledoc false | ||
use Ash.Resource, | ||
domain: AshPostgres.Test.Domain, | ||
data_layer: AshPostgres.DataLayer, | ||
authorizers: [Ash.Policy.Authorizer] | ||
|
||
attributes do | ||
uuid_primary_key(:id) | ||
attribute(:text, :string, public?: true) | ||
attribute(:is_good, :boolean, default: false, public?: true) | ||
create_timestamp(:inserted_at, public?: true) | ||
update_timestamp(:updated_at, public?: true) | ||
end | ||
|
||
relationships do | ||
belongs_to(:comedian, AshPostgres.Test.Comedian, public?: true) | ||
end | ||
|
||
actions do | ||
defaults([:read]) | ||
end | ||
|
||
postgres do | ||
table("jokes") | ||
repo(AshPostgres.TestRepo) | ||
end | ||
end |