Skip to content

Instantly share code, notes, and snippets.

@idengager
Created November 19, 2013 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idengager/7543959 to your computer and use it in GitHub Desktop.
Save idengager/7543959 to your computer and use it in GitHub Desktop.
AccessDenied
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