Skip to content

Instantly share code, notes, and snippets.

@Paxa
Created June 13, 2009 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Paxa/129425 to your computer and use it in GitHub Desktop.
Save Paxa/129425 to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
def create
@podcast = Podcast.find params[:comment][:podcast_id]
params[:comment][:podcast_id] = nil
@comment = @podcast.comments.new params[:comment]
if @comment.save
flash[:notice] = "Comment writen"
redirect_to @podcast
else
@podcast = Podcast.find params[:comment][:podcast_id]
@comments = @podcast.comments
render "podcasts/show"
end
end
end
#spec
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe CommentsController do
describe "handling POST /comments with valid data" do
before(:each) do
@podcast = mock_model(Podcast)
Podcast.stub!(:find).and_return(@podcast)
Podcast.stub!(:comments).and_return([@comment])
@comment_params = Factory.attributes_for(:comment)
@comment_params[:podcast_id] = @podcast.id
@comment = mock_model(Comment)
Comment.stub!(:new).and_return(@comment)
@podcast.stub!(:comments).and_return([@comment])
@comment.stub!(:save).and_return(true)
end
it "should save comment" do
@comment.should_receive(:save).and_return(true)
post :create, { :comment => @comment_params }
end
end
end
#error
NoMethodError in 'CommentsController handling POST /comments with valid data should save comment'
undefined method `new' for [#<Comment:0x..fdb94fd94 @name="Comment_1028">]:Array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment