all the specs pass with before each

This commit is contained in:
zhitomirskiyi 2011-01-21 10:18:10 -08:00
parent 56831cec63
commit 46b94bc130
4 changed files with 6 additions and 6 deletions

View file

@ -3,7 +3,7 @@ class DataPoint < ActiveRecord::Base
def self.users_with_posts_on_day(time, number) def self.users_with_posts_on_day(time, number)
sql = ActiveRecord::Base.connection() 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) self.new(:key => number.to_s, :value => value)
end end
end end

View file

@ -7,13 +7,13 @@ describe StatisticsController do
sign_in :user, alice sign_in :user, alice
end end
before(:all) do before do
@stat = Statistic.new @stat = Statistic.new
5.times do |n| 5.times do |n|
bob.post(:status_message, :message => 'hi', :to => bob.aspects.first) bob.post(:status_message, :message => 'hi', :to => bob.aspects.first)
end end
(0..10).each do |n| (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 end
@stat.save @stat.save
end end

View file

@ -7,7 +7,7 @@ describe DataPoint do
end end
context '.posts_per_day_last_week' do context '.posts_per_day_last_week' do
before(:all) do before do
1.times do |n| 1.times do |n|
alice.post(:status_message, :message => 'hi', :to => alice.aspects.first) alice.post(:status_message, :message => 'hi', :to => alice.aspects.first)
end end

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Statistic do describe Statistic do
before(:all) do before do
@stat = Statistic.new @stat = Statistic.new
@time = Time.now @time = Time.now
@ -80,7 +80,7 @@ describe Statistic do
end end
describe '.generate' do describe '.generate' do
before(:all) do before do
@time = Time.now - 1.day @time = Time.now - 1.day
1.times do |n| 1.times do |n|