mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2026-01-07 00:36:08 +08:00
Remove uniqueness validation on Experiment name
SCI-5288
This commit is contained in:
parent
2d4b0fdbdc
commit
4ff1770d50
4 changed files with 8 additions and 33 deletions
|
|
@ -29,10 +29,7 @@ class Experiment < ApplicationRecord
|
|||
has_one_attached :workflowimg
|
||||
|
||||
auto_strip_attributes :name, :description, nullify: false
|
||||
validates :name,
|
||||
length: { minimum: Constants::NAME_MIN_LENGTH,
|
||||
maximum: Constants::NAME_MAX_LENGTH },
|
||||
uniqueness: { scope: :project, case_sensitive: false }
|
||||
validates :name, length: { minimum: Constants::NAME_MIN_LENGTH, maximum: Constants::NAME_MAX_LENGTH }
|
||||
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
|
||||
validates :project, presence: true
|
||||
validates :created_by, presence: true
|
||||
|
|
|
|||
|
|
@ -55,13 +55,7 @@ module Experiments
|
|||
return false
|
||||
end
|
||||
|
||||
e = Experiment.find_by(name: @exp.name, project: @project)
|
||||
|
||||
if e
|
||||
@errors[:project_with_exp] =
|
||||
['Project already contains experiment with this name']
|
||||
false
|
||||
elsif !@exp.moveable_projects(@user).include?(@project)
|
||||
if !@exp.moveable_projects(@user).include?(@project)
|
||||
@errors[:target_project_not_valid] =
|
||||
['Experiment cannot be moved to this project']
|
||||
false
|
||||
|
|
|
|||
|
|
@ -58,18 +58,6 @@ describe Experiment, type: :model do
|
|||
.is_at_most(Constants::TEXT_MAX_LENGTH)
|
||||
end
|
||||
|
||||
it 'should have uniq name scoped on project' do
|
||||
create :experiment, name: 'experiment',
|
||||
project: project,
|
||||
created_by: project.created_by,
|
||||
last_modified_by: project.created_by
|
||||
new_exp = build_stubbed :experiment, name: 'experiment',
|
||||
project: project,
|
||||
created_by: project.created_by,
|
||||
last_modified_by: project.created_by
|
||||
expect(new_exp).to_not be_valid
|
||||
end
|
||||
|
||||
it 'should have uniq uuid scoped on project' do
|
||||
uuid = SecureRandom.uuid
|
||||
puts uuid
|
||||
|
|
|
|||
|
|
@ -72,25 +72,21 @@ describe Experiments::MoveToProjectService do
|
|||
end
|
||||
|
||||
it 'returns an error on validate' do
|
||||
FactoryBot.create :experiment, project: new_project, name: 'MyExp'
|
||||
allow_any_instance_of(Experiment).to(receive(:moveable_projects).and_return([]))
|
||||
|
||||
expect(service_call.succeed?).to be_falsey
|
||||
end
|
||||
|
||||
it 'returns an error on saving' do
|
||||
expect_any_instance_of(Experiments::MoveToProjectService)
|
||||
.to receive(:valid?)
|
||||
.and_return(true)
|
||||
FactoryBot.create :experiment, project: new_project, name: 'MyExp'
|
||||
experiment.name = Faker::Lorem.characters(number: 300)
|
||||
experiment.save(validate: false)
|
||||
|
||||
expect(service_call.succeed?).to be_falsey
|
||||
end
|
||||
|
||||
it 'rollbacks cloned tags after unsucessful save' do
|
||||
expect_any_instance_of(Experiments::MoveToProjectService)
|
||||
.to receive(:valid?)
|
||||
.and_return(true)
|
||||
FactoryBot.create :experiment, project: new_project, name: 'MyExp'
|
||||
experiment
|
||||
experiment.name = Faker::Lorem.characters(number: 300)
|
||||
experiment.save(validate: false)
|
||||
|
||||
expect { service_call }.not_to(change { Tag.count })
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue