From b580b7bd2cc931735c7f2f2faa535837d327fad7 Mon Sep 17 00:00:00 2001
From: Raphael <raphael@joindiaspora.com>
Date: Tue, 18 Jan 2011 10:42:50 -0800
Subject: [PATCH] Putting fixtures in specs...

---
 Gemfile                                      |  2 +-
 Gemfile.lock                                 |  4 +--
 spec/controllers/aspects_controller_spec.rb  | 10 +++-----
 spec/controllers/comments_controller_spec.rb | 26 ++++++++++----------
 spec/misc_spec.rb                            | 25 ++++++++-----------
 spec/spec_helper.rb                          |  2 ++
 spec/support/fixture_builder.rb              | 12 +++++++++
 7 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/Gemfile b/Gemfile
index 45d4565803..4c739a098a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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'
diff --git a/Gemfile.lock b/Gemfile.lock
index fc31e4b6c0..95cdd36715 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -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!
diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb
index e3445f2d4b..01ce07cc4a 100644
--- a/spec/controllers/aspects_controller_spec.rb
+++ b/spec/controllers/aspects_controller_spec.rb
@@ -9,14 +9,12 @@ describe AspectsController do
   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
diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb
index ad4fa790e8..61a89fdd8c 100644
--- a/spec/controllers/comments_controller_spec.rb
+++ b/spec/controllers/comments_controller_spec.rb
@@ -7,14 +7,14 @@ require 'spec_helper'
 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 @@ describe CommentsController do
     }
     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 @@ describe CommentsController do
 
     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,10 +46,10 @@ describe CommentsController do
         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'
@@ -57,10 +57,10 @@ describe CommentsController do
     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
diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb
index 43a83c8667..cbe75cccf9 100644
--- a/spec/misc_spec.rb
+++ b/spec/misc_spec.rb
@@ -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
 
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index ecb34ba165..fa3ef253bf 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -17,9 +17,11 @@ include HelperMethods
 #
 # 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
 
diff --git a/spec/support/fixture_builder.rb b/spec/support/fixture_builder.rb
index c81d2f55b8..1fc3a88390 100644
--- a/spec/support/fixture_builder.rb
+++ b/spec/support/fixture_builder.rb
@@ -13,3 +13,15 @@ FixtureBuilder.configure do |fbuilder|
     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
-- 
GitLab