I am trying to implement the following scenario, but I am stuck …
The thing is I want to initialize a variable @comment when the stub
function “find_comment” is called.
The way I do it below doesn’t work, since
“before_filter :find_comment” returns true/false and @comment
initialization is done inside it. Could you please give me a hint how
to do it?
One solution would be to use
Comment.stub!(:find).and_return(@comment) and do not use the stub
But how to do it in general, when there is no expression like “@var =
my_var.function” in the controller and variable @var is defined in
another place and controller just uses it.
my_var.stub!(:function).and_return(@var) doesn’t seem to be working.
Is there is something like
before_filter :find_comment, :only => [:destroy]
@destroy_id = @comment.id #to be used in rendering partial
respond_to do |format| format.js end
@comment = Comment.find(:first, :conditions => [‘id= ?’,params
describe CommentsController, “while deleting a comment” do
it “should render destroy.rjs in case of success” do
@comment = mock_model(Comment)