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 conteneurs
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
1d6a69ea
Valider
1d6a69ea
rédigé
14 years ago
par
Sarah Mei
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
refactor photos controller spec
parent
1702081a
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/controllers/photos_controller_spec.rb
+87
-72
87 ajouts, 72 suppressions
spec/controllers/photos_controller_spec.rb
avec
87 ajouts
et
72 suppressions
spec/controllers/photos_controller_spec.rb
+
87
−
72
Voir le fichier @
1d6a69ea
...
@@ -8,147 +8,162 @@ describe PhotosController do
...
@@ -8,147 +8,162 @@ describe PhotosController do
render_views
render_views
before
do
before
do
@
user1
=
alice
@
alice
=
alice
@
user2
=
bob
@
bob
=
bob
@a
spect1
=
@user1
.
aspects
.
first
@a
lices_photo
=
@alice
.
post
(
:photo
,
:user_file
=>
uploaded_photo
,
:to
=>
@alice
.
aspects
.
first
.
id
)
@
aspect2
=
@user2
.
aspects
.
first
@
bobs_photo
=
@bob
.
post
(
:photo
,
:user_file
=>
uploaded_photo
,
:to
=>
@bob
.
aspects
.
first
.
id
,
:public
=>
true
)
@photo1
=
@user1
.
post
(
:photo
,
:user_file
=>
uploaded_photo
,
:to
=>
@aspect1
.
id
)
@controller
.
stub!
(
:current_user
).
and_return
(
@alice
)
@photo2
=
@user2
.
post
(
:photo
,
:user_file
=>
uploaded_photo
,
:to
=>
@aspect2
.
id
,
:public
=>
true
)
sign_in
:user
,
@alice
@controller
.
stub!
(
:current_user
).
and_return
(
@user1
)
sign_in
:user
,
@user1
request
.
env
[
"HTTP_REFERER"
]
=
''
request
.
env
[
"HTTP_REFERER"
]
=
''
end
end
it
'has working context'
do
@photo1
.
url
.
should_not
be_nil
Photo
.
find
(
@photo1
.
id
).
url
.
should_not
be_nil
@photo2
.
url
.
should_not
be_nil
Photo
.
find
(
@photo2
.
id
).
url
.
should_not
be_nil
end
describe
'#create'
do
describe
'#create'
do
before
do
before
do
@controller
.
stub!
(
:file_handler
).
and_return
(
uploaded_photo
)
@controller
.
stub!
(
:file_handler
).
and_return
(
uploaded_photo
)
@params
=
{
:photo
=>
{
:user_file
=>
uploaded_photo
,
:aspect_ids
=>
"all"
}
}
@params
=
{
:photo
=>
{
:user_file
=>
uploaded_photo
,
:aspect_ids
=>
"all"
}
}
end
end
it
'can make
a photo
'
do
it
"creates
a photo
"
do
lambda
{
lambda
{
post
:create
,
@params
post
:create
,
@params
}.
should
change
(
Photo
,
:count
).
by
(
1
)
}.
should
change
(
Photo
,
:count
).
by
(
1
)
end
end
it
'can set the photo as the profile photo'
do
it
'can set the photo as the profile photo'
do
old_url
=
@
user1
.
person
.
profile
.
image_url
old_url
=
@
alice
.
person
.
profile
.
image_url
@params
[
:photo
][
:set_profile_photo
]
=
true
@params
[
:photo
][
:set_profile_photo
]
=
true
post
:create
,
@params
post
:create
,
@params
@
user1
.
reload
.
person
.
profile
.
image_url
.
should_not
==
old_url
@
alice
.
reload
.
person
.
profile
.
image_url
.
should_not
==
old_url
end
end
end
end
describe
'#index'
do
describe
'#index'
do
it
"displays the logged in user's pictures"
do
it
"displays the logged in user's pictures"
do
get
:index
,
:person_id
=>
@
user1
.
person
.
id
.
to_s
get
:index
,
:person_id
=>
@
alice
.
person
.
id
.
to_s
assigns
[
:person
].
should
==
@
user1
.
person
assigns
[
:person
].
should
==
@
alice
.
person
assigns
[
:posts
].
should
==
[
@photo
1
]
assigns
[
:posts
].
should
==
[
@
alices_
photo
]
end
end
it
"displays another person's pictures"
do
it
"displays another person's pictures"
do
get
:index
,
:person_id
=>
@user2
.
person
.
id
.
to_s
get
:index
,
:person_id
=>
@bob
.
person
.
id
.
to_s
assigns
[
:person
].
should
==
@bob
.
person
assigns
[
:person
].
should
==
@user2
.
person
assigns
[
:posts
].
should
==
[
@bobs_photo
]
assigns
[
:posts
].
should
==
[
@photo2
]
end
end
end
end
describe
'#show'
do
describe
'#show'
do
it
'assigns the photo based on the photo id'
do
context
"user's own photo"
do
get
:show
,
:id
=>
@photo1
.
id
before
do
response
.
status
.
should
==
200
get
:show
,
:id
=>
@alices_photo
.
id
end
assigns
[
:photo
].
should
==
@photo1
it
"succeeds"
do
assigns
[
:ownership
].
should
be_true
response
.
should
be_success
end
end
it
"assigns the photo"
do
it
"renders a show page for another user's photo"
do
assigns
[
:photo
].
should
==
@alices_photo
get
:show
,
:id
=>
@photo2
.
id
assigns
[
:ownership
].
should
be_true
response
.
status
.
should
==
200
end
end
assigns
[
:photo
].
should
==
@photo2
context
"private photo user can see"
do
assigns
[
:ownership
].
should
be_false
before
do
end
get
:show
,
:id
=>
@bobs_photo
.
id
end
it
'shows a public photo of someone who is not friends'
do
it
"succeeds"
do
sign_out
@user1
response
.
should
be_success
user3
=
Factory
(
:user
)
end
sign_in
:user
,
user3
it
"assigns the photo"
do
get
:show
,
:id
=>
@photo2
.
id
assigns
[
:photo
].
should
==
@bobs_photo
response
.
status
.
should
==
200
assigns
[
:ownership
].
should
be_false
assigns
[
:photo
].
should
==
@photo2
end
end
end
context
"private photo user cannot see"
do
it
'redirects to the root url if the photo if you can not see it'
do
before
do
get
:show
,
:id
=>
23424
user3
=
Factory
(
:user_with_aspect
)
response
.
status
.
should
==
302
@photo
=
user3
.
post
(
:photo
,
:user_file
=>
uploaded_photo
,
:to
=>
user3
.
aspects
.
first
.
id
)
end
it
"redirects to the referrer"
do
request
.
env
[
"HTTP_REFERER"
]
=
"http://google.com"
get
:show
,
:id
=>
@photo
.
to_param
response
.
should
redirect_to
(
"http://google.com"
)
end
it
"redirects to the aspects page if there's no referrer"
do
request
.
env
.
delete
(
"HTTP_REFERER"
)
get
:show
,
:id
=>
@photo
.
to_param
response
.
should
redirect_to
(
aspects_path
)
end
end
context
"public photo"
do
before
do
user3
=
Factory
(
:user_with_aspect
)
@photo
=
user3
.
post
(
:photo
,
:user_file
=>
uploaded_photo
,
:to
=>
user3
.
aspects
.
first
.
id
,
:public
=>
true
)
get
:show
,
:id
=>
@photo
.
to_param
end
it
"succeeds"
do
response
.
should
be_success
end
it
"assigns the photo"
do
assigns
[
:photo
].
should
==
@photo
assigns
[
:ownership
].
should
be_false
end
end
end
end
end
describe
'#edit'
do
describe
'#edit'
do
it
'let
s
t
he user
edit a
photo
'
do
it
"succeed
s
w
he
n
user
owns the
photo
"
do
get
:edit
,
:id
=>
@photo
1
.
id
get
:edit
,
:id
=>
@
alices_
photo
.
id
response
.
s
tatus
.
should
==
200
response
.
s
hould
be_success
end
end
it
'does not let the user edit a photo that is not his'
do
it
"redirects when the user does not own the photo"
do
get
:edit
,
:id
=>
@photo
2
.
id
get
:edit
,
:id
=>
@
bobs_
photo
.
id
response
.
should
redirect_to
(
:action
=>
:index
,
:person_id
=>
@
user1
.
person
.
id
.
to_s
)
response
.
should
redirect_to
(
:action
=>
:index
,
:person_id
=>
@
alice
.
person
.
id
.
to_s
)
end
end
end
end
describe
'#destroy'
do
describe
'#destroy'
do
it
'allows the user to delete his photos'
do
it
'allows the user to delete his photos'
do
delete
:destroy
,
:id
=>
@photo
1
.
id
delete
:destroy
,
:id
=>
@
alices_
photo
.
id
Photo
.
find_by_id
(
@photo
1
.
id
).
should
be_nil
Photo
.
find_by_id
(
@
alices_
photo
.
id
).
should
be_nil
end
end
it
'will not let you destory posts you do not own'
do
it
'will not let you destory posts you do not own'
do
delete
:destroy
,
:id
=>
@photo
2
.
id
delete
:destroy
,
:id
=>
@
bobs_
photo
.
id
Photo
.
find_by_id
(
@photo
2
.
id
).
should
be_true
Photo
.
find_by_id
(
@
bobs_
photo
.
id
).
should
be_true
end
end
end
end
describe
"#update"
do
describe
"#update"
do
it
"updates the caption of a photo"
do
it
"updates the caption of a photo"
do
put
:update
,
:id
=>
@photo
1
.
id
,
:photo
=>
{
:caption
=>
"now with lasers!"
}
put
:update
,
:id
=>
@
alices_
photo
.
id
,
:photo
=>
{
:caption
=>
"now with lasers!"
}
@photo
1
.
reload
.
caption
.
should
==
"now with lasers!"
@
alices_
photo
.
reload
.
caption
.
should
==
"now with lasers!"
end
end
it
"doesn't overwrite random attributes"
do
it
"doesn't overwrite random attributes"
do
new_user
=
Factory
.
create
(
:user
)
new_user
=
Factory
.
create
(
:user
)
params
=
{
:caption
=>
"now with lasers!"
,
:author_id
=>
new_user
.
id
}
params
=
{
:caption
=>
"now with lasers!"
,
:author_id
=>
new_user
.
id
}
put
:update
,
:id
=>
@photo
1
.
id
,
:photo
=>
params
put
:update
,
:id
=>
@
alices_
photo
.
id
,
:photo
=>
params
@photo
1
.
reload
.
author_id
.
should
==
@
user1
.
person
.
id
@
alices_
photo
.
reload
.
author_id
.
should
==
@
alice
.
person
.
id
end
end
it
'redirects if you do not have access to the post'
do
it
'redirects if you do not have access to the post'
do
params
=
{
:caption
=>
"now with lasers!"
}
params
=
{
:caption
=>
"now with lasers!"
}
put
:update
,
:id
=>
@photo
2
.
id
,
:photo
=>
params
put
:update
,
:id
=>
@
bobs_
photo
.
id
,
:photo
=>
params
response
.
should
redirect_to
(
:action
=>
:index
,
:person_id
=>
@
user1
.
person
.
id
.
to_s
)
response
.
should
redirect_to
(
:action
=>
:index
,
:person_id
=>
@
alice
.
person
.
id
.
to_s
)
end
end
end
end
describe
"#make_profile_photo"
do
describe
"#make_profile_photo"
do
it
'should return a 201 on a js success'
do
it
'should return a 201 on a js success'
do
get
:make_profile_photo
,
:photo_id
=>
@photo
1
.
id
,
:format
=>
'js'
get
:make_profile_photo
,
:photo_id
=>
@
alices_
photo
.
id
,
:format
=>
'js'
response
.
code
.
should
==
"201"
response
.
code
.
should
==
"201"
end
end
it
'should return a 406 on failure'
do
it
'should return a 406 on failure'
do
get
:make_profile_photo
,
:photo_id
=>
@photo
2
.
id
get
:make_profile_photo
,
:photo_id
=>
@
bobs_
photo
.
id
response
.
code
.
should
==
"406"
response
.
code
.
should
==
"406"
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