Rename age_groups method
The name was confusing because it seemed to return a list of age groups.
This commit is contained in:
@@ -55,7 +55,11 @@ module Statisticable
|
||||
[80, 84],
|
||||
[85, 89],
|
||||
[90, 300]
|
||||
].map do |start, finish|
|
||||
]
|
||||
end
|
||||
|
||||
def participants_by_age
|
||||
age_groups.map do |start, finish|
|
||||
users = participants.where("date_of_birth > ? AND date_of_birth < ?",
|
||||
finish.years.ago.beginning_of_year,
|
||||
start.years.ago.end_of_year)
|
||||
@@ -90,7 +94,7 @@ module Statisticable
|
||||
def stats_methods
|
||||
%i[total_participants total_male_participants
|
||||
total_female_participants total_unknown_gender_or_age
|
||||
male_percentage female_percentage age_groups]
|
||||
male_percentage female_percentage participants_by_age]
|
||||
end
|
||||
|
||||
def stats_cache(*method_names)
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @stats[:age_groups].values.each do |group| %>
|
||||
<% @stats[:participants_by_age].values.each do |group| %>
|
||||
<tr>
|
||||
<td><%= group[:range] %></td>
|
||||
<td>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% stats[:age_groups].values.each do |group| %>
|
||||
<% stats[:participants_by_age].values.each do |group| %>
|
||||
<tr>
|
||||
<td><%= group[:range] %></td>
|
||||
<td>
|
||||
|
||||
@@ -148,21 +148,21 @@ describe Budget::Stats do
|
||||
|
||||
end
|
||||
|
||||
context "#age_groups" do
|
||||
context "#participants_by_age" do
|
||||
|
||||
it "returns the age groups hash" do
|
||||
expect(stats[:age_groups]["16 - 19"][:count]).to be 0
|
||||
expect(stats[:age_groups]["20 - 24"][:count]).to be 7
|
||||
expect(stats[:age_groups]["25 - 29"][:count]).to be 1
|
||||
expect(stats[:age_groups]["30 - 34"][:count]).to be 0
|
||||
expect(stats[:age_groups]["35 - 39"][:count]).to be 1
|
||||
expect(stats[:age_groups]["40 - 44"][:count]).to be 1
|
||||
expect(stats[:age_groups]["45 - 49"][:count]).to be 0
|
||||
expect(stats[:age_groups]["50 - 54"][:count]).to be 1
|
||||
expect(stats[:age_groups]["55 - 59"][:count]).to be 0
|
||||
expect(stats[:age_groups]["60 - 64"][:count]).to be 0
|
||||
expect(stats[:age_groups]["65 - 69"][:count]).to be 0
|
||||
expect(stats[:age_groups]["70 - 74"][:count]).to be 0
|
||||
expect(stats[:participants_by_age]["16 - 19"][:count]).to be 0
|
||||
expect(stats[:participants_by_age]["20 - 24"][:count]).to be 7
|
||||
expect(stats[:participants_by_age]["25 - 29"][:count]).to be 1
|
||||
expect(stats[:participants_by_age]["30 - 34"][:count]).to be 0
|
||||
expect(stats[:participants_by_age]["35 - 39"][:count]).to be 1
|
||||
expect(stats[:participants_by_age]["40 - 44"][:count]).to be 1
|
||||
expect(stats[:participants_by_age]["45 - 49"][:count]).to be 0
|
||||
expect(stats[:participants_by_age]["50 - 54"][:count]).to be 1
|
||||
expect(stats[:participants_by_age]["55 - 59"][:count]).to be 0
|
||||
expect(stats[:participants_by_age]["60 - 64"][:count]).to be 0
|
||||
expect(stats[:participants_by_age]["65 - 69"][:count]).to be 0
|
||||
expect(stats[:participants_by_age]["70 - 74"][:count]).to be 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user