Permalink
Browse files

Putting fixtures in specs...

  • Loading branch information...
1 parent fdc9534 commit b580b7bd2cc931735c7f2f2faa535837d327fad7 Raphael committed Jan 18, 2011
View
@@ -62,7 +62,7 @@ group :test do
gem 'rspec', '>= 2.0.0'
gem 'rspec-rails', '>= 2.0.0'
gem 'mocha'
- gem 'database_cleaner', '0.5.2'
+ gem 'database_cleaner', '0.6.0'
gem 'webmock', :require => false
gem 'jasmine', :path => 'vendor/gems/jasmine', :require => false
gem 'mongrel', :require => false if RUBY_VERSION.include? '1.8'
View
@@ -136,7 +136,7 @@ GEM
cucumber (>= 0.8.0)
culerity (0.2.14)
daemons (1.1.0)
- database_cleaner (0.5.2)
+ database_cleaner (0.6.0)
devise (1.1.3)
bcrypt-ruby (~> 2.1.2)
warden (~> 0.10.7)
@@ -366,7 +366,7 @@ DEPENDENCIES
chef (= 0.9.12)
cloudfiles (= 1.4.10)
cucumber-rails (= 0.3.2)
- database_cleaner (= 0.5.2)
+ database_cleaner (= 0.6.0)
devise (= 1.1.3)
devise_invitable (= 0.3.5)
em-websocket!
@@ -9,14 +9,12 @@
render_views
before do
- @user = Factory.create(:user)
- @user2 = Factory.create(:user)
+ @user = alice
+ @user2 = bob
- @aspect0 = @user.aspects.create(:name => "lame-os")
+ @aspect0 = @user.aspects.first
@aspect1 = @user.aspects.create(:name => "another aspect")
- @aspect2 = @user2.aspects.create(:name => "party people")
-
- connect_users(@user, @aspect0, @user2, @aspect2)
+ @aspect2 = @user2.aspects.first
@contact = @user.contact_for(@user2.person)
@user.getting_started = false
@@ -7,14 +7,14 @@
describe CommentsController do
render_views
- let!(:user1) { Factory.create(:user) }
- let!(:aspect1) { user1.aspects.create(:name => "AWESOME!!") }
+ before do
+ @user1 = alice
+ @user2 = bob
- let!(:user2) { Factory.create(:user) }
- let!(:aspect2) { user2.aspects.create(:name => "WIN!!") }
+ @aspect1 = @user1.aspects.first
+ @aspect2 = @user2.aspects.first
- before do
- sign_in :user, user1
+ sign_in :user, @user1
end
describe '#create' do
@@ -24,7 +24,7 @@
}
context "on my own post" do
before do
- @post = user1.post :status_message, :message => 'GIANTS', :to => aspect1.id
+ @post = @user1.post :status_message, :message => 'GIANTS', :to => @aspect1.id
end
it 'responds to format js' do
post :create, comment_hash.merge(:format => 'js')
@@ -35,8 +35,8 @@
context "on a post from a contact" do
before do
- connect_users(user1, aspect1, user2, aspect2)
- @post = user2.post :status_message, :message => 'GIANTS', :to => aspect2.id
+ connect_users(@user1, @aspect1, @user2, @aspect2)
+ @post = @user2.post :status_message, :message => 'GIANTS', :to => @aspect2.id
end
it 'comments' do
post :create, comment_hash
@@ -46,21 +46,21 @@
new_user = Factory.create(:user)
comment_hash[:person_id] = new_user.person.id.to_s
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
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
post :create, comment_hash
old_comment.reload.text.should == 'hello'
end
end
context 'on a post from a stranger' do
before do
- @post = user2.post :status_message, :message => 'GIANTS', :to => aspect2.id
+ @post = @user2.post :status_message, :message => 'GIANTS', :to => @aspect2.id
end
it 'posts no comment' do
- user1.should_not_receive(:comment)
+ @user1.should_not_receive(:comment)
post :create, comment_hash
response.code.should == '406'
end
View
@@ -5,30 +5,25 @@
require 'spec_helper'
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)
loaded_user = User.find(user.id)
loaded_user.person.owner_id.should == user.id
end
-
- describe 'factories' do
- describe 'build' do
- 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
+ describe 'fixtures' do
+ it 'loads fixtures' do
+ User.count.should == 3
end
end
describe '#connect_users' do
before do
- @user1 = Factory.create(:user)
- @aspect1 = @user1.aspects.create(:name => "losers")
- @user2 = Factory.create(:user)
- @aspect2 = @user2.aspects.create(:name => "bruisers")
+ @user1 = User.where(:username => 'alice').first
+ @user2 = User.where(:username => 'eve').first
+
+ @aspect1 = @user1.aspects.first
+ @aspect2 = @user2.aspects.first
+
connect_users(@user1, @aspect1, @user2, @aspect2)
end
View
@@ -17,9 +17,11 @@
#
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
+#DatabaseCleaner.clean_with(:truncation)
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config|
+ #DatabaseCleaner.strategy = nil
config.mock_with :mocha
config.mock_with :rspec
@@ -13,3 +13,15 @@
connect_users(bob, bob.aspects.first, eve, eve.aspects.first)
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

0 comments on commit b580b7b

Please sign in to comment.