Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions test/map_field_type_expr_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SPDX-FileCopyrightText: 2019 ash_postgres contributors <https://github.com/ash-project/ash_postgres/graphs/contributors>
#
# SPDX-License-Identifier: MIT

defmodule AshPostgres.MapFieldTypeExprTest do
@moduledoc false
use AshPostgres.RepoCase, async: false

alias AshPostgres.Test.Post

require Ash.Query
import Ash.Expr

setup do
post =
Post
|> Ash.Changeset.for_create(:create, %{
title: "a",
keyword_map: [display_template: "{{foo}}", size: 3]
})
|> Ash.create!()

%{post: post}
end

test "a field declared an integer is compared as an integer", %{post: post} do

Check failure on line 26 in test/map_field_type_expr_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (17) / mix test

test a field declared an integer is compared as an integer (AshPostgres.MapFieldTypeExprTest)

Check failure on line 26 in test/map_field_type_expr_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (16) / mix test

test a field declared an integer is compared as an integer (AshPostgres.MapFieldTypeExprTest)

Check failure on line 26 in test/map_field_type_expr_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (18) / mix test

test a field declared an integer is compared as an integer (AshPostgres.MapFieldTypeExprTest)

Check failure on line 26 in test/map_field_type_expr_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (15) / mix test

test a field declared an integer is compared as an integer (AshPostgres.MapFieldTypeExprTest)

Check failure on line 26 in test/map_field_type_expr_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (14) / mix test

test a field declared an integer is compared as an integer (AshPostgres.MapFieldTypeExprTest)
assert [found] =
Post
|> Ash.Query.filter(keyword_map[:size] == 3)
|> Ash.read!()

assert found.id == post.id
end

test "a field declared an integer orders numerically" do

Check failure on line 35 in test/map_field_type_expr_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (17) / mix test

test a field declared an integer orders numerically (AshPostgres.MapFieldTypeExprTest)

Check failure on line 35 in test/map_field_type_expr_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (16) / mix test

test a field declared an integer orders numerically (AshPostgres.MapFieldTypeExprTest)

Check failure on line 35 in test/map_field_type_expr_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (18) / mix test

test a field declared an integer orders numerically (AshPostgres.MapFieldTypeExprTest)

Check failure on line 35 in test/map_field_type_expr_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (15) / mix test

test a field declared an integer orders numerically (AshPostgres.MapFieldTypeExprTest)

Check failure on line 35 in test/map_field_type_expr_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (14) / mix test

test a field declared an integer orders numerically (AshPostgres.MapFieldTypeExprTest)
Post
|> Ash.Changeset.for_create(:create, %{
title: "b",
keyword_map: [display_template: "{{bar}}", size: 10]
})
|> Ash.create!()

assert [%{keyword_map: [display_template: "{{bar}}", size: 10]}] =
Post
|> Ash.Query.filter(keyword_map[:size] > 9)
|> Ash.read!()
end

test "a field declared a string still compares as a string", %{post: post} do
assert [found] =
Post
|> Ash.Query.filter(keyword_map[:display_template] == "{{foo}}")
|> Ash.read!()

assert found.id == post.id
end
end
3 changes: 3 additions & 0 deletions test/support/resources/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ defmodule AshPostgres.Test.Post do
fields: [
display_template: [
type: :string
],
size: [
type: :integer
]
]
)
Expand Down
Loading