# 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 StatusMessage do
before do
@user = alice
@aspect = @user.aspects.first
end
describe '#diaspora_handle=' do
it 'sets #person' do
person = Factory.create(:person)
post = Factory.create(:status_message, :person => @user.person)
post.diaspora_handle = person.diaspora_handle
post.person.should == person
end
end
it "should have either a message or at least one photo" do
n = Factory.build(:status_message, :message => nil)
n.valid?.should be_false
n.message = ""
n.valid?.should be_false
n.message = "wales"
n.valid?.should be_true
n.message = nil
photo = @user.build_post(:photo, :user_file => uploaded_photo, :to => @aspect.id)
photo.save!
n.photos << photo
n.valid?
n.errors.full_messages.should == []
end
it 'should be postable through the user' do
message = "Users do things"
status = @user.post(:status_message, :message => message, :to => @aspect.id)
db_status = StatusMessage.find(status.id)
db_status.message.should == message
end
it 'should require status messages to be less than 1000 characters' do
message = ''
1001.times do message = message +'1';end
status = Factory.build(:status_message, :message => message)
status.should_not be_valid
end
describe 'mentions' do
before do
@people = [alice, bob, eve].map{|u| u.person}
@test_string = <<-STR
@{Raphael; #{@people[0].diaspora_handle}} can mention people like Raphael @{Ilya; #{@people[1].diaspora_handle}}
can mention people like Raphaellike Raphael @{Daniel; #{@people[2].diaspora_handle}} can mention people like Raph
STR
@sm = Factory.create(:status_message, :message => @test_string )
end
it 'adds the links in the formated message text' do
@sm.formatted_message.should == <<-STR
#{@people[0].name} can mention people like Raphael #{@people[1].name}
can mention people like Raphaellike Raphael #{@people[2].name} can mention people like Raph
STR
end
it 'extracts the mentioned people from the message' do
@sm.mentioned_people.to_set.should == @people.to_set
end
end
describe "XML" do
before do
@message = Factory.create(:status_message, :message => "I hate WALRUSES!", :person => @user.person)
@xml = @message.to_xml.to_s
end
it 'serializes the message' do
@xml.should include "