构造不保存属性

问题描述:

我无法让我的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,调试(PARAMS),并在视图上调试(@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) 
+0

我试过无济于事 - 同一切。 – gmassanek 2011-06-01 16:27:50

你或许应该做一个:

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