-
-
-
<%= t "admin.stats.show.stats_title" %>
-
-
-
-
- <%= t "stats.index.visits" %>
- <%= number_with_delimiter(@visits) %>
-
-
-
- <%= t "stats.index.debates" %>
- <%= number_with_delimiter(@debates) %>
-
-
- <%= t "stats.index.proposals" %>
- <%= number_with_delimiter(@proposals) %>
-
-
- <%= t "stats.index.comments" %>
- <%= number_with_delimiter(@comments) %>
-
-
-
-
-
- <%= t "stats.index.proposal_votes" %>
- <%= number_with_delimiter(@proposal_votes) %>
-
-
-
- <%= t "stats.index.debate_votes" %>
- <%= number_with_delimiter(@debate_votes) %>
-
-
-
- <%= t "stats.index.comment_votes" %>
- <%= number_with_delimiter(@comment_votes) %>
-
-
-
- <%= t "stats.index.votes" %>
- <%= number_with_delimiter(@votes) %>
-
-
-
-
-
- <%= t "stats.index.verified_users" %>
- <%= number_with_delimiter(@verified_users) %>
-
-
-
- <%= t "stats.index.unverified_users" %>
- <%= number_with_delimiter(@unverified_users) %>
-
-
-
-
-
-
diff --git a/app/views/stats/index.json.erb b/app/views/stats/index.json.erb
deleted file mode 100644
index c2c27702f..000000000
--- a/app/views/stats/index.json.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "<%= t("stats.index.visits") %>" : "<%= number_with_delimiter(@visits) %>",
- "<%= t("stats.index.debates") %>" : "<%= number_with_delimiter(@debates) %>",
- "<%= t("stats.index.proposals") %>" : "<%= number_with_delimiter(@proposals) %>",
- "<%= t("stats.index.comments") %>" : "<%= number_with_delimiter(@comments) %>",
- "<%= t("stats.index.proposal_votes") %>" : "<%= number_with_delimiter(@proposal_votes) %>",
- "<%= t("stats.index.debate_votes") %>" : "<%= number_with_delimiter(@debate_votes) %>",
- "<%= t("stats.index.comment_votes") %>" : "<%= number_with_delimiter(@comment_votes) %>",
- "<%= t("stats.index.votes") %>" : "<%= number_with_delimiter(@votes) %>",
- "<%= t("stats.index.verified_users") %>" : "<%= number_with_delimiter(@verified_users) %>",
- "<%= t("stats.index.unverified_users") %>" : "<%= number_with_delimiter(@unverified_users) %>"
-}
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index c1b8d651e..66ff65ea1 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -1480,7 +1480,6 @@ en:
verified_users_who_didnt_vote_proposals: Verified users who didn't votes proposals
visits: Visits
votes: Total votes
- budgets_title: Participatory budgeting
participatory_budgets: Participatory Budgets
direct_messages: Direct messages
proposal_notifications: Proposal notifications
@@ -1488,10 +1487,15 @@ en:
polls: Polls
sdg: SDG
graph:
- debate_created: Debates
- visit: Visits
- level_2_user: Level 2 users
- proposal_created: Citizen proposals
+ budget_investment_created: Budget investments created
+ budget_investment_supported: Budget investments supported
+ debate_created: Debates created
+ legislation_annotation_created: Legislation annotations created
+ legislation_answer_created: Legislation answers created
+ level_3_user: Level 3 users verified
+ proposal_created: Citizen proposals created
+ title: Graphs
+ visits: Visits
budgets:
no_data_before_balloting_phase: "There isn't any data to show before the balloting phase."
title: "Participatory Budgets - Participation stats"
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index f8c76bb55..755d67391 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -761,18 +761,6 @@ en:
youtube: "%{org} YouTube"
telegram: "%{org} Telegram"
instagram: "%{org} Instagram"
- stats:
- index:
- visits: Visits
- debates: Debates
- proposals: Proposals
- comments: Comments
- proposal_votes: Votes on proposals
- debate_votes: Votes on debates
- comment_votes: Votes on comments
- votes: Total votes
- verified_users: Verified users
- unverified_users: Unverified users
unauthorized:
default: You do not have permission to access this page.
manage:
diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml
index de6059657..d1efc19a6 100644
--- a/config/locales/en/settings.yml
+++ b/config/locales/en/settings.yml
@@ -116,8 +116,6 @@ en:
allow_attached_documents_description: "Allows users to upload documents when creating proposals and investment projects from Participatory Budgets"
guides: "Guides to create proposals or investment projects"
guides_description: "Displays a guide to differences between proposals and investment projects if there is an active participatory budget"
- public_stats: "Public stats"
- public_stats_description: "Display public stats in the Administration panel"
help_page: "Help page"
help_page_description: 'Displays a Help menu that contains a page with an info section about each enabled feature. Also custom pages and menus can be created in the "Custom pages" and "Custom content blocks" sections'
remote_translations: "Remote translation"
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index e0b9ce808..81297a548 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -1480,7 +1480,6 @@ es:
verified_users_who_didnt_vote_proposals: Usuarios verificados que no han votado propuestas
visits: Visitas
votes: Votos
- budgets_title: Presupuestos participativos
participatory_budgets: Presupuestos Participativos
direct_messages: Mensajes directos
proposal_notifications: Notificaciones de propuestas
@@ -1488,10 +1487,15 @@ es:
polls: Votaciones
sdg: ODS
graph:
- debate_created: Debates
+ budget_investment_created: Proyectos de gasto creados
+ budget_investment_supported: Proyectos de gasto apoyados
+ debate_created: Debates creados
+ legislation_annotation_created: Anotaciones creadas
+ legislation_answer_created: Repuestas de legislación colaborativa creadas
+ level_3_user: Usuarios de nivel 3 verificados
+ proposal_created: Propuestas Ciudadanas creadas
+ title: Gráficos
visit: Visitas
- level_2_user: Usuarios nivel 2
- proposal_created: Propuestas Ciudadanas
budgets:
no_data_before_balloting_phase: "No hay datos que mostrar hasta que la fase de votación no esté abierta."
title: "Presupuestos participativos - Estadisticas de participación"
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index 507ee7701..d8b03580f 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -761,18 +761,6 @@ es:
youtube: "YouTube de %{org}"
telegram: "Telegram de %{org}"
instagram: "Instagram de %{org}"
- stats:
- index:
- visits: Visitas
- debates: Debates
- proposals: Propuestas ciudadanas
- comments: Comentarios
- proposal_votes: Votos en propuestas
- debate_votes: Votos en debates
- comment_votes: Votos en comentarios
- votes: Votos
- verified_users: Usuarios verificados
- unverified_users: Usuarios sin verificar
unauthorized:
default: No tienes permiso para acceder a esta página.
manage:
diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml
index 08d0b3ae8..13261a050 100644
--- a/config/locales/es/settings.yml
+++ b/config/locales/es/settings.yml
@@ -116,8 +116,6 @@ es:
allow_attached_documents_description: "Permite que los usuarios suban documentos al crear propuestas y proyectos de gasto de los Presupuestos participativos"
guides: "Guías para crear propuestas o proyectos de inversión"
guides_description: "Muestra una guía de diferencias entre las propuestas y los proyectos de gasto si hay un presupuesto participativo activo"
- public_stats: "Estadísticas públicas"
- public_stats_description: "Muestra las estadísticas públicas en el panel de Administración"
help_page: "Página de ayuda"
help_page_description: 'Muestra un menú Ayuda que contiene una página con una sección de información sobre cada funcionalidad habilitada. También se pueden crear páginas y menús personalizados en las secciones "Personalizar páginas" y "Personalizar bloques"'
remote_translations: "Traducciones remotas"
diff --git a/config/routes.rb b/config/routes.rb
index 29a4083c6..3d64fe247 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -32,7 +32,6 @@ Rails.application.routes.draw do
get "/consul.json", to: "installation#details"
get "robots.txt", to: "robots#index"
- resources :stats, only: [:index]
resources :images, only: [:destroy]
resources :documents, only: [:destroy]
resources :follows, only: [:create, :destroy]
diff --git a/config/routes/admin.rb b/config/routes/admin.rb
index 5ffbf5eba..4e72dae01 100644
--- a/config/routes/admin.rb
+++ b/config/routes/admin.rb
@@ -241,10 +241,6 @@ namespace :admin do
end
end
- namespace :api do
- resource :stats, only: :show
- end
-
resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy]
namespace :site_customization do
diff --git a/spec/components/admin/stats/chart_component_spec.rb b/spec/components/admin/stats/chart_component_spec.rb
new file mode 100644
index 000000000..c6d0bdafb
--- /dev/null
+++ b/spec/components/admin/stats/chart_component_spec.rb
@@ -0,0 +1,13 @@
+require "rails_helper"
+
+describe Admin::Stats::ChartComponent do
+ it "renders a tag with JSON data" do
+ create(:user, :level_three, verified_at: "2009-09-09")
+ chart = Ahoy::Chart.new(:level_3_user)
+
+ render_inline Admin::Stats::ChartComponent.new(chart)
+
+ expect(page).to have_css "h2", exact_text: "Level 3 users verified (1)"
+ expect(page).to have_css "[data-graph='{\"x\":[\"2009-09-09\"],\"Level 3 users verified\":[1]}']"
+ end
+end
diff --git a/spec/components/admin/stats/event_links_component_spec.rb b/spec/components/admin/stats/event_links_component_spec.rb
new file mode 100644
index 000000000..489f22e1d
--- /dev/null
+++ b/spec/components/admin/stats/event_links_component_spec.rb
@@ -0,0 +1,16 @@
+require "rails_helper"
+
+describe Admin::Stats::EventLinksComponent do
+ it "renders a list of links" do
+ render_inline Admin::Stats::EventLinksComponent.new(
+ %w[legislation_annotation_created legislation_answer_created]
+ )
+
+ expect(page).to have_link count: 2
+
+ page.find("ul") do |list|
+ expect(list).to have_link "Legislation annotations created"
+ expect(list).to have_link "Legislation answers created"
+ end
+ end
+end
diff --git a/spec/components/admin/stats/global_chart_component_spec.rb b/spec/components/admin/stats/global_chart_component_spec.rb
new file mode 100644
index 000000000..8d8eb63d6
--- /dev/null
+++ b/spec/components/admin/stats/global_chart_component_spec.rb
@@ -0,0 +1,18 @@
+require "rails_helper"
+
+describe Admin::Stats::GlobalChartComponent do
+ before do
+ allow(Ahoy::Chart).to receive(:active_event_names).and_return(
+ %i[budget_investment_created level_3_user]
+ )
+ end
+
+ it "renders an
tag with a graph and links" do
+ render_inline Admin::Stats::GlobalChartComponent.new
+
+ expect(page).to have_css "h2", exact_text: "Graphs"
+ expect(page).to have_css "[data-graph]"
+ expect(page).to have_link "Budget investments created"
+ expect(page).to have_link "Level 3 users verified"
+ end
+end
diff --git a/spec/components/admin/stats/sdg_component_spec.rb b/spec/components/admin/stats/sdg_component_spec.rb
new file mode 100644
index 000000000..2f222b44f
--- /dev/null
+++ b/spec/components/admin/stats/sdg_component_spec.rb
@@ -0,0 +1,11 @@
+require "rails_helper"
+
+describe Admin::Stats::SDGComponent do
+ include Rails.application.routes.url_helpers
+
+ it "renders a links to go back to the admin stats index" do
+ render_inline Admin::Stats::SDGComponent.new(SDG::Goal.all)
+
+ expect(page).to have_link "Go back", href: admin_stats_path
+ end
+end
diff --git a/spec/controllers/admin/api/stats_controller_spec.rb b/spec/controllers/admin/api/stats_controller_spec.rb
deleted file mode 100644
index ee9fd7605..000000000
--- a/spec/controllers/admin/api/stats_controller_spec.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-require "rails_helper"
-
-describe Admin::Api::StatsController, :admin do
- describe "GET index" do
- context "events or visits not present" do
- it "responds with bad_request" do
- get :show
-
- expect(response).not_to be_ok
- expect(response).to have_http_status 400
- end
- end
-
- context "events present" do
- before do
- time_1 = Time.zone.local(2015, 01, 01)
- time_2 = Time.zone.local(2015, 01, 02)
- time_3 = Time.zone.local(2015, 01, 03)
-
- create(:ahoy_event, name: "foo", time: time_1)
- create(:ahoy_event, name: "foo", time: time_1)
- create(:ahoy_event, name: "foo", time: time_2)
- create(:ahoy_event, name: "bar", time: time_1)
- create(:ahoy_event, name: "bar", time: time_3)
- create(:ahoy_event, name: "bar", time: time_3)
- end
-
- it "returns single events formated for working with c3.js" do
- get :show, params: { event: "foo" }
-
- expect(response).to be_ok
- expect(response.parsed_body).to eq "x" => ["2015-01-01", "2015-01-02"], "Foo" => [2, 1]
- end
- end
-
- context "visits present" do
- it "returns visits formated for working with c3.js" do
- time_1 = Time.zone.local(2015, 01, 01)
- time_2 = Time.zone.local(2015, 01, 02)
-
- create(:visit, started_at: time_1)
- create(:visit, started_at: time_1)
- create(:visit, started_at: time_2)
-
- get :show, params: { visits: true }
-
- expect(response).to be_ok
- expect(response.parsed_body).to eq "x" => ["2015-01-01", "2015-01-02"], "Visits" => [2, 1]
- end
- end
-
- context "budget investments present" do
- it "returns budget investments formated for working with c3.js" do
- time_1 = Time.zone.local(2017, 04, 01)
- time_2 = Time.zone.local(2017, 04, 02)
-
- create(:budget_investment, created_at: time_1)
- create(:budget_investment, created_at: time_2)
- create(:budget_investment, created_at: time_2)
-
- get :show, params: { budget_investments: true }
-
- expect(response).to be_ok
- expect(response.parsed_body).to eq "x" => ["2017-04-01", "2017-04-02"], "Budget Investments" => [1, 2]
- end
- end
- end
-end
diff --git a/spec/controllers/debates_controller_spec.rb b/spec/controllers/debates_controller_spec.rb
index c3d96dcea..a9ed78059 100644
--- a/spec/controllers/debates_controller_spec.rb
+++ b/spec/controllers/debates_controller_spec.rb
@@ -9,34 +9,6 @@ describe DebatesController do
end
end
- describe "POST create" do
- before do
- InvisibleCaptcha.timestamp_enabled = false
- end
-
- after do
- InvisibleCaptcha.timestamp_enabled = true
- end
-
- it "creates an ahoy event" do
- debate_attributes = {
- terms_of_service: "1",
- translations_attributes: {
- "0" => {
- title: "A sample debate",
- description: "this is a sample debate",
- locale: "en"
- }
- }
- }
- sign_in create(:user)
-
- post :create, params: { debate: debate_attributes }
- expect(Ahoy::Event.where(name: :debate_created).count).to eq 1
- expect(Ahoy::Event.last.properties["debate_id"]).to eq Debate.last.id
- end
- end
-
describe "PUT mark_featured" do
it "ignores query parameters" do
debate = create(:debate)
diff --git a/spec/controllers/legislation/annotations_controller_spec.rb b/spec/controllers/legislation/annotations_controller_spec.rb
index 575e9626d..cbefc4721 100644
--- a/spec/controllers/legislation/annotations_controller_spec.rb
+++ b/spec/controllers/legislation/annotations_controller_spec.rb
@@ -36,27 +36,6 @@ describe Legislation::AnnotationsController do
end
let(:user) { create(:user, :level_two) }
- it "creates an ahoy event" do
- sign_in user
-
- post :create, params: {
- process_id: legal_process.id,
- draft_version_id: draft_version.id,
- legislation_annotation: {
- "quote" => "ipsum",
- "ranges" => [{
- "start" => "/p[1]",
- "startOffset" => 6,
- "end" => "/p[1]",
- "endOffset" => 11
- }],
- "text" => "una anotacion"
- }
- }
- expect(Ahoy::Event.where(name: :legislation_annotation_created).count).to eq 1
- expect(Ahoy::Event.last.properties["legislation_annotation_id"]).to eq Legislation::Annotation.last.id
- end
-
it "does not create an annotation if the draft version is a final version" do
sign_in user
diff --git a/spec/controllers/legislation/answers_controller_spec.rb b/spec/controllers/legislation/answers_controller_spec.rb
index 04bc21dce..11dc1bc2a 100644
--- a/spec/controllers/legislation/answers_controller_spec.rb
+++ b/spec/controllers/legislation/answers_controller_spec.rb
@@ -10,20 +10,6 @@ describe Legislation::AnswersController do
let(:question_option) { create(:legislation_question_option, question: question, value: "Yes") }
let(:user) { create(:user, :level_two) }
- it "creates an ahoy event" do
- sign_in user
-
- post :create, params: {
- process_id: legal_process.id,
- question_id: question.id,
- legislation_answer: {
- legislation_question_option_id: question_option.id
- }
- }
- expect(Ahoy::Event.where(name: :legislation_answer_created).count).to eq 1
- expect(Ahoy::Event.last.properties["legislation_answer_id"]).to eq Legislation::Answer.last.id
- end
-
it "creates an answer if the process debate phase is open" do
sign_in user
diff --git a/spec/factories/analytics.rb b/spec/factories/analytics.rb
index bc7fa2654..8afd58ffa 100644
--- a/spec/factories/analytics.rb
+++ b/spec/factories/analytics.rb
@@ -1,17 +1,6 @@
FactoryBot.define do
- factory :ahoy_event, class: "Ahoy::Event" do
- id { SecureRandom.uuid }
- time { DateTime.current }
- sequence(:name) { |n| "Event #{n} type" }
- end
-
factory :visit do
id { SecureRandom.uuid }
started_at { DateTime.current }
end
-
- factory :campaign do
- sequence(:name) { |n| "Campaign #{n}" }
- sequence(:track_id, &:to_s)
- end
end
diff --git a/spec/models/ahoy/chart_spec.rb b/spec/models/ahoy/chart_spec.rb
new file mode 100644
index 000000000..e69d9d13e
--- /dev/null
+++ b/spec/models/ahoy/chart_spec.rb
@@ -0,0 +1,106 @@
+require "rails_helper"
+
+describe Ahoy::Chart do
+ describe ".active_events_data_points" do
+ it "groups several events together" do
+ create(:budget_investment, created_at: "2010-01-01")
+ create(:budget_investment, created_at: "2010-01-02")
+ create(:legislation_annotation, created_at: "2010-01-01")
+ create(:legislation_annotation, created_at: "2010-01-03")
+
+ expect(Ahoy::Chart.active_events_data_points).to eq({
+ x: ["2010-01-01", "2010-01-02", "2010-01-03"],
+ "Budget investments created" => [1, 1, 0],
+ "Legislation annotations created" => [1, 0, 1]
+ })
+ end
+
+ it "sorts events alphabetically" do
+ create(:budget_investment, created_at: "2010-01-01")
+ create(:legislation_annotation, created_at: "2010-01-01")
+
+ I18n.with_locale(:es) do
+ expect(Ahoy::Chart.active_events_data_points.keys).to eq([
+ :x,
+ "Anotaciones creadas",
+ "Proyectos de gasto creados"
+ ])
+ end
+ end
+ end
+
+ describe "#data_points" do
+ it "raises an exception for unknown events" do
+ chart = Ahoy::Chart.new(:mystery)
+
+ expect { chart.data_points }.to raise_exception "Unknown event mystery"
+ end
+
+ it "returns data associated with the event" do
+ time_1 = Time.zone.local(2015, 01, 01)
+ time_2 = Time.zone.local(2015, 01, 02)
+ time_3 = Time.zone.local(2015, 01, 03)
+
+ create(:proposal, created_at: time_1)
+ create(:proposal, created_at: time_1)
+ create(:proposal, created_at: time_2)
+ create(:debate, created_at: time_1)
+ create(:debate, created_at: time_3)
+
+ chart = Ahoy::Chart.new(:proposal_created)
+
+ expect(chart.data_points).to eq x: ["2015-01-01", "2015-01-02"],
+ "Citizen proposals created" => [2, 1]
+ end
+
+ it "accepts strings as the event name" do
+ create(:proposal, created_at: Time.zone.local(2015, 01, 01))
+ create(:debate, created_at: Time.zone.local(2015, 01, 02))
+
+ chart = Ahoy::Chart.new("proposal_created")
+
+ expect(chart.data_points).to eq x: ["2015-01-01"], "Citizen proposals created" => [1]
+ end
+
+ it "returns visits data for the visits event" do
+ time_1 = Time.zone.local(2015, 01, 01)
+ time_2 = Time.zone.local(2015, 01, 02)
+
+ create(:visit, started_at: time_1)
+ create(:visit, started_at: time_1)
+ create(:visit, started_at: time_2)
+
+ chart = Ahoy::Chart.new(:visits)
+
+ expect(chart.data_points).to eq x: ["2015-01-01", "2015-01-02"], "Visits" => [2, 1]
+ end
+
+ it "returns user supports for the budget_investment_supported event" do
+ time_1 = Time.zone.local(2017, 04, 01)
+ time_2 = Time.zone.local(2017, 04, 02)
+
+ create(:vote, votable: create(:budget_investment), created_at: time_1)
+ create(:vote, votable: create(:budget_investment), created_at: time_2)
+ create(:vote, votable: create(:budget_investment), created_at: time_2)
+ create(:vote, votable: create(:proposal), created_at: time_2)
+
+ chart = Ahoy::Chart.new(:budget_investment_supported)
+
+ expect(chart.data_points).to eq x: ["2017-04-01", "2017-04-02"],
+ "Budget investments supported" => [1, 2]
+ end
+
+ it "returns level three verified dates for the level_3_user event" do
+ time_1 = Time.zone.local(2001, 01, 01)
+ time_2 = Time.zone.local(2001, 01, 02)
+
+ create(:user, :level_two, level_two_verified_at: time_1)
+ create(:user, :level_three, verified_at: time_2)
+ create(:user, :level_three, verified_at: time_2, level_two_verified_at: time_1)
+
+ chart = Ahoy::Chart.new(:level_3_user)
+
+ expect(chart.data_points).to eq x: ["2001-01-02"], "Level 3 users verified" => [2]
+ end
+ end
+end
diff --git a/spec/models/ahoy/data_source_spec.rb b/spec/models/ahoy/data_source_spec.rb
index df8d2756d..185ba6a11 100644
--- a/spec/models/ahoy/data_source_spec.rb
+++ b/spec/models/ahoy/data_source_spec.rb
@@ -2,18 +2,9 @@ require "rails_helper"
describe Ahoy::DataSource do
describe "#build" do
- before do
- time_1 = Time.zone.local(2015, 01, 01)
- time_2 = Time.zone.local(2015, 01, 02)
- time_3 = Time.zone.local(2015, 01, 03)
-
- create(:ahoy_event, name: "foo", time: time_1)
- create(:ahoy_event, name: "foo", time: time_1)
- create(:ahoy_event, name: "foo", time: time_2)
- create(:ahoy_event, name: "bar", time: time_1)
- create(:ahoy_event, name: "bar", time: time_3)
- create(:ahoy_event, name: "bar", time: time_3)
- end
+ let(:january_first) { Time.zone.local(2015, 01, 01) }
+ let(:january_second) { Time.zone.local(2015, 01, 02) }
+ let(:january_third) { Time.zone.local(2015, 01, 03) }
it "works without data sources" do
ds = Ahoy::DataSource.new
@@ -22,17 +13,27 @@ describe Ahoy::DataSource do
it "works with single data sources" do
ds = Ahoy::DataSource.new
- ds.add "foo", Ahoy::Event.where(name: "foo").group_by_day(:time).count
+ ds.add "foo", { january_first => 2, january_second => 1 }
expect(ds.build).to eq :x => ["2015-01-01", "2015-01-02"], "foo" => [2, 1]
end
it "combines data sources" do
ds = Ahoy::DataSource.new
- ds.add "foo", Ahoy::Event.where(name: "foo").group_by_day(:time).count
- ds.add "bar", Ahoy::Event.where(name: "bar").group_by_day(:time).count
+ ds.add "foo", { january_first => 2, january_second => 1 }
+ ds.add "bar", { january_first => 1, january_third => 2 }
expect(ds.build).to eq :x => ["2015-01-01", "2015-01-02", "2015-01-03"],
"foo" => [2, 1, 0],
"bar" => [1, 0, 2]
end
+
+ it "returns data ordered by dates" do
+ ds = Ahoy::DataSource.new
+ ds.add "foo", { january_third => 2, january_second => 1 }
+ ds.add "bar", { january_first => 2, january_second => 1 }
+
+ expect(ds.build).to eq :x => ["2015-01-01", "2015-01-02", "2015-01-03"],
+ "foo" => [0, 1, 2],
+ "bar" => [2, 1, 0]
+ end
end
end
diff --git a/spec/system/admin/stats_spec.rb b/spec/system/admin/stats_spec.rb
index fe6103b75..88c77cf2d 100644
--- a/spec/system/admin/stats_spec.rb
+++ b/spec/system/admin/stats_spec.rb
@@ -72,18 +72,6 @@ describe "Stats", :admin do
expect(page).to have_content "UNVERIFIED USERS\n1"
expect(page).to have_content "TOTAL USERS\n1"
end
-
- scenario "Level 2 user Graph" do
- create(:geozone)
- visit account_path
- click_link "Verify my account"
- verify_residence
- confirm_phone
-
- visit admin_stats_path
-
- expect(page).to have_content "LEVEL TWO USERS\n1"
- end
end
describe "Budget investments" do
@@ -150,21 +138,30 @@ describe "Stats", :admin do
end
end
- context "graphs" do
- scenario "event graphs", :with_frozen_time do
- campaign = create(:campaign)
-
- visit root_path(track_id: campaign.track_id)
-
- expect(page).to have_content "Sign out"
+ describe "graphs", :with_frozen_time do
+ scenario "event graphs" do
+ create(:debate)
visit admin_stats_path
within("#stats") do
- click_link campaign.name
+ click_link "Debates created"
end
- expect(page).to have_content "#{campaign.name} (1)"
+ expect(page).to have_content "Debates created (1)"
+
+ within("#graph") do
+ expect(page).to have_content Date.current.strftime("%Y-%m-%d")
+ end
+ end
+
+ scenario "Level 3 user Graph" do
+ create(:user, :level_three)
+
+ visit admin_stats_path
+ click_link "Level 3 users verified"
+
+ expect(page).to have_content "Level 3 users verified (1)"
within("#graph") do
expect(page).to have_content Date.current.strftime("%Y-%m-%d")
@@ -183,6 +180,8 @@ describe "Stats", :admin do
visit admin_stats_path
click_link "Proposal notifications"
+ expect(page).to have_link "Go back", href: admin_stats_path
+
within("#proposal_notifications_count") do
expect(page).to have_content "3"
end
@@ -232,6 +231,8 @@ describe "Stats", :admin do
visit admin_stats_path
click_link "Direct messages"
+ expect(page).to have_link "Go back", href: admin_stats_path
+
within("#direct_messages_count") do
expect(page).to have_content "3"
end
@@ -253,6 +254,8 @@ describe "Stats", :admin do
click_link "Polls"
end
+ expect(page).to have_link "Go back", href: admin_stats_path
+
within("#web_participants") do
expect(page).to have_content "3"
end
diff --git a/spec/system/campaigns_spec.rb b/spec/system/campaigns_spec.rb
deleted file mode 100644
index 7fe4b6afe..000000000
--- a/spec/system/campaigns_spec.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-require "rails_helper"
-
-describe "Email campaigns", :admin do
- let!(:campaign1) { create(:campaign) }
- let!(:campaign2) { create(:campaign) }
-
- scenario "Track email templates" do
- 3.times { visit root_path(track_id: campaign1.track_id) }
- 5.times { visit root_path(track_id: campaign2.track_id) }
-
- visit admin_stats_path
- click_link campaign1.name
-
- expect(page).to have_content "#{campaign1.name} (3)"
-
- click_link "Go back"
- click_link campaign2.name
-
- expect(page).to have_content "#{campaign2.name} (5)"
- end
-
- scenario "Do not track erroneous track_ids" do
- invalid_id = Campaign.last.id + 1
-
- visit root_path(track_id: campaign1.track_id)
- visit root_path(track_id: invalid_id)
-
- visit admin_stats_path
-
- expect(page).to have_content campaign1.name
- expect(page).not_to have_content campaign2.name
-
- click_link campaign1.name
-
- expect(page).to have_content "#{campaign1.name} (1)"
- end
-end
diff --git a/spec/system/notifications_spec.rb b/spec/system/notifications_spec.rb
index 379aaed3a..c79cf239e 100644
--- a/spec/system/notifications_spec.rb
+++ b/spec/system/notifications_spec.rb
@@ -164,23 +164,25 @@ describe "Notifications" do
end
scenario "With internal link" do
- admin_notification.update!(link: "/stats")
+ admin_notification.update!(link: "/debates")
visit notifications_path
expect(page).to have_content("Notification title")
expect(page).to have_content("Notification body")
first("#notification_#{notification.id} a").click
- expect(page).to have_current_path("/stats")
+
+ expect(page).to have_current_path "/debates"
end
scenario "Without a link" do
- admin_notification.update!(link: "/stats")
+ admin_notification.update!(link: nil)
visit notifications_path
- expect(page).to have_content("Notification title")
- expect(page).to have_content("Notification body")
- expect(page).not_to have_link(notification_path(notification), visible: :all)
+
+ expect(page).to have_content "Notification title"
+ expect(page).to have_content "Notification body"
+ expect(page).not_to have_link href: notification_path(notification), visible: :all
end
end
diff --git a/spec/system/stats_spec.rb b/spec/system/stats_spec.rb
deleted file mode 100644
index 595f737d2..000000000
--- a/spec/system/stats_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require "rails_helper"
-
-describe "Stats" do
- context "Summary" do
- scenario "General" do
- create(:debate)
- 2.times { create(:proposal) }
- 3.times { create(:comment, commentable: Debate.first) }
- 4.times { create(:visit) }
-
- visit stats_path
-
- expect(page).to have_content "DEBATES\n1"
- expect(page).to have_content "PROPOSALS\n2"
- expect(page).to have_content "COMMENTS\n3"
- expect(page).to have_content "VISITS\n4"
- end
-
- scenario "Votes" do
- create(:debate, voters: Array.new(1) { create(:user) })
- create(:proposal, voters: Array.new(2) { create(:user) })
- create(:comment, voters: Array.new(3) { create(:user) })
-
- visit stats_path
-
- expect(page).to have_content "VOTES ON DEBATES\n1"
- expect(page).to have_content "VOTES ON PROPOSALS\n2"
- expect(page).to have_content "VOTES ON COMMENTS\n3"
- expect(page).to have_content "TOTAL VOTES\n6"
- end
-
- scenario "Users" do
- 1.times { create(:user, :level_three) }
- 2.times { create(:user, :level_two) }
- 2.times { create(:user) }
-
- visit stats_path
-
- expect(page).to have_content "VERIFIED USERS\n3"
- expect(page).to have_content "UNVERIFIED USERS\n2"
- end
- end
-end