I have the following two tests for a Rails app I'm working on.
This one fails:
test "should save comment without parent comment" do
comment = Comment.new(:text => "hello world")
comment.user = users(:charlie)
comment.story = stories(:one)
assert comment.save
end
And this one passes:
test "should save comment without parent comment" do
comment = Comment.new(:text => "hello world")
comment.user = users(:charlie)
comment.story = stories(:one)
comment.save
assert comment.save
end
When I change the assert line in the first (fai开发者_高级运维ling) test to this:
assert comment.save, Proc.new { "#{comment.errors.messages.inspect} -- valid? #{comment.valid?} -- save? #{comment.save}" }
It prints out this as the error message:
{} -- valid? true -- save? true
I'm completely at a loss as to why my Comment model requires two calls to save
. It works fine in my controller with just one call to save
.
I have an after_create
callback, but I don't think it should be affecting anything (as I said, this all works fine from my controller):
after_create :create_upvote_from_user
def create_upvote_from_user
Vote.create! :user => user, :vote => 1, "#{self.class.name.underscore}_id" => id
end
精彩评论