Skip to content

Commit e206e57

Browse files
committed
Fix error with default values on float properties
1 parent bfa8e0b commit e206e57

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
1414

1515
### Fixed
1616

17+
- Defining a default value on a `:float` property was causing an error
1718
- Fix unwanted normalization of list values in `custom_fields`
1819

1920

lib/grax/schema/property.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ defmodule Grax.Schema.DataProperty do
116116
do: raise(ArgumentError, "the :default option is not supported on list types")
117117

118118
defp init_default(nil, default), do: default
119+
defp init_default(RDF.XSD.Float, default) when is_float(default), do: default
119120

120121
defp init_default(type, default) do
121122
if Literal.new(default) |> Literal.is_a?(type) do

test/grax/grax_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,14 @@ defmodule GraxTest do
499499
__id__: IRI.new(EX.User0),
500500
email: ["foo@example.com"]
501501
}}
502+
503+
assert Example.DefaultValues.build!(EX.S)
504+
|> Grax.put(:float, 1.23) ==
505+
{:ok,
506+
%Example.DefaultValues{
507+
__id__: IRI.new(EX.S),
508+
float: 1.23
509+
}}
502510
end
503511

504512
test "when the property does not exist" do

test/support/example_schemas.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ defmodule Example do
378378
property foo: EX.foo(), default: "foo"
379379
property bar: EX.bar(), type: :string, default: "bar"
380380
property baz: EX.baz(), type: :integer, default: 42
381+
property float: EX.float(), type: :float, default: 3.14
381382
link user: EX.user(), type: Example.User
382383
link posts: EX.post(), type: list_of(Example.Post)
383384
end

0 commit comments

Comments
 (0)