mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 13:14:29 +08:00
fix validation in asset model and change formatted method in repository_asset_value model
This commit is contained in:
parent
64e26e1c60
commit
34f5c2c7ac
3 changed files with 10 additions and 7 deletions
|
@ -44,7 +44,7 @@ class Asset < ApplicationRecord
|
||||||
# Asset validation
|
# Asset validation
|
||||||
# This could cause some problems if you create empty asset and want to
|
# This could cause some problems if you create empty asset and want to
|
||||||
# assign it to result
|
# assign it to result
|
||||||
validate :step_or_result_or_repository_cell
|
validate :step_or_result_or_repository_asset_value
|
||||||
|
|
||||||
belongs_to :created_by,
|
belongs_to :created_by,
|
||||||
foreign_key: 'created_by_id',
|
foreign_key: 'created_by_id',
|
||||||
|
@ -496,13 +496,16 @@ class Asset < ApplicationRecord
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def step_or_result_or_repository_cell
|
def step_or_result_or_repository_asset_value
|
||||||
# We must allow both step and result to be blank because of GUI
|
# We must allow both step and result to be blank because of GUI
|
||||||
# (even though it's not really a "valid" asset)
|
# (even though it's not really a "valid" asset)
|
||||||
if step.present? && result.present? ||
|
if step.present? && result.present? ||
|
||||||
step.present? && repository_cell.present? ||
|
step.present? && repository_asset_value.present? ||
|
||||||
result.present? && repository_cell.present?
|
result.present? && repository_asset_value.present?
|
||||||
errors.add(:base, "Asset can only be result or step or repository cell, not ever.")
|
errors.add(
|
||||||
|
:base,
|
||||||
|
'Asset can only be result or step or repository cell, not ever.'
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,6 @@ class RepositoryAssetValue < ApplicationRecord
|
||||||
validates :asset, :repository_cell, presence: true
|
validates :asset, :repository_cell, presence: true
|
||||||
|
|
||||||
def formatted
|
def formatted
|
||||||
asset.file
|
asset.file_file_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,7 +43,7 @@ describe RepositoryAssetValue, type: :model do
|
||||||
repository_column: repository_column,
|
repository_column: repository_column,
|
||||||
repository_row: repository_row
|
repository_row: repository_row
|
||||||
}
|
}
|
||||||
expect(repository_asset_value.reload.formatted.instance).to eq asset
|
expect(repository_asset_value.reload.formatted).to eq 'my file'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue