From 97ca10dddaac9b956b7b6d8ff99dc7148c6ca40d Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Sun, 10 Jul 2011 16:51:29 -0700 Subject: Huge commit I know, but move show and destroy routes into PostsController and PostsController#show into PublicsController --- .../activity_streams/photos_controller_spec.rb | 10 --- spec/controllers/posts_controller_spec.rb | 74 +++++++++++++++++----- spec/controllers/publics_controller_spec.rb | 22 +++++++ .../controllers/status_messages_controller_spec.rb | 58 ----------------- spec/helpers/notifications_helper_spec.rb | 6 +- spec/lib/fake_spec.rb | 2 +- spec/support/i18n_raise_errors.rb | 2 +- 7 files changed, 86 insertions(+), 88 deletions(-) (limited to 'spec') diff --git a/spec/controllers/activity_streams/photos_controller_spec.rb b/spec/controllers/activity_streams/photos_controller_spec.rb index d088c5b9c..cb33880c9 100644 --- a/spec/controllers/activity_streams/photos_controller_spec.rb +++ b/spec/controllers/activity_streams/photos_controller_spec.rb @@ -1,15 +1,5 @@ require 'spec_helper' describe ActivityStreams::PhotosController do - describe '#show' do - before do - @photo = Factory(:activity_streams_photo, :author => bob.person) - sign_in :user, alice - end - it 'succeeds' do - get :show, :id => @photo.id - response.should be_success - end - end end 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 diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 8783c0fad..0e4b6d465 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -61,6 +61,28 @@ describe PublicsController do end end + describe '#post' do + it 'shows a public post' do + status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all') + + get :post, :id => status.id + response.status= 200 + end + + it 'does not show a private post' do + status = alice.post(:status_message, :text => "hello", :public => false, :to => 'all') + get :post, :id => status.id + response.status = 302 + 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 :post, :id => status.id + response.should be_redirect + end + end + describe '#hcard' do it "succeeds", :fixture => true do post :hcard, "guid" => @user.person.guid.to_s diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 5ccb76abd..ce6fa6485 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -39,36 +39,6 @@ describe StatusMessagesController do end end - describe '#show' do - before do - @message = alice.build_post :status_message, :text => "ohai", :to => @aspect1.id - @message.save! - - alice.add_to_streams(@message, [@aspect1]) - alice.dispatch_post @message, :to => @aspect1.id - end - - 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 - end - describe '#create' do let(:status_message_hash) { { :status_message => { @@ -164,32 +134,4 @@ describe StatusMessagesController do end end end - - describe '#destroy' do - before do - @message = alice.post(:status_message, :text => "hey", :to => @aspect1.id) - @message2 = bob.post(:status_message, :text => "hey", :to => @aspect2.id) - @message3 = eve.post(:status_message, :text => "hey", :to => eve.aspects.first.id) - end - - it 'let a user delete his message' do - delete :destroy, :format => :js, :id => @message.id - StatusMessage.find_by_id(@message.id).should be_nil - end - - it 'sends a retraction on delete' do - alice.should_receive(:retract).with(@message) - delete :destroy, :format => :js, :id => @message.id - end - - it 'will not let you destroy posts visible to you' do - delete :destroy, :format => :js, :id => @message2.id - StatusMessage.find_by_id(@message2.id).should be_true - end - - it 'will not let you destory posts you do not own' do - delete :destroy, :format => :js, :id => @message3.id - StatusMessage.find_by_id(@message3.id).should be_true - end - end end diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb index 646384aae..3e4d599a2 100644 --- a/spec/helpers/notifications_helper_spec.rb +++ b/spec/helpers/notifications_helper_spec.rb @@ -10,7 +10,7 @@ describe NotificationsHelper do @person2 = Factory(:person) @notification = Notification.notify(@user, Factory(:like, :author => @person, :post => @post), @person) @notification = Notification.notify(@user, Factory(:like, :author => @person2, :post => @post), @person2) - + end describe '#notification_people_link' do context 'formatting' do @@ -68,14 +68,14 @@ describe NotificationsHelper do describe 'for a like' do it 'should include a link to the post' do output = object_link(@notification, notification_people_link(@notification)) - output.should include status_message_path(@post) + output.should include post_path(@post) end it 'includes the boilerplate translation' do output = object_link(@notification, notification_people_link(@notification)) output.should include t("#{@notification.popup_translation_key}.one", :actors => notification_people_link(@notification), - :post_link => "#{t('notifications.post')}") + :post_link => "#{t('notifications.post')}") end context 'when post is deleted' do diff --git a/spec/lib/fake_spec.rb b/spec/lib/fake_spec.rb index 7e6cb5aea..f43302381 100644 --- a/spec/lib/fake_spec.rb +++ b/spec/lib/fake_spec.rb @@ -55,7 +55,7 @@ describe PostsFake do sm = Factory(:status_message) fake = PostsFake::Fake.new(sm, @fakes) - status_message_path(fake).should == status_message_path(sm) + post_path(fake).should == post_path(sm) end end end diff --git a/spec/support/i18n_raise_errors.rb b/spec/support/i18n_raise_errors.rb index 0564e2743..414867feb 100644 --- a/spec/support/i18n_raise_errors.rb +++ b/spec/support/i18n_raise_errors.rb @@ -1,6 +1,6 @@ module I18n def self.just_raise_that_exception(*args) - raise args.first + raise "Translation not found: #{args.first.key}" end end -- cgit v1.2.3