Skip to content

Commit

Permalink
Merge pull request #8 from shoplineapp/feature/support-decimal128-to-…
Browse files Browse the repository at this point in the history
…string

feat(BSON::Decimal128): as string
  • Loading branch information
rayway30419 authored Apr 8, 2024
2 parents be9cb1c + 27cc9d2 commit 4a004f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongoid-avro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def convert_to_fields(klass, optional:)

def convert_to_avro_format(type: , optional: true)
case type.to_s
when "String", "Symbol" then "string"
when "String", "Symbol", "BSON::Decimal128" then "string"
when "Integer" then "int"
when "Float" then "double"
when "BigDecimal" then "decimal"
Expand Down
9 changes: 9 additions & 0 deletions spec/mongoid_avro_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TestModel
field :total, type: Money
field :subtotal, type: Money
field :object, type: Hash
field :decimal128, type: BSON::Decimal128
field :updated_at, type: Time, avro_format: {
type: "long",
logicalType: "timestamp-micros"
Expand Down Expand Up @@ -60,6 +61,14 @@ def get_field_by_name(fields, name)
expect(field["type"]).to eq("string")
end

context "when default type is BSON::Decimal128" do
let(:field_name) { "decimal128" }

it "convert decimal 128 to string" do
expect(field["type"]).to eq("string")
end
end

context "when default type is Time" do
let(:field_name) { "created_at" }

Expand Down

0 comments on commit 4a004f0

Please sign in to comment.