RS, IZ; ApplicationHelper specs now passed, specs for mine? moved into person spec as specs for owns?

This commit is contained in:
Raphael 2010-08-06 11:52:33 -07:00
parent 6449d20687
commit d130b82e42
4 changed files with 37 additions and 42 deletions

View file

@ -8,7 +8,7 @@ module ApplicationHelper
end end
def mine?(post) def mine?(post)
post.person.id == current_user.person.id current_user.owns? post
end end
def type_partial(post) def type_partial(post)

View file

@ -1,10 +1,11 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
include ApplicationHelper
describe DashboardsController do describe DashboardsController do
render_views render_views
before do before do
@user = Factory.create(:user) @user = Factory.create(:user)
@user.person.save @user.person.save
@person = Factory.create(:person)
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user) request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user)
end end

View file

@ -5,23 +5,8 @@ describe ApplicationHelper do
before do before do
@user = Factory.create(:user) @user = Factory.create(:user)
@person = Factory.create(:person) @person = Factory.create(:person)
#env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user)
sign_in @user
@user.save
end end
it "should specifiy if a post is not owned user" do
p = Factory.create(:post, :person => @person)
mine?(p).should be false
end
it "should specifiy if a post is owned current user" do
p = Factory.create(:post, :person => @user.person)
puts p.person.id == @user.person.id
mine?(p).should be true
end
it "should provide a correct show path for a given person" do it "should provide a correct show path for a given person" do
person_url(@person).should == "/people/#{@person.id}" person_url(@person).should == "/people/#{@person.id}"

View file

@ -1,39 +1,50 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe Person do describe Person do
before do
@person = Factory.create(:person)
end
it 'should not allow two people with the same email' do it 'should not allow two people with the same email' do
person_one = Factory.create(:person) person_two = Factory.build(:person, :url => @person.email)
person_two = Factory.build(:person, :url => person_one.email)
person_two.valid?.should == false person_two.valid?.should == false
end end
describe 'xml' do
before do
@xml = @person.to_xml.to_s
end
it 'should serialize to xml' do it 'should serialize to xml' do
person = Factory.create(:person) (@xml.include? "person").should == true
xml = person.to_xml.to_s
(xml.include? "person").should == true
end end
it 'should have a profile in its xml' do it 'should have a profile in its xml' do
person = Factory.create(:person) (@xml.include? "first_name").should == true
xml = person.to_xml.to_s end
(xml.include? "first_name").should == true end
it 'should know when a post belongs to it' do
person_message = Factory.create(:status_message, :person => @person)
person_two = Factory.create(:person)
@person.owns?(person_message).should be true
person_two.owns?(person_message).should be false
end end
it 'should delete all of user except comments upon user deletion' do it 'should delete all of user except comments upon user deletion' do
Factory.create(:user) Factory.create(:user)
f = Factory.create(:person) f = Factory.create(:person)
p = Factory.create(:person)
Factory.create(:status_message, :person => f) Factory.create(:status_message, :person => f)
Factory.create(:blog, :person => f) Factory.create(:blog, :person => f)
Factory.create(:bookmark, :person => f) Factory.create(:bookmark, :person => f)
Factory.create(:status_message, :person => f) Factory.create(:status_message, :person => f)
s = Factory.create(:status_message, :person => p) s = Factory.create(:status_message, :person => @person)
Factory.create(:comment, :person_id => f.id, :text => "yes i do", :post => s) Factory.create(:comment, :person_id => f.id, :text => "yes i do", :post => s)
Factory.create(:comment, :person_id => f.id, :text => "i love you", :post => s) Factory.create(:comment, :person_id => f.id, :text => "i love you", :post => s)
Factory.create(:comment, :person_id => f.id, :text => "hello", :post => s) Factory.create(:comment, :person_id => f.id, :text => "hello", :post => s)
Factory.create(:comment, :person_id => p.id, :text => "you are creepy", :post => s) Factory.create(:comment, :person_id => @person.id, :text => "you are creepy", :post => s)
f.destroy f.destroy
@ -47,15 +58,14 @@ describe Person do
user = Factory.create(:user) user = Factory.create(:user)
user.save user.save
person = Factory.create(:person)
user.friends << person user.friends << @person
person.user_refs += 1 @person.user_refs += 1
person.save @person.save
Person.all.count.should == 2 Person.all.count.should == 2
user.friends.count.should == 1 user.friends.count.should == 1
user.unfriend(person.id) user.unfriend(@person.id)
user.friends.count.should == 0 user.friends.count.should == 0
Person.all.count.should == 1 Person.all.count.should == 1
end end
@ -67,21 +77,20 @@ describe Person do
user_one.save user_one.save
user_two.save user_two.save
person = Factory.create(:person)
user_one.friends << person user_one.friends << @person
user_two.friends << person user_two.friends << @person
user_one.save user_one.save
user_two.save user_two.save
person.user_refs += 2 @person.user_refs += 2
person.save @person.save
Person.all.count.should == 3 Person.all.count.should == 3
user_one.friends.count.should == 1 user_one.friends.count.should == 1
user_two.friends.count.should == 1 user_two.friends.count.should == 1
user_one.unfriend(person.id) user_one.unfriend(@person.id)
user_one.friends.count.should == 0 user_one.friends.count.should == 0
user_two.friends.count.should == 1 user_two.friends.count.should == 1