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:
parent
2ccda12cc2
commit
4e07079056
8 changed files with 44 additions and 52 deletions
|
@ -231,24 +231,6 @@ class App.UiElement.object_manager_attribute extends App.UiElement.ApplicationUi
|
||||||
item.find('.js-datetimeDiff').html(datetimeDiff.form)
|
item.find('.js-datetimeDiff').html(datetimeDiff.form)
|
||||||
|
|
||||||
@date: (item, localParams, params) ->
|
@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 = [
|
configureAttributes = [
|
||||||
{ name: 'data_option::diff', display: 'Default time Diff (hours)', tag: 'integer', null: false, default: 24 },
|
{ 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
|
noFieldset: true
|
||||||
params: params
|
params: params
|
||||||
)
|
)
|
||||||
item.find('.js-dateFuture').html(dateFuture.form)
|
|
||||||
item.find('.js-datePast').html(datePast.form)
|
|
||||||
item.find('.js-dateDiff').html(dateDiff.form)
|
item.find('.js-dateDiff').html(dateDiff.form)
|
||||||
|
|
||||||
@integer: (item, localParams, params) ->
|
@integer: (item, localParams, params) ->
|
||||||
|
|
|
@ -1001,11 +1001,7 @@ is certain attribute used by triggers, overviews or schedulers
|
||||||
{ failed: local_data_option[:diff].nil?,
|
{ failed: local_data_option[:diff].nil?,
|
||||||
message: 'must have integer value for :diff (in hours)' }]
|
message: 'must have integer value for :diff (in hours)' }]
|
||||||
when 'date'
|
when 'date'
|
||||||
[{ failed: local_data_option[:future].nil?,
|
[{ failed: local_data_option[:diff].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?,
|
|
||||||
message: 'must have integer value for :diff (in days)' }]
|
message: 'must have integer value for :diff (in days)' }]
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class ObjectManager::Attribute::Validation::Date < ObjectManager::Attribute::Validation::Backend
|
class ObjectManager::Attribute::Validation::FuturePast < ObjectManager::Attribute::Validation::Backend
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
return if value.blank?
|
return if value.blank?
|
||||||
|
@ -11,7 +11,7 @@ class ObjectManager::Attribute::Validation::Date < ObjectManager::Attribute::Val
|
||||||
private
|
private
|
||||||
|
|
||||||
def irrelevant_attribute?
|
def irrelevant_attribute?
|
||||||
%w[date datetime].exclude?(attribute.data_type)
|
attribute.data_type != 'datetime'.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_past
|
def validate_past
|
|
@ -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
|
|
@ -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
|
|
@ -69,8 +69,6 @@ FactoryBot.define do
|
||||||
data_type 'date'
|
data_type 'date'
|
||||||
data_option do
|
data_option do
|
||||||
{
|
{
|
||||||
'future' => true,
|
|
||||||
'past' => true,
|
|
||||||
'diff' => 24,
|
'diff' => 24,
|
||||||
'null' => true,
|
'null' => true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
require 'models/object_manager/attribute/validation/backend_examples'
|
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(:record) { build(:user) }
|
||||||
let(:attribute) { build(:object_manager_attribute_date) }
|
let(:attribute) { build(:object_manager_attribute_datetime) }
|
||||||
subject do
|
subject do
|
||||||
described_class.new(
|
described_class.new(
|
||||||
record: record,
|
record: record,
|
|
@ -284,25 +284,6 @@ class ObjectManagerTest < ActiveSupport::TestCase
|
||||||
object: 'Ticket',
|
object: 'Ticket',
|
||||||
name: 'test11',
|
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_equal(false, ObjectManager::Attribute.pending_migration?)
|
||||||
|
|
||||||
assert_raises(RuntimeError) do
|
assert_raises(RuntimeError) do
|
||||||
|
|
Loading…
Reference in a new issue