asciinema.org/spec/controllers/user_tokens_controller_spec.rb

50 lines
1.2 KiB
Ruby
Raw Normal View History

2012-03-04 19:30:26 +00:00
require 'spec_helper'
describe UserTokensController do
describe '#create' do
let(:user) { Factory(:user) }
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
it 'redirects to ~nickname' do
2012-03-04 19:30:26 +00:00
post :create, :user_token => user_token.token
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