diff --git a/spec/controllers/bookmarks_controller_spec.rb b/spec/controllers/bookmarks_controller_spec.rb index 61dd7ca20..32604ec0e 100644 --- a/spec/controllers/bookmarks_controller_spec.rb +++ b/spec/controllers/bookmarks_controller_spec.rb @@ -4,10 +4,12 @@ describe BookmarksController do before do #TODO(dan) Mocking Warden; this is a temp fix request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user) - User.create(:email => "bob@aol.com", :password => "secret") - Bookmark.create(:link => "http://www.yahooligans.com/") + @bob = Factory.create(:user) + @bookmark = Factory.build(:bookmark) + @bookmark.save #TODO figure out why validations are not working end + render_views it "index action should render index template" do @@ -36,9 +38,10 @@ describe BookmarksController do #TODO(dan) look into why we need to create a new bookmark object here Bookmark.any_instance.stubs(:valid?).returns(true) - n = Bookmark.create(:link => "http://hotub.com") - puts n.inspect - put :update, :id => n.id + n = Factory.create(:bookmark, :link => "http://hotub.com") + n.save + #puts n.inspect + put :update, :id => Bookmark.first.id response.should redirect_to(bookmark_url(assigns[:bookmark])) end diff --git a/spec/controllers/friends_controller_spec.rb b/spec/controllers/friends_controller_spec.rb index 4637aa15b..4c51d7497 100644 --- a/spec/controllers/friends_controller_spec.rb +++ b/spec/controllers/friends_controller_spec.rb @@ -5,7 +5,7 @@ describe FriendsController do before do #TODO(dan) Mocking Warden; this is a temp fix request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user) - Friend.create(:username => "max", :url => "http://max.com/") + @friend = Factory.build(:friend) end it "index action should render index template" do @@ -15,18 +15,19 @@ describe FriendsController do end it "show action should render show template" do + @friend.save request.env['warden'].should_receive(:authenticate?).at_least(:once) - get :show, :id => Friend.first.id + get :show, :id => @friend.id response.should render_template(:show) end it "destroy action should destroy model and redirect to index action" do - friend = Friend.first - delete :destroy, :id => friend.id + @friend.save + delete :destroy, :id => @friend.id response.should redirect_to(friends_url) - Friend.first(:conditions => {:id => friend.id}).should be_nil + Friend.first(:conditions => {:id => @friend.id}).should be_nil end - + it "new action should render new template" do request.env['warden'].should_receive(:authenticate?).at_least(:once) get :new diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 50cba6a45..516de5aab 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -4,8 +4,10 @@ describe StatusMessagesController do before do #TODO(dan) Mocking Warden; this is a temp fix request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user) - User.create(:email => "bob@aol.com", :password => "secret") - StatusMessage.create(:message => "yodels.") + @bob = Factory.build(:user,:email => "bob@aol.com", :password => "secret") + @status_message = Factory.build(:status_message, :message => "yodels.") + @bob.save + @status_message.save #TODO for some reason it complains about validations even though they are valid fields end render_views @@ -38,15 +40,14 @@ describe StatusMessagesController do end it "destroy action should destroy model and redirect to index action" do - status_message = StatusMessage.first - delete :destroy, :id => status_message.id + delete :destroy, :id => @status_message.id response.should redirect_to(status_messages_url) - StatusMessage.first(:conditions => {:id => status_message.id }).nil?.should be true + StatusMessage.first(:conditions => {:id => @status_message.id }).nil?.should be true end it "show action should render show template" do request.env['warden'].should_receive(:authenticate?).at_least(:once) - get :show, :id => StatusMessage.first.id + get :show, :id => @status_message.id response.should render_template(:show) end diff --git a/spec/factories.rb b/spec/factories.rb index ca8c54483..0ebbb93e2 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -15,3 +15,7 @@ Factory.define :user do |u| u.sequence(:email) {|n| "bob#{n}@aol.com"} u.password "bluepin7" end + +Factory.define :bookmark do |b| + b.link "http://www.yahooligans.com/" +end diff --git a/spec/models/bookmark_spec.rb b/spec/models/bookmark_spec.rb index 309969bf0..ac65dc5e4 100644 --- a/spec/models/bookmark_spec.rb +++ b/spec/models/bookmark_spec.rb @@ -2,15 +2,16 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Bookmark do it "should have a link" do - bookmark = Bookmark.new + bookmark = Factory.build(:bookmark, :link => nil) bookmark.valid?.should be false bookmark.link = "http://angjoo.com/" bookmark.valid?.should be true end it "should add an owner if none is present" do - User.create(:email => "bob@aol.com", :password => "big bux") - n = Bookmark.create(:link => "http://www.validurl.com/") - n.owner.should == "bob@aol.com" + #User.create(:email => "bob@aol.com", :password => "big bux") + Factory.create(:user, :email => "bob@aol.com") + n = Factory.create(:bookmark) + n.owner.should == "bob@aol.com" end -end \ No newline at end of file +end