Skip to content

Commit c832316

Browse files
authored
Merge pull request #49 from belaustegui/releases/2.0.2
Prepare 2.0.2 release
2 parents f0b2fb5 + 8c50ab0 commit c832316

File tree

5 files changed

+21
-29
lines changed

5 files changed

+21
-29
lines changed

.travis.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
language: elixir
22
elixir:
3-
- 1.3.2
4-
- 1.3.3
53
- 1.3.4
6-
- 1.4.0
7-
- 1.4.1
8-
- 1.4.2
4+
- 1.4.5
5+
- 1.5.1
96
otp_release:
107
- 18.3
118
- 19.0
129
- 19.1
1310
- 19.2
1411
- 19.3
12+
- 20.0
1513
addons:
1614
postgresql: "9.4"
15+
matrix:
16+
exclude:
17+
- elixir: 1.3.4
18+
otp_release: 20.0
19+
1720
before_script:
1821
- cp config/test.travis.exs config/test.exs
1922
- mix deps.get

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 2.0.2 - 2017-09-29
8+
- Support Elixir 1.5 and Erlant/OTP 20.
9+
- Fix bug when passing the locale in a variable to `Trans.QueryBuilder.translated/3`.
10+
711
## 2.0.1 - 2017-07-09
812
- Relax `Poison` dependency version restriction.
913
- Integrate Ebert for code style checks and static analysis.

lib/trans/query_builder.ex

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,23 @@ if Code.ensure_loaded?(Ecto.Query) do
8282
with field <- field(translatable) do
8383
with {module_name, []} <- Module.eval_quoted(__CALLER__, module) do
8484
validate_field(module_name, field)
85-
generate_query(schema(translatable), module_name, field, locale(locale))
85+
generate_query(schema(translatable), module_name, field, locale)
8686
end
8787
end
8888
end
8989

9090
defp generate_query(schema, module, nil, locale) do
9191
quote do
92-
fragment("(?->?)", field(unquote(schema), unquote(module.__trans__(:container))), ^unquote(locale))
92+
fragment("(?->?)", field(unquote(schema), unquote(module.__trans__(:container))), ^to_string(unquote(locale)))
9393
end
9494
end
9595

9696
defp generate_query(schema, module, field, locale) do
9797
quote do
98-
fragment("(?->?->>?)", field(unquote(schema), unquote(module.__trans__(:container))), ^unquote(locale), ^unquote(field))
98+
fragment("(?->?->>?)", field(unquote(schema), unquote(module.__trans__(:container))), ^to_string(unquote(locale)), ^unquote(field))
9999
end
100100
end
101101

102-
defp locale(locale) when is_atom(locale) and not is_nil(locale), do: to_string(locale)
103-
defp locale(locale) when is_binary(locale), do: locale
104-
defp locale(_), do: raise ArgumentError, message: "The locale code must be either an atom or a string"
105-
106102
defp schema({{:., _, [schema, _field]}, _metadata, _args}), do: schema
107103
defp schema(schema), do: schema
108104

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Trans.Mixfile do
22
use Mix.Project
33

4-
@version "2.0.1"
4+
@version "2.0.2"
55

66
def project do
77
[app: :trans,

test/query_builder_test.exs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,10 @@ defmodule QueryBuilderTest do
148148
fn -> Code.eval_quoted(invalid_module) end
149149
end
150150

151-
test "should raise when an invalid locale is specified" do
152-
invalid_module = quote do
153-
defmodule TestWrongQuery do
154-
require Ecto.Query
155-
import Ecto.Query, only: [from: 2]
156-
157-
def invalid_query do
158-
from a in Article,
159-
where: not is_nil(translated(Article, a.title, nil))
160-
end
161-
end
162-
end
163-
164-
assert_raise ArgumentError,
165-
"The locale code must be either an atom or a string",
166-
fn -> Code.eval_quoted(invalid_module) end
151+
test "should allow passing the locale from a variable" do
152+
locale = :es
153+
articles = Repo.all(from a in Article,
154+
order_by: translated(Article, a.title, locale))
155+
assert Enum.any?(articles)
167156
end
168157
end

0 commit comments

Comments
 (0)