简体   繁体   English

Rails 3 Rspec错误-SQLite3 :: SQLException:没有这样的列:comments.article_id

[英]Rails 3 Rspec Error - SQLite3::SQLException: no such column: comments.article_id

I am trying to test for a comment deletion using Rspec. 我正在尝试使用Rspec测试注释删除。 I think my test is wrong because when I try to delete a comment in my browser, it works. 我认为我的测试是错误的,因为当我尝试在浏览器中删除评论时,它可以工作。

Here is the Rspec test that I am running: 这是我正在运行的Rspec测试:

before(:each) do
    @admin = Factory(:user, :admin => true)
    @user = Factory(:user, :email => "example1@example.com")
    @article = Factory(:article, :user => @user, :title => "Article Title", :content => "Article Content")
    @comment = Factory(:comment, :user => @user, :article => @article, :title => "Comment Title", :content => "Comment Content")
  end

  it "should allow access to 'destroy'" do
    lambda do
      delete :destroy, :id => @comment, :article_id => @article
    end.should change(Comment, :count).by(-1)
  end

Here is the error I get: 这是我得到的错误:

1) CommentsController access control for admin should allow access to 'destroy'
    Failure/Error: delete :destroy, :id => @comment, :article_id => @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

Here is the destroy portion of my comments controller: 这是我的注释控制器的销毁部分:

  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

Here's the create portion of my comments controller: 这是我的评论控制器的创建部分:

  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 => params[:page])
      render 'articles/show'
    end
  end

I explicitly set @comment.article_id = @article.id, so I don't know why it would say that there is no column that exists... 我显式设置@ comment.article_id = @ article.id,所以我不知道为什么会说不存在任何列...

Maybe the test database is out of sync? 也许测试数据库不同步? Did you try checking the schema in the test db to see if the column is there? 您是否尝试检查测试数据库中的架构以查看该列是否存在?

I was having a similar problem with my tests showing that I couldn't GET a page because the table didn't exist. 我在测试中遇到了类似的问题,因为该表不存在,因此无法获取页面。 I was able to resolve it by running rake db:test:prepare and then running Rspec. 我可以通过运行rake db:test:prepare然后运行Rspec来解决它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RoR错误:SQLite3 :: SQLException:没有这样的列:comments.micropost_id:SELECT“comments”。* FROM“comments”WHERE“comments”。“micropost_id”= 2 - RoR error: SQLite3::SQLException: no such column: comments.micropost_id: SELECT “comments”.* FROM “comments” WHERE “comments”.“micropost_id” = 2 Rails中的SQLite3错误SQLite3 :: SQLException:没有这样的列 - SQLite3 error in rails SQLite3::SQLException: no such column Rails 4 SQLite3 :: SQLException错误 - Rails 4 SQLite3::SQLException error RoR-SQLite3 :: SQLException:没有这样的列:-Rails不将_id附加到生成的查询中 - RoR - SQLite3::SQLException: no such column: - Rails not appending _id to generated query Ruby on Rails:SQLite3 :: SQLException:没有这样的列: - Ruby on Rails: SQLite3::SQLException: no such column: Rails关联:SQLite3 :: SQLException:没有这样的列 - Rails Associations: SQLite3::SQLException: no such column rails_admin SQLite3 :: SQLException:没有这样的列 - rails_admin SQLite3::SQLException: no such column SQLite3 :: SQLException:Rails 4.2.6中没有这样的列 - SQLite3::SQLException : no such column in rails 4.2.6 Rails SQLite3 :: SQLException - Rails SQLite3::SQLException Rails 3 / RSpec:控制器测试-在我的测试中访问类函数将返回SQLite3 :: SQLException“无此表”错误 - Rails 3 / RSpec: Controller tests — access to a class function in my test returns an SQLite3::SQLException “no such table” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM