Created
March 5, 2009 14:55
-
-
Save jpemberthy/74370 to your computer and use it in GitHub Desktop.
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 UsersController do | |
| fixtures :users | |
| include UserSpecHelper | |
| it 'allows signup' do | |
| lambda do | |
| create_user | |
| response.should be_redirect | |
| end.should change(User, :count).by(1) | |
| end | |
| it 'requires login on signup' do | |
| lambda do | |
| create_user(:login => nil) | |
| assigns[:user].errors.on(:login).should_not be_nil | |
| response.should be_success | |
| end.should_not change(User, :count) | |
| end | |
| it 'requires password on signup' do | |
| lambda do | |
| create_user(:password => nil) | |
| assigns[:user].errors.on(:password).should_not be_nil | |
| response.should be_success | |
| end.should_not change(User, :count) | |
| end | |
| it 'requires password confirmation on signup' do | |
| lambda do | |
| create_user(:password_confirmation => nil) | |
| assigns[:user].errors.on(:password_confirmation).should_not be_nil | |
| response.should be_success | |
| end.should_not change(User, :count) | |
| end | |
| it 'requires email on signup' do | |
| lambda do | |
| create_user(:email => nil) | |
| assigns[:user].errors.on(:email).should_not be_nil | |
| response.should be_success | |
| end.should_not change(User, :count) | |
| end | |
| end | |
| describe UsersController do | |
| describe "Responding to GET New" do | |
| it "should create an instance of User" do | |
| User.should_receive(:new).with(no_args()).and_return(mock_model(User)) | |
| get :new | |
| response.should be_success | |
| end | |
| end | |
| describe "Responding to POST create" do | |
| include UserSpecHelper | |
| before do | |
| @user = mock_model(User, :save => true, :to_param => "1") | |
| User.stub!(:new).and_return(@user) | |
| @user.errors.stub!(:empty?).with().and_return(true) | |
| @params = {'login' => 'quire', 'email' => '[email protected]', | |
| 'password' => 'quire69', 'password_confirmation' => 'quire69'} | |
| end | |
| def do_post | |
| post :create, :user => @params | |
| end | |
| it "should create a valid user user" do | |
| User.should_receive(:new).with(@params).and_return(@user) | |
| do_post | |
| end | |
| it "should redirect to the the user's portafolio" do | |
| @user.stub!(:portafolio) | |
| do_post | |
| p = Portafolio.find_by_user_id(@user.id) | |
| response.should redirect_to(portafolio_url(p.id)) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment