Skip to content

Commit

Permalink
feat(BSON::Decimal128): add annotation with decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Su committed Apr 8, 2024
1 parent 4a004f0 commit 20ccfba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/mongoid-avro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ def convert_to_fields(klass, optional:)

def convert_to_avro_format(type: , optional: true)
case type.to_s
when "String", "Symbol", "BSON::Decimal128" then "string"
when "String", "Symbol" then "string"
when "BSON::Decimal128"
{
"type": "string",
"logicalType": "decimal"
}
when "Integer" then "int"
when "Float" then "double"
when "BigDecimal" then "decimal"
Expand Down
7 changes: 6 additions & 1 deletion spec/mongoid_avro_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ def get_field_by_name(fields, name)
let(:field_name) { "decimal128" }

it "convert decimal 128 to string" do
expect(field["type"]).to eq("string")
expect(field["type"]).to eq(
{
"type" => "string",
"logicalType" => "decimal"
}
)
end
end

Expand Down

0 comments on commit 20ccfba

Please sign in to comment.