-
-
Save ogredude/1078874 to your computer and use it in GitHub Desktop.
UsersConroller#create spec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'POST create' do | |
context 'with valid params' do | |
before(:each) { User.any_instance.stub!(:valid?).and_return(true) } | |
it 'creates new user and redirects to the home page with a notice' do | |
post :create, :user => Factory.attributes_for(:user, :username => 'dude') | |
assigns[:user].should be_persisted | |
# assigns[:user].username.should eq('dude') # Unnecessary, model tests should cover this | |
flash[:notice].should_not be_blank # be_blank instead of be_nil | |
response.should redirect_to(root_path) # path here, not url | |
end | |
it 'delivers the activation email' do | |
user = Factory.build(:user) | |
User.stub!(:new).and_return(user) | |
user.should_receive(:deliver_activation_instructions!) | |
post :create | |
end | |
end | |
context 'with invalid params' do | |
it 'fails to create the user and redirects to the form again' do | |
post :create, :user => Factory.attributes_for(:user, :username => nil) | |
flash[:error].should_not be_blank | |
response.should redirect_to(new_user_path) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment