Extract method to get vote counts by votable type
This commit is contained in:
@@ -7,9 +7,9 @@ class Admin::StatsController < Admin::BaseController
|
|||||||
@proposals = Proposal.with_hidden.count
|
@proposals = Proposal.with_hidden.count
|
||||||
@comments = Comment.not_valuations.with_hidden.count
|
@comments = Comment.not_valuations.with_hidden.count
|
||||||
|
|
||||||
@debate_votes = Vote.where(votable_type: "Debate").count
|
@debate_votes = Vote.count_for("Debate")
|
||||||
@proposal_votes = Vote.where(votable_type: "Proposal").count
|
@proposal_votes = Vote.count_for("Proposal")
|
||||||
@comment_votes = Vote.where(votable_type: "Comment").count
|
@comment_votes = Vote.count_for("Comment")
|
||||||
|
|
||||||
@votes = Vote.count
|
@votes = Vote.count
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ class StatsController < ApplicationController
|
|||||||
@proposals = daily_cache("proposals") { Proposal.with_hidden.count }
|
@proposals = daily_cache("proposals") { Proposal.with_hidden.count }
|
||||||
@comments = daily_cache("comments") { Comment.not_valuations.with_hidden.count }
|
@comments = daily_cache("comments") { Comment.not_valuations.with_hidden.count }
|
||||||
|
|
||||||
@debate_votes = daily_cache("debate_votes") { Vote.where(votable_type: "Debate").count }
|
@debate_votes = daily_cache("debate_votes") { Vote.count_for("Debate") }
|
||||||
@proposal_votes = daily_cache("proposal_votes") { Vote.where(votable_type: "Proposal").count }
|
@proposal_votes = daily_cache("proposal_votes") { Vote.count_for("Proposal") }
|
||||||
@comment_votes = daily_cache("comment_votes") { Vote.where(votable_type: "Comment").count }
|
@comment_votes = daily_cache("comment_votes") { Vote.count_for("Comment") }
|
||||||
@investment_votes = daily_cache("budget_investment_votes") { Vote.where(votable_type: "Budget::Investment").count }
|
@investment_votes = daily_cache("budget_investment_votes") { Vote.count_for("Budget::Investment") }
|
||||||
@votes = daily_cache("votes") { Vote.count }
|
@votes = daily_cache("votes") { Vote.count }
|
||||||
|
|
||||||
@verified_users = daily_cache("verified_users") { User.with_hidden.level_two_or_three_verified.count }
|
@verified_users = daily_cache("verified_users") { User.with_hidden.level_two_or_three_verified.count }
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ ActsAsVotable::Vote.class_eval do
|
|||||||
where(votable: [Debate.public_for_api, Proposal.public_for_api, Comment.public_for_api])
|
where(votable: [Debate.public_for_api, Proposal.public_for_api, Comment.public_for_api])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.count_for(votable_type)
|
||||||
|
where(votable_type: votable_type).count
|
||||||
|
end
|
||||||
|
|
||||||
def value
|
def value
|
||||||
vote_flag
|
vote_flag
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Vote do
|
describe Vote do
|
||||||
|
describe ".count_for" do
|
||||||
|
it "returns the number of records for a votable type" do
|
||||||
|
3.times { create(:vote, votable: create(:debate)) }
|
||||||
|
2.times { create(:vote, votable: create(:proposal)) }
|
||||||
|
|
||||||
|
expect(Vote.count_for("Debate")).to eq 3
|
||||||
|
expect(Vote.count_for("Proposal")).to eq 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#value" do
|
describe "#value" do
|
||||||
it "returns vote flag" do
|
it "returns vote flag" do
|
||||||
vote = create(:vote, vote_flag: true)
|
vote = create(:vote, vote_flag: true)
|
||||||
|
|||||||
Reference in New Issue
Block a user