51 lines
1.7 KiB
Ruby
51 lines
1.7 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe "User API ", :type => :api do
|
|
|
|
include Rack::Test::Methods
|
|
|
|
subject { page }
|
|
|
|
def login(user)
|
|
post '/sessions', "session[email]" => user.email, "session[password]" => user.password
|
|
rack_mock_session.cookie_jar["remember_token"].should == user.remember_token
|
|
end
|
|
|
|
describe "profile page" do
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
before(:each) do
|
|
UserMailer.deliveries.clear
|
|
end
|
|
|
|
it "successful signup" do
|
|
post '/api/users.json', { :name => "user1", :email => "user1@jamkazam.com", :password => "jam123", :password_confirmation => "jam123",
|
|
:city => "Austin", :state => "TX", :country => "United States" }.to_json, "CONTENT_TYPE" => 'application/json'
|
|
last_response.status.should == 200
|
|
last_response.body.should == "{}"
|
|
|
|
created_user = User.find_by_email("user1@jamkazam.com")
|
|
|
|
# login as another user, and verify that this user can't be seen yet because email_confired=false
|
|
login(user)
|
|
get "/api/users/#{created_user.id}.json"
|
|
last_response.status.should == 404
|
|
|
|
# we should see one email created as a result of creating the user
|
|
UserMailer.deliveries.length.should == 1
|
|
email = UserMailer.deliveries[0]
|
|
|
|
# check that the signup url is in the email
|
|
email.html_part.body.include?(created_user.signup_token).should be_true
|
|
|
|
post "/api/users/confirm/#{created_user.signup_token}.json", "{}"
|
|
last_response.status.should == 201
|
|
|
|
get last_response.headers["Location"] + ".json"
|
|
last_response.status.should == 200
|
|
found_user = JSON.parse(last_response.body)
|
|
found_user["id"].should == created_user.id
|
|
end
|
|
end
|
|
end
|