Skip to content
Extraits de code Groupes Projets
Valider 216a2c3c rédigé par Raphael's avatar Raphael Validation de Raphael Sofaer
Parcourir les fichiers

write formatted_message

parent 51e129b5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -22,6 +22,24 @@ class StatusMessage < Post
get_youtube_title message
end
def formatted_message
people = self.mentioned_people
regex = /@\{([^;]+); ([^\}]+)\}/
message.gsub(regex) do |matched_string|
people.detect{ |p|
p.diaspora_handle == matched_string.match(regex).captures.last
}.name
end
end
def mentioned_people
regex = /@\{([^;]+); ([^\}]+)\}/
identifiers = self.message.scan(regex).map do |match|
match.last
end
Person.where(:diaspora_handle => identifiers)
end
def to_activity
<<-XML
<entry>
......
......@@ -51,9 +51,30 @@ describe StatusMessage do
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)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter