Skip to content

Commit

Permalink
Merge pull request #264 from GUI/offset
Browse files Browse the repository at this point in the history
Fix erroneous offset/start behavior
  • Loading branch information
n-rodriguez committed Feb 17, 2018
2 parents eb47002 + 5fe09e9 commit a94a0d3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/ajax-datatables-rails/datatable/datatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def paginate?
end

def offset
(page - 1) * per_page
options.fetch(:start, 0).to_i
end

def page
Expand Down
4 changes: 2 additions & 2 deletions spec/ajax-datatables-rails/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@
expect(datatable.datatable.send(:offset)).to eq(0)
end

it 'matches the value on view params[:start] minus 1' do
it 'matches the value on view params[:start]' do
paginated_view = double('view', params: { start: '11' })
datatable = described_class.new(paginated_view)
expect(datatable.datatable.send(:offset)).to eq(10)
expect(datatable.datatable.send(:offset)).to eq(11)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/ajax-datatables-rails/datatable/datatable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
end

it 'offset' do
expect(datatable.offset).to eq(45)
expect(datatable.offset).to eq(50)
end

it 'page' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
if AjaxDatatablesRails.config.db_adapter.in? %i[oracle oracleenhanced]
if Rails.version.in? %w[4.0.13 4.1.16 4.2.10]
expect(datatable.paginate_records(records).to_sql).to include(
'rownum <= 50'
'rownum <= 51'
)
else
expect(datatable.paginate_records(records).to_sql).to include(
'rownum <= (25 + 25)'
'rownum <= (26 + 25)'
)
end
else
expect(datatable.paginate_records(records).to_sql).to include(
'LIMIT 25 OFFSET 25'
'LIMIT 25 OFFSET 26'
)
end
end
Expand Down

0 comments on commit a94a0d3

Please sign in to comment.