Created
November 9, 2012 13:33
-
-
Save vastus/4045686 to your computer and use it in GitHub Desktop.
This file contains 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
class UsersController < ApplicationController | |
def new | |
@user = User.new | |
end | |
def create | |
user = User.new(params[:user]) | |
user.save # breaks the: "creates a new user with the given attributes" with error: Mock "User_1001" received unexpected message :save with (no args) | |
render :nothing => true | |
end | |
end |
This file contains 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
require 'spec_helper' | |
describe UsersController do | |
let(:user) { mock_model(User) } | |
let(:user_attrs) do | |
{"name" => "testos", | |
"email" => "testos@teroni.fi", | |
"password" => "secretos" } | |
end | |
describe "GET new" do | |
it "assigns new user" do | |
get :new | |
assigns[:user].should be_a_new User | |
end | |
it "renders the new user template" do | |
get :new | |
response.should render_template :new | |
end | |
end | |
describe "POST create" do | |
before do | |
User.stub(:new).and_return(user) | |
end | |
it "creates a new user with the given attributes" do | |
User.should_receive(:new).with(user_attrs).and_return(user) | |
post :create, :user => user_attrs | |
end | |
it "saves the user" do | |
user.should_receive(:save) | |
post :create | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment