Skip to content

Commit

Permalink
support long number
Browse files Browse the repository at this point in the history
  • Loading branch information
Giallombardo Nathan committed Jul 15, 2024
1 parent 80ec914 commit 3b185a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/couchbase-orm/attributes/dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions spec/attribute_dynamic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3b185a7

Please sign in to comment.