Commit 50224f9e312feedf027bd9fdfaf4a5491966bddf

Authored by Luke Baker
1 parent 5b4c64ce

add site_stats API call

CHANGELOG.md
  1 + * Add site_stats call to API
1 2 * Fix bug in response user_generated_ideas totals over time, where the min and max dates were getting added as strings instead of date objects
2 3 * Update choices to act_as_versioned
3 4  
... ...
app/controllers/questions_controller.rb
... ... @@ -326,6 +326,21 @@ class QuestionsController < InheritedResources::Base
326 326 update!
327 327 end
328 328  
  329 + def site_stats
  330 + results = Question.connection.select_one("SELECT COUNT(*) as total_questions, SUM(votes_count) as votes_count, SUM(choices_count) choices_count FROM questions where site_id = #{current_user.id}")
  331 + results.each do |key, value|
  332 + results[key] = value.to_i
  333 + end
  334 + respond_to do |format|
  335 + format.xml {
  336 + render :xml => results.to_xml
  337 + }
  338 + format.js{
  339 + render :json => results.to_json
  340 + }
  341 + end
  342 + end
  343 +
329 344 def index
330 345  
331 346 counts = {}
... ...
config/routes.rb
... ... @@ -14,6 +14,7 @@ ActionController::Routing::Routes.draw do |map|
14 14 :export => :post} ,
15 15 :collection => {:all_num_votes_by_visitor_id => :get,
16 16 :all_object_info_totals_by_date => :get,
  17 + :site_stats => :get,
17 18 :object_info_totals_by_question_id => :get,
18 19 :recent_votes_by_question_id => :get} do |question|
19 20 question.resources :prompts, :only => :show,
... ...
spec/integration/questions_spec.rb
... ... @@ -11,6 +11,16 @@ describe "Questions" do
11 11 end
12 12 end
13 13  
  14 + describe "GET 'site_stats'" do
  15 + it "should return site_stats" do
  16 + Factory.create(:vote, :question => @questions.first)
  17 + get_auth site_stats_questions_path(:format => 'xml')
  18 + response.should be_success
  19 + response.body.should have_tag("total-questions", :text => @questions.count)
  20 + response.body.should have_tag("votes-count", :text => 1)
  21 + end
  22 + end
  23 +
14 24 describe "GET 'median_votes_per_session'" do
15 25 it "should return the median" do
16 26 Factory.create(:vote, :question => @questions.first)
... ...