IZ factories in controller specs as well as bookmark
This commit is contained in:
parent
8a37843cd9
commit
653392f738
5 changed files with 32 additions and 22 deletions
|
|
@ -4,10 +4,12 @@ describe BookmarksController do
|
||||||
before do
|
before do
|
||||||
#TODO(dan) Mocking Warden; this is a temp fix
|
#TODO(dan) Mocking Warden; this is a temp fix
|
||||||
request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user)
|
request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user)
|
||||||
User.create(:email => "bob@aol.com", :password => "secret")
|
@bob = Factory.create(:user)
|
||||||
Bookmark.create(:link => "http://www.yahooligans.com/")
|
@bookmark = Factory.build(:bookmark)
|
||||||
|
@bookmark.save #TODO figure out why validations are not working
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
it "index action should render index template" do
|
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
|
#TODO(dan) look into why we need to create a new bookmark object here
|
||||||
Bookmark.any_instance.stubs(:valid?).returns(true)
|
Bookmark.any_instance.stubs(:valid?).returns(true)
|
||||||
n = Bookmark.create(:link => "http://hotub.com")
|
n = Factory.create(:bookmark, :link => "http://hotub.com")
|
||||||
puts n.inspect
|
n.save
|
||||||
put :update, :id => n.id
|
#puts n.inspect
|
||||||
|
put :update, :id => Bookmark.first.id
|
||||||
response.should redirect_to(bookmark_url(assigns[:bookmark]))
|
response.should redirect_to(bookmark_url(assigns[:bookmark]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ describe FriendsController do
|
||||||
before do
|
before do
|
||||||
#TODO(dan) Mocking Warden; this is a temp fix
|
#TODO(dan) Mocking Warden; this is a temp fix
|
||||||
request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user)
|
request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user)
|
||||||
Friend.create(:username => "max", :url => "http://max.com/")
|
@friend = Factory.build(:friend)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "index action should render index template" do
|
it "index action should render index template" do
|
||||||
|
|
@ -15,18 +15,19 @@ describe FriendsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "show action should render show template" do
|
it "show action should render show template" do
|
||||||
|
@friend.save
|
||||||
request.env['warden'].should_receive(:authenticate?).at_least(:once)
|
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)
|
response.should render_template(:show)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "destroy action should destroy model and redirect to index action" do
|
it "destroy action should destroy model and redirect to index action" do
|
||||||
friend = Friend.first
|
@friend.save
|
||||||
delete :destroy, :id => friend.id
|
delete :destroy, :id => @friend.id
|
||||||
response.should redirect_to(friends_url)
|
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
|
end
|
||||||
|
|
||||||
it "new action should render new template" do
|
it "new action should render new template" do
|
||||||
request.env['warden'].should_receive(:authenticate?).at_least(:once)
|
request.env['warden'].should_receive(:authenticate?).at_least(:once)
|
||||||
get :new
|
get :new
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,10 @@ describe StatusMessagesController do
|
||||||
before do
|
before do
|
||||||
#TODO(dan) Mocking Warden; this is a temp fix
|
#TODO(dan) Mocking Warden; this is a temp fix
|
||||||
request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user)
|
request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user)
|
||||||
User.create(:email => "bob@aol.com", :password => "secret")
|
@bob = Factory.build(:user,:email => "bob@aol.com", :password => "secret")
|
||||||
StatusMessage.create(:message => "yodels.")
|
@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
|
end
|
||||||
|
|
||||||
render_views
|
render_views
|
||||||
|
|
@ -38,15 +40,14 @@ describe StatusMessagesController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "destroy action should destroy model and redirect to index action" do
|
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)
|
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
|
end
|
||||||
|
|
||||||
it "show action should render show template" do
|
it "show action should render show template" do
|
||||||
request.env['warden'].should_receive(:authenticate?).at_least(:once)
|
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)
|
response.should render_template(:show)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,3 +15,7 @@ Factory.define :user do |u|
|
||||||
u.sequence(:email) {|n| "bob#{n}@aol.com"}
|
u.sequence(:email) {|n| "bob#{n}@aol.com"}
|
||||||
u.password "bluepin7"
|
u.password "bluepin7"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Factory.define :bookmark do |b|
|
||||||
|
b.link "http://www.yahooligans.com/"
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,16 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
describe Bookmark do
|
describe Bookmark do
|
||||||
it "should have a link" do
|
it "should have a link" do
|
||||||
bookmark = Bookmark.new
|
bookmark = Factory.build(:bookmark, :link => nil)
|
||||||
bookmark.valid?.should be false
|
bookmark.valid?.should be false
|
||||||
bookmark.link = "http://angjoo.com/"
|
bookmark.link = "http://angjoo.com/"
|
||||||
bookmark.valid?.should be true
|
bookmark.valid?.should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should add an owner if none is present" do
|
it "should add an owner if none is present" do
|
||||||
User.create(:email => "bob@aol.com", :password => "big bux")
|
#User.create(:email => "bob@aol.com", :password => "big bux")
|
||||||
n = Bookmark.create(:link => "http://www.validurl.com/")
|
Factory.create(:user, :email => "bob@aol.com")
|
||||||
n.owner.should == "bob@aol.com"
|
n = Factory.create(:bookmark)
|
||||||
|
n.owner.should == "bob@aol.com"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue