Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 2.0.2 (Next)

* [#53](https://github.com/mongoid/mongoid-scroll/pull/53): Cover float cursor round trips, serialization errors, abstract contracts and descending tiebreaker inclusion - [@dblock](https://github.com/dblock).
* Your contribution here.

### 2.0.1 (2026/10/15)
Expand Down
38 changes: 38 additions & 0 deletions spec/mongoid/scroll/base_cursor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper'

describe Mongoid::Scroll::BaseCursor do
it 'requires subclasses to implement serialization' do
expect { described_class.new(nil).to_s }.to raise_error(NotImplementedError, /to_s/)
end

it 'requires subclasses to implement parsing' do
expect { described_class.new(nil).send(:parse, 'cursor') }.to raise_error(NotImplementedError, /parse/)
end

it 'round trips a floating-point cursor' do
id = BSON::ObjectId.new
cursor = Mongoid::Scroll::Cursor.from_record({ 'score' => 1.25, '_id' => id }, field_name: 'score', field_type: Float)

expect(cursor.to_s).to eq("1.25:#{id}")
expect(Mongoid::Scroll::Cursor.new(cursor.to_s, field_name: 'score', field_type: Float).value).to eq(1.25)
end

it 'rejects an unsupported field type during serialization' do
cursor = Mongoid::Scroll::Cursor.new(nil, field_name: 'values', field_type: Array)
cursor.value = [1]
cursor.tiebreak_id = BSON::ObjectId.new

expect { cursor.to_s }.to raise_error(Mongoid::Scroll::Errors::UnsupportedFieldTypeError, /Array/)
end

it 'includes the descending tiebreaker record when requested' do
id = BSON::ObjectId.new
cursor = described_class.new(3, field_name: 'score', field_type: Integer, direction: -1, include_current: true, tiebreak_id: id)

expected = [
{ 'score' => { '$lt' => 3 } },
{ 'score' => 3, '_id' => { '$lte' => id } }
]
expect(cursor.criteria).to eq('$or' => expected)
end
end
7 changes: 7 additions & 0 deletions spec/mongoid/scroll_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe Mongoid::Scroll do
it 'defines a semantic version' do
expect(Mongoid::Scroll::VERSION).to match(/\A\d+\.\d+\.\d+\z/)
end
end
Loading