From 82eb0bd902aa60b135178802d6e7b1e7e0aa9e83 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 28 Oct 2015 11:30:11 +0100 Subject: [PATCH 01/19] Adds comments filter for debates and proposals --- app/assets/stylesheets/layout.scss | 19 +++++++++++++++++++ app/views/debates/_comments.html.erb | 17 +++++++++++++++++ app/views/proposals/_comments.html.erb | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 086dc92d7..3f23b11f4 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -1937,6 +1937,25 @@ table { opacity: 0.4; } +.filter-comments { + float: none; + margin-top: 0; + + @media (min-width: $small-breakpoint) { + float: right; + margin-top: rem-calc(-24); + } + + label { + padding-right: rem-calc(12); + float: none; + + @media (min-width: $small-breakpoint) { + float: right; + } + } +} + // 19. Flags // - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/views/debates/_comments.html.erb b/app/views/debates/_comments.html.erb index 8aa26ed03..6018f1bdf 100644 --- a/app/views/debates/_comments.html.erb +++ b/app/views/debates/_comments.html.erb @@ -7,6 +7,23 @@ (<%= @debate.comments_count %>) + +
+
+
+ +
+
+ +
+
+
+ + <% if user_signed_in? %> <%= render 'comments/form', {commentable: @debate, parent_id: nil, toggeable: false} %> <% else %> diff --git a/app/views/proposals/_comments.html.erb b/app/views/proposals/_comments.html.erb index 2442bd230..8f682c3b4 100644 --- a/app/views/proposals/_comments.html.erb +++ b/app/views/proposals/_comments.html.erb @@ -2,11 +2,29 @@
+

<%= t("proposals.show.comments_title") %> (<%= @proposal.comments_count %>)

