# 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
render_views
before do
@user1 = alice
@user2 = bob
@aspect1 = @user1.aspects.first
@aspect2 = @user2.aspects.first
request.env["HTTP_REFERER"] = ""
sign_in :user, @user1
@controller.stub!(:current_user).and_return(@user1)
@user1.reload
end
describe '#show' do
before do
@message = @user1.build_post :status_message, :message => "ohai", :to => @aspect1.id
@message.save!
@user1.add_to_streams(@message, [@aspect1])
@user1.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",
:message => "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', :message => xss)
json = JSON.parse(response.body)
json['html'].should_not =~ /