Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
8f92915e
Commit
8f92915e
authored
May 15, 2015
by
Sean Hammond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove code duplication when stubbing session
parent
9595453e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
50 deletions
+29
-50
account-controller-test.coffee
h/static/scripts/account/test/account-controller-test.coffee
+29
-50
No files found.
h/static/scripts/account/test/account-controller-test.coffee
View file @
8f92915e
...
...
@@ -266,6 +266,13 @@ describe "h:AccountController", ->
)
return
$rootScope
# Return a minimal stub version of h's session service.
getStubSession
=
({
profile
,
edit_profile
})
->
return
{
profile
:
->
profile
or
{
$promise
:
Promise
.
resolve
({})}
edit_profile
:
edit_profile
or
->
{
$promise
:
Promise
.
resolve
({})}
}
###
Return an AccountController instance and stub services.
...
...
@@ -306,7 +313,7 @@ describe "h:AccountController", ->
flash
:
flash
or
{}
formRespond
:
formRespond
or
{}
identity
:
identity
or
{}
session
:
session
or
{
profile
:
->
{
$promise
:
Promise
.
resolve
()}}
session
:
session
or
getStubSession
({})
}
locals
[
"ctrl"
]
=
getControllerService
()(
"AccountController"
,
locals
)
return
locals
...
...
@@ -323,8 +330,7 @@ describe "h:AccountController", ->
profilePromise
=
Promise
.
resolve
({
email
:
"test_user@test_email.com"
})
session
=
{
profile
:
->
{
$promise
:
profilePromise
}}
{
$scope
}
=
controller
(
session
:
session
)
{
$scope
}
=
controller
(
session
:
{
profile
:
->
{
$promise
:
profilePromise
}})
profilePromise
.
then
(
->
assert
$scope
.
email
==
"test_user@test_email.com"
...
...
@@ -340,14 +346,9 @@ describe "h:AccountController", ->
edit_profile
=
sinon
.
stub
()
edit_profile
.
returns
({
$promise
:
Promise
.
resolve
({})})
session
=
{
edit_profile
:
edit_profile
profile
:
->
{
$promise
:
Promise
.
resolve
()}
}
{
$scope
}
=
controller
(
formRespond
:
->
session
:
session
session
:
getStubSession
(
edit_profile
:
edit_profile
)
# Simulate a logged-in user with username "joeuser"
$filter
:
->
->
"joeuser"
)
...
...
@@ -372,16 +373,16 @@ describe "h:AccountController", ->
it
"updates placeholder after successfully changing the email address"
,
->
new_email_addr
=
"new_email_address@test.com"
session
=
{
# AccountController expects session.edit_profile() to respond with the
# newly saved email address.
edit_profile
:
->
{
$promise
:
Promise
.
resolve
({
email
:
new_email_addr
})}
profile
:
->
{
$promise
:
Promise
.
resolve
()}
}
{
$scope
}
=
controller
(
formRespond
:
->
session
:
session
)
# AccountController expects session.edit_profile() to respond with the
# newly saved email address.
session
:
getStubSession
(
edit_profile
:
->
{
$promise
:
Promise
.
resolve
({
email
:
new_email_addr
})
}
)
)
form
=
{
$name
:
"changeEmailForm"
...
...
@@ -405,14 +406,11 @@ describe "h:AccountController", ->
emailAgain
:
"The emails must match."
}
session
=
{
edit_profile
:
->
{
$promise
:
Promise
.
reject
(
server_response
)}
profile
:
->
{
$promise
:
Promise
.
resolve
()}
}
{
$scope
}
=
controller
(
formRespond
:
require
(
"../../form-respond"
)()
session
:
session
session
:
getStubSession
(
edit_profile
:
->
{
$promise
:
Promise
.
reject
(
server_response
)}
)
)
form
=
{
...
...
@@ -433,13 +431,7 @@ describe "h:AccountController", ->
it
"broadcasts 'formState' 'changeEmailForm' 'loading' on submit"
,
->
new_email_address
=
"new_email_address@test.com"
session
=
{
edit_profile
:
->
{
$promise
:
Promise
.
resolve
({})}
profile
:
->
{
$promise
:
Promise
.
resolve
()}
}
{
$scope
}
=
controller
(
formRespond
:
->
session
:
session
)
{
$scope
}
=
controller
(
formRespond
:
->
)
$scope
.
$broadcast
=
sinon
.
stub
()
...
...
@@ -459,14 +451,7 @@ describe "h:AccountController", ->
it
"broadcasts 'formState' 'changeEmailForm' 'success' on success"
,
->
new_email_address
=
"new_email_address@test.com"
session
=
{
edit_profile
:
->
{
$promise
:
Promise
.
resolve
({})}
profile
:
->
{
$promise
:
Promise
.
resolve
()}
}
{
$scope
}
=
controller
(
formRespond
:
->
session
:
session
)
{
$scope
}
=
controller
(
formRespond
:
->
)
$scope
.
$broadcast
=
sinon
.
stub
()
...
...
@@ -487,15 +472,12 @@ describe "h:AccountController", ->
it
"broadcasts 'formState' 'changeEmailForm' '' on error"
,
->
new_email_address
=
"new_email_address@test.com"
session
=
{
edit_profile
:
->
{
$promise
:
Promise
.
reject
({
data
:
{}})}
profile
:
->
{
$promise
:
Promise
.
resolve
()}
}
{
$scope
}
=
controller
(
formRespond
:
->
session
:
session
flash
:
{
error
:
->
}
session
:
getStubSession
(
edit_profile
:
->
{
$promise
:
Promise
.
reject
({
data
:
{}})}
)
)
$scope
.
$broadcast
=
sinon
.
stub
()
...
...
@@ -526,14 +508,11 @@ describe "h:AccountController", ->
statusText
:
"Unauthorized"
}
session
=
{
edit_profile
:
->
{
$promise
:
Promise
.
reject
(
server_response
)}
profile
:
->
{
$promise
:
Promise
.
resolve
()}
}
{
$scope
}
=
controller
(
formRespond
:
require
(
"../../form-respond"
)()
session
:
session
session
:
getStubSession
(
edit_profile
:
->
{
$promise
:
Promise
.
reject
(
server_response
)}
)
)
form
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment