Created
January 4, 2012 21:53
-
-
Save noahhendrix/1562378 to your computer and use it in GitHub Desktop.
API Spec
This file contains hidden or 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
module Todo | |
class API < Grape::API | |
use Rack::Session::Cookie | |
version 'v1', :format => :json | |
resource do | |
http_basic do |username, password| | |
User.authenticate(username, password) | |
end | |
resource '/user' do | |
get do | |
current_user | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or 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' | |
require 'api' | |
require 'rack/test' | |
set :environment, :test | |
describe Todo::API do | |
include Rack::Test::Methods | |
def app | |
Todo::API | |
end | |
let(:user) { 'valid user' } | |
describe 'GET /v1/user' do | |
context 'not authenticated' do | |
it 'returns unauthorized and empty body' do | |
get '/v1/user' | |
last_response.status.should == 401 | |
last_response.body.should be_empty | |
end | |
end | |
end | |
context 'authenticated' do | |
before(:each) do | |
User.should_receive(:authenticate).and_return user | |
app.stub(:current_user).and_return user | |
end | |
describe 'GET /v1/user' do | |
it 'returns user hash' do | |
get '/v1/user' | |
last_response.body.should == user.to_json | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment