asciinema.org/spec/controllers/users_controller_spec.rb

77 lines
1.5 KiB
Ruby
Raw Normal View History

2012-03-04 22:07:45 +00:00
require 'spec_helper'
describe UsersController do
describe "#create" do
2012-03-10 13:58:10 +00:00
let(:user) { mock_model(User).as_null_object }
2012-03-06 22:04:35 +00:00
before do
User.stub(:new).and_return(user)
end
context "when user saved" do
2012-03-10 13:58:10 +00:00
let(:provider) { 'foo' }
let(:uid) { '123' }
2012-04-09 13:56:26 +00:00
let(:avatar_url) { 'url' }
2012-03-10 13:58:10 +00:00
2012-03-06 22:04:35 +00:00
before do
2012-04-09 13:56:26 +00:00
session[:new_user] = {
:provider => provider,
:uid => uid,
:avatar_url => avatar_url
}
2012-03-10 13:58:10 +00:00
2012-03-06 22:04:35 +00:00
user.stub!(:save => true)
end
2012-03-10 13:58:10 +00:00
it "assigns provider and uid" do
user.should_receive(:provider=).with(provider).and_return(true)
user.should_receive(:uid=).with(uid).and_return(true)
2012-04-09 13:56:26 +00:00
user.should_receive(:avatar_url=).with(avatar_url).and_return(true)
2012-03-10 13:58:10 +00:00
post :create
end
2012-03-06 22:04:35 +00:00
it "sets current_user" do
post :create
@controller.current_user.should_not be_nil
end
2012-03-10 13:58:10 +00:00
it "clears user session data" do
post :create
2012-04-09 13:56:26 +00:00
session[:new_user].should be_nil
2012-03-10 13:58:10 +00:00
end
2012-03-06 22:04:35 +00:00
it "redirects back" do
post :create
should redirect_to(root_url)
end
end
context "when not valid data" do
before do
user.stub!(:save => false)
end
it "renders user/new" do
post :create
should render_template('users/new')
end
end
end
2012-04-09 21:53:38 +00:00
describe '#show' do
it 'should have specs'
end
describe '#edit' do
it 'should have specs'
end
describe '#update' do
it 'should have specs'
end
2012-03-04 22:07:45 +00:00
end