diff --git a/app/models/data_point.rb b/app/models/data_point.rb index a283e197e..980577f6a 100644 --- a/app/models/data_point.rb +++ b/app/models/data_point.rb @@ -3,7 +3,7 @@ class DataPoint < ActiveRecord::Base def self.users_with_posts_on_day(time, number) sql = ActiveRecord::Base.connection() - value = sql.execute("SELECT COUNT(*) FROM (SELECT COUNT(*) AS post_sum, DATE(created_at) AS date, person_id FROM posts GROUP BY person_id, date HAVING date = '#{time.utc.to_date}') AS t1 WHERE t1.post_sum = #{number};").first[0] + value = sql.execute("SELECT COUNT(*) FROM (SELECT COUNT(*) AS post_sum, person_id FROM posts WHERE created_at >= '#{(time - 1.days).utc.to_datetime}' AND created_at <= '#{time.utc.to_datetime}' GROUP BY person_id) AS t1 WHERE t1.post_sum = #{number};").first[0] self.new(:key => number.to_s, :value => value) end end diff --git a/spec/controllers/statistics_controller_spec.rb b/spec/controllers/statistics_controller_spec.rb index 0724be0ce..84e64cd52 100644 --- a/spec/controllers/statistics_controller_spec.rb +++ b/spec/controllers/statistics_controller_spec.rb @@ -7,13 +7,13 @@ describe StatisticsController do sign_in :user, alice end - before(:all) do + before do @stat = Statistic.new 5.times do |n| bob.post(:status_message, :message => 'hi', :to => bob.aspects.first) end (0..10).each do |n| - @stat.data_points << DataPoint.users_with_posts_today(n) + @stat.data_points << DataPoint.users_with_posts_on_day(Time.now, n) end @stat.save end diff --git a/spec/models/data_point_spec.rb b/spec/models/data_point_spec.rb index 3d14e27b5..71ab389cb 100644 --- a/spec/models/data_point_spec.rb +++ b/spec/models/data_point_spec.rb @@ -7,7 +7,7 @@ describe DataPoint do end context '.posts_per_day_last_week' do - before(:all) do + before do 1.times do |n| alice.post(:status_message, :message => 'hi', :to => alice.aspects.first) end diff --git a/spec/models/statistic_spec.rb b/spec/models/statistic_spec.rb index a1190ff52..2187764f4 100644 --- a/spec/models/statistic_spec.rb +++ b/spec/models/statistic_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Statistic do - before(:all) do + before do @stat = Statistic.new @time = Time.now @@ -80,7 +80,7 @@ describe Statistic do end describe '.generate' do - before(:all) do + before do @time = Time.now - 1.day 1.times do |n|