Putting fixtures in specs...

This commit is contained in:
Raphael 2011-01-18 10:42:50 -08:00
parent fdc9534fc7
commit b580b7bd2c
7 changed files with 45 additions and 38 deletions

View file

@ -62,7 +62,7 @@ group :test do
gem 'rspec', '>= 2.0.0' gem 'rspec', '>= 2.0.0'
gem 'rspec-rails', '>= 2.0.0' gem 'rspec-rails', '>= 2.0.0'
gem 'mocha' gem 'mocha'
gem 'database_cleaner', '0.5.2' gem 'database_cleaner', '0.6.0'
gem 'webmock', :require => false gem 'webmock', :require => false
gem 'jasmine', :path => 'vendor/gems/jasmine', :require => false gem 'jasmine', :path => 'vendor/gems/jasmine', :require => false
gem 'mongrel', :require => false if RUBY_VERSION.include? '1.8' gem 'mongrel', :require => false if RUBY_VERSION.include? '1.8'

View file

@ -136,7 +136,7 @@ GEM
cucumber (>= 0.8.0) cucumber (>= 0.8.0)
culerity (0.2.14) culerity (0.2.14)
daemons (1.1.0) daemons (1.1.0)
database_cleaner (0.5.2) database_cleaner (0.6.0)
devise (1.1.3) devise (1.1.3)
bcrypt-ruby (~> 2.1.2) bcrypt-ruby (~> 2.1.2)
warden (~> 0.10.7) warden (~> 0.10.7)
@ -366,7 +366,7 @@ DEPENDENCIES
chef (= 0.9.12) chef (= 0.9.12)
cloudfiles (= 1.4.10) cloudfiles (= 1.4.10)
cucumber-rails (= 0.3.2) cucumber-rails (= 0.3.2)
database_cleaner (= 0.5.2) database_cleaner (= 0.6.0)
devise (= 1.1.3) devise (= 1.1.3)
devise_invitable (= 0.3.5) devise_invitable (= 0.3.5)
em-websocket! em-websocket!

View file

@ -9,14 +9,12 @@ describe AspectsController do
render_views render_views
before do before do
@user = Factory.create(:user) @user = alice
@user2 = Factory.create(:user) @user2 = bob
@aspect0 = @user.aspects.create(:name => "lame-os") @aspect0 = @user.aspects.first
@aspect1 = @user.aspects.create(:name => "another aspect") @aspect1 = @user.aspects.create(:name => "another aspect")
@aspect2 = @user2.aspects.create(:name => "party people") @aspect2 = @user2.aspects.first
connect_users(@user, @aspect0, @user2, @aspect2)
@contact = @user.contact_for(@user2.person) @contact = @user.contact_for(@user2.person)
@user.getting_started = false @user.getting_started = false

View file

@ -7,14 +7,14 @@ require 'spec_helper'
describe CommentsController do describe CommentsController do
render_views render_views
let!(:user1) { Factory.create(:user) }
let!(:aspect1) { user1.aspects.create(:name => "AWESOME!!") }
let!(:user2) { Factory.create(:user) }
let!(:aspect2) { user2.aspects.create(:name => "WIN!!") }
before do before do
sign_in :user, user1 @user1 = alice
@user2 = bob
@aspect1 = @user1.aspects.first
@aspect2 = @user2.aspects.first
sign_in :user, @user1
end end
describe '#create' do describe '#create' do
@ -24,7 +24,7 @@ describe CommentsController do
} }
context "on my own post" do context "on my own post" do
before do before do
@post = user1.post :status_message, :message => 'GIANTS', :to => aspect1.id @post = @user1.post :status_message, :message => 'GIANTS', :to => @aspect1.id
end end
it 'responds to format js' do it 'responds to format js' do
post :create, comment_hash.merge(:format => 'js') post :create, comment_hash.merge(:format => 'js')
@ -35,8 +35,8 @@ describe CommentsController do
context "on a post from a contact" do context "on a post from a contact" do
before do before do
connect_users(user1, aspect1, user2, aspect2) connect_users(@user1, @aspect1, @user2, @aspect2)
@post = user2.post :status_message, :message => 'GIANTS', :to => aspect2.id @post = @user2.post :status_message, :message => 'GIANTS', :to => @aspect2.id
end end
it 'comments' do it 'comments' do
post :create, comment_hash post :create, comment_hash
@ -46,10 +46,10 @@ describe CommentsController do
new_user = Factory.create(:user) new_user = Factory.create(:user)
comment_hash[:person_id] = new_user.person.id.to_s comment_hash[:person_id] = new_user.person.id.to_s
post :create, comment_hash post :create, comment_hash
Comment.find_by_text(comment_hash[:text]).person_id.should == user1.person.id Comment.find_by_text(comment_hash[:text]).person_id.should == @user1.person.id
end end
it "doesn't overwrite id" do it "doesn't overwrite id" do
old_comment = user1.comment("hello", :on => @post) old_comment = @user1.comment("hello", :on => @post)
comment_hash[:id] = old_comment.id comment_hash[:id] = old_comment.id
post :create, comment_hash post :create, comment_hash
old_comment.reload.text.should == 'hello' old_comment.reload.text.should == 'hello'
@ -57,10 +57,10 @@ describe CommentsController do
end end
context 'on a post from a stranger' do context 'on a post from a stranger' do
before do before do
@post = user2.post :status_message, :message => 'GIANTS', :to => aspect2.id @post = @user2.post :status_message, :message => 'GIANTS', :to => @aspect2.id
end end
it 'posts no comment' do it 'posts no comment' do
user1.should_not_receive(:comment) @user1.should_not_receive(:comment)
post :create, comment_hash post :create, comment_hash
response.code.should == '406' response.code.should == '406'
end end

View file

@ -5,30 +5,25 @@
require 'spec_helper' require 'spec_helper'
describe 'making sure the spec runner works' do describe 'making sure the spec runner works' do
it 'factoy creates a user with a person saved' do it 'factory creates a user with a person saved' do
user = Factory.create(:user) user = Factory.create(:user)
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 'factories' do it 'loads fixtures' do
describe 'build' do User.count.should == 3
it 'does not save a built user' do
Factory.build(:user).should_not be_persisted
end
it 'does not save a built person' do
Factory.build(:person).should_not be_persisted
end
end end
end end
describe '#connect_users' do describe '#connect_users' do
before do before do
@user1 = Factory.create(:user) @user1 = User.where(:username => 'alice').first
@aspect1 = @user1.aspects.create(:name => "losers") @user2 = User.where(:username => 'eve').first
@user2 = Factory.create(:user)
@aspect2 = @user2.aspects.create(:name => "bruisers") @aspect1 = @user1.aspects.first
@aspect2 = @user2.aspects.first
connect_users(@user1, @aspect1, @user2, @aspect2) connect_users(@user1, @aspect1, @user2, @aspect2)
end end

View file

@ -17,9 +17,11 @@ include HelperMethods
# #
# 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.
#DatabaseCleaner.clean_with(:truncation)
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config| RSpec.configure do |config|
#DatabaseCleaner.strategy = nil
config.mock_with :mocha config.mock_with :mocha
config.mock_with :rspec config.mock_with :rspec

View file

@ -13,3 +13,15 @@ FixtureBuilder.configure do |fbuilder|
connect_users(bob, bob.aspects.first, eve, eve.aspects.first) connect_users(bob, bob.aspects.first, eve, eve.aspects.first)
end end
end end
def alice
User.where(:username => 'alice').first
end
def bob
User.where(:username => 'bob').first
end
def eve
User.where(:username => 'eve').first
end