Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
parlote-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
parlote-facil
Validations
40fa91ea
Valider
40fa91ea
rédigé
il y a 14 ans
par
Sarah Mei
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Start refactor of comment_spec.
parent
83576d75
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
spec/models/comment_spec.rb
+80
-88
80 ajouts, 88 suppressions
spec/models/comment_spec.rb
avec
80 ajouts
et
88 suppressions
spec/models/comment_spec.rb
+
80
−
88
Voir le fichier @
40fa91ea
...
@@ -5,66 +5,58 @@
...
@@ -5,66 +5,58 @@
require
'spec_helper'
require
'spec_helper'
describe
Comment
do
describe
Comment
do
let
(
:user
)
{
alice
}
before
do
let
(
:aspect
)
{
user
.
aspects
.
first
}
@alices_aspect
=
alice
.
aspects
.
first
@bobs_aspect
=
bob
.
aspects
.
first
let
(
:user2
)
{
bob
}
let
(
:aspect2
)
{
user2
.
aspects
.
first
}
describe
'comment#notification_type'
do
let
(
:user3
)
{
Factory
(
:user
)}
let
(
:aspect3
)
{
user3
.
aspects
.
create
(
:name
=>
"Faces"
)}
let!
(
:connecting2
)
{
connect_users
(
user
,
aspect
,
user3
,
aspect3
)
}
before
do
@post2
=
user2
.
post
(
:status_message
,
:message
=>
'yo'
,
:to
=>
aspect2
.
id
)
@post1
=
user
.
post
(
:status_message
,
:message
=>
"hello"
,
:to
=>
aspect
.
id
)
@c11
=
user2
.
comment
"why so formal?"
,
:on
=>
@post1
@c12
=
user
.
comment
"I simply felt like issuing a greeting. Do step off."
,
:on
=>
@post1
@c22
=
user2
.
comment
"I simply felt like issuing a greeting. Do step off."
,
:on
=>
@post2
end
it
"returns 'comment_on_post' if the comment is on a post you own"
do
@c11
.
notification_type
(
user
,
user2
.
person
).
should
==
'comment_on_post'
end
it
'returns false if the comment is not on a post you own and noone "also_commented"'
do
@c12
.
notification_type
(
user3
,
user
.
person
).
should
==
false
end
context
"also commented"
do
before
do
@c13
=
user3
.
comment
"I also commented on the first user's post"
,
:on
=>
@post1
end
it
'does not return also commented if the user commented'
do
@c13
.
notification_type
(
user3
,
user
.
person
).
should
==
false
end
it
"returns 'also_commented' if another person commented on a post you commented on"
do
@c13
.
notification_type
(
user2
,
user
.
person
).
should
==
'also_commented'
end
end
end
end
describe
'comment#notification_type'
do
before
do
@sam
=
Factory
(
:user_with_aspect
)
connect_users
(
alice
,
@alices_aspect
,
@sam
,
@sam
.
aspects
.
first
)
@alices_post
=
alice
.
post
(
:status_message
,
:message
=>
"hello"
,
:to
=>
@alices_aspect
.
id
)
end
it
"returns 'comment_on_post' if the comment is on a post you own"
do
comment
=
bob
.
comment
(
"why so formal?"
,
:on
=>
@alices_post
)
comment
.
notification_type
(
alice
,
bob
.
person
).
should
==
'comment_on_post'
end
it
'returns false if the comment is not on a post you own and no one "also_commented"'
do
comment
=
alice
.
comment
(
"I simply felt like issuing a greeting. Do step off."
,
:on
=>
@alices_post
)
comment
.
notification_type
(
@sam
,
alice
.
person
).
should
==
false
end
context
"also commented"
do
before
do
bob
.
comment
(
"a-commenta commenta"
,
:on
=>
@alices_post
)
@comment
=
@sam
.
comment
(
"I also commented on the first user's post"
,
:on
=>
@alices_post
)
end
it
'does not return also commented if the user commented'
do
@comment
.
notification_type
(
@sam
,
alice
.
person
).
should
==
false
end
it
"returns 'also_commented' if another person commented on a post you commented on"
do
@comment
.
notification_type
(
bob
,
alice
.
person
).
should
==
'also_commented'
end
end
end
describe
'User#comment'
do
describe
'User#comment'
do
before
do
before
do
@status
=
user
.
post
(
:status_message
,
:message
=>
"hello"
,
:to
=>
aspect
.
id
)
@status
=
alice
.
post
(
:status_message
,
:message
=>
"hello"
,
:to
=>
@alices_
aspect
.
id
)
end
end
it
"should be able to comment on his own status"
do
it
"should be able to comment on one's own status"
do
@status
.
comments
.
should
==
[]
alice
.
comment
(
"Yeah, it was great"
,
:on
=>
@status
)
user
.
comment
"Yeah, it was great"
,
:on
=>
@status
@status
.
reload
.
comments
.
first
.
text
.
should
==
"Yeah, it was great"
@status
.
reload
.
comments
.
first
.
text
.
should
==
"Yeah, it was great"
end
end
it
"should be able to comment on a
person
's status"
do
it
"should be able to comment on a
contact
's status"
do
user2
.
comment
"sup dog"
,
:on
=>
@status
bob
.
comment
(
"sup dog"
,
:on
=>
@status
)
@status
.
reload
.
comments
.
first
.
text
.
should
==
"sup dog"
@status
.
reload
.
comments
.
first
.
text
.
should
==
"sup dog"
end
end
end
end
...
@@ -72,67 +64,67 @@ describe Comment do
...
@@ -72,67 +64,67 @@ describe Comment do
context
'comment propagation'
do
context
'comment propagation'
do
before
do
before
do
@person
=
Factory
.
create
(
:person
)
@person
=
Factory
.
create
(
:person
)
user
.
activate_contact
(
@person
,
aspect
)
alice
.
activate_contact
(
@person
,
@alices_
aspect
)
@person2
=
Factory
.
create
(
:person
)
@person2
=
Factory
.
create
(
:person
)
@person3
=
Factory
.
create
(
:person
)
@person3
=
Factory
.
create
(
:person
)
user
.
activate_contact
(
@person3
,
aspect
)
alice
.
activate_contact
(
@person3
,
@alices_
aspect
)
@person_status
=
Factory
.
create
(
:status_message
,
:person
=>
@person
)
@person_status
=
Factory
.
create
(
:status_message
,
:person
=>
@person
)
user
.
reload
alice
.
reload
@user_status
=
user
.
post
:status_message
,
:message
=>
"hi"
,
:to
=>
aspect
.
id
@user_status
=
alice
.
post
:status_message
,
:message
=>
"hi"
,
:to
=>
@alices_
aspect
.
id
aspect
.
reload
@alices_
aspect
.
reload
user
.
reload
alice
.
reload
end
end
it
'should send the comment to the postman'
do
it
'should send the comment to the postman'
do
m
=
mock
()
m
=
mock
()
m
.
stub!
(
:post
)
m
.
stub!
(
:post
)
Postzord
::
Dispatch
.
should_receive
(
:new
).
and_return
(
m
)
Postzord
::
Dispatch
.
should_receive
(
:new
).
and_return
(
m
)
user
.
comment
"yo"
,
:on
=>
@person_status
alice
.
comment
"yo"
,
:on
=>
@person_status
end
end
describe
'#subscribers'
do
describe
'#subscribers'
do
it
'returns the posts original audience, if the post is owned by the user'
do
it
'returns the posts original audience, if the post is owned by the user'
do
comment
=
user
.
build_comment
"yo"
,
:on
=>
@person_status
comment
=
alice
.
build_comment
"yo"
,
:on
=>
@person_status
comment
.
subscribers
(
user
).
should
=~
[
@person
]
comment
.
subscribers
(
alice
).
should
=~
[
@person
]
end
end
it
'returns the owner of the original post, if the user owns the comment'
do
it
'returns the owner of the original post, if the user owns the comment'
do
comment
=
user
.
build_comment
"yo"
,
:on
=>
@user_status
comment
=
alice
.
build_comment
"yo"
,
:on
=>
@user_status
comment
.
subscribers
(
user
).
map
{
|
s
|
s
.
id
}.
should
=~
[
@person
,
@person3
,
user2
.
person
].
map
{
|
s
|
s
.
id
}
comment
.
subscribers
(
alice
).
map
{
|
s
|
s
.
id
}.
should
=~
[
@person
,
@person3
,
bob
.
person
].
map
{
|
s
|
s
.
id
}
end
end
end
end
context
'testing a method only used for testing'
do
context
'testing a method only used for testing'
do
it
"should send a user's comment on a person's post to that person"
do
it
"should send a user's comment on a person's post to that person"
do
m
=
mock
()
m
=
mock
()
m
.
stub!
(
:post
)
m
.
stub!
(
:post
)
Postzord
::
Dispatch
.
should_receive
(
:new
).
and_return
(
m
)
Postzord
::
Dispatch
.
should_receive
(
:new
).
and_return
(
m
)
user
.
comment
"yo"
,
:on
=>
@person_status
alice
.
comment
"yo"
,
:on
=>
@person_status
end
end
end
end
it
'should not clear the aspect post array on receiving a comment'
do
it
'should not clear the aspect post array on receiving a comment'
do
aspect
.
post_ids
.
include?
(
@user_status
.
id
).
should
be_true
@alices_
aspect
.
post_ids
.
include?
(
@user_status
.
id
).
should
be_true
comment
=
Comment
.
new
(
:person_id
=>
@person
.
id
,
:text
=>
"cats"
,
:post
=>
@user_status
)
comment
=
Comment
.
new
(
:person_id
=>
@person
.
id
,
:text
=>
"cats"
,
:post
=>
@user_status
)
zord
=
Postzord
::
Receiver
.
new
(
user
,
:person
=>
@person
)
zord
=
Postzord
::
Receiver
.
new
(
alice
,
:person
=>
@person
)
zord
.
parse_and_receive
(
comment
.
to_diaspora_xml
)
zord
.
parse_and_receive
(
comment
.
to_diaspora_xml
)
aspect
.
reload
@alices_
aspect
.
reload
aspect
.
post_ids
.
include?
(
@user_status
.
id
).
should
be_true
@alices_
aspect
.
post_ids
.
include?
(
@user_status
.
id
).
should
be_true
end
end
end
end
describe
'xml'
do
describe
'xml'
do
before
do
before
do
@commenter
=
Factory
.
create
(
:user
)
@commenter
=
Factory
.
create
(
:user
)
@commenter_aspect
=
@commenter
.
aspects
.
create
(
:name
=>
"bruisers"
)
@commenter_aspect
=
@commenter
.
aspects
.
create
(
:name
=>
"bruisers"
)
connect_users
(
user
,
aspect
,
@commenter
,
@commenter_aspect
)
connect_users
(
alice
,
@alices_
aspect
,
@commenter
,
@commenter_aspect
)
@post
=
user
.
post
:status_message
,
:message
=>
"hello"
,
:to
=>
aspect
.
id
@post
=
alice
.
post
:status_message
,
:message
=>
"hello"
,
:to
=>
@alices_
aspect
.
id
@comment
=
@commenter
.
comment
"Fool!"
,
:on
=>
@post
@comment
=
@commenter
.
comment
"Fool!"
,
:on
=>
@post
@xml
=
@comment
.
to_xml
.
to_s
@xml
=
@comment
.
to_xml
.
to_s
end
end
...
@@ -156,53 +148,53 @@ describe Comment do
...
@@ -156,53 +148,53 @@ describe Comment do
end
end
describe
'local commenting'
do
describe
'local commenting'
do
before
do
before
do
@status
=
user
.
post
(
:status_message
,
:message
=>
"hello"
,
:to
=>
aspect
.
id
)
@status
=
alice
.
post
(
:status_message
,
:message
=>
"hello"
,
:to
=>
@alices_
aspect
.
id
)
end
end
it
'does not multi-post a comment'
do
it
'does not multi-post a comment'
do
lambda
{
lambda
{
user
.
comment
'hello'
,
:on
=>
@status
alice
.
comment
'hello'
,
:on
=>
@status
}.
should
change
{
Comment
.
count
}.
by
(
1
)
}.
should
change
{
Comment
.
count
}.
by
(
1
)
end
end
end
end
describe
'comments'
do
describe
'comments'
do
before
do
before
do
@remote_message
=
user2
.
post
:status_message
,
:message
=>
"hello"
,
:to
=>
aspect
2
.
id
@remote_message
=
bob
.
post
:status_message
,
:message
=>
"hello"
,
:to
=>
@bobs_
aspect
.
id
@message
=
user
.
post
:status_message
,
:message
=>
"hi"
,
:to
=>
aspect
.
id
@message
=
alice
.
post
:status_message
,
:message
=>
"hi"
,
:to
=>
@alices_
aspect
.
id
end
end
it
'should attach the creator signature if the user is commenting'
do
it
'should attach the creator signature if the user is commenting'
do
comment
=
user
.
comment
"Yeah, it was great"
,
:on
=>
@remote_message
comment
=
alice
.
comment
"Yeah, it was great"
,
:on
=>
@remote_message
@remote_message
.
comments
.
reset
@remote_message
.
comments
.
reset
@remote_message
.
comments
.
first
.
signature_valid?
.
should
be_true
@remote_message
.
comments
.
first
.
signature_valid?
.
should
be_true
end
end
it
'should sign the comment if the user is the post creator'
do
it
'should sign the comment if the user is the post creator'
do
message
=
user
.
post
:status_message
,
:message
=>
"hi"
,
:to
=>
aspect
.
id
message
=
alice
.
post
:status_message
,
:message
=>
"hi"
,
:to
=>
@alices_
aspect
.
id
user
.
comment
"Yeah, it was great"
,
:on
=>
message
alice
.
comment
"Yeah, it was great"
,
:on
=>
message
message
.
comments
.
reset
message
.
comments
.
reset
message
.
comments
.
first
.
signature_valid?
.
should
be_true
message
.
comments
.
first
.
signature_valid?
.
should
be_true
message
.
comments
.
first
.
verify_post_creator_signature
.
should
be_true
message
.
comments
.
first
.
verify_post_creator_signature
.
should
be_true
end
end
it
'should verify a comment made on a remote post by a different contact'
do
it
'should verify a comment made on a remote post by a different contact'
do
comment
=
Comment
.
new
(
:person
=>
user2
.
person
,
:text
=>
"cats"
,
:post
=>
@remote_message
)
comment
=
Comment
.
new
(
:person
=>
bob
.
person
,
:text
=>
"cats"
,
:post
=>
@remote_message
)
comment
.
creator_signature
=
comment
.
send
(
:sign_with_key
,
user2
.
encryption_key
)
comment
.
creator_signature
=
comment
.
send
(
:sign_with_key
,
bob
.
encryption_key
)
comment
.
signature_valid?
.
should
be_true
comment
.
signature_valid?
.
should
be_true
comment
.
verify_post_creator_signature
.
should
be_false
comment
.
verify_post_creator_signature
.
should
be_false
comment
.
post_creator_signature
=
comment
.
send
(
:sign_with_key
,
user
.
encryption_key
)
comment
.
post_creator_signature
=
comment
.
send
(
:sign_with_key
,
alice
.
encryption_key
)
comment
.
verify_post_creator_signature
.
should
be_true
comment
.
verify_post_creator_signature
.
should
be_true
end
end
it
'should reject comments on a remote post with only a creator sig'
do
it
'should reject comments on a remote post with only a creator sig'
do
comment
=
Comment
.
new
(
:person
=>
user2
.
person
,
:text
=>
"cats"
,
:post
=>
@remote_message
)
comment
=
Comment
.
new
(
:person
=>
bob
.
person
,
:text
=>
"cats"
,
:post
=>
@remote_message
)
comment
.
creator_signature
=
comment
.
send
(
:sign_with_key
,
user2
.
encryption_key
)
comment
.
creator_signature
=
comment
.
send
(
:sign_with_key
,
bob
.
encryption_key
)
comment
.
signature_valid?
.
should
be_true
comment
.
signature_valid?
.
should
be_true
comment
.
verify_post_creator_signature
.
should
be_false
comment
.
verify_post_creator_signature
.
should
be_false
end
end
it
'should receive remote comments on a user post with a creator sig'
do
it
'should receive remote comments on a user post with a creator sig'
do
comment
=
Comment
.
new
(
:person
=>
user2
.
person
,
:text
=>
"cats"
,
:post
=>
@message
)
comment
=
Comment
.
new
(
:person
=>
bob
.
person
,
:text
=>
"cats"
,
:post
=>
@message
)
comment
.
creator_signature
=
comment
.
send
(
:sign_with_key
,
user2
.
encryption_key
)
comment
.
creator_signature
=
comment
.
send
(
:sign_with_key
,
bob
.
encryption_key
)
comment
.
signature_valid?
.
should
be_true
comment
.
signature_valid?
.
should
be_true
comment
.
verify_post_creator_signature
.
should
be_false
comment
.
verify_post_creator_signature
.
should
be_false
end
end
...
@@ -210,7 +202,7 @@ describe Comment do
...
@@ -210,7 +202,7 @@ describe Comment do
describe
'youtube'
do
describe
'youtube'
do
before
do
before
do
@message
=
user
.
post
:status_message
,
:message
=>
"hi"
,
:to
=>
aspect
.
id
@message
=
alice
.
post
:status_message
,
:message
=>
"hi"
,
:to
=>
@alices_
aspect
.
id
end
end
it
'should process youtube titles on the way in'
do
it
'should process youtube titles on the way in'
do
video_id
=
"ABYnqp-bxvg"
video_id
=
"ABYnqp-bxvg"
...
@@ -222,7 +214,7 @@ describe Comment do
...
@@ -222,7 +214,7 @@ describe Comment do
mock_http
.
should_receive
(
:get
).
with
(
'/feeds/api/videos/'
+
video_id
+
'?v=2'
,
nil
).
and_return
(
mock_http
.
should_receive
(
:get
).
with
(
'/feeds/api/videos/'
+
video_id
+
'?v=2'
,
nil
).
and_return
(
[
nil
,
'Foobar <title>'
+
expected_title
+
'</title> hallo welt <asd><dasdd><a>dsd</a>'
])
[
nil
,
'Foobar <title>'
+
expected_title
+
'</title> hallo welt <asd><dasdd><a>dsd</a>'
])
comment
=
user
.
build_comment
url
,
:on
=>
@message
comment
=
alice
.
build_comment
url
,
:on
=>
@message
comment
.
save!
comment
.
save!
Comment
.
find
(
comment
.
id
).
youtube_titles
.
should
==
{
video_id
=>
CGI
::
escape
(
expected_title
)}
Comment
.
find
(
comment
.
id
).
youtube_titles
.
should
==
{
video_id
=>
CGI
::
escape
(
expected_title
)}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter