diff --git a/app/presenters/statistics_presenter.rb b/app/presenters/statistics_presenter.rb index 88f378c786ce2bce3ca28f557e24c4e1d6b469f0..e07dcc6e008ed91aa3bd05d7f47863198fe6af7c 100644 --- a/app/presenters/statistics_presenter.rb +++ b/app/presenters/statistics_presenter.rb @@ -17,9 +17,15 @@ class StatisticsPresenter if AppConfig.privacy.statistics.comment_counts? result['local_comments'] = self.local_comments end + + AppConfig.services.each do |service, options| + result[service] = options ? !!options["enable"] : false + + end + result end - + def local_posts Post.where(:type => "StatusMessage").joins(:author).where("owner_id IS NOT null").count end diff --git a/spec/presenters/statistics_presenter_spec.rb b/spec/presenters/statistics_presenter_spec.rb index 786b0750c0add0a530f4a84beffea855f3c74e47..e1d17103bf1eaac3c94f8f1bf5368122eac35a39 100644 --- a/spec/presenters/statistics_presenter_spec.rb +++ b/spec/presenters/statistics_presenter_spec.rb @@ -18,28 +18,44 @@ describe StatisticsPresenter do AppConfig.privacy.statistics.user_counts = false AppConfig.privacy.statistics.post_counts = false AppConfig.privacy.statistics.comment_counts = false + AppConfig.services = {"facebook" => nil} @presenter.as_json.should == { "name" => AppConfig.settings.pod_name, "version" => AppConfig.version_string, - "registrations_open" => AppConfig.settings.enable_registrations + "registrations_open" => AppConfig.settings.enable_registrations, + "facebook" => false } end - it 'provides generic pod data and counts in json' do - AppConfig.privacy.statistics.user_counts = true - AppConfig.privacy.statistics.post_counts = true - AppConfig.privacy.statistics.comment_counts = true + context 'when services are enabled' do + before do + AppConfig.privacy.statistics.user_counts = true + AppConfig.privacy.statistics.post_counts = true + AppConfig.privacy.statistics.comment_counts = true + AppConfig.services = { + "facebook" => {"enable" => true}, + "twitter" => {"enable" => true}, + "wordpress" => {"enable" => false}, + "tumblr" => {"enable" => false} + } + end - @presenter.as_json.should == { - "name" => AppConfig.settings.pod_name, - "version" => AppConfig.version_string, - "registrations_open" => AppConfig.settings.enable_registrations, - "total_users" => User.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 - } + it 'provides generic pod data and counts in json' do + @presenter.as_json.should == { + "name" => AppConfig.settings.pod_name, + "version" => AppConfig.version_string, + "registrations_open" => AppConfig.settings.enable_registrations, + "total_users" => User.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, + "facebook" => true, + "twitter" => true, + "tumblr" => false, + "wordpress" => false + } + end end end