jam-cloud/spec/requests/users_api_spec.rb

51 lines
1.5 KiB
Ruby
Raw Normal View History

2012-11-12 12:59:43 +00:00
require 'spec_helper'
describe "User API ", :type => :api do
include Rack::Test::Methods
subject { page }
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before(:each) do
UserMailer.deliveries.clear
end
2012-11-14 05:37:50 +00:00
it "successful login" do
# can't access most apis; not logged in yet!'
get '/api/users.json', "CONTENT_TYPE" => 'application/json'
last_response.status.should == 403
# login
post '/api/auth_session.json', { :email => user.email, :password => user.password }.to_json, "CONTENT_TYPE" => 'application/json'
2012-11-12 12:59:43 +00:00
last_response.status.should == 200
2012-11-14 05:37:50 +00:00
JSON.parse(last_response.body).should == { "success" => true }
2012-11-12 12:59:43 +00:00
2012-11-14 05:37:50 +00:00
# can now login
get '/api/users.json', "CONTENT_TYPE" => 'application/json'
last_response.status.should == 200
2012-11-12 12:59:43 +00:00
2012-11-14 05:37:50 +00:00
# log back out
delete '/api/auth_session.json', "CONTENT_TYPE" => 'application/json'
2012-11-14 05:37:50 +00:00
# can't access most apis; not logged in yet!'
get '/api/users.json', "CONTENT_TYPE" => 'application/json'
last_response.status.should == 403
end
it "bad login" do
# login
post '/api/auth_session.json', { :email => "nothing", :password => "mur" }.to_json, "CONTENT_TYPE" => 'application/json'
2012-11-12 12:59:43 +00:00
last_response.status.should == 404
2012-11-14 05:37:50 +00:00
JSON.parse(last_response.body).should == { "success" => false }
2012-11-12 12:59:43 +00:00
2012-11-14 05:37:50 +00:00
# can't access most apis; not logged in yet!'
get '/api/users.json', "CONTENT_TYPE" => 'application/json'
last_response.status.should == 403
2012-11-12 12:59:43 +00:00
end
end
end