我的模型有一些RSpec测试,我想打开SQL ActiveRecord日志,就像我在Rails服务器模式中看到的那样.怎么做?
我开始测试了
RAILS_ENV=test bundle exec rspec my/test_spec.rb
Run Code Online (Sandbox Code Playgroud)
谢谢
用户可以通过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)