Ruby on rails 为什么升级到Rails 4后会出现这些PostgreSQL错误?
在升级到Ruby 2和Rails 4之前,我的Rspec测试套件完全通过了测试 自那时以来,我:Ruby on rails 为什么升级到Rails 4后会出现这些PostgreSQL错误?,ruby-on-rails,postgresql,rspec,ruby-on-rails-4,factory-bot,Ruby On Rails,Postgresql,Rspec,Ruby On Rails 4,Factory Bot,在升级到Ruby 2和Rails 4之前,我的Rspec测试套件完全通过了测试 自那时以来,我: 从Ruby 1.9.2升级到Ruby 2.0.0 从Rails 3.2.11升级到 Rails 4.0.2根据需要升级了一些gem 现在,我收到以下错误消息: PG::ProtocolViolation: ERROR: bind message supplies 2 parameters, but prepared statement "a24" requires 1 (此问题末尾粘贴了完整
- 从Ruby 1.9.2升级到Ruby 2.0.0
- 从Rails 3.2.11升级到
- Rails 4.0.2根据需要升级了一些gem
PG::ProtocolViolation: ERROR: bind message supplies 2 parameters, but prepared statement "a24" requires 1
(此问题末尾粘贴了完整堆栈跟踪。)
有问题的测试是:
it "should update a survey" do
@product = create(:product)
@question = create(:question, :product => @product)
@f1 = create(:field, :question => @question)
@f2 = create(:field, :question => @question)
@f3 = create(:field, :question => @question)
@f4 = create(:field, :question => @question)
@review = create(:review, :product => @product)
@competitor = @review.competitors.first
@survey = @competitor.surveys.find_by_question_id(@question.id)
@parameters = {"api_key"=>"redacted", "id"=>"#{@survey.id}", "environment"=>"production", "postback_url"=>"redacted", "blueprint"=>"three_radio_buttons_simple", "input"=>{redacted}, "status"=>"complete", "output"=>{"Pick_one"=>"option_1", "Sensible"=>"", "Bugs"=>""}, "verbose_output"=>{"Pick_one"=>"option_1", "Sensible"=>"", "Bugs"=>""}}
post :receive, {:id => @survey.id, :params => @parameters}
@postback = @survey.postbacks.last
@postback.content["params"].should == @parameters
end
有问题的行调用以下工厂:
factory :review do
sequence(:client_name) {|n| "client-#{n}"}
url {"http://#{client_name.downcase}.com"}
test_client true
product
end
这些模型是这样关联的:
class Product < ActiveRecord::Base
has_many :reviews
end
class Review < ActiveRecord::Base
belongs_to :product
end
解决方案位于
数据库中。yml
:
test:
prepared_statements: false
这在Rails 4.0.4中已经修复,升级让痛苦消失了你能发布你的
调查
模型吗?Stacktrace指向/survey.rb:78
听起来像是又一次。这些问题没有答案,但评论似乎有解决办法。嗨,穆,是的,我看到了其他问题,但没有找到足够的信息继续前进。嗨,斯里坎特。谢谢现在发布。我刚刚将第78行更新为Rails 4标准--fields.map{f | results.find_或_create_by(:field_id=>f.id)},除非销毁?
——但我仍然得到相同的错误。
class Survey < ActiveRecord::Base
belongs_to :competitor, :touch => true
belongs_to :question
belongs_to :battery, :touch => true
belongs_to :review
has_many :screenshots
has_many :results, :dependent => :delete_all
has_many :postbacks, :dependent => :delete_all
attr_accessible :selection, :input_id, :condition_id, :precondition_id, :override_points, :override_explanation, :bugs, :oddities
delegate :potential_inputs, :product, :categories, :inputs, :to => :competitor, :allow_nil => true
delegate :name, :standard, :element, :meta, :fields, :additive, :pictures, :to => :question, :allow_nil => true
delegate :about, :pic_links, :manual, :level, :requires_data_from_other_question, :input_id, :to => :question, :allow_nil => true
delegate :url_helpers, to: 'Rails.application.routes'
after_create :create_matching_results, :delay_create_matching_batteries, :touch_review
after_touch :delayed_reset_cache, :touch_dependencies
after_destroy :destroy_battery_if_empty
def create_matching_results
fields.map{|f| results.find_or_create_by_field_id(f.id)} unless destroyed? # line 78
end
end
test:
prepared_statements: false