Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for atomic ops on NoBrainer::Array (and any other Array subclasses) #292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/no_brainer/document/atomic_ops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def self._new(instance, field, value, is_user_value)
type ||= value.class unless value.nil?

case
when type == Array then PendingAtomicArray
when type.nil? then self
when type <= Array then PendingAtomicArray
when type == Set then PendingAtomicSet
else self
end.new(instance, field, value, is_user_value, type)
Expand All @@ -26,7 +27,8 @@ def initialize(instance, field, value, is_user_value, type)

def default_value
case
when @type == Array then []
when @type.nil? then nil
when @type <= Array then []
when @type == Set then []
when @type == Integer then 0
when @type == Float then 0.0
Expand Down
5 changes: 5 additions & 0 deletions spec/integration/atomic_ops_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@
before { doc.field1 = [] }
it_behaves_like 'arrays'
end

context 'when using a typed array' do
before { SimpleDocument.field :field1, :type => NoBrainer::TypedArray.of(String), :default => [] }
it_behaves_like 'arrays'
end
end

context 'when using sets' do
Expand Down
Loading