diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index d00747a2d..1f24f3fed 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -7,65 +7,68 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe User do - before do - @user = Factory.create :user - @aspect = @user.aspect(:name => 'heroes') - @aspect1 = @user.aspect(:name => 'heroes') - @user2 = Factory.create(:user) - @aspect2 = @user2.aspect(:name => 'losers') + let(:user) { Factory(:user) } + let(:user2) { Factory(:user) } + let(:user3) { Factory(:user) } + let(:user4) { Factory(:user) } - @user3 = Factory.create(:user) - @aspect3 = @user3.aspect(:name => 'heroes') + let(:aspect) {user.aspect(:name => 'heroes')} + let!(:aspect1) {user.aspect(:name => 'heroes')} + let!(:aspect2) {user2.aspect(:name => 'losers')} + let!(:aspect3) {user3.aspect(:name => 'heroes')} + let!(:aspect4) {user4.aspect(:name => 'heroes')} - @user4 = Factory.create(:user) - @aspect4 = @user4.aspect(:name => 'heroes') - - friend_users(@user, @aspect, @user2, @aspect2) - friend_users(@user, @aspect, @user3, @aspect3) - friend_users(@user, @aspect1, @user4, @aspect4) - end - - it 'should not be able to post without a aspect' do - proc {@user.post(:status_message, :message => "heyheyhey")}.should raise_error /You must post to someone/ + before do + friend_users(user, aspect, user2, aspect2) + friend_users(user, aspect, user3, aspect3) + friend_users(user, aspect1, user4, aspect4) end - it 'should not be able to post to someone elses aspect' do - proc {@user.post(:status_message, :message => "heyheyhey", :to => @aspect2.id)}.should raise_error /Cannot post to an aspect you do not own./ - end - - it 'should put the post in the aspect post array' do - post = @user.post(:status_message, :message => "hey", :to => @aspect.id) - @aspect.reload - @aspect.post_ids.include?(post.id).should be true + context 'posting' do + describe '#post' do + it 'should not be able to post without a aspect' do + proc {user.post(:status_message, :message => "heyheyhey")}.should raise_error /You must post to someone/ + end + + it 'should not be able to post to someone elses aspect' do + proc {user.post(:status_message, :message => "heyheyhey", :to => aspect2.id)}.should raise_error /Cannot post to an aspect you do not own./ + end + + it 'should put the post in the aspect post array' do + post = user.post(:status_message, :message => "hey", :to => aspect.id) + aspect.reload + aspect.posts.should include post + end + + it 'should put an album in the aspect post array' do + album = user.post :album, :name => "Georges", :to => aspect.id + aspect.reload + aspect.posts.should include album + end + end end - it 'should put an album in the aspect post array' do - album = @user.post :album, :name => "Georges", :to => @aspect.id - @aspect.reload - @aspect.post_ids.include?(album.id).should be true - @aspect.posts.include?(album).should be true - end + context 'dispatching' do + let!(:post) { user.build_post :status_message, :message => "hey" } - describe 'dispatching' do - before do - @post = @user.build_post :status_message, :message => "hey" - end - it 'should push a post to a aspect' do - @user.should_receive(:salmon).twice - @user.push_to_aspects(@post, @aspect.id) + describe '#push_to_aspects' do + it 'should push a post to a aspect' do + user.should_receive(:salmon).twice + user.push_to_aspects(post, aspect.id) + end + + it 'should push a post to all aspects' do + user.should_receive(:salmon).exactly(3).times + user.push_to_aspects(post, :all) + end end - it 'should push a post to all aspects' do - @user.should_receive(:salmon).exactly(3).times - @user.push_to_aspects(@post, :all) + describe '#push_to_people' do + it 'should push to people' do + user.should_receive(:salmon).twice + user.push_to_people(post, [user2.person, user3.person]) + end end - - it 'should push to people' do - @user.should_receive(:salmon).twice - @user.push_to_people(@post, [@user2.person, @user3.person]) - end - - end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 63639bc73..2249ae0b1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -18,14 +18,7 @@ describe User do end end - it 'should create with pivotal or allowed emails' do - user1 = Factory.create(:user, :email => "kimfuh@yahoo.com") - user2 = Factory.create(:user, :email => "awesome@sofaer.net") - user3 = Factory.create(:user, :email => "steveellis@pivotallabs.com") - user1.created_at.nil?.should be false - user2.created_at.nil?.should be false - user3.created_at.nil?.should be false - end + describe 'profiles' do it 'should be able to update their profile and send it to their friends' do @@ -64,4 +57,5 @@ describe User do @user.aspects.include?(@aspect).should == true end end + end