Fix checks_import_examples.rb when applied to non-importable classes

This commit is contained in:
Ryan Lue 2019-01-23 14:42:54 +08:00 committed by Martin Edenhofer
parent 2cf614d302
commit 205a99c56a

View file

@ -1,17 +1,8 @@
RSpec.shared_examples 'ApplicationModel::ChecksImport' do
subject { build(described_class.name.underscore, id: unused_id) }
let(:unused_id) { described_class.pluck(:id).max * 2 }
let(:unused_id) { (described_class.pluck(:id).max || 1) * 2 }
context 'when Setting.get("system_init_done") is true AND Setting.get("import_mode") is false' do
before { Setting.set('system_init_done', true) }
before { Setting.set('import_mode', false) }
it 'prevents explicit setting of #id attribute' do
expect { subject.save }.to change { subject.id }
end
end
context 'when Setting.get("system_init_done") is false' do
context 'when Setting.get("system_init_done") is false (regardless of import_mode)' do
before { Setting.set('system_init_done', false) }
it 'allows explicit setting of #id attribute' do
@ -19,7 +10,18 @@ RSpec.shared_examples 'ApplicationModel::ChecksImport' do
end
end
context 'when Setting.get("import_mode") is true' do
context 'when Setting.get("system_init_done") is true' do
before { Setting.set('system_init_done', true) }
context 'and Setting.get("import_mode") is false' do
before { Setting.set('import_mode', false) }
it 'prevents explicit setting of #id attribute' do
expect { subject.save }.to change { subject.id }
end
end
context 'and Setting.get("import_mode") is true' do
before { Setting.set('import_mode', true) }
shared_examples 'importable classes' do
@ -36,4 +38,5 @@ RSpec.shared_examples 'ApplicationModel::ChecksImport' do
include_examples described_class.importable? ? 'importable classes' : 'non-importable classes'
end
end
end