相关疑难解决方法(0)

如何在RSpec测试中打开ActiveRecord的SQL调试日志记录?

我的模型有一些RSpec测试,我想打开SQL ActiveRecord日志,就像我在Rails服务器模式中看到的那样.怎么做?

我开始测试了

RAILS_ENV=test bundle exec rspec my/test_spec.rb
Run Code Online (Sandbox Code Playgroud)

谢谢

ruby activerecord ruby-on-rails rspec-rails

85
推荐指数
4
解决办法
6万
查看次数

Rails测试错误:WHERE的参数必须是boolean类型,而不是类型integer

用户可以通过has_many关联投票给帖子.我从运行测试中收到此错误:

ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type integer
Run Code Online (Sandbox Code Playgroud)

从这个测试:

test "should unvote a post the standard way" do
  @user.vote(@post_2)
  postvoterelationship = @user.active_post_vote_relationships.find_by(voted_id: @post_2.id)
  assert_difference '@user.postvoting.count', -1 do
    delete postvoterelationship_path(postvoterelationship)
  end
end
Run Code Online (Sandbox Code Playgroud)

postvoterelationships_controller.rb

def destroy
  @user = Postvoterelationship.find(params[:id]).voter
  @post = Postvoterelationship.find_by(params[:id]).voted
  @user.unvote(@post)
  respond_to do |format|
    format.html do
      redirect_to @user
    end
    format.js
  end
end # destroy
Run Code Online (Sandbox Code Playgroud)

的routes.rb

resources :postvoterelationships,  only: [:create, :destroy]
Run Code Online (Sandbox Code Playgroud)

postvoterelationship.rb

class Postvoterelationship < ActiveRecord::Base
  belongs_to :voter, class_name: "User"
  belongs_to :voted, class_name: "Post"
  validates …
Run Code Online (Sandbox Code Playgroud)

testing ruby-on-rails

2
推荐指数
1
解决办法
3403
查看次数

标签 统计

ruby-on-rails ×2

activerecord ×1

rspec-rails ×1

ruby ×1

testing ×1