Follow up - 444e48e377 - Removed future and past data_options of Date ObjectManager::Attribute because they are not determinable due to time zones.

This commit is contained in:
Thorsten Eckel 2019-03-14 11:06:49 +01:00
parent 2ccda12cc2
commit 4e07079056
8 changed files with 44 additions and 52 deletions

View file

@ -231,24 +231,6 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi
item.find('.js-datetimeDiff').html(datetimeDiff.form)
@date: (item, localParams, params) ->
configureAttributes = [
{ name: 'data_option::future', display: 'Allow future', tag: 'boolean', null: false, default: true },
]
dateFuture = new App.ControllerForm(
model:
configure_attributes: configureAttributes
noFieldset: true
params: params
)
configureAttributes = [
{ name: 'data_option::past', display: 'Allow past', tag: 'boolean', null: false, default: true },
]
datePast = new App.ControllerForm(
model:
configure_attributes: configureAttributes
noFieldset: true
params: params
)
configureAttributes = [
{ name: 'data_option::diff', display: 'Default time Diff (hours)', tag: 'integer', null: false, default: 24 },
]
@ -258,8 +240,6 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi
noFieldset: true
params: params
)
item.find('.js-dateFuture').html(dateFuture.form)
item.find('.js-datePast').html(datePast.form)
item.find('.js-dateDiff').html(dateDiff.form)
@integer: (item, localParams, params) ->

View file

@ -1001,11 +1001,7 @@ is certain attribute used by triggers, overviews or schedulers
{ failed: local_data_option[:diff].nil?,
message: 'must have integer value for :diff (in hours)' }]
when 'date'
[{ failed: local_data_option[:future].nil?,
message: 'must have boolean value for :future' },
{ failed: local_data_option[:past].nil?,
message: 'must have boolean value for :past' },
{ failed: local_data_option[:diff].nil?,
[{ failed: local_data_option[:diff].nil?,
message: 'must have integer value for :diff (in days)' }]
else
[]

View file

@ -1,4 +1,4 @@
class ObjectManager::Attribute::Validation::Date < ObjectManager::Attribute::Validation::Backend
class ObjectManager::Attribute::Validation::FuturePast < ObjectManager::Attribute::Validation::Backend
def validate
return if value.blank?
@ -11,7 +11,7 @@ class ObjectManager::Attribute::Validation::Date < ObjectManager::Attribute::Val
private
def irrelevant_attribute?
%w[date datetime].exclude?(attribute.data_type)
attribute.data_type != 'datetime'.freeze
end
def validate_past

View file

@ -0,0 +1,12 @@
class ObjectManagerAttributeDateRemoveFuturePast < ActiveRecord::Migration[5.1]
def change
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
ObjectManager::Attribute.where(data_type: 'date').each do |attribute|
attribute.data_option = attribute.data_option.except(:future, :past)
attribute.save!
end
end
end

View file

@ -0,0 +1,25 @@
require 'rails_helper'
RSpec.describe ObjectManagerAttributeDateRemoveFuturePast, type: :db_migration do
context 'when Date ObjectManager::Attribute exists' do
it 'removes future and past data_option' do
subject = build(:object_manager_attribute_date)
# add data_options manually because the factory doesn't contain them anymore
subject.data_option = subject.data_option.merge(
future: false,
past: false,
)
# mock interfaces to save time
# otherwise we would have to reseed the database
expect(ObjectManager::Attribute).to receive(:where).and_return([subject])
expect(subject).to receive(:save!)
migrate
expect(subject.data_option).to_not include(:past, :future)
end
end
end

View file

@ -69,10 +69,8 @@ FactoryBot.define do
data_type 'date'
data_option do
{
'future' => true,
'past' => true,
'diff' => 24,
'null' => true,
'diff' => 24,
'null' => true,
}
end
end

View file

@ -1,10 +1,10 @@
require 'rails_helper'
require 'models/object_manager/attribute/validation/backend_examples'
RSpec.describe ::ObjectManager::Attribute::Validation::Date do
RSpec.describe ::ObjectManager::Attribute::Validation::FuturePast do
let(:record) { build(:user) }
let(:attribute) { build(:object_manager_attribute_date) }
let(:attribute) { build(:object_manager_attribute_datetime) }
subject do
described_class.new(
record: record,

View file

@ -284,25 +284,6 @@ class ObjectManagerTest < ActiveSupport::TestCase
object: 'Ticket',
name: 'test11',
)
assert_raises(ActiveRecord::RecordInvalid) do
attribute12 = ObjectManager::Attribute.add(
object: 'Ticket',
name: 'test12',
display: 'Test 12',
data_type: 'date',
data_option: {
past: false,
diff: 24,
null: true,
},
active: true,
screens: {},
position: 20,
created_by_id: 1,
updated_by_id: 1,
)
end
assert_equal(false, ObjectManager::Attribute.pending_migration?)
assert_raises(RuntimeError) do