+ +
+
+
+ +
+
+ +
+
+
+ + <% if user_signed_in? %> <%= render 'comments/form', {commentable: @proposal, parent_id: nil, toggeable: false} %> <% else %> From e4bfc72649a7413a13e2583c2074e492030ee676 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Oct 2015 15:48:48 +0100 Subject: [PATCH 02/19] Refactors design of comments order selector into a partial with i18n --- app/assets/stylesheets/layout.scss | 4 ++-- app/controllers/debates_controller.rb | 1 + app/controllers/proposals_controller.rb | 1 + app/views/debates/_comments.html.erb | 19 ++------------- app/views/proposals/_comments.html.erb | 19 ++------------- .../shared/_wide_order_selector.html.erb | 24 +++++++++++++++++++ app/views/shared/_wide_order_selector.rb | 16 +++++++++++++ config/locales/en.yml | 4 ++++ config/locales/es.yml | 4 ++++ 9 files changed, 56 insertions(+), 36 deletions(-) create mode 100644 app/views/shared/_wide_order_selector.html.erb create mode 100644 app/views/shared/_wide_order_selector.rb diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 3f23b11f4..e9429a495 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -1937,7 +1937,7 @@ table { opacity: 0.4; } -.filter-comments { +.wide-order-selector { float: none; margin-top: 0; @@ -1993,4 +1993,4 @@ table { overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; -} \ No newline at end of file +} diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 7981fb121..1c0765c64 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -7,6 +7,7 @@ class DebatesController < ApplicationController before_action :authenticate_user!, except: [:index, :show] has_orders %w{hot_score confidence_score created_at most_commented random}, only: :index + has_orders %w{most_voted created_at}, only: :show load_and_authorize_resource respond_to :html, :js diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index aa91ad02f..4c308ebe2 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -7,6 +7,7 @@ class ProposalsController < ApplicationController before_action :authenticate_user!, except: [:index, :show] has_orders %w{hot_score confidence_score created_at most_commented random}, only: :index + has_orders %w{most_voted created_at}, only: :show load_and_authorize_resource respond_to :html, :js diff --git a/app/views/debates/_comments.html.erb b/app/views/debates/_comments.html.erb index 6018f1bdf..4c9ad6a69 100644 --- a/app/views/debates/_comments.html.erb +++ b/app/views/debates/_comments.html.erb @@ -7,22 +7,7 @@ (<%= @debate.comments_count %>) - -
-
-
- -
-
- -
-
-
- + <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> <% if user_signed_in? %> <%= render 'comments/form', {commentable: @debate, parent_id: nil, toggeable: false} %> @@ -43,4 +28,4 @@
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/proposals/_comments.html.erb b/app/views/proposals/_comments.html.erb index 8f682c3b4..6a6868f5c 100644 --- a/app/views/proposals/_comments.html.erb +++ b/app/views/proposals/_comments.html.erb @@ -8,22 +8,7 @@ (<%= @proposal.comments_count %>) - -
-
-
- -
-
- -
-
-
- + <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> <% if user_signed_in? %> <%= render 'comments/form', {commentable: @proposal, parent_id: nil, toggeable: false} %> @@ -44,4 +29,4 @@ -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/shared/_wide_order_selector.html.erb b/app/views/shared/_wide_order_selector.html.erb new file mode 100644 index 000000000..defa8415e --- /dev/null +++ b/app/views/shared/_wide_order_selector.html.erb @@ -0,0 +1,24 @@ +<% # Params: + # + # i18n_namespace: for example "moderation.debates.index" +%> + +
+
+
+ +
+
+ +
+
+
diff --git a/app/views/shared/_wide_order_selector.rb b/app/views/shared/_wide_order_selector.rb new file mode 100644 index 000000000..883205493 --- /dev/null +++ b/app/views/shared/_wide_order_selector.rb @@ -0,0 +1,16 @@ +<% # Params: + # + # i18n_namespace: for example "moderation.debates.index" +%> + +
+ + +
diff --git a/config/locales/en.yml b/config/locales/en.yml index e1af67760..83a4bf0e4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -243,6 +243,10 @@ en: form: submit_button: "Save changes" comments: + select_order: "Sort by" + orders: + most_voted: "Most voted" + created_at: "Newest" form: leave_comment: Write a comment comment_as_moderator: Comment as moderator diff --git a/config/locales/es.yml b/config/locales/es.yml index d5a615850..c17484c99 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -243,6 +243,10 @@ es: form: submit_button: "Guardar cambios" comments: + select_order: "Ordenar por" + orders: + most_voted: "Más votados" + created_at: "Más nuevos" form: leave_comment: Deja tu comentario comment_as_moderator: Comentar como moderador From 094ec095769e4f8f48f3370b997ad8a2f4d1aecf Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Oct 2015 16:00:34 +0100 Subject: [PATCH 03/19] Adds migration for comment.confidence_score --- .../20151028145921_add_confidence_score_to_comments.rb | 5 +++++ db/schema.rb | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20151028145921_add_confidence_score_to_comments.rb diff --git a/db/migrate/20151028145921_add_confidence_score_to_comments.rb b/db/migrate/20151028145921_add_confidence_score_to_comments.rb new file mode 100644 index 000000000..636b648bb --- /dev/null +++ b/db/migrate/20151028145921_add_confidence_score_to_comments.rb @@ -0,0 +1,5 @@ +class AddConfidenceScoreToComments < ActiveRecord::Migration + def change + add_column :comments, :confidence_score, :integer, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 436fe1b7f..67626bf0b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,8 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151021113348) do +ActiveRecord::Schema.define(version: 20151028145921) do + # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -72,6 +73,7 @@ ActiveRecord::Schema.define(version: 20151021113348) do t.integer "cached_votes_down", default: 0 t.datetime "confirmed_hide_at" t.string "ancestry" + t.integer "confidence_score" end add_index "comments", ["ancestry"], name: "index_comments_on_ancestry", using: :btree From da19d4d773bf8b411734d0d91ddf6b9fba128cbd Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Oct 2015 16:02:40 +0100 Subject: [PATCH 04/19] replace most_voted by confidence_score in comment views --- app/controllers/debates_controller.rb | 2 +- app/controllers/proposals_controller.rb | 2 +- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 1c0765c64..1b1184f59 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -7,7 +7,7 @@ class DebatesController < ApplicationController before_action :authenticate_user!, except: [:index, :show] has_orders %w{hot_score confidence_score created_at most_commented random}, only: :index - has_orders %w{most_voted created_at}, only: :show + has_orders %w{confidence_score created_at}, only: :show load_and_authorize_resource respond_to :html, :js diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 4c308ebe2..f91e65b8a 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -7,7 +7,7 @@ class ProposalsController < ApplicationController before_action :authenticate_user!, except: [:index, :show] has_orders %w{hot_score confidence_score created_at most_commented random}, only: :index - has_orders %w{most_voted created_at}, only: :show + has_orders %w{confidence_score created_at}, only: :show load_and_authorize_resource respond_to :html, :js diff --git a/config/locales/en.yml b/config/locales/en.yml index 83a4bf0e4..21b4a6872 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -245,7 +245,7 @@ en: comments: select_order: "Sort by" orders: - most_voted: "Most voted" + confidence_score: "Most voted" created_at: "Newest" form: leave_comment: Write a comment diff --git a/config/locales/es.yml b/config/locales/es.yml index c17484c99..9150404e3 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -245,7 +245,7 @@ es: comments: select_order: "Ordenar por" orders: - most_voted: "Más votados" + confidence_score: "Más votados" created_at: "Más nuevos" form: leave_comment: Deja tu comentario From f5d9ea4357f1d4f433927c448c714f50e8701a17 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Oct 2015 16:25:35 +0100 Subject: [PATCH 05/19] adds confidence_score capacity to the comment model --- app/models/comment.rb | 8 ++++++++ spec/factories.rb | 4 ++++ spec/models/comment_spec.rb | 38 +++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/app/models/comment.rb b/app/models/comment.rb index e9bb59775..6fdf4d294 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -17,10 +17,13 @@ class Comment < ActiveRecord::Base belongs_to :commentable, -> { with_hidden }, polymorphic: true, counter_cache: true belongs_to :user, -> { with_hidden } + before_save :calculate_confidence_score + scope :recent, -> { order(id: :desc) } scope :for_render, -> { with_hidden.includes(user: :organization) } scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } + scope :sort_by_confidence_score , -> { order(confidence_score: :desc) } scope :sort_by_created_at, -> { order(created_at: :desc) } after_create :call_after_commented @@ -88,6 +91,11 @@ class Comment < ActiveRecord::Base 1000 end + def calculate_confidence_score + self.confidence_score = ScoreCalculator.confidence_score(cached_votes_total, + cached_votes_up) + end + private def validate_body_length diff --git a/spec/factories.rb b/spec/factories.rb index eff656edf..ddbb1d072 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -216,6 +216,10 @@ FactoryGirl.define do Flag.flag(FactoryGirl.create(:user), debate) end end + + trait :with_confidence_score do + before(:save) { |d| d.calculate_confidence_score } + end end factory :administrator do diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 6d37eb71b..636bf21a4 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -39,6 +39,44 @@ describe Comment do end end + describe "#confidence_score" do + + it "takes into account percentage of total votes and total_positive and total negative votes" do + comment = create(:comment, :with_confidence_score, cached_votes_up: 100, cached_votes_total: 100) + expect(comment.confidence_score).to eq(10000) + + comment = create(:comment, :with_confidence_score, cached_votes_up: 0, cached_votes_total: 100) + expect(comment.confidence_score).to eq(0) + + comment = create(:comment, :with_confidence_score, cached_votes_up: 75, cached_votes_total: 100) + expect(comment.confidence_score).to eq(3750) + + comment = create(:comment, :with_confidence_score, cached_votes_up: 750, cached_votes_total: 1000) + expect(comment.confidence_score).to eq(37500) + + comment = create(:comment, :with_confidence_score, cached_votes_up: 10, cached_votes_total: 100) + expect(comment.confidence_score).to eq(-800) + end + + describe 'actions which affect it' do + let(:comment) { create(:comment, :with_confidence_score) } + + it "increases with like" do + previous = comment.confidence_score + 5.times { comment.vote_by(voter: create(:user), vote: true) } + expect(previous).to be < comment.confidence_score + end + + it "decreases with dislikes" do + comment.vote_by(voter: create(:user), vote: true) + previous = comment.confidence_score + 3.times { comment.vote_by(voter: create(:user), vote: false) } + expect(previous).to be > comment.confidence_score + end + end + + end + describe "cache" do let(:comment) { create(:comment) } From 4aa364a5610a7fd075c9d56c5c5ca6af38840964 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Oct 2015 17:23:04 +0100 Subject: [PATCH 06/19] Adds a rake task to calculate the confidence score of all the comments in the system --- lib/tasks/comments.rake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/tasks/comments.rake b/lib/tasks/comments.rake index 6c3f32687..61f137156 100644 --- a/lib/tasks/comments.rake +++ b/lib/tasks/comments.rake @@ -6,4 +6,11 @@ namespace :comments do Proposal.all.pluck(:id).each{ |id| Proposal.reset_counters(id, :comments) } end + desc "Recalculates all the comment confidence scores (used for sorting comments)" + task confidence_score: :environment do + Comment.find_in_batches do |comments| + comments.each(&:save) + end + end + end From b2918621ab4b30a6d346d69c76c22130ecf5998b Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Oct 2015 17:33:24 +0100 Subject: [PATCH 07/19] Refactors in children count when rendering comments --- app/helpers/comments_helper.rb | 5 +++++ app/views/comments/_comment.html.erb | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 0f8eca926..7fef232c5 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -17,6 +17,11 @@ module CommentsHelper comments.select{|c| c.parent_id == parent.id} end + def count_children(comments, parent) + return 0 if comments.blank? + comments.count{ |c| c.parent_id == parent.id } + end + def user_level_class(comment) if comment.as_administrator? "is-admin" diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index c353fb499..ac54238a0 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -3,7 +3,7 @@
<% if comment.hidden? || comment.user.hidden? %> - <% if select_children(@comments, comment).size > 0 %> + <% if count_children(@comments, comment) > 0 %>

