Skip to content
代码片段 群组 项目
未验证 提交 8262f11a 编辑于 作者: Alper Akgun's avatar Alper Akgun
浏览文件

Capture model experiment creation RecordNotUnique error

Changelog: fixed
上级 e0fa5452
No related branches found
No related tags found
2 合并请求!3031Merge per-main-jh to main-jh by luzhiyuan,!3030Merge per-main-jh to main-jh
...@@ -15,6 +15,9 @@ def execute ...@@ -15,6 +15,9 @@ def execute
return error(experiment.errors.full_messages) unless experiment.persisted? return error(experiment.errors.full_messages) unless experiment.persisted?
success(experiment) success(experiment)
rescue ActiveRecord::RecordNotUnique => e
error([e.message])
end end
private private
......
...@@ -41,5 +41,28 @@ ...@@ -41,5 +41,28 @@
expect(response.message).to include("Name can't be blank") expect(response.message).to include("Name can't be blank")
end end
end end
context 'when a RecordNotUnique error occurs' do
let_it_be(:pg_error) { 'PG::UniqueViolation: ERROR: duplicate key value violates unique constraint' }
before do
allow_next_instance_of(::Ml::Experiment) do |experiment|
allow(experiment).to receive(:save).and_raise(
ActiveRecord::RecordNotUnique.new(pg_error)
)
end
end
it 'returns an error response with the exception message' do
response = create_experiment
expect(response).to be_error
expect(response.message).to include(pg_error)
end
it 'does not persist the experiment' do
expect { create_experiment }.not_to change { Ml::Experiment.count }
end
end
end end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册