summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNermin Vehabovic <nermin.vehabovic90@gmail.com>2019-02-16 16:11:31 +0100
committermfluharty <mfluharty@gitlab.com>2019-02-20 11:20:33 -0700
commitd3c60a25c8e9494970d57b467f6f558aa31dd904 (patch)
treee4d7c5fd5326f503246c482074a6a843676a9c6c
parent16e492f429759d507ad8b4f7619e567d937f84d2 (diff)
downloadgitlab-ce-d3c60a25c8e9494970d57b467f6f558aa31dd904.tar.gz
Added: Specs for sort page breaks on notes
-rw-r--r--lib/api/helpers.rb12
-rw-r--r--spec/support/shared_examples/requests/api/notes.rb42
2 files changed, 43 insertions, 11 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 4656b27c5d1..54cd4cd9cdb 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -299,6 +299,12 @@ module API
items.search(text)
end
+ def order_options_with_tie_breaker
+ order_options = { params[:order_by] => params[:sort] }
+ order_options['id'] ||= 'desc'
+ order_options
+ end
+
# error helpers
def forbidden!(reason = nil)
@@ -397,12 +403,6 @@ module API
end
# rubocop: enable CodeReuse/ActiveRecord
- def order_options_with_tie_breaker
- order_options = { params[:order_by] => params[:sort] }
- order_options['id'] ||= 'desc'
- order_options
- end
-
def project_finder_params
finder_params = { without_deleted: true }
finder_params[:owned] = true if params[:owned].present?
diff --git a/spec/support/shared_examples/requests/api/notes.rb b/spec/support/shared_examples/requests/api/notes.rb
index 71499e85654..57eefd5ef01 100644
--- a/spec/support/shared_examples/requests/api/notes.rb
+++ b/spec/support/shared_examples/requests/api/notes.rb
@@ -8,13 +8,45 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
create_list(:note, 3, params)
end
- it 'sorts by created_at in descending order by default' do
- get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user)
+ context 'without sort params' do
+ it 'sorts by created_at in descending order by default' do
+ get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user)
- response_dates = json_response.map { |note| note['created_at'] }
+ response_dates = json_response.map { |note| note['created_at'] }
- expect(json_response.length).to eq(4)
- expect(response_dates).to eq(response_dates.sort.reverse)
+ expect(json_response.length).to eq(4)
+ expect(response_dates).to eq(response_dates.sort.reverse)
+ end
+
+ context '2 notes with equal created_at' do
+ before do
+ @first_note = Note.first
+
+ params = { noteable: noteable, author: user }
+ params[:project] = parent if parent.is_a?(Project)
+ params[:created_at] = @first_note.created_at
+
+ @note2 = create(:note, params)
+ end
+
+ it 'page breaks first page correctly' do
+ get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes?per_page=4", user)
+
+ response_ids = json_response.map { |note| note['id'] }
+
+ expect(response_ids).to include(@note2.id)
+ expect(response_ids).not_to include(@first_note.id)
+ end
+
+ it 'page breaks second page correctly' do
+ get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes?per_page=4&page=2", user)
+
+ response_ids = json_response.map { |note| note['id'] }
+
+ expect(response_ids).not_to include(@note2.id)
+ expect(response_ids).to include(@first_note.id)
+ end
+ end
end
it 'sorts by ascending order when requested' do