Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 Rspec Error - SQLite3::SQLException: no such column: comments.article_id
    primarykey
    data
    text
    <p>I am trying to test for a comment deletion using Rspec. I think my test is wrong because when I try to delete a comment in my browser, it works.</p> <p>Here is the Rspec test that I am running:</p> <pre><code>before(:each) do @admin = Factory(:user, :admin =&gt; true) @user = Factory(:user, :email =&gt; "example1@example.com") @article = Factory(:article, :user =&gt; @user, :title =&gt; "Article Title", :content =&gt; "Article Content") @comment = Factory(:comment, :user =&gt; @user, :article =&gt; @article, :title =&gt; "Comment Title", :content =&gt; "Comment Content") end it "should allow access to 'destroy'" do lambda do delete :destroy, :id =&gt; @comment, :article_id =&gt; @article end.should change(Comment, :count).by(-1) end </code></pre> <p>Here is the error I get:</p> <pre><code>1) CommentsController access control for admin should allow access to 'destroy' Failure/Error: delete :destroy, :id =&gt; @comment, :article_id =&gt; @article SQLite3::SQLException: no such column: comments.article_id: SELECT "comments"."id", "comments"."parent_id", "comments"."title", "comments"."content", "comments"."user_id", "comments"."created_at", "comments"."updated_at" FROM "comments" WHERE ("comments".article_id = 1) AND ("comments"."id" = 1) ORDER BY comments.created_at DESC LIMIT 1 </code></pre> <p>Here is the destroy portion of my comments controller:</p> <pre><code> def destroy @article = Article.find(params[:article_id]) if @article.comments.find(params[:id]).destroy flash[:success] = "Comment deleted." else flash[:error] = "Comment could not be deleted." end redirect_to @article end </code></pre> <p>Here's the create portion of my comments controller:</p> <pre><code> def create @article = Article.find(params[:article_id]) @comment = @article.comments.build(params[:comment]) @comment.user_id = current_user.id @comment.article_id = @article.id if @comment.save flash[:success] = "Comment saved." redirect_to @article else flash[:error] = "Error in creating comment." @comments = @article.comments.paginate(:page =&gt; params[:page]) render 'articles/show' end end </code></pre> <p>I explicitly set @comment.article_id = @article.id, so I don't know why it would say that there is no column that exists...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload