gpt4 book ai didi

ruby-on-rails - Rails 3的工厂女孩​​给出错误消息:'Validation failed: Name can't是空白的

转载 作者:行者123 更新时间:2023-12-02 04:07:11 26 4
gpt4 key购买 nike

我正在运行Rails 3.0.9和ruby 1.9.2,并从Hartl ruby​​ on rails教程中进行工作。我也在跑spork。使用factory_girl_rails 1.1.0版

Failures:

1) UsersController GET 'show' should be successful
Failure/Error: @user = Factory(:user)
ActiveRecord::RecordInvalid:
Validation failed: Name can't be blank
# ./spec/controllers/users_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

Finished in 0.38122 seconds
3 examples, 1 failure

Failed examples:

rspec ./spec/controllers/users_controller_spec.rb:12 # UsersController GET 'show' should be successful

Mr factory.rb文件
Factory.define :user do |user|

user.name "Michael Hartl"
user.email "mhartl@example.com"
user.password "foobar"
user.password_confirmation "foobar"

end

User_controller_spec.rb文件
require 'spec_helper'

describe UsersController do
render_views

describe "GET 'show'" do

before(:each) do
@user = Factory(:user)
end

it "should be successful" do
get :show, :id => @user
response.should be_success
end

# it "show the right user" do
# get :show, :id => @user
# assigns(:user).should == @user
# end
end

describe "GET 'new'" do
it "should be successful" do
get 'new'
response.should be_success
end

it "should have the right title" do
get :new
response.should have_selector('title', :content => "Sign up")
end
end

end

show.html.rb文件
<%= @user.name %>, <%= @user.email %>

最佳答案

只是一个想法,但是您是否重新启动了Spork服务器?有时这是必要的,有关更多信息,请参见Spork: how to refresh validations and other code?

关于ruby-on-rails - Rails 3的工厂女孩​​给出错误消息:'Validation failed: Name can't是空白的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7022078/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com