<%= t("comments.comment.deleted") %>

@@ -73,7 +73,7 @@
- <%= t("comments.comment.responses", count: select_children(@comments, comment).size) %> + <%= t("comments.comment.responses", count: count_children(@comments, comment)) %> <% if user_signed_in? %>  |  From a7daf0108b8cca811550287490aa7a640fe205b5 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Oct 2015 17:34:02 +0100 Subject: [PATCH 08/19] sorts comments by creation date after sorting by confidence_score --- app/models/comment.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 6fdf4d294..9805b55f9 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -19,11 +19,10 @@ class Comment < ActiveRecord::Base before_save :calculate_confidence_score - scope :recent, -> { order(id: :desc) } scope :for_render, -> { with_hidden.includes(user: :organization) } scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } - scope :sort_by_confidence_score , -> { order(confidence_score: :desc) } + scope :sort_by_confidence_score , -> { order(confidence_score: :desc, created_at: :desc) } scope :sort_by_created_at, -> { order(created_at: :desc) } after_create :call_after_commented From d6396b38b6b2185edb56f8aa95e42007d0f0423c Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Oct 2015 17:34:51 +0100 Subject: [PATCH 09/19] Adds missing comments order in management controller --- app/controllers/management/proposals_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/management/proposals_controller.rb b/app/controllers/management/proposals_controller.rb index e6fcc69ea..a8c51edd0 100644 --- a/app/controllers/management/proposals_controller.rb +++ b/app/controllers/management/proposals_controller.rb @@ -7,6 +7,7 @@ class Management::ProposalsController < Management::BaseController before_action :parse_search_terms, only: :index has_orders %w{confidence_score hot_score created_at most_commented random}, only: [:index, :print] + has_orders %w{confidence_score created_at}, only: :show def vote @proposal.register_vote(current_user, 'yes') From 26a9ca58cdab007d274269dbd54ab3601001335b Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Oct 2015 17:35:59 +0100 Subject: [PATCH 10/19] Fixes failing tests which failed due to a new form existing now --- spec/features/comments/debates_spec.rb | 1 - spec/features/comments/proposals_spec.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/spec/features/comments/debates_spec.rb b/spec/features/comments/debates_spec.rb index 82d9708ad..8fc4d1d0b 100644 --- a/spec/features/comments/debates_spec.rb +++ b/spec/features/comments/debates_spec.rb @@ -71,7 +71,6 @@ feature 'Commenting debates' do within('#comments') do expect(page).to_not have_content 'Write a comment' expect(page).to_not have_content 'Reply' - expect(page).to_not have_css('form') end end end diff --git a/spec/features/comments/proposals_spec.rb b/spec/features/comments/proposals_spec.rb index 751329989..9ba74ea81 100644 --- a/spec/features/comments/proposals_spec.rb +++ b/spec/features/comments/proposals_spec.rb @@ -71,7 +71,6 @@ feature 'Commenting proposals' do within('#comments') do expect(page).to_not have_content 'Write a comment' expect(page).to_not have_content 'Reply' - expect(page).to_not have_css('form') end end end From 50fdd005a48c452ef747d3c94cc79c584c5f23eb Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 28 Oct 2015 18:40:32 +0100 Subject: [PATCH 11/19] Implements comment sorting in proposals and debates --- app/controllers/concerns/commentable_actions.rb | 4 ++-- spec/factories.rb | 2 +- spec/features/comments/debates_spec.rb | 16 ++++++++++++++++ spec/features/comments/proposals_spec.rb | 16 ++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index a6ddf7b57..525586f18 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -16,7 +16,7 @@ module CommentableActions def show set_resource_votes(resource) @commentable = resource - @root_comments = resource.comments.roots.recent.page(params[:page]).per(10).for_render + @root_comments = resource.comments.roots.send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render @comments = @root_comments.inject([]){|all, root| all + Comment.descendants_of(root).for_render} @all_visible_comments = @root_comments + @comments @@ -91,4 +91,4 @@ module CommentableActions def index_customization nil end -end \ No newline at end of file +end diff --git a/spec/factories.rb b/spec/factories.rb index ddbb1d072..878627e0d 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -197,7 +197,7 @@ FactoryGirl.define do factory :comment do association :commentable, factory: :debate user - body 'Comment body' + sequence(:body) { |n| "Comment body #{n}" } trait :hidden do hidden_at Time.now diff --git a/spec/features/comments/debates_spec.rb b/spec/features/comments/debates_spec.rb index 8fc4d1d0b..db4b68060 100644 --- a/spec/features/comments/debates_spec.rb +++ b/spec/features/comments/debates_spec.rb @@ -20,6 +20,22 @@ feature 'Commenting debates' do end end + scenario 'Comment order' do + c1 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.now - 2) + c2 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1) + c3 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.now) + + visit debate_path(debate) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) + + visit debate_path(debate, order: :created_at) + + expect(c3.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c1.body) + end + scenario 'Turns links into html links' do create :comment, commentable: debate, body: 'Built with http://rubyonrails.org/' diff --git a/spec/features/comments/proposals_spec.rb b/spec/features/comments/proposals_spec.rb index 9ba74ea81..61ae53d38 100644 --- a/spec/features/comments/proposals_spec.rb +++ b/spec/features/comments/proposals_spec.rb @@ -20,6 +20,22 @@ feature 'Commenting proposals' do end end + scenario 'Comment order' do + c1 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.now - 2) + c2 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1) + c3 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.now) + + visit proposal_path(proposal) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) + + visit proposal_path(proposal, order: :created_at) + + expect(c3.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c1.body) + end + scenario 'Turns links into html links' do create :comment, commentable: proposal, body: 'Built with http://rubyonrails.org/' From bfd89ed15ad1b5086688c7507ea65eba0ec094bc Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 29 Oct 2015 17:36:50 +0100 Subject: [PATCH 12/19] Adds current order to the comments cache in proposals and debates --- app/views/debates/_comments.html.erb | 2 +- app/views/proposals/_comments.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/debates/_comments.html.erb b/app/views/debates/_comments.html.erb index 4c9ad6a69..73405705a 100644 --- a/app/views/debates/_comments.html.erb +++ b/app/views/debates/_comments.html.erb @@ -1,4 +1,4 @@ -<% cache [locale_and_user_status, commentable_cache_key(@debate), @all_visible_comments, @all_visible_comments.map(&:author), @debate.comments_count, @comment_flags] do %> +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@debate), @all_visible_comments, @all_visible_comments.map(&:author), @debate.comments_count, @comment_flags] do %>
diff --git a/app/views/proposals/_comments.html.erb b/app/views/proposals/_comments.html.erb index 6a6868f5c..47713c8d5 100644 --- a/app/views/proposals/_comments.html.erb +++ b/app/views/proposals/_comments.html.erb @@ -1,4 +1,4 @@ -<% cache [locale_and_user_status, commentable_cache_key(@proposal), @all_visible_comments, @all_visible_comments.map(&:author), @proposal.comments_count, @comment_flags] do %> +<% cache [locale_and_user_status, commentable_cache_key(@proposal), @current_order, @all_visible_comments, @all_visible_comments.map(&:author), @proposal.comments_count, @comment_flags] do %>
From 60b3c65b050a68e55a85b61b767f8471b3686f16 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 30 Oct 2015 17:00:32 +0100 Subject: [PATCH 13/19] Refactor comment tree calculation using a PORO --- .../concerns/commentable_actions.rb | 7 ++--- app/helpers/comments_helper.rb | 11 ++------ app/views/comments/_comment.html.erb | 6 ++-- app/views/debates/_comments.html.erb | 6 ++-- app/views/proposals/_comments.html.erb | 6 ++-- lib/comment_tree.rb | 28 +++++++++++++++++++ 6 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 lib/comment_tree.rb diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 525586f18..9eb27226b 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -16,11 +16,8 @@ module CommentableActions def show set_resource_votes(resource) @commentable = resource - @root_comments = resource.comments.roots.send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render - @comments = @root_comments.inject([]){|all, root| all + Comment.descendants_of(root).for_render} - @all_visible_comments = @root_comments + @comments - - set_comment_flags(@all_visible_comments) + @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) + set_comment_flags(@comment_tree.comments) set_resource_instance end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 7fef232c5..9ac29e4da 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -12,14 +12,9 @@ module CommentsHelper parent_id.blank? ? dom_id(commentable) : "comment_#{parent_id}" end - def select_children(comments, parent) - return [] if comments.blank? - comments.select{|c| c.parent_id == parent.id} - end - - def count_children(comments, parent) - return 0 if comments.blank? - comments.count{ |c| c.parent_id == parent.id } + def child_comments_of(parent) + return [] unless @comment_tree + @comment_tree.children_of(parent) end def user_level_class(comment) diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index ac54238a0..1ec571633 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -3,7 +3,7 @@
<% if comment.hidden? || comment.user.hidden? %> - <% if count_children(@comments, comment) > 0 %> + <% if child_comments_of(comment).size > 0 %>

