From a3a9a78015b9c2bb1d1dcefac5a45ff7acd95b0a Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 7 May 2017 10:02:15 -0500 Subject: [PATCH] /comments.json: default to id_desc order instead undefined order. --- app/models/comment.rb | 1 - test/unit/comment_test.rb | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 5a5f86a6e..09fad3e53 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -86,7 +86,6 @@ class Comment < ActiveRecord::Base def search(params) q = where("true") - return q if params.blank? if params[:body_matches].present? q = q.body_matches(params[:body_matches]) diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 17cf09db9..47541cb09 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -209,6 +209,13 @@ class CommentTest < ActiveSupport::TestCase assert_equal(c1.id, matches.all[1].id) end + should "default to id_desc order when searched with no options specified" do + comms = FactoryGirl.create_list(:comment, 3) + matches = Comment.search({}) + + assert_equal([comms[2].id, comms[1].id, comms[0].id], matches.map(&:id)) + end + context "that is edited by a moderator" do setup do @post = FactoryGirl.create(:post)