Created
August 22, 2013 18:50
-
-
Save otherjohn/6311222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: List Users | |
Background: | |
Given I send and accept JSON | |
Scenario: Successfully list users when logged in user is admin | |
Given the following users exist | |
|id|email |first_name |last_name |password |authentication_token|role | | |
|10|[email protected] |First |User |test1234 |auth_token_123 |user | | |
|11|[email protected] |Second |User |test1234 |auth_token_223 |user | | |
|12|[email protected] |Third |User |test1234 |auth_token_323 |user | | |
|13|[email protected] |Fourth |User |test1234 |auth_token_423 |user | | |
|14|[email protected] |Fifth |User |test1234 |auth_token_523 |admin| | |
When I authenticate as the user "auth_token_523" with the password "random string" | |
And I send a GET request to "/api/v1/users" | |
And the JSON response should be: | |
""" | |
{ | |
"users": [ | |
{ | |
"email": "[email protected]", | |
"first_name": "First", | |
"last_name": "User" | |
}, | |
{ | |
"email": "[email protected]", | |
"first_name": "Second", | |
"last_name": "User" | |
}, | |
{ | |
"email": "[email protected]", | |
"first_name": "Third", | |
"last_name": "User" | |
}, | |
{ | |
"email": "[email protected]", | |
"first_name": "Fourth", | |
"last_name": "User" | |
}, | |
{ | |
"email": "[email protected]", | |
"first_name": "Fifth", | |
"last_name": "User" | |
} | |
] | |
} | |
""" | |
Then the response status should be "200" | |
Scenario: Logged in user is not admin | |
Given the following users exist | |
|id|email |first_name |last_name |password |authentication_token|role | | |
|10|[email protected] |First |User |test1234 |auth_token_123 |user | | |
|11|[email protected] |Second |User |test1234 |auth_token_223 |user | | |
|12|[email protected] |Third |User |test1234 |auth_token_323 |user | | |
|13|[email protected] |Fourth |User |test1234 |auth_token_423 |user | | |
|14|[email protected] |Fifth |User |test1234 |auth_token_523 |admin| | |
When I authenticate as the user "auth_token_123" with the password "random string" | |
And I send a GET request to "/api/v1/users" | |
Then the response status should be "403" | |
And the JSON response should be: | |
""" | |
{"errors" : ["Insufficient privileges"]} | |
""" | |
Scenario: User is not authenticated | |
When I authenticate as the user "invalid_auth_token" with the password "random string" | |
And I send a GET request to "/api/v1/users" | |
Then the response status should be "401" | |
And the JSON response should be: | |
""" | |
{ "errors": ["Invalid login"] } | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Wushhouse::Application.routes.draw do | |
namespace :api, defaults: {format: 'json'} do | |
devise_for :users, path: '/v1/users',controllers: { | |
registrations: 'api/v1/custom_devise/registrations' | |
} | |
end | |
namespace :api, defaults: {format: 'json'} do | |
namespace :v1 do | |
resources :users, :only => [:index] | |
end | |
end | |
#root :to => "home#index" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment