diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb
index fe224eb8d..5802ee9e9 100644
--- a/app/controllers/stats_controller.rb
+++ b/app/controllers/stats_controller.rb
@@ -3,7 +3,7 @@ class StatsController < ApplicationController
skip_authorization_check
def show
- @event_types = Ahoy::Event.select(:name).uniq.pluck(:name)
+ @event_types = Ahoy::Event.group(:name).count
end
private
diff --git a/app/controllers/verification/sms_controller.rb b/app/controllers/verification/sms_controller.rb
index 8b4d24b9f..9f282c2c9 100644
--- a/app/controllers/verification/sms_controller.rb
+++ b/app/controllers/verification/sms_controller.rb
@@ -27,6 +27,7 @@ class Verification::SmsController < ApplicationController
@sms = Verification::Sms.new(sms_params.merge(user: current_user))
if @sms.verify?
current_user.update(confirmed_phone: current_user.unconfirmed_phone)
+ ahoy.track :level_2_user, user_id: current_user.id
if VerifiedUser.phone?(current_user)
current_user.update(verified_at: Time.now)
diff --git a/app/views/stats/show.html.erb b/app/views/stats/show.html.erb
index f5df82b98..da366aa1a 100644
--- a/app/views/stats/show.html.erb
+++ b/app/views/stats/show.html.erb
@@ -10,13 +10,13 @@
Combined
- <%= events_chart_tag @event_types, id: 'combined' %>
+ <%= events_chart_tag @event_types.keys, id: 'combined' %>
- <% @event_types.each do |event_type| %>
-
<%= event_type.titleize %>
- <%= events_chart_tag event_type %>
+ <% @event_types.each do |event, count| %>
+ <%= event.titleize %> (<%= count %>)
+ <%= events_chart_tag event %>
<% end %>
diff --git a/spec/features/stats_spec.rb b/spec/features/stats_spec.rb
new file mode 100644
index 000000000..2363e3ff6
--- /dev/null
+++ b/spec/features/stats_spec.rb
@@ -0,0 +1,21 @@
+require 'rails_helper'
+
+feature 'Stats' do
+
+ scenario 'Level 2 user' do
+ admin = create(:administrator)
+ user = create(:user)
+ login_as(user)
+
+ visit account_path
+ click_link 'Verify my account'
+ verify_residence
+ confirm_phone
+
+ login_as(admin.user)
+ visit stats_path
+
+ expect(page).to have_content "Level 2 User (1)"
+ end
+
+end
\ No newline at end of file
diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb
index 4753abbbb..c1d382b4e 100644
--- a/spec/support/common_actions.rb
+++ b/spec/support/common_actions.rb
@@ -110,4 +110,17 @@ module CommonActions
click_button 'Verify residence'
expect(page).to have_content 'Residence verified'
end
+
+ def confirm_phone
+ fill_in 'sms_phone', with: "611111111"
+ click_button 'Send'
+
+ expect(page).to have_content 'Security code confirmation'
+
+ user = User.last.reload
+ fill_in 'sms_confirmation_code', with: user.sms_confirmation_code
+ click_button 'Send'
+
+ expect(page).to have_content 'Correct code'
+ end
end