diff options
Diffstat (limited to 'spec/controllers/posts_controller_spec.rb')
-rw-r--r-- | spec/controllers/posts_controller_spec.rb | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 951fd7b0b..25c12b90a 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -6,28 +6,72 @@ require 'spec_helper' describe PostsController do before do - alice - end + sign_in alice + aspect = alice.aspects.first + @message = alice.build_post :status_message, :text => "ohai", :to => aspect.id + @message.save! + alice.add_to_streams(@message, [aspect]) + alice.dispatch_post @message, :to => aspect.id + end describe '#show' do - it 'shows a public post' do - status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all') - get :show, :id => status.id - response.status= 200 + + it 'succeeds' do + get :show, "id" => @message.id.to_s + response.should be_success + end + + it 'marks a corresponding notification as read' do + alice.comment("comment after me", :post => @message) + bob.comment("here you go", :post => @message) + note = Notification.where(:recipient_id => alice.id, :target_id => @message.id).first + lambda{ + get :show, :id => @message.id + note.reload + }.should change(note, :unread).from(true).to(false) + end + + it 'redirects to back if there is no status message' do + get :show, :id => 2345 + response.status.should == 302 + end + + it 'succeeds with a AS/photo' do + photo = Factory(:activity_streams_photo, :author => bob.person) + get :show, :id => photo.id + response.should be_success + end + end + describe '#destroy' do + + it 'let a user delete his message' do + message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id) + delete :destroy, :format => :js, :id => message.id + response.should be_success + StatusMessage.find_by_id(message.id).should be_nil + end + + it 'sends a retraction on delete' do + controller.stub!(:current_user).and_return alice + message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id) + alice.should_receive(:retract).with(message) + delete :destroy, :format => :js, :id => message.id + response.should be_success end - it 'does not show a private post' do - status = alice.post(:status_message, :text => "hello", :public => false, :to => 'all') - get :show, :id => status.id - response.status = 302 + it 'will not let you destroy posts visible to you' do + message = bob.post(:status_message, :text => "hey", :to => bob.aspects.first.id) + delete :destroy, :format => :js, :id => message.id + response.should_not be_success + StatusMessage.exists?(message.id).should be_true end - it 'redirects to the proper show page if the user has visibility of the post' do - status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all') - sign_in bob - get :show, :id => status.id - response.should be_redirect + it 'will not let you destory posts you do not own' do + message = eve.post(:status_message, :text => "hey", :to => eve.aspects.first.id) + delete :destroy, :format => :js, :id => message.id + response.should_not be_success + StatusMessage.exists?(message.id).should be_true end end end |