Moved delete action to service

This commit is contained in:
Urban Rotnik 2019-12-10 13:58:47 +01:00
parent 5345cf0342
commit d35f7119b7
14 changed files with 9 additions and 64 deletions

View file

@ -33,8 +33,6 @@ class RepositoryAssetValue < ApplicationRecord
end
def update_data!(new_data, user)
destroy! && return if new_data == '-1'
if new_data.is_a?(String) # assume it's a signed_id_token
asset.file.attach(new_data)
elsif new_data[:file_data]

View file

@ -16,8 +16,6 @@ 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

View file

@ -16,8 +16,6 @@ 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!
@ -26,6 +24,6 @@ class RepositoryDateTimeValueBase < ApplicationRecord
private
def formatted(format)
I18n.l(d, format: format)
I18n.l(data, format: format)
end
end

View file

@ -34,8 +34,6 @@ 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!

View file

@ -23,8 +23,6 @@ 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!

View file

@ -23,8 +23,6 @@ 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!

View file

@ -18,8 +18,7 @@ module RepositoryRows
return self unless valid?
ActiveRecord::Base.transaction do
@repository_row = RepositoryRow.new(params[:repository_row])
@repository_row.repository = @repository
@repository_row = @repository.repository_rows.new(params[:repository_row])
@repository_row.last_modified_by = @user
@repository_row.created_by = @user
@repository_row.save!

View file

@ -24,6 +24,13 @@ module RepositoryRows
next unless column
cell = @repository_row.repository_cells.find_by(repository_column_id: column.id)
if cell && value.empty?
cell.destroy!
@record_updated = true
next
end
unless cell
RepositoryCell.create_with_value!(@repository_row, column, value, @user)
@record_updated = true

View file

@ -81,14 +81,6 @@ describe RepositoryAssetValue, type: :model do
end
end
end
context 'when delete cell value' do
it do
repository_asset_value.save
expect { repository_asset_value.update_data!('-1', user) }.to change(RepositoryAssetValue, :count).by(-1)
end
end
end
describe 'self.new_with_payload' do

View file

@ -47,15 +47,6 @@ describe RepositoryDateTimeRangeValueBase, type: :model do
.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
describe '.data' do

View file

@ -38,13 +38,5 @@ describe RepositoryDateTimeValueBase, type: :model do
.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

View file

@ -84,14 +84,6 @@ RSpec.describe RepositoryListValue, type: :model do
.and(change { repository_list_value.reload.data }))
end
end
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
describe 'self.new_with_payload' do

View file

@ -54,14 +54,6 @@ describe RepositoryStatusValue do
.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
describe 'self.new_with_payload' do

View file

@ -62,14 +62,6 @@ describe RepositoryTextValue, type: :model do
.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
describe 'self.new_with_payload' do