Remove statistics.json

This commit is contained in:
Steffen van Bergerem 2017-03-27 15:12:58 +02:00
parent d9b02418b6
commit e8ee74ef87
No known key found for this signature in database
GPG key ID: 315C9787D548DC6B
4 changed files with 1 additions and 177 deletions

View file

@ -1,7 +1,4 @@
class NodeInfoController < ApplicationController
respond_to :json
respond_to :html, only: :statistics
def jrd
render json: NodeInfo.jrd(CGI.unescape(node_info_url("123.123").sub("123.123", "%{version}")))
end
@ -16,9 +13,6 @@ class NodeInfoController < ApplicationController
end
def statistics
respond_to do |format|
format.json { render json: StatisticsPresenter.new }
format.all { @statistics = NodeInfoPresenter.new("1.0") }
end
@statistics = NodeInfoPresenter.new("1.0")
end
end

View file

@ -1,49 +0,0 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
# TODO: Drop after 0.6
class StatisticsPresenter < NodeInfoPresenter
def initialize
super("1.0")
end
def as_json(_options={})
base_data.merge(user_counts)
.merge(post_counts)
.merge(comment_counts)
end
def base_data
{
"name" => name,
"network" => "Diaspora",
"version" => version,
"registrations_open" => open_registrations?,
"services" => available_services
}
end
def user_counts
return {} unless expose_user_counts?
{
"total_users" => total_users,
"active_users_monthly" => monthly_users,
"active_users_halfyear" => halfyear_users
}
end
def post_counts
return {} unless expose_posts_counts?
{
"local_posts" => local_posts
}
end
def comment_counts
return {} unless expose_comment_counts?
{
"local_comments" => local_comments
}
end
end

View file

@ -51,17 +51,6 @@ describe NodeInfoController do
end
describe "#statistics" do
it "responds to format json" do
get :statistics, format: "json"
expect(response.code).to eq("200")
end
it "contains json" do
get :statistics, format: "json"
json = JSON.parse(response.body)
expect(json["name"]).to be_present
end
it "responds to html" do
get :statistics, format: "html"
expect(response.code).to eq("200")

View file

@ -1,110 +0,0 @@
describe StatisticsPresenter do
before do
@presenter = StatisticsPresenter.new
end
describe "#as_json" do
it "works" do
expect(@presenter.as_json).to be_present
expect(@presenter.as_json).to be_a Hash
end
end
describe "#statistics contents" do
before do
AppConfig.privacy.statistics.user_counts = false
AppConfig.privacy.statistics.post_counts = false
AppConfig.privacy.statistics.comment_counts = false
end
it "provides generic pod data in json" do
expect(@presenter.as_json).to eq(
"name" => AppConfig.settings.pod_name,
"network" => "Diaspora",
"version" => AppConfig.version_string,
"registrations_open" => AppConfig.settings.enable_registrations?,
"services" => AppConfig.configured_services.map(&:to_s)
)
end
context "when services are enabled" do
before do
AppConfig.services = {
"facebook" => {
"enable" => true,
"authorized" => true
},
"twitter" => {"enable" => true},
"wordpress" => {"enable" => false},
"tumblr" => {
"enable" => true,
"authorized" => false
}
}
end
it "provides services in json" do
expect(@presenter.as_json).to eq(
"name" => AppConfig.settings.pod_name,
"network" => "Diaspora",
"version" => AppConfig.version_string,
"registrations_open" => AppConfig.settings.enable_registrations?,
"services" => %w(twitter facebook)
)
end
end
context "when some services are set to username authorized" do
before do
AppConfig.services = {
"facebook" => {
"enable" => true,
"authorized" => "bob"
},
"twitter" => {"enable" => true},
"wordpress" => {
"enable" => true,
"authorized" => "alice"
},
"tumblr" => {
"enable" => true,
"authorized" => false
}
}
end
it "provides services in json" do
expect(@presenter.as_json).to eq(
"name" => AppConfig.settings.pod_name,
"network" => "Diaspora",
"version" => AppConfig.version_string,
"registrations_open" => AppConfig.settings.enable_registrations?,
"services" => ["twitter"]
)
end
end
context "when counts are enabled" do
before do
AppConfig.privacy.statistics.user_counts = true
AppConfig.privacy.statistics.post_counts = true
AppConfig.privacy.statistics.comment_counts = true
end
it "provides generic pod data and counts in json" do
expect(@presenter.as_json).to eq(
"name" => AppConfig.settings.pod_name,
"network" => "Diaspora",
"version" => AppConfig.version_string,
"registrations_open" => AppConfig.settings.enable_registrations?,
"total_users" => User.active.count,
"active_users_halfyear" => User.halfyear_actives.count,
"active_users_monthly" => User.monthly_actives.count,
"local_posts" => @presenter.local_posts,
"local_comments" => @presenter.local_comments,
"services" => AppConfig.configured_services.map(&:to_s)
)
end
end
end
end