如何解决伪造不是保存属性
| 我无法使用Fabricate gem使我的rspec / capybara集成规范之一通过。 这是我的规格:it \"shows current node as top node on page\" do
@node = Fabricate(:node)
visit node_path(@node)
page.should have_content(@node.title)
end
我的制作人:
Fabricator(:node) do
title { Faker::Lorem.words(3).join(\" \") }
description {Faker::Lorem.paragraphs(3).join(\"\\n\") }
end
我节点的表演动作:
def show
@node = Node.find(params[:id])
end
我的show.html.haml:
%h1= @node.title
我的规格输出:
1) Node shows current node as top node on page
Failure/Error: page.should have_content(@node.title)
expected #has_content?(\"nostrum qui sed\") to return true,got false
最后,我在视图上放置一个save_and_open_page,一个debug(params)和debug(@node),这是输出:
action: show
controller: nodes
id: \"1\"
--- !ruby/object:Node
attributes:
id: \"1\"
title:
description:
created_at: 2011-06-01 03:14:45.645663
updated_at: 2011-06-01 03:14:45.645663
attributes_cache: {}
changed_attributes: {}
destroyed: false
marked_for_destruction: false
new_record: false
previously_changed: {}
readonly: false
有人知道为什么标题和描述未保存到数据库吗?
提前致谢!
-----------------更新6-1 ------------------------
我的节点模型:
class Node < ActiveRecord::Base
attr_accessor :title,:description
validates :title,:presence => true
validates :description,:presence => true
end
解决方法
在两者之间
@node = Fabricate(:node)
visit node_path(@node)
尝试插入保存!看看这是否是某种验证问题:
@node = Fabricate(:node)
@node.save!
visit node_path(@node)
, 您可能应该执行以下操作:
class Node < ActiveRecord::Base
attr_accessible :title,:description
validates :title,:presence => true
validates :description,:presence => true
end
, 您的模型应该是
class Node < ActiveRecord::Base
validates :title,:presence => true
validates :description,:presence => true
end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。