From 3b185a7df4e58739f670b981ca406d96cff77a70 Mon Sep 17 00:00:00 2001 From: Giallombardo Nathan Date: Mon, 15 Jul 2024 14:22:59 +0000 Subject: [PATCH] support long number --- lib/couchbase-orm/attributes/dynamic.rb | 3 ++- spec/attribute_dynamic_spec.rb | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/couchbase-orm/attributes/dynamic.rb b/lib/couchbase-orm/attributes/dynamic.rb index 5b8ab6e3..cec07850 100644 --- a/lib/couchbase-orm/attributes/dynamic.rb +++ b/lib/couchbase-orm/attributes/dynamic.rb @@ -51,7 +51,7 @@ def _assign_attribute(name, value) # @return [Symbol] The determined type of the attribute. # # @example Determining types of various values - # define_attribute_type(123) # => :integer + # define_attribute_type(123) # => :big_integer # define_attribute_type("Hello") # => :string # define_attribute_type(true) # => :boolean # define_attribute_type(false) # => :boolean @@ -63,6 +63,7 @@ def define_attribute_type(value) return :boolean if type == :true_class return :boolean if type == :false_class return :raw if type == :nil_class + return :big_integer if type == :integer type end diff --git a/spec/attribute_dynamic_spec.rb b/spec/attribute_dynamic_spec.rb index 01fef1fb..685035da 100644 --- a/spec/attribute_dynamic_spec.rb +++ b/spec/attribute_dynamic_spec.rb @@ -26,19 +26,31 @@ class AttributeDynamicTest < CouchbaseOrm::Base end context 'with integer' do - it 'accepts unknown attribute from Coucbbase' do + it 'accepts unknown small integer from Coucbbase' do dynamic = AttributeDynamicTest.create!(name: 'joe', new_attribute: 2) expect(AttributeDynamicTest.find_by_id(dynamic.id)).to have_attributes(new_attribute: 2) dynamic.destroy end + + it 'accepts unknown long integer from Coucbbase' do + dynamic = AttributeDynamicTest.create!(name: 'joe', new_attribute: 202302241231) + expect(AttributeDynamicTest.find_by_id(dynamic.id)).to have_attributes(new_attribute: 202302241231) + dynamic.destroy + end end context 'with decimal' do - it 'accepts unknown attribute from Coucbbase' do + it 'accepts unknown small decimal from Coucbbase' do dynamic = AttributeDynamicTest.create!(name: 'joe', new_attribute: 2.0) expect(AttributeDynamicTest.find_by_id(dynamic.id)).to have_attributes(new_attribute: 2.0) dynamic.destroy end + + it 'accepts unknown long decimal from Coucbbase' do + dynamic = AttributeDynamicTest.create!(name: 'joe', new_attribute: 2.02302241231) + expect(AttributeDynamicTest.find_by_id(dynamic.id)).to have_attributes(new_attribute: 2.02302241231) + dynamic.destroy + end end context 'with true_class' do