Hi,
In a Rails functional test, you can say this:
post :create, :post => { :body => ‘This is my post.’, :title => ‘Welcome
to
my post’ }
This works until you change the Post class’ validation properties. Is
there
a way to convert an object (that happens to be already valid) to the
hash
form required by the functional test?
CmdJohnson
Commander J. wrote:
Let me clarify:
The moment you add any validations to a scaffold model the functional
tests
start to fail.
[…]
Try using factories. There’s a recent Railscast on the subject.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Let me clarify:
The moment you add any validations to a scaffold model the functional
tests
start to fail.
I currently use this solution:
class CommentsControllerTest < ActionController::TestCase
def comment
{ :body => ‘Hello!’, :email => ‘[email protected]’, :name
=>
‘CmdJohnson’ }
end
def test_should_create_comment
assert_difference(‘Comment.count’) do
post :create, :comment => comment
end
assert_redirected_to comment_path(assigns(:comment))
end
Further tests here …
end
Possible solutions include:
- Keep a hash ‘role model’ that is always valid and must be changed
with
model validations
- Convert an existing object to a Hash that can be passed to the ‘get’
method.
On Thu, Apr 23, 2009 at 4:27 PM, Commander J. <