2012-03-04 22:07:45 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UsersController do
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
let(:store) { {} }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:store) { store }
|
|
|
|
end
|
2012-03-06 22:04:35 +00:00
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
describe '#new' do
|
2012-03-06 22:04:35 +00:00
|
|
|
before do
|
2013-10-19 18:59:39 +00:00
|
|
|
store[:new_user_email] = 'foo@bar.com'
|
|
|
|
|
|
|
|
get :new
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns user with a stored email' do
|
|
|
|
expect(assigns(:user).email).to eq('foo@bar.com')
|
2012-03-06 22:04:35 +00:00
|
|
|
end
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
it 'renders new template' do
|
|
|
|
should render_template('new')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#create" do
|
|
|
|
let!(:user) { stub_model(User) }
|
|
|
|
|
|
|
|
subject { post :create, user: { nickname: 'jola' } }
|
2012-03-10 13:58:10 +00:00
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
before do
|
|
|
|
allow(controller).to receive(:current_user=)
|
|
|
|
allow(User).to receive(:new).with('nickname' => 'jola') { user }
|
|
|
|
store[:new_user_email] = 'foo@bar.com'
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is persisted" do
|
2012-03-06 22:04:35 +00:00
|
|
|
before do
|
2013-10-19 18:59:39 +00:00
|
|
|
allow(user).to receive(:save) { true }
|
2012-03-10 13:58:10 +00:00
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
subject
|
2012-03-06 22:04:35 +00:00
|
|
|
end
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
it 'removes the email from the store' do
|
|
|
|
expect(store.key?(:new_user_email)).to be(false)
|
|
|
|
end
|
2012-03-10 13:58:10 +00:00
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
it 'assigns the stored email to the user' do
|
|
|
|
expect(user.email).to eq('foo@bar.com')
|
2012-03-10 13:58:10 +00:00
|
|
|
end
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
it 'sets the current_user' do
|
|
|
|
expect(controller).to have_received(:current_user=).with(user)
|
2012-03-06 22:04:35 +00:00
|
|
|
end
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
it 'redirects to the root_path with a notice' do
|
|
|
|
expect(flash[:notice]).to_not be_blank
|
|
|
|
should redirect_to(root_path)
|
|
|
|
end
|
|
|
|
end
|
2012-03-10 13:58:10 +00:00
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
context "when user isn't persisted" do
|
|
|
|
before do
|
|
|
|
allow(user).to receive(:save) { false }
|
|
|
|
|
|
|
|
subject
|
2012-03-10 13:58:10 +00:00
|
|
|
end
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
it "doesn't remove the email from the store" do
|
|
|
|
expect(store.key?(:new_user_email)).to be(true)
|
2012-03-06 22:04:35 +00:00
|
|
|
end
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
it "doesn't set the current_user" do
|
|
|
|
expect(controller).to_not have_received(:current_user=)
|
|
|
|
end
|
2012-03-06 22:04:35 +00:00
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
it 'assigns user with a stored email' do
|
|
|
|
expect(assigns(:user).email).to eq('foo@bar.com')
|
2012-03-06 22:04:35 +00:00
|
|
|
end
|
|
|
|
|
2013-10-19 18:59:39 +00:00
|
|
|
it 'renders "new" template' do
|
|
|
|
should render_template('new')
|
2012-03-06 22:04:35 +00:00
|
|
|
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
|
2013-10-19 18:59:39 +00:00
|
|
|
|
2012-03-04 22:07:45 +00:00
|
|
|
end
|