Took 90 seconds off the build. Fixture builder FTFW.
Cleaned up spec_helper - moved stuff into support files.
This commit is contained in:
parent
b7815f0d84
commit
dc499293b3
9 changed files with 105 additions and 108 deletions
|
|
@ -10,9 +10,10 @@ describe 'making sure the spec runner works' do
|
||||||
loaded_user = User.find(user.id)
|
loaded_user = User.find(user.id)
|
||||||
loaded_user.person.owner_id.should == user.id
|
loaded_user.person.owner_id.should == user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'fixtures' do
|
describe 'fixtures' do
|
||||||
it 'loads fixtures' do
|
it 'loads fixtures' do
|
||||||
User.count.should == 3
|
User.count.should_not == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,26 +7,6 @@ describe DataPoint do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.users_with_posts_on_day' do
|
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
|
it 'returns a DataPoint object' do
|
||||||
DataPoint.users_with_posts_on_day(@time, 1).class.should == DataPoint
|
DataPoint.users_with_posts_on_day(@time, 1).class.should == DataPoint
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,30 +2,8 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Statistic do
|
describe Statistic do
|
||||||
before do
|
before do
|
||||||
@stat = Statistic.new
|
@stat = Statistic.first
|
||||||
@time = Time.now
|
@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
|
end
|
||||||
|
|
||||||
describe '#compute_average' do
|
describe '#compute_average' do
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ describe "attack vectors" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "ignores retractions on a post not owned by the retraction's sender" do
|
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
|
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
|
||||||
|
|
||||||
salmon_xml = user2.salmon(original_message).xml_for(user.person)
|
salmon_xml = user2.salmon(original_message).xml_for(user.person)
|
||||||
|
|
@ -135,6 +136,7 @@ describe "attack vectors" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "disregards retractions for non-existent posts that are from someone other than the post's author" do
|
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
|
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
|
||||||
id = original_message.reload.id
|
id = original_message.reload.id
|
||||||
|
|
||||||
|
|
@ -145,7 +147,7 @@ describe "attack vectors" do
|
||||||
|
|
||||||
original_message.delete
|
original_message.delete
|
||||||
|
|
||||||
StatusMessage.count.should be 0
|
StatusMessage.count.should == 0
|
||||||
proc {
|
proc {
|
||||||
salmon_xml = user3.salmon(ret).xml_for(user.person)
|
salmon_xml = user3.salmon(ret).xml_for(user.person)
|
||||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||||
|
|
|
||||||
|
|
@ -275,6 +275,7 @@ describe Diaspora::UserModules::Connecting do
|
||||||
|
|
||||||
context 'with a post' do
|
context 'with a post' do
|
||||||
before do
|
before do
|
||||||
|
StatusMessage.delete_all
|
||||||
@message = user.post(:status_message, :message => "hi", :to => aspect.id)
|
@message = user.post(:status_message, :message => "hi", :to => aspect.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,9 @@ include Devise::TestHelpers
|
||||||
include WebMock::API
|
include WebMock::API
|
||||||
include HelperMethods
|
include HelperMethods
|
||||||
|
|
||||||
|
# Force fixture rebuild
|
||||||
`rm #{File.join(Rails.root, 'tmp', 'fixture_builder.yml')}`
|
`rm #{File.join(Rails.root, 'tmp', 'fixture_builder.yml')}`
|
||||||
#
|
|
||||||
# Requires supporting files with custom matchers and macros, etc,
|
# Requires supporting files with custom matchers and macros, etc,
|
||||||
# in ./support/ and its subdirectories.
|
# in ./support/ and its subdirectories.
|
||||||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
||||||
|
|
@ -34,6 +35,8 @@ RSpec.configure do |config|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ImageUploader.enable_processing = false
|
||||||
|
|
||||||
def set_up_friends
|
def set_up_friends
|
||||||
local_luke = Factory(:user_with_aspect, :username => "luke")
|
local_luke = Factory(:user_with_aspect, :username => "luke")
|
||||||
local_leia = Factory(:user_with_aspect, :username => "leia")
|
local_leia = Factory(:user_with_aspect, :username => "leia")
|
||||||
|
|
@ -45,7 +48,6 @@ def set_up_friends
|
||||||
[local_luke, local_leia, remote_raphael]
|
[local_luke, local_leia, remote_raphael]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def alice
|
def alice
|
||||||
#users(:alice)
|
#users(:alice)
|
||||||
User.where(:username => 'alice').first
|
User.where(:username => 'alice').first
|
||||||
|
|
@ -60,64 +62,4 @@ def eve
|
||||||
#users(:eve)
|
#users(:eve)
|
||||||
User.where(:username => 'eve').first
|
User.where(:username => 'eve').first
|
||||||
end
|
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
|
|
||||||
|
|
|
||||||
42
spec/support/fake_http_request.rb
Normal file
42
spec/support/fake_http_request.rb
Normal 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
|
||||||
17
spec/support/fake_redis.rb
Normal file
17
spec/support/fake_redis.rb
Normal 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
|
||||||
|
|
@ -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|
|
FixtureBuilder.configure do |fbuilder|
|
||||||
# rebuild fixtures automatically when these files change:
|
# 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"]
|
fbuilder.files_to_check += Dir["app/models/*.rb", "lib/**/*.rb", "spec/factories/*.rb", "spec/support/fixture_builder.rb"]
|
||||||
|
|
||||||
# now declare objects
|
# now declare objects
|
||||||
fbuilder.factory do
|
fbuilder.factory do
|
||||||
|
# Users
|
||||||
alice = Factory(:user_with_aspect, :username => "alice")
|
alice = Factory(:user_with_aspect, :username => "alice")
|
||||||
eve = Factory(:user_with_aspect, :username => "eve")
|
eve = Factory(:user_with_aspect, :username => "eve")
|
||||||
bob = Factory(:user_with_aspect, :username => "bob")
|
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, alice, alice.aspects.first)
|
||||||
connect_users(bob, bob.aspects.first, eve, eve.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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue