From d130b82e425538b036621b5839ec758ffcacbec9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 6 Aug 2010 11:52:33 -0700 Subject: [PATCH] RS, IZ; ApplicationHelper specs now passed, specs for mine? moved into person spec as specs for owns? --- app/helpers/application_helper.rb | 2 +- .../controllers/dashboards_controller_spec.rb | 3 +- spec/helpers/application_helper_spec.rb | 15 ----- spec/models/person_spec.rb | 59 +++++++++++-------- 4 files changed, 37 insertions(+), 42 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0c4c0b61e..69011b563 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -8,7 +8,7 @@ module ApplicationHelper end def mine?(post) - post.person.id == current_user.person.id + current_user.owns? post end def type_partial(post) diff --git a/spec/controllers/dashboards_controller_spec.rb b/spec/controllers/dashboards_controller_spec.rb index a485d275a..6e1138a35 100644 --- a/spec/controllers/dashboards_controller_spec.rb +++ b/spec/controllers/dashboards_controller_spec.rb @@ -1,10 +1,11 @@ require File.dirname(__FILE__) + '/../spec_helper' - +include ApplicationHelper describe DashboardsController do render_views before do @user = Factory.create(:user) @user.person.save + @person = Factory.create(:person) request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user) end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index cfece45ed..d03987740 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -5,23 +5,8 @@ describe ApplicationHelper do before do @user = Factory.create(:user) @person = Factory.create(:person) - #env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user) - sign_in @user - @user.save 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 person_url(@person).should == "/people/#{@person.id}" diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index ca3b9aead..6fcd775d3 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -1,39 +1,50 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Person do + before do + @person = Factory.create(:person) + end it 'should not allow two people with the same email' do - person_one = Factory.create(:person) - person_two = Factory.build(:person, :url => person_one.email) + person_two = Factory.build(:person, :url => @person.email) person_two.valid?.should == false end - it 'should serialize to xml' do - person = Factory.create(:person) - xml = person.to_xml.to_s - (xml.include? "person").should == true - end + describe 'xml' do + before do + @xml = @person.to_xml.to_s + end + it 'should serialize to xml' do + (@xml.include? "person").should == true + end - it 'should have a profile in its xml' do - person = Factory.create(:person) - xml = person.to_xml.to_s - (xml.include? "first_name").should == true + it 'should have a profile in its xml' do + (@xml.include? "first_name").should == true + end + 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 it 'should delete all of user except comments upon user deletion' do Factory.create(:user) f = Factory.create(:person) - p = Factory.create(:person) + Factory.create(:status_message, :person => f) Factory.create(:blog, :person => f) Factory.create(:bookmark, :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 => "i love you", :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 @@ -47,15 +58,14 @@ describe Person do user = Factory.create(:user) user.save - person = Factory.create(:person) - user.friends << person - person.user_refs += 1 - person.save + user.friends << @person + @person.user_refs += 1 + @person.save Person.all.count.should == 2 user.friends.count.should == 1 - user.unfriend(person.id) + user.unfriend(@person.id) user.friends.count.should == 0 Person.all.count.should == 1 end @@ -67,21 +77,20 @@ describe Person do user_one.save user_two.save - person = Factory.create(:person) - user_one.friends << person - user_two.friends << person + user_one.friends << @person + user_two.friends << @person user_one.save user_two.save - person.user_refs += 2 - person.save + @person.user_refs += 2 + @person.save Person.all.count.should == 3 user_one.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_two.friends.count.should == 1