123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- require 'rails_helper'
- RSpec.describe CheckForObjectAttributes, type: :db_migration do
- it 'performs no action for new systems', system_init_done: false do
- migrate do |instance|
- expect(instance).not_to receive(:attributes)
- end
- end
- context 'valid [:data_option]' do
- it 'does not change converted text attribute' do
- attribute = create(:object_manager_attribute_text)
- expect do
- migrate
- end.not_to change {
- attribute.reload.data_option
- }
- end
- it 'does not change select attribute' do
- attribute = create(:object_manager_attribute_select)
- expect do
- migrate
- end.not_to change {
- attribute.reload.data_option
- }
- end
- it 'does not change tree_select attribute' do
- attribute = create(:object_manager_attribute_tree_select)
- expect do
- migrate
- end.not_to change {
- attribute.reload.data_option
- }
- end
- end
- context '[:data_option]' do
- it 'ensures an empty Hash' do
- attribute = create(:object_manager_attribute_text, data_option: nil)
- migrate
- attribute.reload
- expect(attribute[:data_option]).to be_a(Hash)
- end
- end
- context '[:data_option][:options]' do
- it 'ensures an empty Hash' do
- attribute = create(:object_manager_attribute_text, data_option: {})
- migrate
- attribute.reload
- expect(attribute[:data_option][:options]).to be_a(Hash)
- end
- it 'converts String to Hash' do
- wrong = {
- default: '',
- options: '',
- relation: '',
- null: true
- }
- attribute = create(:object_manager_attribute_text, data_option: wrong)
- migrate
- attribute.reload
- expect(attribute[:data_option][:options]).to be_a(Hash)
- expect(attribute[:data_option][:options]).to be_blank
- end
- end
- context '[:data_option][:relation]' do
- it 'ensures an empty String' do
- wrong = {
- default: '',
- options: {},
- null: true
- }
- attribute = create(:object_manager_attribute_text, data_option: wrong)
- migrate
- attribute.reload
- expect(attribute[:data_option][:relation]).to be_a(String)
- end
- it 'converts Hash to String' do
- wrong = {
- default: '',
- options: {},
- relation: {},
- null: true
- }
- attribute = create(:object_manager_attribute_text, data_option: wrong)
- migrate
- attribute.reload
- expect(attribute[:data_option][:relation]).to be_a(String)
- expect(attribute[:data_option][:relation]).to be_blank
- end
- end
- end
|