IZ factories in controller specs as well as bookmark

This commit is contained in:
ilya 2010-06-15 14:56:32 -04:00
parent 8a37843cd9
commit 653392f738
5 changed files with 32 additions and 22 deletions

View file

@ -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

View file

@ -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,16 +15,17 @@ 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

View file

@ -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

View file

@ -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

View file

@ -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/")
#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