gpt4 book ai didi

ruby-on-rails - 事件模型在机架测试期间发送验证错误两次。

转载 作者:太空宇宙 更新时间:2023-11-03 16:36:48 24 4
gpt4 key购买 nike

我有一个简单的 restful rails api 设置来提供 json 响应,我有一个模型 line.rb,我在其中进行了以下验证。

validates :title, :presence => true, :length => {:minimum => 3, :maximum => 40},
:appropriate_title => {:message => "cannot have . and /"}
validates :department, :presence => true
validates :owner, :presence => true
validates :account, :presence => true
validate :unique_inputs
validates :title, :uniqueness => {
:scope => :account,
:message => 'is already taken for this account',
:case_sensitive => false }

在我的规范中,我有以下套件

 it "with invalid attributes" do
post"#{url}/#{account.name}.json", :api_key => application.key, :line => {:department => "Survey"}
--some assertions --
body = JSON.parse(last_response.body)
body.should eql({"error"=>{"message"=>"[\"Title can't be blank\", \"Title is too short (minimum is 3 characters)\",]"}})
end

如您所见,因为我没有提供行的标题,所以它应该触发验证错误并满足我的断言,但是我两次遇到相同的验证错误。

  {"error"=>{
"message"=>"[\"Title can't be blank\", \"Title is too short (minimum is 3 characters)\", \"Title can't be blank\", \"Title is too short (minimum is 3 characters)\"]"
}}

这真的很奇怪,因为在开发模式下我没有两次收到此验证错误。如果您怀疑我在我的 Controller 中做错了什么,以下是我在我的 Controller 中的内容

@line = @current_user.lines.new(params[:line])
if @line.save
respond_with(@line)
else
render :json => {:error => {:message => @line.errors.full_messages}}
end

我不知道这是机架测试的错误还是我做错了什么。

最佳答案

你试过吗:

validates :department, :presence => true
validates :owner, :presence => true
validates :account, :presence => true
validate :unique_inputs
validates :title, :presence => true,
:length => {:minimum => 3, :maximum => 40},
:appropriate_title => {:message => "cannot have . and /"},
:uniqueness => {
:scope => :account,
:message => 'is already taken for this account',
:case_sensitive => false }

关于ruby-on-rails - 事件模型在机架测试期间发送验证错误两次。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6859322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com