<%= t("comments.comment.deleted") %>

@@ -73,7 +73,7 @@
- <%= t("comments.comment.responses", count: count_children(@comments, comment)) %> + <%= t("comments.comment.responses", count: child_comments_of(comment).size) %> <% if user_signed_in? %>  |  @@ -88,7 +88,7 @@
<% end %>
- <% select_children(@comments, comment).each do |child| %> + <% child_comments_of(comment).each do |child| %> <%= render 'comments/comment', comment: child %> <% end %>
diff --git a/app/views/debates/_comments.html.erb b/app/views/debates/_comments.html.erb index 73405705a..538847a62 100644 --- a/app/views/debates/_comments.html.erb +++ b/app/views/debates/_comments.html.erb @@ -1,4 +1,4 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@debate), @all_visible_comments, @all_visible_comments.map(&:author), @debate.comments_count, @comment_flags] do %> +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@debate), @comment_tree.comments, @comment_tree.comment_authors, @debate.comments_count, @comment_flags] do %>
@@ -21,10 +21,10 @@
<% end %> - <% @root_comments.each do |comment| %> + <% @comment_tree.root_comments.each do |comment| %> <%= render 'comments/comment', comment: comment %> <% end %> - <%= paginate @root_comments %> + <%= paginate @comment_tree.root_comments %>
diff --git a/app/views/proposals/_comments.html.erb b/app/views/proposals/_comments.html.erb index 47713c8d5..eb54f9796 100644 --- a/app/views/proposals/_comments.html.erb +++ b/app/views/proposals/_comments.html.erb @@ -1,4 +1,4 @@ -<% cache [locale_and_user_status, commentable_cache_key(@proposal), @current_order, @all_visible_comments, @all_visible_comments.map(&:author), @proposal.comments_count, @comment_flags] do %> +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@proposal), @comment_tree.comments, @comment_tree.comment_authors, @proposal.comments_count, @comment_flags] do %>
@@ -22,10 +22,10 @@
<% end %> - <% @root_comments.each do |comment| %> + <% @comment_tree.root_comments.each do |comment| %> <%= render 'comments/comment', comment: comment %> <% end %> - <%= paginate @root_comments %> + <%= paginate @comment_tree.root_comments %>
diff --git a/lib/comment_tree.rb b/lib/comment_tree.rb new file mode 100644 index 000000000..818a02006 --- /dev/null +++ b/lib/comment_tree.rb @@ -0,0 +1,28 @@ +class CommentTree + + ROOT_COMMENTS_PER_PAGE = 10 + + attr_accessor :root_comments, :comments + + def initialize(commentable, page, order = 'confidence_score') + @root_comments = commentable.comments.roots.send("sort_by_#{order}").page(page).per(ROOT_COMMENTS_PER_PAGE).for_render + + root_descendants = @root_comments.each_with_object([]) do |root, col| + col += Comment.descendants_of(root).send("sort_by_#{order}").for_render.to_a + end + + @comments = root_comments + root_descendants + + @comments_by_parent_id = @comments.each_with_object({}) do |comment, col| + (col[comment.parent_id] ||= []) << comment + end + end + + def children_of(parent) + @comments_by_parent_id[parent.id] || [] + end + + def comment_authors + comments.map(&:author) + end +end From 0cf592af7133bd38a0b27628a65c8b9a321cc893 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 30 Oct 2015 20:06:36 +0100 Subject: [PATCH 14/19] Fixes two issues in comment_tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * The descendants list for a comment was not being built correctly * The root comments must be ordered “newest first”, but their descendants must be ordered “newest last” --- app/models/comment.rb | 2 ++ lib/comment_tree.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 9805b55f9..bea03a65a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -23,7 +23,9 @@ class Comment < ActiveRecord::Base scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_by_confidence_score , -> { order(confidence_score: :desc, created_at: :desc) } + scope :sort_descendants_by_confidence_score , -> { order(confidence_score: :desc, created_at: :asc) } scope :sort_by_created_at, -> { order(created_at: :desc) } + scope :sort_descendants_by_created_at, -> { order(created_at: :asc) } after_create :call_after_commented diff --git a/lib/comment_tree.rb b/lib/comment_tree.rb index 818a02006..8d0e072dd 100644 --- a/lib/comment_tree.rb +++ b/lib/comment_tree.rb @@ -8,7 +8,7 @@ class CommentTree @root_comments = commentable.comments.roots.send("sort_by_#{order}").page(page).per(ROOT_COMMENTS_PER_PAGE).for_render root_descendants = @root_comments.each_with_object([]) do |root, col| - col += Comment.descendants_of(root).send("sort_by_#{order}").for_render.to_a + col.concat(Comment.descendants_of(root).send("sort_descendants_by_#{order}").for_render.to_a) end @comments = root_comments + root_descendants From ddc8097e7d599d9f2f014ef1b33f32c939167a5b Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 30 Oct 2015 20:28:06 +0100 Subject: [PATCH 15/19] adds feature tests for the descendant comment sorting --- spec/features/comments/debates_spec.rb | 17 +++++++++++++++++ spec/features/comments/proposals_spec.rb | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/spec/features/comments/debates_spec.rb b/spec/features/comments/debates_spec.rb index db4b68060..b077e4773 100644 --- a/spec/features/comments/debates_spec.rb +++ b/spec/features/comments/debates_spec.rb @@ -36,6 +36,23 @@ feature 'Commenting debates' do expect(c2.body).to appear_before(c1.body) end + scenario 'Creation date works differently in roots and in child comments, even when sorting by confidence_score' do + old_root = create(:comment, commentable: debate, created_at: Time.now - 10) + new_root = create(:comment, commentable: debate, created_at: Time.now) + old_child = create(:comment, commentable: debate, parent_id: new_root.id, created_at: Time.now - 10) + new_child = create(:comment, commentable: debate, parent_id: new_root.id, created_at: Time.now) + + visit debate_path(debate) + + expect(new_root.body).to appear_before(old_root.body) + expect(old_child.body).to appear_before(new_child.body) + + visit debate_path(debate, order: :created_at) + + expect(new_root.body).to appear_before(old_root.body) + expect(old_child.body).to appear_before(new_child.body) + end + scenario 'Turns links into html links' do create :comment, commentable: debate, body: 'Built with http://rubyonrails.org/' diff --git a/spec/features/comments/proposals_spec.rb b/spec/features/comments/proposals_spec.rb index 61ae53d38..a706bcfaa 100644 --- a/spec/features/comments/proposals_spec.rb +++ b/spec/features/comments/proposals_spec.rb @@ -20,7 +20,7 @@ feature 'Commenting proposals' do end end - scenario 'Comment order' do + scenario 'Comment order' do c1 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.now - 2) c2 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1) c3 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.now) @@ -36,6 +36,23 @@ feature 'Commenting proposals' do expect(c2.body).to appear_before(c1.body) end + scenario 'Creation date works differently in roots and in child comments, even when sorting by confidence_score' do + old_root = create(:comment, commentable: proposal, created_at: Time.now - 10) + new_root = create(:comment, commentable: proposal, created_at: Time.now) + old_child = create(:comment, commentable: proposal, parent_id: new_root.id, created_at: Time.now - 10) + new_child = create(:comment, commentable: proposal, parent_id: new_root.id, created_at: Time.now) + + visit proposal_path(proposal) + + expect(new_root.body).to appear_before(old_root.body) + expect(old_child.body).to appear_before(new_child.body) + + visit proposal_path(proposal, order: :created_at) + + expect(new_root.body).to appear_before(old_root.body) + expect(old_child.body).to appear_before(new_child.body) + end + scenario 'Turns links into html links' do create :comment, commentable: proposal, body: 'Built with http://rubyonrails.org/' From 8dd60b47f649f3ee89f0f6adb3ff172b5f752e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baz=C3=A1n?= Date: Sun, 1 Nov 2015 15:24:55 +0100 Subject: [PATCH 16/19] removes duplicated file --- app/views/shared/_wide_order_selector.rb | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 app/views/shared/_wide_order_selector.rb diff --git a/app/views/shared/_wide_order_selector.rb b/app/views/shared/_wide_order_selector.rb deleted file mode 100644 index 883205493..000000000 --- a/app/views/shared/_wide_order_selector.rb +++ /dev/null @@ -1,16 +0,0 @@ -<% # Params: - # - # i18n_namespace: for example "moderation.debates.index" -%> - -
- - -
From 73c306a673cffd481fc9c52c0b14a1bc6b37e491 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 2 Nov 2015 14:01:29 +0100 Subject: [PATCH 17/19] Adds 3 orders for comments: most_voted, newest, oldest --- app/controllers/debates_controller.rb | 2 +- app/controllers/proposals_controller.rb | 2 +- app/models/comment.rb | 13 +++++++++---- config/locales/en.yml | 5 +++-- config/locales/es.yml | 5 +++-- spec/features/comments/debates_spec.rb | 18 ++++++++++++++---- spec/features/comments/proposals_spec.rb | 20 +++++++++++++++----- 7 files changed, 46 insertions(+), 19 deletions(-) diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 1b1184f59..8a5def88b 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -7,7 +7,7 @@ class DebatesController < ApplicationController before_action :authenticate_user!, except: [:index, :show] has_orders %w{hot_score confidence_score created_at most_commented random}, only: :index - has_orders %w{confidence_score created_at}, only: :show + has_orders %w{most_voted newest oldest}, only: :show load_and_authorize_resource respond_to :html, :js diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 50b436e58..1be046b7a 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -7,7 +7,7 @@ class ProposalsController < ApplicationController before_action :authenticate_user!, except: [:index, :show] has_orders %w{hot_score confidence_score created_at most_commented random}, only: :index - has_orders %w{confidence_score created_at}, only: :show + has_orders %w{most_voted newest oldest}, only: :show load_and_authorize_resource respond_to :html, :js diff --git a/app/models/comment.rb b/app/models/comment.rb index bea03a65a..f486850a6 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -22,10 +22,15 @@ class Comment < ActiveRecord::Base scope :for_render, -> { with_hidden.includes(user: :organization) } scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } - scope :sort_by_confidence_score , -> { order(confidence_score: :desc, created_at: :desc) } - scope :sort_descendants_by_confidence_score , -> { order(confidence_score: :desc, created_at: :asc) } - scope :sort_by_created_at, -> { order(created_at: :desc) } - scope :sort_descendants_by_created_at, -> { order(created_at: :asc) } + + scope :sort_by_most_voted , -> { order(confidence_score: :desc, created_at: :desc) } + scope :sort_descendants_by_most_voted , -> { order(confidence_score: :desc, created_at: :asc) } + + scope :sort_by_newest, -> { order(created_at: :desc) } + scope :sort_descendants_by_newest, -> { order(created_at: :desc) } + + scope :sort_by_oldest, -> { order(created_at: :asc) } + scope :sort_descendants_by_oldest, -> { order(created_at: :asc) } after_create :call_after_commented diff --git a/config/locales/en.yml b/config/locales/en.yml index 715b12d33..2d963f3be 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -241,8 +241,9 @@ en: comments: select_order: "Sort by" orders: - confidence_score: "Most voted" - created_at: "Newest" + most_voted: "Most voted" + newest: "Newest first" + oldest: "Oldest first" form: leave_comment: "Leave your comment" comment_as_moderator: "Comment as moderator" diff --git a/config/locales/es.yml b/config/locales/es.yml index 96ea81c10..34871cce8 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -241,8 +241,9 @@ es: comments: select_order: "Ordenar por" orders: - confidence_score: "Más votados" - created_at: "Más nuevos" + most_voted: "Más votados" + newest: "Más nuevos primero" + oldest: "Más antiguos primero" form: leave_comment: "Deja tu comentario" comment_as_moderator: "Comentar como moderador" diff --git a/spec/features/comments/debates_spec.rb b/spec/features/comments/debates_spec.rb index cd00e98f8..ca9a33eb8 100644 --- a/spec/features/comments/debates_spec.rb +++ b/spec/features/comments/debates_spec.rb @@ -25,15 +25,20 @@ feature 'Commenting debates' do c2 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1) c3 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.now) - visit debate_path(debate) + visit debate_path(debate, order: :most_voted) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) - visit debate_path(debate, order: :created_at) + visit debate_path(debate, order: :newest) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) + + visit debate_path(debate, order: :oldest) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) end scenario 'Creation date works differently in roots and in child comments, even when sorting by confidence_score' do @@ -42,14 +47,19 @@ feature 'Commenting debates' do old_child = create(:comment, commentable: debate, parent_id: new_root.id, created_at: Time.now - 10) new_child = create(:comment, commentable: debate, parent_id: new_root.id, created_at: Time.now) - visit debate_path(debate) + visit debate_path(debate, order: :most_voted) expect(new_root.body).to appear_before(old_root.body) expect(old_child.body).to appear_before(new_child.body) - visit debate_path(debate, order: :created_at) + visit debate_path(debate, order: :newest) expect(new_root.body).to appear_before(old_root.body) + expect(new_child.body).to appear_before(old_child.body) + + visit debate_path(debate, order: :oldest) + + expect(old_root.body).to appear_before(new_root.body) expect(old_child.body).to appear_before(new_child.body) end diff --git a/spec/features/comments/proposals_spec.rb b/spec/features/comments/proposals_spec.rb index 90b6f7d02..1c277cf4d 100644 --- a/spec/features/comments/proposals_spec.rb +++ b/spec/features/comments/proposals_spec.rb @@ -25,31 +25,41 @@ feature 'Commenting proposals' do c2 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.now - 1) c3 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.now) - visit proposal_path(proposal) + visit proposal_path(proposal, order: :most_voted) expect(c1.body).to appear_before(c2.body) expect(c2.body).to appear_before(c3.body) - visit proposal_path(proposal, order: :created_at) + visit proposal_path(proposal, order: :newest) expect(c3.body).to appear_before(c2.body) expect(c2.body).to appear_before(c1.body) + + visit proposal_path(proposal, order: :oldest) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) end - scenario 'Creation date works differently in roots and in child comments, even when sorting by confidence_score' do + scenario 'Creation date works differently in roots and in child comments, when sorting by confidence_score' do old_root = create(:comment, commentable: proposal, created_at: Time.now - 10) new_root = create(:comment, commentable: proposal, created_at: Time.now) old_child = create(:comment, commentable: proposal, parent_id: new_root.id, created_at: Time.now - 10) new_child = create(:comment, commentable: proposal, parent_id: new_root.id, created_at: Time.now) - visit proposal_path(proposal) + visit proposal_path(proposal, order: :most_voted) expect(new_root.body).to appear_before(old_root.body) expect(old_child.body).to appear_before(new_child.body) - visit proposal_path(proposal, order: :created_at) + visit proposal_path(proposal, order: :newest) expect(new_root.body).to appear_before(old_root.body) + expect(new_child.body).to appear_before(old_child.body) + + visit proposal_path(proposal, order: :oldest) + + expect(old_root.body).to appear_before(new_root.body) expect(old_child.body).to appear_before(new_child.body) end From f0e90053322919837f09f3d826e7fec46848f55e Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 2 Nov 2015 14:01:40 +0100 Subject: [PATCH 18/19] Adds missing spec to comment --- spec/models/comment_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 636bf21a4..cb2c61181 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -111,4 +111,10 @@ describe Comment do .to change { [comment.reload.updated_at, comment.author.updated_at] } end end + + describe "#author_id?" do + it "returns the user's id" do + expect(comment.author_id).to eq(comment.user.id) + end + end end From cf31e892044d7dcdd88b6675ed2e2cce0ab27ae2 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 2 Nov 2015 15:54:15 +0100 Subject: [PATCH 19/19] Fixes issues in moderation spex related with comment sort --- app/controllers/management/proposals_controller.rb | 2 +- app/controllers/moderation/comments_controller.rb | 2 +- config/locales/moderation.en.yml | 2 +- config/locales/moderation.es.yml | 2 +- spec/features/management/proposals_spec.rb | 2 +- spec/features/moderation/comments_spec.rb | 10 +++++----- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/management/proposals_controller.rb b/app/controllers/management/proposals_controller.rb index a8c51edd0..4d96af093 100644 --- a/app/controllers/management/proposals_controller.rb +++ b/app/controllers/management/proposals_controller.rb @@ -7,7 +7,7 @@ class Management::ProposalsController < Management::BaseController before_action :parse_search_terms, only: :index has_orders %w{confidence_score hot_score created_at most_commented random}, only: [:index, :print] - has_orders %w{confidence_score created_at}, only: :show + has_orders %w{most_voted newest}, only: :show def vote @proposal.register_vote(current_user, 'yes') diff --git a/app/controllers/moderation/comments_controller.rb b/app/controllers/moderation/comments_controller.rb index cf3197383..d5fbf7954 100644 --- a/app/controllers/moderation/comments_controller.rb +++ b/app/controllers/moderation/comments_controller.rb @@ -2,7 +2,7 @@ class Moderation::CommentsController < Moderation::BaseController include ModerateActions has_filters %w{pending_flag_review all with_ignored_flag}, only: :index - has_orders %w{flags created_at}, only: :index + has_orders %w{flags newest}, only: :index before_action :load_resources, only: [:index, :moderate] diff --git a/config/locales/moderation.en.yml b/config/locales/moderation.en.yml index b66ffd136..5c85ebf69 100755 --- a/config/locales/moderation.en.yml +++ b/config/locales/moderation.en.yml @@ -24,7 +24,7 @@ en: with_ignored_flag: "Marked as viewed" order: "Order" orders: - created_at: "Newest" + newest: "Newest" flags: "Most flagged" confirm: "Are you sure?" debates: diff --git a/config/locales/moderation.es.yml b/config/locales/moderation.es.yml index 6b4a64692..d99a48877 100644 --- a/config/locales/moderation.es.yml +++ b/config/locales/moderation.es.yml @@ -24,7 +24,7 @@ es: with_ignored_flag: "Marcados como revisados" order: "Orden" orders: - created_at: "Más nuevos" + newest: "Más nuevos" flags: "Más denunciados" confirm: "¿Estás seguro?" debates: diff --git a/spec/features/management/proposals_spec.rb b/spec/features/management/proposals_spec.rb index e33c1a179..ffab09f55 100644 --- a/spec/features/management/proposals_spec.rb +++ b/spec/features/management/proposals_spec.rb @@ -197,4 +197,4 @@ feature 'Proposals' do end end -end \ No newline at end of file +end diff --git a/spec/features/moderation/comments_spec.rb b/spec/features/moderation/comments_spec.rb index 1774a1585..4a7249042 100644 --- a/spec/features/moderation/comments_spec.rb +++ b/spec/features/moderation/comments_spec.rb @@ -104,15 +104,15 @@ feature 'Moderate comments' do scenario "remembering page, filter and order" do create_list(:comment, 52) - visit moderation_comments_path(filter: 'all', page: '2', order: 'created_at') + visit moderation_comments_path(filter: 'all', page: '2', order: 'newest') click_on "Mark as viewed" - expect(page).to have_selector('.js-order-selector[data-order="created_at"]') + expect(page).to have_selector('.js-order-selector[data-order="newest"]') expect(current_url).to include('filter=all') expect(current_url).to include('page=2') - expect(current_url).to include('order=created_at') + expect(current_url).to include('order=newest') end end @@ -174,7 +174,7 @@ feature 'Moderate comments' do create(:comment, body: "Flagged newer comment", created_at: Time.now - 12.hours, flags_count: 3) create(:comment, body: "Newer comment", created_at: Time.now) - visit moderation_comments_path(order: 'created_at') + visit moderation_comments_path(order: 'newest') expect("Flagged newer comment").to appear_before("Flagged comment") @@ -182,7 +182,7 @@ feature 'Moderate comments' do expect("Flagged comment").to appear_before("Flagged newer comment") - visit moderation_comments_path(filter: 'all', order: 'created_at') + visit moderation_comments_path(filter: 'all', order: 'newest') expect("Newer comment").to appear_before("Flagged newer comment") expect("Flagged newer comment").to appear_before("Flagged comment")