Skip to content

Commit

Permalink
Add support for booleans to LogMessage ecto type (#2675)
Browse files Browse the repository at this point in the history
Fixes #2666
  • Loading branch information
stuartc authored Nov 14, 2024
1 parent ccad141 commit 2ad8f07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ and this project adheres to

### Fixed

- Error when the logger receives a boolean
[#2666](https://github.com/OpenFn/lightning/issues/2666)

## [v2.10.1] - 2024-11-13

### Fixed
Expand Down
3 changes: 3 additions & 0 deletions lib/lightning/ecto_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ defmodule Lightning.LogMessage do
def cast(d) when is_integer(d),
do: Ecto.Type.cast(:string, d |> Integer.to_string())

def cast(d) when is_boolean(d),
do: Ecto.Type.cast(:string, d |> to_string())

def cast(d) when is_float(d),
do: Ecto.Type.cast(:string, d |> Float.to_string())

Expand Down
8 changes: 8 additions & 0 deletions test/lightning/ecto_types_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ defmodule Lightning.EctoTypesTest do
assert {:ok, ~s<5.893>} =
LogMessage.cast(5.893)
end

test "can be cast from a boolean" do
assert {:ok, ~s<true>} =
LogMessage.cast(true)

assert {:ok, ~s<false>} =
LogMessage.cast(false)
end
end

describe "UnixDateTime" do
Expand Down

0 comments on commit 2ad8f07

Please sign in to comment.