Created
November 19, 2013 11:23
-
-
Save idengager/7543959 to your computer and use it in GitHub Desktop.
AccessDenied
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
require 'spec_helper' | |
describe 'User.show' do | |
include CalendarApp | |
context 'when user is not logged in' do | |
before { get 'users/non-existent-id' } | |
it 'should return HTTP 403' do | |
last_response.status.should == 403 | |
end | |
it 'should return error message' do | |
parsed_last_response['message'].should == 'Forbidden' | |
end | |
end | |
context 'when user is logged in' do | |
context 'for invalid request params' do | |
let(:user) { User.create(email: 'example@example.com', password: 'foo') } | |
before do | |
get "/login", { email: user.email, password: user.password } | |
get "/users/#{user.id}", | |
{ token: user.token, id: User.find_by(token: user.token).id } | |
end | |
it 'should return data in JSON' do | |
last_response.header['Content-type'].should == "application/json;charset=utf-8" | |
end | |
it 'should return HTTP 404' do | |
last_response.status.should == 404 | |
end | |
it 'should return error message' do | |
parsed_last_response['message'].should == 'User not found' | |
end | |
end | |
context 'for valid request params' do | |
let(:user) { User.create(email: 'example@example.com', password: 'foo') } | |
before do | |
get "/users/#{user.id}", { token: user.token, id: User.find_by(token: user.token).id } | |
end | |
it 'should return HTTP 200' do | |
last_response.status.should == 200 | |
end | |
it 'should return data in JSON' do | |
last_response.header['Content-type'].should == "application/json;charset=utf-8" | |
end | |
it 'should contain user e-mail address' do | |
parsed_last_response['message']['email'].should == user.email | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment