I am having trouble getting one of my rspec/capybara integration specs to pass using the Fabricate gem.
Here is my spec:
it "shows current node as top node on page" do
@node = Fabricate(:node)
visit node_path(@node)
page.should have_content(@node.title)
end
My Fabricator:
Fabricator(:node) do
title { Faker::Lorem.words(3).join(" ") }
description {Faker::Lorem.paragraphs(3).join("\n") }
end
My node's show action:
def show
@node = Node.find(params[:id])
end
My show.html.haml:
%h1= @node.title
Th开发者_运维知识库e output of my spec:
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
And lastly, I put a save_and_open_page, a debug(params) and debug(@node) on the view, here's that output:
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
Anybody have any idea why title and description are not being saved to the DB?
Thanks in advance!
----------------- update 6-1 ------------------------
My node model:
class Node < ActiveRecord::Base
attr_accessor :title, :description
validates :title, :presence => true
validates :description, :presence => true
end
In between
@node = Fabricate(:node)
visit node_path(@node)
Try inserting a save! to see if it's a validation issue of some kind:
@node = Fabricate(:node)
@node.save!
visit node_path(@node)
You should probably do a:
class Node < ActiveRecord::Base
attr_accessible :title, :description
validates :title, :presence => true
validates :description, :presence => true
end
Your Model should be
class Node < ActiveRecord::Base
validates :title, :presence => true
validates :description, :presence => true
end
精彩评论