Skip to content

Instantly share code, notes, and snippets.

@phillipkoebbe
Created March 22, 2010 19:47
Show Gist options
  • Save phillipkoebbe/340458 to your computer and use it in GitHub Desktop.
Save phillipkoebbe/340458 to your computer and use it in GitHub Desktop.
# How I would have done it last week
describe 'post :create' do
context 'with correct email and password' do
before :each do
email = 'some@email.com'
password = 'password'
@user_id = 1
User.should_receive(:authenticate).with(email, password).and_return([@user_id, Messages::LOGIN_SUCCESSFUL])
post :create, {:email => email, :password => password}
end
should_set_session :user_id, :to => proc{ @user_id }
should_set_the_flash :info, :to => Messages::LOGIN_SUCCESSFUL
should_redirect_to { web_user_path(@user_id) }
end
end
# "Proper" way of doing it
describe 'post :create' do
context 'with correct email and password' do
before :each do
@email = 'some@email.com'
@password = 'password'
@user_id = 1
end
it 'User should receive authenticate' do
User.should_receive(:authenticate).with(@email, @password).and_return([@user_id, Messages::LOGIN_SUCCESSFUL])
post :create, {:email => @email, :password => @password}
end
# but now I have to put these in a context so the post :create happens first...
# or stop using Remarkable
#should_set_session :user_id, :to => proc{ @user_id }
#should_set_the_flash :info, :to => Messages::LOGIN_SUCCESSFUL
#should_redirect_to { web_user_path(@user_id) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment