diaspora/spec/presenters/statistics_presenter_spec.rb
Jason Robinson 7c0e50c2c2 Introduce 'authorized' configuration option for services
Since the Facebook API has changed and additional permissions are required for all users on a pod to cross-post, an additional 'authorized' flag is needed to be set for the Facebook service.
This flag allows either all users, one user or no users to use the cross-posting service.

Clarifies the situation for #5923, #5260 and #5085.

closes #5985
2015-05-25 04:18:38 +02:00

138 lines
4.4 KiB
Ruby

require "spec_helper"
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" => ["facebook"],
"facebook" => true,
"tumblr" => false,
"twitter" => false,
"wordpress" => false
)
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),
"facebook" => true,
"twitter" => true,
"tumblr" => false,
"wordpress" => false
)
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"],
"facebook" => false,
"twitter" => true,
"tumblr" => false,
"wordpress" => false
)
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" => ["facebook"],
"facebook" => true,
"twitter" => false,
"tumblr" => false,
"wordpress" => false
)
end
end
context "when registrations are closed" do
before do
AppConfig.settings.enable_registrations = false
end
it "should mark open_registrations to be false" do
expect(@presenter.open_registrations?).to be false
end
end
end
end