Merge pull request #3565 from consul/fix_annotation_comments_order

Fix order in annotation comments with same score
This commit is contained in:
Javier Martín
2019-05-30 18:25:04 +02:00
committed by GitHub
4 changed files with 13 additions and 25 deletions

View File

@@ -8,7 +8,7 @@ class Legislation::AnnotationsController < Legislation::BaseController
load_and_authorize_resource :draft_version, through: :process
load_and_authorize_resource
has_orders %w{most_voted newest}, only: :show
has_orders %w[most_voted newest oldest], only: :show
def index
@annotations = @draft_version.annotations

View File

@@ -2,14 +2,17 @@ class CommentTree
ROOT_COMMENTS_PER_PAGE = 10
attr_accessor :root_comments, :comments, :commentable, :page, :order
attr_reader :root_comments, :commentable, :page, :order
def initialize(commentable, page, order = "confidence_score", valuations: false)
@commentable = commentable
@page = page
@order = order
@valuations = valuations
@comments = root_comments + root_descendants
end
def comments
@comments ||= root_comments + root_descendants
end
def root_comments

View File

@@ -1,28 +1,13 @@
class MergedCommentTree < CommentTree
attr_accessor :commentables, :array_order
attr_reader :commentables
def initialize(commentables, page, order = "confidence_score")
@commentables = commentables
@commentable = commentables.first
@page = page
@order = order
@array_order = set_array_order(order)
@comments = root_comments + root_descendants
super(commentables.first, page, order)
end
def root_comments
Kaminari.paginate_array(commentables.flatten.map(&:comments).map(&:roots).flatten.sort_by {|a| a[array_order]}.reverse).
page(page).per(ROOT_COMMENTS_PER_PAGE)
end
def set_array_order(order)
case order
when "newest"
"created_at"
else
"confidence_score"
end
def base_comments
Comment.where(commentable: commentables.flatten)
end
end

View File

@@ -14,7 +14,7 @@ describe "Commenting legislation questions" do
expect(page).to have_css(".comment", count: 4)
comment = Comment.first
comment = Comment.last
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
@@ -144,7 +144,7 @@ describe "Commenting legislation questions" do
legislation_annotation.draft_version,
legislation_annotation)
within all(".comment").last do
within all(".comment").first do
expect(page).to have_content "Built with http://rubyonrails.org/"
expect(page).to have_link("http://rubyonrails.org/", href: "http://rubyonrails.org/")
expect(find_link("http://rubyonrails.org/")[:rel]).to eq("nofollow")
@@ -160,7 +160,7 @@ describe "Commenting legislation questions" do
legislation_annotation.draft_version,
legislation_annotation)
within all(".comment").last do
within all(".comment").first do
expect(page).to have_content "click me http://www.url.com"
expect(page).to have_link("http://www.url.com", href: "http://www.url.com")
expect(page).not_to have_link("click me")