2012-03-04 19:30:26 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UserTokensController do
|
|
|
|
describe '#create' do
|
|
|
|
let(:user) { Factory(:user) }
|
2012-03-06 18:09:15 +00:00
|
|
|
let(:user_token) { FactoryGirl.build(:user_token, :user => nil) }
|
2012-03-04 19:30:26 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
@controller.stub!(:current_user => user)
|
|
|
|
user.stub!(:add_user_token => user_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when given token is valid' do
|
|
|
|
before do
|
|
|
|
user_token.stub!(:valid? => true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls Asciicast.assign_user' do
|
|
|
|
Asciicast.should_receive(:assign_user).with(user_token.token, user).and_return(1)
|
|
|
|
|
|
|
|
post :create, :user_token => user_token.token
|
|
|
|
end
|
|
|
|
|
2012-03-06 18:44:05 +00:00
|
|
|
it 'redirects to ~nickname' do
|
2012-03-04 19:30:26 +00:00
|
|
|
post :create, :user_token => user_token.token
|
|
|
|
|
2012-03-06 18:44:05 +00:00
|
|
|
response.should redirect_to(profile_path(user))
|
2012-03-04 19:30:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when given token is invalid' do
|
|
|
|
before do
|
|
|
|
user_token.stub!(:valid? => false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls Asciicast.assign_user' do
|
|
|
|
Asciicast.should_not_receive(:assign_user)
|
|
|
|
|
|
|
|
post :create, :user_token => user_token.token
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders :error' do
|
|
|
|
post :create, :user_token => user_token.token
|
|
|
|
|
|
|
|
response.should render_template(:error)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|