Include hidden users in stats
If users participated and were hidden after participating, we should still count them in the participants stats. In the tests, we set users' `hidden_at` attribute before they vote. Although in real life they would vote first and then they would be hidden, I've written the tests like this for the sake of simplicity.
This commit is contained in:
@@ -34,7 +34,7 @@ module Statisticable
|
||||
end
|
||||
|
||||
def participants
|
||||
User.where(id: participant_ids)
|
||||
User.unscoped.where(id: participant_ids)
|
||||
end
|
||||
|
||||
def total_male_participants
|
||||
|
||||
@@ -7,10 +7,10 @@ describe Budget::Stats do
|
||||
|
||||
describe "#participants" do
|
||||
let(:author) { investment.author }
|
||||
let(:author_and_voter) { create(:user) }
|
||||
let(:author_and_voter) { create(:user, hidden_at: Time.current) }
|
||||
let(:voter) { create(:user) }
|
||||
let(:voter_and_balloter) { create(:user) }
|
||||
let(:balloter) { create(:user) }
|
||||
let(:balloter) { create(:user, hidden_at: Time.current) }
|
||||
let(:poll_balloter) { create(:user, :level_two) }
|
||||
let(:non_participant) { create(:user, :level_two) }
|
||||
|
||||
@@ -29,7 +29,7 @@ describe Budget::Stats do
|
||||
create(:poll_voter, :from_booth, user: non_participant, budget: create(:budget))
|
||||
end
|
||||
|
||||
it "returns unique participants, including authors" do
|
||||
it "returns unique participants, including authors and hidden users" do
|
||||
expect(stats.participants).to match_array(
|
||||
[author, author_and_voter, voter, voter_and_balloter, balloter, poll_balloter]
|
||||
)
|
||||
|
||||
@@ -4,6 +4,15 @@ describe Poll::Stats do
|
||||
let(:poll) { create(:poll) }
|
||||
let(:stats) { Poll::Stats.new(poll) }
|
||||
|
||||
describe "#participants" do
|
||||
it "includes hidden users" do
|
||||
create(:poll_voter, poll: poll)
|
||||
create(:poll_voter, poll: poll, user: create(:user, :level_two, hidden_at: Time.current))
|
||||
|
||||
expect(stats.participants.count).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
describe "total participants" do
|
||||
before { allow(stats).to receive(:total_web_white).and_return(1) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user