diff --git a/app/models/comment.rb b/app/models/comment.rb index 824f1dbf0..a9dc68505 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -49,7 +49,15 @@ class Comment < ActiveRecord::Base end def total_votes - votes_for.size + cached_votes_total + end + + def total_likes + cached_votes_up + end + + def total_dislikes + cached_votes_down end def not_visible? diff --git a/app/views/comments/_votes.html.erb b/app/views/comments/_votes.html.erb index 73efa56ba..d7af65bff 100644 --- a/app/views/comments/_votes.html.erb +++ b/app/views/comments/_votes.html.erb @@ -1,5 +1,4 @@ - <%= t('debates.comment.votes', count: comment.total_votes) %>  |  @@ -8,7 +7,7 @@ method: "post", remote: true do %> <% end %> - <%= comment.get_likes.size %> + <%= comment.total_likes %> @@ -16,5 +15,5 @@ method: "post", remote: true do %> <% end %> - <%= comment.get_dislikes.size %> + <%= comment.total_dislikes %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 279b2a00e..e3ebf62d6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -61,7 +61,6 @@ en: zero: No votes one: 1 vote other: "%{count} votes" - votes_weighted_score: "Total: %{score}" form: debate_title: Debate title title_instructions: "SBe clear and precise with the title, but make it informative" diff --git a/config/locales/es.yml b/config/locales/es.yml index 98c463b1e..4097c22b9 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -61,7 +61,6 @@ es: zero: Sin votos one: 1 voto other: "%{count} votos" - votes_weighted_score: "Total: %{score}" form: debate_title: Título del debate title_instructions: "Sé claro y conciso a la hora de poner un título, pero recuerda que debe explicar bien tu idea, ¡es tu carta de entrada!" diff --git a/spec/factories.rb b/spec/factories.rb index 4fa2a70e3..0a4922411 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -37,6 +37,9 @@ FactoryGirl.define do association :votable, factory: :debate association :voter, factory: :user vote_flag true + after(:create) do |vote, _| + vote.votable.update_cached_votes + end end factory :comment do