all the specs pass with before each
This commit is contained in:
parent
56831cec63
commit
46b94bc130
4 changed files with 6 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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|
|
||||
|
|
|
|||
Loading…
Reference in a new issue