2019-03-13 23:51:22 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'models/object_manager/attribute/validation/backend_examples'
|
|
|
|
|
2019-03-14 10:06:49 +00:00
|
|
|
RSpec.describe ::ObjectManager::Attribute::Validation::FuturePast do
|
2019-03-13 23:51:22 +00:00
|
|
|
|
|
|
|
let(:record) { build(:user) }
|
2019-03-14 10:06:49 +00:00
|
|
|
let(:attribute) { build(:object_manager_attribute_datetime) }
|
2019-03-13 23:51:22 +00:00
|
|
|
subject do
|
|
|
|
described_class.new(
|
|
|
|
record: record,
|
|
|
|
attribute: attribute
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:value).and_return(value)
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'data_option validator' do |data_option:, value:|
|
|
|
|
context "for data_option '#{data_option}'" do
|
|
|
|
|
|
|
|
let(:value) { value }
|
|
|
|
|
|
|
|
context 'when data_option is set to true' do
|
|
|
|
|
|
|
|
before { attribute.data_option[data_option] = true }
|
|
|
|
|
|
|
|
it_behaves_like 'a validation without errors'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when data_option is set to false' do
|
|
|
|
|
|
|
|
before { attribute.data_option[data_option] = false }
|
|
|
|
|
|
|
|
it_behaves_like 'a validation with errors'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'data_option validator', data_option: :future, value: Time.current.tomorrow.midnight
|
|
|
|
it_behaves_like 'data_option validator', data_option: :past, value: Time.current.yesterday.midnight
|
|
|
|
|
|
|
|
context 'when validation should not be performed' do
|
|
|
|
|
|
|
|
context 'for blank value' do
|
|
|
|
|
|
|
|
let(:value) { nil }
|
|
|
|
|
|
|
|
it_behaves_like 'a validation without errors'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for irrelevant attribute data_type' do
|
|
|
|
|
|
|
|
let(:value) { 'some_value' }
|
|
|
|
|
|
|
|
before { attribute.data_type = 'select' }
|
|
|
|
|
|
|
|
it_behaves_like 'a validation without errors'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|