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
ab2118ff
Valider
ab2118ff
rédigé
il y a 8 ans
par
Benjamin Neff
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
don't participate own posts
parent
2f2fe71c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
app/models/user/social_actions.rb
+1
-0
1 ajout, 0 suppression
app/models/user/social_actions.rb
spec/models/user/social_actions_spec.rb
+46
-63
46 ajouts, 63 suppressions
spec/models/user/social_actions_spec.rb
avec
47 ajouts
et
63 suppressions
app/models/user/social_actions.rb
+
1
−
0
Voir le fichier @
ab2118ff
...
@@ -48,6 +48,7 @@ module User::SocialActions
...
@@ -48,6 +48,7 @@ module User::SocialActions
end
end
def
update_or_create_participation!
(
target
)
def
update_or_create_participation!
(
target
)
return
if
target
.
author
==
person
participation
=
participations
.
where
(
target_id:
target
).
first
participation
=
participations
.
where
(
target_id:
target
).
first
if
participation
.
present?
if
participation
.
present?
participation
.
update!
(
count:
participation
.
count
.
next
)
participation
.
update!
(
count:
participation
.
count
.
next
)
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
spec/models/user/social_actions_spec.rb
+
46
−
63
Voir le fichier @
ab2118ff
require
"spec_helper"
require
"spec_helper"
describe
User
::
SocialActions
,
:type
=>
:model
do
describe
User
::
SocialActions
,
type: :model
do
before
do
let
(
:status
)
{
FactoryGirl
.
create
(
:status_message
,
public:
true
,
author:
bob
.
person
)
}
@bobs_aspect
=
bob
.
aspects
.
where
(
:name
=>
"generic"
).
first
@status
=
bob
.
post
(
:status_message
,
:text
=>
"hello"
,
:to
=>
@bobs_aspect
.
id
)
end
describe
'
User#comment!
'
do
describe
"
User#comment!
"
do
it
"sets the comment text"
do
it
"sets the comment text"
do
expect
(
alice
.
comment!
(
@
status
,
"unicorn_mountain"
).
text
).
to
eq
(
"unicorn_mountain"
)
expect
(
alice
.
comment!
(
status
,
"unicorn_mountain"
).
text
).
to
eq
(
"unicorn_mountain"
)
end
end
it
"creates a participation"
do
it
"creates a participation"
do
expect
{
alice
.
comment!
(
@
status
,
"bro"
)
}.
to
change
(
Participation
,
:count
).
by
(
1
)
expect
{
alice
.
comment!
(
status
,
"bro"
)
}.
to
change
(
Participation
,
:count
).
by
(
1
)
expect
(
alice
.
participations
.
last
.
target
).
to
eq
(
@
status
)
expect
(
alice
.
participations
.
last
.
target
).
to
eq
(
status
)
expect
(
alice
.
participations
.
last
.
count
).
to
eq
(
1
)
expect
(
alice
.
participations
.
last
.
count
).
to
eq
(
1
)
end
end
it
"creates the comment"
do
it
"does not create a participation for the post author"
do
expect
{
alice
.
comment!
(
@status
,
"bro"
)
}.
to
change
(
Comment
,
:count
).
by
(
1
)
expect
{
bob
.
comment!
(
status
,
"bro"
)
}.
not_to
change
(
Participation
,
:count
)
end
it
"federates"
do
allow_any_instance_of
(
Participation
::
Generator
).
to
receive
(
:create!
)
expect
(
Diaspora
::
Federation
::
Dispatcher
).
to
receive
(
:defer_dispatch
)
alice
.
comment!
(
@status
,
"omg"
)
end
end
describe
'User#like!'
do
it
"creates a participation"
do
expect
{
alice
.
like!
(
@status
)
}.
to
change
(
Participation
,
:count
).
by
(
1
)
expect
(
alice
.
participations
.
last
.
target
).
to
eq
(
@status
)
end
end
it
"creates the
like
"
do
it
"creates the
comment
"
do
expect
{
alice
.
like
!
(
@
status
)
}.
to
change
(
Like
,
:count
).
by
(
1
)
expect
{
alice
.
comment
!
(
status
,
"bro"
)
}.
to
change
(
Comment
,
:count
).
by
(
1
)
end
end
it
"federates"
do
it
"federates"
do
#participation and like
allow_any_instance_of
(
Participation
::
Generator
).
to
receive
(
:create!
)
allow_any_instance_of
(
Participation
::
Generator
).
to
receive
(
:create!
)
expect
(
Diaspora
::
Federation
::
Dispatcher
).
to
receive
(
:defer_dispatch
)
expect
(
Diaspora
::
Federation
::
Dispatcher
).
to
receive
(
:defer_dispatch
)
alice
.
like
!
(
@
status
)
alice
.
comment
!
(
status
,
"omg"
)
end
end
end
end
describe
'
User#like!
'
do
describe
"
User#like!
"
do
before
do
it
"creates a participation"
do
@bobs_aspect
=
bob
.
aspects
.
where
(
:name
=>
"generic"
).
first
expect
{
alice
.
like!
(
status
)
}.
to
change
(
Participation
,
:count
).
by
(
1
)
@status
=
bob
.
post
(
:status_message
,
:text
=>
"hello"
,
:to
=>
@bobs_aspect
.
id
)
expect
(
alice
.
participations
.
last
.
target
).
to
eq
(
status
)
end
end
it
"create
s
a participation"
do
it
"
does not
create a participation
for the post author
"
do
expect
{
alice
.
like!
(
@
status
)
}.
to
change
(
Participation
,
:count
)
.
by
(
1
)
expect
{
bob
.
like!
(
status
)
}.
not_
to
change
(
Participation
,
:count
)
end
end
it
"creates the like"
do
it
"creates the like"
do
expect
{
alice
.
like!
(
@
status
)
}.
to
change
(
Like
,
:count
).
by
(
1
)
expect
{
alice
.
like!
(
status
)
}.
to
change
(
Like
,
:count
).
by
(
1
)
end
end
it
"federates"
do
it
"federates"
do
#participation and like
allow_any_instance_of
(
Participation
::
Generator
).
to
receive
(
:create!
)
expect
(
Diaspora
::
Federation
::
Dispatcher
).
to
receive
(
:defer_dispatch
)
.
twice
expect
(
Diaspora
::
Federation
::
Dispatcher
).
to
receive
(
:defer_dispatch
)
alice
.
like!
(
@
status
)
alice
.
like!
(
status
)
end
end
it
"should be able to like on one's own status"
do
it
"should be able to like on one's own status"
do
like
=
alice
.
like!
(
@
status
)
like
=
bob
.
like!
(
status
)
expect
(
@
status
.
reload
.
likes
.
first
).
to
eq
(
like
)
expect
(
status
.
reload
.
likes
.
first
).
to
eq
(
like
)
end
end
it
"should be able to like on a contact's status"
do
it
"should be able to like on a contact's status"
do
like
=
bob
.
like!
(
@
status
)
like
=
alice
.
like!
(
status
)
expect
(
@
status
.
reload
.
likes
.
first
).
to
eq
(
like
)
expect
(
status
.
reload
.
likes
.
first
).
to
eq
(
like
)
end
end
it
"does not allow multiple likes"
do
it
"does not allow multiple likes"
do
alice
.
like!
(
@
status
)
alice
.
like!
(
status
)
likes
=
@
status
.
likes
likes
=
status
.
likes
expect
{
alice
.
like!
(
@
status
)
}.
to
raise_error
ActiveRecord
::
RecordInvalid
expect
{
alice
.
like!
(
status
)
}.
to
raise_error
ActiveRecord
::
RecordInvalid
expect
(
@
status
.
reload
.
likes
).
to
eq
(
likes
)
expect
(
status
.
reload
.
likes
).
to
eq
(
likes
)
end
end
end
end
describe
'User#participate_in_poll!'
do
describe
"User#participate_in_poll!"
do
before
do
let
(
:poll
)
{
FactoryGirl
.
create
(
:poll
,
status_message:
status
)
}
@bobs_aspect
=
bob
.
aspects
.
where
(
:name
=>
"generic"
).
first
let
(
:answer
)
{
poll
.
poll_answers
.
first
}
@status
=
bob
.
post
(
:status_message
,
:text
=>
"hello"
,
:to
=>
@bobs_aspect
.
id
)
@poll
=
FactoryGirl
.
create
(
:poll
,
:status_message
=>
@status
)
@answer
=
@poll
.
poll_answers
.
first
end
it
"federates"
do
it
"federates"
do
allow_any_instance_of
(
Participation
::
Generator
).
to
receive
(
:create!
)
allow_any_instance_of
(
Participation
::
Generator
).
to
receive
(
:create!
)
expect
(
Diaspora
::
Federation
::
Dispatcher
).
to
receive
(
:defer_dispatch
)
expect
(
Diaspora
::
Federation
::
Dispatcher
).
to
receive
(
:defer_dispatch
)
alice
.
participate_in_poll!
(
@status
,
@answer
)
alice
.
participate_in_poll!
(
status
,
answer
)
end
it
"creates a participation"
do
expect
{
alice
.
participate_in_poll!
(
status
,
answer
)
}.
to
change
(
Participation
,
:count
).
by
(
1
)
end
end
it
"create
s
a partcipation"
do
it
"
does not
create a part
i
cipation
for the post author
"
do
expect
{
alice
.
participate_in_poll!
(
@
status
,
@
answer
)
}.
to
change
(
Participation
,
:count
)
.
by
(
1
)
expect
{
bob
.
participate_in_poll!
(
status
,
answer
)
}.
not_
to
change
(
Participation
,
:count
)
end
end
it
"creates the poll participation"
do
it
"creates the poll participation"
do
expect
{
alice
.
participate_in_poll!
(
@
status
,
@
answer
)
}.
to
change
(
PollParticipation
,
:count
).
by
(
1
)
expect
{
alice
.
participate_in_poll!
(
status
,
answer
)
}.
to
change
(
PollParticipation
,
:count
).
by
(
1
)
end
end
it
"sets the poll answer id"
do
it
"sets the poll answer id"
do
expect
(
alice
.
participate_in_poll!
(
@
status
,
@
answer
).
poll_answer
).
to
eq
(
@
answer
)
expect
(
alice
.
participate_in_poll!
(
status
,
answer
).
poll_answer
).
to
eq
(
answer
)
end
end
end
end
describe
"many actions"
do
describe
"many actions"
do
it
"two coments"
do
it
"two com
m
ents"
do
alice
.
comment!
(
@
status
,
"bro..."
)
alice
.
comment!
(
status
,
"bro..."
)
alice
.
comment!
(
@
status
,
"...ther"
)
alice
.
comment!
(
status
,
"...ther"
)
expect
(
alice
.
participations
.
last
.
count
).
to
eq
(
2
)
expect
(
alice
.
participations
.
last
.
count
).
to
eq
(
2
)
end
end
it
"like and comment"
do
it
"like and comment"
do
alice
.
comment!
(
@
status
,
"bro..."
)
alice
.
comment!
(
status
,
"bro..."
)
alice
.
like!
(
@
status
)
alice
.
like!
(
status
)
expect
(
alice
.
participations
.
last
.
count
).
to
eq
(
2
)
expect
(
alice
.
participations
.
last
.
count
).
to
eq
(
2
)
end
end
end
end
...
...
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