こんにちはコミュニティ私はユーザーが(新しいユーザーとして)登録できる簡単なアプリケーションを実行しているので、ユーザーコントローラーで新しいユーザーを作成しようとしています:
class UserController < ApplicationController
def create
@users = User.new
if @users.save
flash[:notice] = 'new user was successfully created.'
redirect_to posts_path
else
render :action => :new
end
end
def new
@user = User.new
end
end
これが私のrspecテストuser_controller_specです:
require 'spec/spec_helper'
describe UserController do
it "create new user" do
get :create
assigns[:users].should_not be_new_record
end
end
テストすると、次のエラーが表示されます。
失敗:
1)UserControllerは新しいユーザーを作成します
Failure/Error: assigns[:users].should_not be_new_record
expected nil not to be a new record
# ./spec/controllers/user_controller_spec.rb:7
0.15482秒で終了1例、1失敗
最後にここに私のモデルがあります
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
has_many :cars
validates_presence_of :email
end