# Copyright (c) 2010, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. require 'spec_helper' describe StatusMessagesController do before do @aspect1 = alice.aspects.first @aspect2 = bob.aspects.first request.env["HTTP_REFERER"] = "" sign_in :user, alice @controller.stub!(:current_user).and_return(alice) alice.reload end describe '#bookmarklet' do it 'succeeds' do get :bookmarklet response.should be_success end end describe '#new' do it 'succeeds' do get :new, :person_id => bob.person.id response.should be_success end it 'generates a jasmine fixture', :fixture => 'jasmine' do contact = alice.contact_for(bob.person) aspect = alice.aspects.create(:name => 'people') contact.aspects << aspect contact.save get :new, :person_id => bob.person.id, :layout => true save_fixture(html_for("body"), "status_message_new") 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", :on => @message) bob.comment("here you go", :on => @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 => { :public => "true", :text => "facebook, is that you?", }, :aspect_ids => [@aspect1.id.to_s] } } context 'js requests' do it 'responds' do post :create, status_message_hash.merge(:format => 'js') response.status.should == 201 end it 'responds with json' do post :create, status_message_hash.merge(:format => 'js') json = JSON.parse(response.body) json['post_id'].should_not be_nil json['html'].should_not be_nil end it 'escapes XSS' do xss = "" post :create, status_message_hash.merge(:format => 'js', :text => xss) json = JSON.parse(response.body) json['html'].should_not =~ /