Took 90 seconds off the build. Fixture builder FTFW.

Cleaned up spec_helper - moved stuff into support files.
This commit is contained in:
Sarah Mei 2011-02-20 00:35:51 -08:00
parent b7815f0d84
commit dc499293b3
9 changed files with 105 additions and 108 deletions

View file

@ -10,9 +10,10 @@ describe 'making sure the spec runner works' do
loaded_user = User.find(user.id)
loaded_user.person.owner_id.should == user.id
end
describe 'fixtures' do
it 'loads fixtures' do
User.count.should == 3
User.count.should_not == 0
end
end

View file

@ -7,26 +7,6 @@ describe DataPoint do
end
describe '.users_with_posts_on_day' do
before do
1.times do |n|
p = alice.post(:status_message, :message => 'hi', :to => alice.aspects.first)
p.created_at = @time
p.save
end
5.times do |n|
p = bob.post(:status_message, :message => 'hi', :to => bob.aspects.first)
p.created_at = @time
p.save
end
10.times do |n|
p = eve.post(:status_message, :message => 'hi', :to => eve.aspects.first)
p.created_at = @time
p.save
end
end
it 'returns a DataPoint object' do
DataPoint.users_with_posts_on_day(@time, 1).class.should == DataPoint
end

View file

@ -2,30 +2,8 @@ require 'spec_helper'
describe Statistic do
before do
@stat = Statistic.new
@stat = Statistic.first
@time = Time.now
1.times do |n|
p = alice.post(:status_message, :message => 'hi', :to => alice.aspects.first)
p.created_at = @time
p.save
end
5.times do |n|
p = bob.post(:status_message, :message => 'hi', :to => bob.aspects.first)
p.created_at = @time
p.save
end
10.times do |n|
p = eve.post(:status_message, :message => 'hi', :to => eve.aspects.first)
p.created_at = @time
p.save
end
(0..10).each do |n|
@stat.data_points << DataPoint.users_with_posts_on_day(@time, n)
end
end
describe '#compute_average' do

View file

@ -112,6 +112,7 @@ describe "attack vectors" do
end
it "ignores retractions on a post not owned by the retraction's sender" do
StatusMessage.delete_all
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
salmon_xml = user2.salmon(original_message).xml_for(user.person)
@ -135,6 +136,7 @@ describe "attack vectors" do
end
it "disregards retractions for non-existent posts that are from someone other than the post's author" do
StatusMessage.delete_all
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
id = original_message.reload.id
@ -145,7 +147,7 @@ describe "attack vectors" do
original_message.delete
StatusMessage.count.should be 0
StatusMessage.count.should == 0
proc {
salmon_xml = user3.salmon(ret).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)

View file

@ -275,6 +275,7 @@ describe Diaspora::UserModules::Connecting do
context 'with a post' do
before do
StatusMessage.delete_all
@message = user.post(:status_message, :message => "hi", :to => aspect.id)
end

View file

@ -15,8 +15,9 @@ include Devise::TestHelpers
include WebMock::API
include HelperMethods
# Force fixture rebuild
`rm #{File.join(Rails.root, 'tmp', 'fixture_builder.yml')}`
#
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@ -34,6 +35,8 @@ RSpec.configure do |config|
end
end
ImageUploader.enable_processing = false
def set_up_friends
local_luke = Factory(:user_with_aspect, :username => "luke")
local_leia = Factory(:user_with_aspect, :username => "leia")
@ -45,7 +48,6 @@ def set_up_friends
[local_luke, local_leia, remote_raphael]
end
def alice
#users(:alice)
User.where(:username => 'alice').first
@ -60,64 +62,4 @@ def eve
#users(:eve)
User.where(:username => 'eve').first
end
module Diaspora::WebSocket
def self.redis
FakeRedis.new
end
end
class FakeRedis
def rpop(*args)
true
end
def llen(*args)
true
end
def lpush(*args)
true
end
end
ImageUploader.enable_processing = false
class FakeHttpRequest
def initialize(callback_wanted)
@callback = callback_wanted
@callbacks = []
end
def callbacks=(rs)
@callbacks += rs.reverse
end
def response
@callbacks.pop unless @callbacks.nil? || @callbacks.empty?
end
def response_header
self
end
def method_missing(method)
self
end
def post(opts = nil);
self
end
def get(opts = nil)
self
end
def publish(opts = nil)
self
end
def callback(&b)
b.call if @callback == :success
end
def errback(&b)
b.call if @callback == :failure
end
end

View file

@ -0,0 +1,42 @@
class FakeHttpRequest
def initialize(callback_wanted)
@callback = callback_wanted
@callbacks = []
end
def callbacks=(rs)
@callbacks += rs.reverse
end
def response
@callbacks.pop unless @callbacks.nil? || @callbacks.empty?
end
def response_header
self
end
def method_missing(method)
self
end
def post(opts = nil);
self
end
def get(opts = nil)
self
end
def publish(opts = nil)
self
end
def callback(&b)
b.call if @callback == :success
end
def errback(&b)
b.call if @callback == :failure
end
end

View file

@ -0,0 +1,17 @@
module Diaspora::WebSocket
def self.redis
FakeRedis.new
end
end
class FakeRedis
def rpop(*args)
true
end
def llen(*args)
true
end
def lpush(*args)
true
end
end

View file

@ -1,10 +1,12 @@
# I usually put this file in spec/support/fixture_builder.rb
require File.join(File.dirname(__FILE__), "user_methods.rb")
FixtureBuilder.configure do |fbuilder|
# rebuild fixtures automatically when these files change:
fbuilder.files_to_check += Dir["app/models/*.rb", "lib/**/*.rb", "spec/factories/*.rb", "spec/support/fixture_builder.rb"]
# now declare objects
fbuilder.factory do
# Users
alice = Factory(:user_with_aspect, :username => "alice")
eve = Factory(:user_with_aspect, :username => "eve")
bob = Factory(:user_with_aspect, :username => "bob")
@ -12,6 +14,38 @@ FixtureBuilder.configure do |fbuilder|
connect_users(bob, bob.aspects.first, alice, alice.aspects.first)
connect_users(bob, bob.aspects.first, eve, eve.aspects.first)
# Statistics
frodo = Factory(:user_with_aspect, :username => "frodo")
sam = Factory(:user_with_aspect, :username => "sam")
bilbo = Factory(:user_with_aspect, :username => "bilbo")
stat = Statistic.new
time = Time.now
1.times do
p = frodo.post(:status_message, :message => 'hi', :to => frodo.aspects.first)
p.created_at = time
p.save!
end
5.times do
p = sam.post(:status_message, :message => 'hi', :to => sam.aspects.first)
p.created_at = time
p.save!
end
10.times do
p = bilbo.post(:status_message, :message => 'hi', :to => bilbo.aspects.first)
p.created_at = time
p.save!
end
(0..10).each do |n|
stat.data_points << DataPoint.users_with_posts_on_day(time, n)
end
stat.time = time
stat.save!
end
end