mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Add delete condition to update_data method on CellValues
This commit is contained in:
parent
79a50860b6
commit
5b710241e1
12 changed files with 109 additions and 36 deletions
|
@ -33,6 +33,8 @@ class RepositoryAssetValue < ApplicationRecord
|
|||
end
|
||||
|
||||
def update_data!(new_data, user)
|
||||
destroy! && return if new_data == '-1'
|
||||
|
||||
if new_data[:signed_url]
|
||||
asset.update(file: new_data[:sigend_url])
|
||||
else
|
||||
|
|
|
@ -16,6 +16,8 @@ class RepositoryDateTimeRangeValueBase < ApplicationRecord
|
|||
SORTABLE_VALUE_INCLUDE = :repository_date_time_range_value
|
||||
|
||||
def update_data!(new_data, user)
|
||||
destroy! && return if new_data == ''
|
||||
|
||||
self.start_time = Time.zone.parse(new_data[:start_time])
|
||||
self.end_time = Time.zone.parse(new_data[:end_time])
|
||||
self.last_modified_by = user
|
||||
|
|
|
@ -16,6 +16,8 @@ class RepositoryDateTimeValueBase < ApplicationRecord
|
|||
SORTABLE_VALUE_INCLUDE = :repository_date_time_value
|
||||
|
||||
def update_data!(new_data, user)
|
||||
destroy! && return if new_data == ''
|
||||
|
||||
self.data = Time.zone.parse(new_data)
|
||||
self.last_modified_by = user
|
||||
save!
|
||||
|
|
|
@ -34,6 +34,8 @@ class RepositoryListValue < ApplicationRecord
|
|||
end
|
||||
|
||||
def update_data!(new_data, user)
|
||||
destroy! && return if new_data == '-1'
|
||||
|
||||
self.repository_list_item_id = new_data.to_i
|
||||
self.last_modified_by = user
|
||||
save!
|
||||
|
|
|
@ -23,6 +23,8 @@ class RepositoryStatusValue < ApplicationRecord
|
|||
end
|
||||
|
||||
def update_data!(new_data, user)
|
||||
destroy! && return if new_data == '-1'
|
||||
|
||||
self.repository_status_item_id = new_data.to_i
|
||||
self.last_modified_by = user
|
||||
save!
|
||||
|
|
|
@ -23,6 +23,8 @@ class RepositoryTextValue < ApplicationRecord
|
|||
end
|
||||
|
||||
def update_data!(new_data, user)
|
||||
destroy! && return if new_data == ''
|
||||
|
||||
self.data = new_data
|
||||
self.last_modified_by = user
|
||||
save!
|
||||
|
|
|
@ -64,23 +64,33 @@ describe RepositoryAssetValue, type: :model do
|
|||
}
|
||||
end
|
||||
|
||||
context 'when has signed_url' do
|
||||
it 'should change last_modified_by and data' do
|
||||
repository_asset_value.save
|
||||
context 'when update data' do
|
||||
context 'when has signed_url' do
|
||||
it 'should change last_modified_by and data' do
|
||||
repository_asset_value.save
|
||||
|
||||
expect { repository_asset_value.update_data!(new_file_with_signed_url, user) }
|
||||
.to(change { repository_asset_value.reload.last_modified_by.id }
|
||||
.and(change { repository_asset_value.reload.data }))
|
||||
expect { repository_asset_value.update_data!(new_file_with_signed_url, user) }
|
||||
.to(change { repository_asset_value.reload.last_modified_by.id }
|
||||
.and(change { repository_asset_value.reload.data }))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when has base464 file' do
|
||||
it 'should change last_modified_by and data' do
|
||||
repository_asset_value.save
|
||||
|
||||
expect { repository_asset_value.update_data!(new_file_base64, user) }
|
||||
.to(change { repository_asset_value.reload.last_modified_by.id }
|
||||
.and(change { repository_asset_value.reload.data }))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when has base464 file' do
|
||||
it 'should change last_modified_by and data' do
|
||||
context 'when delete cell value' do
|
||||
it do
|
||||
repository_asset_value.save
|
||||
|
||||
expect { repository_asset_value.update_data!(new_file_base64, user) }
|
||||
.to(change { repository_asset_value.reload.last_modified_by.id }
|
||||
.and(change { repository_asset_value.reload.data }))
|
||||
expect { repository_asset_value.update_data!('-1', user) }.to change(RepositoryAssetValue, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,12 +37,24 @@ describe RepositoryDateTimeRangeValueBase, type: :model do
|
|||
end_time: (Time.zone.now + 2.days).utc.to_s
|
||||
}
|
||||
end
|
||||
it 'should change last_modified_by and dates' do
|
||||
repository_date_time_range_value.save
|
||||
|
||||
expect { repository_date_time_range_value.update_data!(new_times, user) }
|
||||
.to(change { repository_date_time_range_value.reload.last_modified_by.id }
|
||||
.and(change { repository_date_time_range_value.reload.data }))
|
||||
context 'when update data' do
|
||||
it 'should change last_modified_by and dates' do
|
||||
repository_date_time_range_value.save
|
||||
|
||||
expect { repository_date_time_range_value.update_data!(new_times, user) }
|
||||
.to(change { repository_date_time_range_value.reload.last_modified_by.id }
|
||||
.and(change { repository_date_time_range_value.reload.data }))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when delete cell value' do
|
||||
it do
|
||||
repository_date_time_range_value.save
|
||||
|
||||
expect { repository_date_time_range_value.update_data!('', user) }
|
||||
.to(change(RepositoryDateTimeRangeValue, :count).by(-1))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -29,12 +29,22 @@ describe RepositoryDateTimeValueBase, type: :model do
|
|||
let(:user) { create :user }
|
||||
let(:new_data) { Time.now.utc.to_s }
|
||||
|
||||
it 'should change last_modified_by and dates' do
|
||||
repository_date_time_value.save
|
||||
context 'when update data' do
|
||||
it 'should change last_modified_by and dates' do
|
||||
repository_date_time_value.save
|
||||
|
||||
expect { repository_date_time_value.update_data!(new_data, user) }
|
||||
.to(change { repository_date_time_value.reload.last_modified_by.id }
|
||||
.and(change { repository_date_time_value.reload.data }))
|
||||
expect { repository_date_time_value.update_data!(new_data, user) }
|
||||
.to(change { repository_date_time_value.reload.last_modified_by.id }
|
||||
.and(change { repository_date_time_value.reload.data }))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when delete cell value' do
|
||||
it do
|
||||
repository_date_time_value.save
|
||||
|
||||
expect { repository_date_time_value.update_data!('', user) }.to change(RepositoryDateTimeValue, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -75,13 +75,22 @@ RSpec.describe RepositoryListValue, type: :model do
|
|||
let(:new_list_item) do
|
||||
create :repository_list_item, repository_column: repository_list_value.repository_list_item.repository_column
|
||||
end
|
||||
context 'when update data' do
|
||||
it 'should change last_modified_by and data' do
|
||||
repository_list_value.save
|
||||
|
||||
it 'should change last_modified_by and data' do
|
||||
repository_list_value.save
|
||||
expect { repository_list_value.update_data!(new_list_item.id, user) }
|
||||
.to(change { repository_list_value.reload.last_modified_by.id }
|
||||
.and(change { repository_list_value.reload.data }))
|
||||
end
|
||||
end
|
||||
|
||||
expect { repository_list_value.update_data!(new_list_item.id, user) }
|
||||
.to(change { repository_list_value.reload.last_modified_by.id }
|
||||
.and(change { repository_list_value.reload.data }))
|
||||
context 'when delete cell value' do
|
||||
it do
|
||||
repository_list_value.save
|
||||
|
||||
expect { repository_list_value.update_data!('-1', user) }.to change(RepositoryListValue, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,12 +45,22 @@ describe RepositoryStatusValue do
|
|||
repository_column: repository_status_value.repository_status_item.repository_column
|
||||
end
|
||||
|
||||
it 'should change last_modified_by and data' do
|
||||
repository_status_value.save
|
||||
context 'when update data' do
|
||||
it 'should change last_modified_by and data' do
|
||||
repository_status_value.save
|
||||
|
||||
expect { repository_status_value.update_data!(new_status_item.id, user) }
|
||||
.to(change { repository_status_value.reload.last_modified_by.id }
|
||||
.and(change { repository_status_value.reload.data }))
|
||||
expect { repository_status_value.update_data!(new_status_item.id, user) }
|
||||
.to(change { repository_status_value.reload.last_modified_by.id }
|
||||
.and(change { repository_status_value.reload.data }))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when delete cell value' do
|
||||
it do
|
||||
repository_status_value.save
|
||||
|
||||
expect { repository_status_value.update_data!('-1', user) }.to change(RepositoryStatusValue, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,12 +53,22 @@ describe RepositoryTextValue, type: :model do
|
|||
describe 'update_data!' do
|
||||
let(:user) { create :user }
|
||||
|
||||
it 'should change last_modified_by and data' do
|
||||
repository_text_value.save
|
||||
context 'when update data' do
|
||||
it 'should change last_modified_by and data' do
|
||||
repository_text_value.save
|
||||
|
||||
expect { repository_text_value.update_data!('newData', user) }
|
||||
.to(change { repository_text_value.reload.last_modified_by.id }
|
||||
.and(change { repository_text_value.reload.data }))
|
||||
expect { repository_text_value.update_data!('newData', user) }
|
||||
.to(change { repository_text_value.reload.last_modified_by.id }
|
||||
.and(change { repository_text_value.reload.data }))
|
||||
end
|
||||
end
|
||||
|
||||
context 'when delete cell value' do
|
||||
it do
|
||||
repository_text_value.save
|
||||
|
||||
expect { repository_text_value.update_data!('', user) }.to change(RepositoryTextValue, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue