Skip to content

Commit d34b183

Browse files
committed
Exclude mix tasks from coverage and cover the current-locale query helper arities
1 parent 56f9629 commit d34b183

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

mix.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ defmodule LocalizeEcto.MixProject do
1717
description: description(),
1818
package: package(),
1919
docs: docs(),
20-
dialyzer: [plt_add_apps: [:mix, :ecto_sql]]
20+
dialyzer: [plt_add_apps: [:mix, :ecto_sql]],
21+
# The audit mix task is CLI glue over `Localize.Ecto.Audit`
22+
# (which is covered); mix tasks are excluded from coverage
23+
# measurement as in the localize repo.
24+
test_coverage: [ignore_modules: [~r/^Mix\.Tasks\./]]
2125
]
2226
end
2327

test/localize/ecto_test.exs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,36 @@ defmodule Localize.EctoTest do
122122
Localize.put_locale("en")
123123
end
124124
end
125+
126+
describe "current-locale arities of the query helpers" do
127+
test "lower/1, upper/1 and initcap/1 use the current locale's collation" do
128+
{:ok, _} = Localize.put_locale("tr")
129+
130+
lower_query = from p in "products", select: lower(p.name)
131+
upper_query = from p in "products", select: upper(p.name)
132+
initcap_query = from p in "products", select: initcap(p.name)
133+
134+
assert to_sql(lower_query) =~ ~s[lower(p0."name" COLLATE "tr-x-icu")]
135+
assert to_sql(upper_query) =~ ~s[upper(p0."name" COLLATE "tr-x-icu")]
136+
assert to_sql(initcap_query) =~ ~s[initcap(p0."name" COLLATE "tr-x-icu")]
137+
after
138+
Localize.put_locale("en")
139+
end
140+
141+
test "ts_match/2 resolves the configuration from the current locale" do
142+
{:ok, _} = Localize.put_locale("de")
143+
query = from p in "products", where: ts_match(p.name, "stuhl"), select: p.name
144+
145+
assert to_sql(query) =~ "to_tsvector"
146+
after
147+
Localize.put_locale("en")
148+
end
149+
150+
test "a pinned zone is accepted by at_time_zone/2" do
151+
zone = "ausyd"
152+
query = from p in "products", select: at_time_zone(p.inserted_at, ^zone)
153+
154+
assert to_sql(query) =~ "AT TIME ZONE"
155+
end
156+
end
125157
end

0 commit comments

Comments
 (0)