我有以下测试代码:
...
let(:person) { create(:person) }
...
it 'test the create route' do
json_data = '{"data":{"attributes":{"email":"muster@max.de","position":""},
"relationships": {"person":{"data":{"id":' + person.id.to_s + ',"type":"people"}}},
"type":"users"}}'
post 'create', body: json_data, format: :json
json = JSON.parse(response.body)
expect(response).to have_http_status(:success)
end
此代码测试控制器类方法:
public def create
action(User::Create)
.otherwise('user_create_error', 401)
.then_render(User::Representer::Out::Default)
end
动作方法:
public def action(op = nil, effective_params = params)
return if op.nil?
# Call the operation
result = op.(effective_params,
'current_user' => current_user,
'document' => request.raw_post)
# Build and return the OperationResult object
Webapp::OperationResult.new(result, method(:render))
end
op
是执行命令的操作(Trailblazer操作):
class User::Create < Webapp::Operation
contract User::Contract::Default
step Model(User, :create)
step Policy::Pundit(User::Policy, :create?)
step Contract::Build()
step Contract::Validate(representer: User::Representer::In::Default)
step Contract::Persist()
end
现在我得到了错误,那个人是零。为什么?我在创建用户之前保存了这个人,并且所有数据都是一起发送的。所需的所有属性都包含在代表中,在用户模型中还有一个指向person(belongs_to)的链接。人物模型还包含指向用户的链接(has_many)。工厂用户和人员也都在那里并且充满了数据。实际上,这必须没有任何问题,但它没有。
由于我无法解释的原因,无法保存(保持)。这是用户模型:
class User < ApplicationRecord
# Associations
belongs_to :person
delegate :firstname, to: :person
delegate :surname, to: :person
....
end
还有其他任何可以移交或为代表设置的内容吗?
答案 0 :(得分:0)
我认为,您必须在操作中添加library(rgl)
with(df, plot3d(x, y, z, type="s", col = as.numeric(system)))
with(df, text3d(x, y, z, text = Joint, adj = 2))
方法:
set_person