fix weird specs

probably only worked because of unintended validation error from automatic validation:

- testing to pass nil as value, though nil-values were explicitly ignored
- assuming a single journal entry, though the WP is saved twice

really needed to be fixed, because of new implementation:

- valdiation errors now indicate CF id and are more specific
pull/2550/head
Jan Sandbrink 10 years ago
parent e4ee92aa3e
commit 0dcd0a0c84
  1. 28
      spec/models/work_package/work_package_custom_fields_spec.rb

@ -56,7 +56,7 @@ describe WorkPackage, type: :model do
before do before do
def self.change_custom_field_value(work_package, value) def self.change_custom_field_value(work_package, value)
work_package.custom_field_values = { custom_field.id => value } unless value.nil? work_package.custom_field_values = { custom_field.id => value }
work_package.save work_package.save
end end
end end
@ -75,45 +75,49 @@ describe WorkPackage, type: :model do
describe 'invalid custom field values' do describe 'invalid custom field values' do
context 'short error message' do context 'short error message' do
shared_examples_for 'custom field with invalid value' do shared_examples_for 'custom field with invalid value' do
let(:modified_work_package_subject) { 'Should not be saved' }
before do before do
work_package.subject = modified_work_package_subject
change_custom_field_value(work_package, custom_field_value) change_custom_field_value(work_package, custom_field_value)
end end
describe 'error message' do describe 'error message' do
before { work_package.save } before { work_package.save }
subject { work_package.errors[:custom_values] } subject { work_package.errors["custom_field_#{custom_field.id}"] }
it { is_expected.to include(I18n.translate('activerecord.errors.messages.invalid')) } it {
is_expected.to include(I18n.translate("activerecord.errors.messages.#{error_key}"))
}
end end
describe 'work package attribute update' do describe 'work package attribute update' do
subject { work_package.save } subject { work_package.save }
it { is_expected.to be_falsey } it { is_expected.to be_false }
end end
end end
context 'no value given' do context 'no value given' do
let(:custom_field_value) { nil } let(:custom_field_value) { nil }
it_behaves_like 'custom field with invalid value' it_behaves_like 'custom field with invalid value' do
let(:error_key) { 'blank' }
end
end end
context 'empty value given' do context 'empty value given' do
let(:custom_field_value) { '' } let(:custom_field_value) { '' }
it_behaves_like 'custom field with invalid value' it_behaves_like 'custom field with invalid value' do
let(:error_key) { 'blank' }
end
end end
context 'invalid value given' do context 'invalid value given' do
let(:custom_field_value) { 'SQLServer' } let(:custom_field_value) { 'SQLServer' }
it_behaves_like 'custom field with invalid value' it_behaves_like 'custom field with invalid value' do
let(:error_key) { 'inclusion' }
end
end end
end end
@ -256,7 +260,7 @@ describe WorkPackage, type: :model do
change_custom_field_value(work_package, value) change_custom_field_value(work_package, value)
end end
subject { work_package.journals.first.customizable_journals.first.value } subject { work_package.journals.last.customizable_journals.first.value }
it { expect(subject).to eq(value) } it { expect(subject).to eq(value) }
end end

Loading…
Cancel
Save