Fix statistics_presenter_spec
This commit is contained in:
parent
309e690a66
commit
66c2f7f869
3 changed files with 22 additions and 9 deletions
|
|
@ -17,8 +17,8 @@ class StatisticsPresenter
|
|||
if AppConfig.privacy.statistics.comment_counts?
|
||||
result['local_comments'] = self.local_comments
|
||||
end
|
||||
AppConfig.services.each do |service, options|
|
||||
result[service] = AppConfig["services.#{service}.enable"]
|
||||
Configuration::KNOWN_SERVICES.each do |service, options|
|
||||
result[service.to_s] = AppConfig["services.#{service}.enable"]
|
||||
end
|
||||
|
||||
result
|
||||
|
|
@ -31,5 +31,5 @@ class StatisticsPresenter
|
|||
def local_comments
|
||||
Comment.joins(:author).where("owner_id IS NOT null").count
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
module Configuration
|
||||
KNOWN_SERVICES = [:twitter, :tumblr, :facebook, :wordpress].freeze
|
||||
|
||||
module Methods
|
||||
def pod_uri
|
||||
return @pod_uri unless @pod_uri.nil?
|
||||
|
|
@ -24,7 +26,7 @@ module Configuration
|
|||
return @configured_services unless @configured_services.nil?
|
||||
|
||||
@configured_services = []
|
||||
[:twitter, :tumblr, :facebook, :wordpress].each do |service|
|
||||
KNOWN_SERVICES.each do |service|
|
||||
@configured_services << service if services.send(service).enable?
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,17 @@ describe StatisticsPresenter do
|
|||
end
|
||||
|
||||
describe '#statistics contents' do
|
||||
|
||||
it 'provides generic pod data in json' do
|
||||
before do
|
||||
AppConfig.privacy.statistics.user_counts = false
|
||||
AppConfig.privacy.statistics.post_counts = false
|
||||
AppConfig.privacy.statistics.comment_counts = false
|
||||
end
|
||||
|
||||
after do
|
||||
AppConfig.privacy = nil
|
||||
end
|
||||
|
||||
it 'provides generic pod data in json' do
|
||||
expect(@presenter.as_json).to eq({
|
||||
"name" => AppConfig.settings.pod_name,
|
||||
"version" => AppConfig.version_string,
|
||||
|
|
@ -28,20 +34,25 @@ describe StatisticsPresenter do
|
|||
"wordpress" => false,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
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},
|
||||
"facebook" => {"enable" => true},
|
||||
"twitter" => {"enable" => true},
|
||||
"wordpress" => {"enable" => false},
|
||||
"tumblr" => {"enable" => false}
|
||||
}
|
||||
end
|
||||
|
||||
after do
|
||||
AppConfig.services = nil
|
||||
AppConfig.privacy = nil
|
||||
end
|
||||
|
||||
it 'provides generic pod data and counts in json' do
|
||||
expect(@presenter.as_json).to eq({
|
||||
"name" => AppConfig.settings.pod_name,
|
||||
|
|
|
|||
Loading…
Reference in a new issue