Add shared example "nameable"
This commit is contained in:
parent
6599d0bcbc
commit
c7c91e9212
|
@ -5,37 +5,15 @@ require 'rails_helper'
|
|||
RSpec.describe PassportMap do
|
||||
subject { create :passport_map }
|
||||
|
||||
it_behaves_like 'nameable'
|
||||
|
||||
it { is_expected.to belong_to :passport }
|
||||
|
||||
it { is_expected.to validate_presence_of(:passport).with_message(:required) }
|
||||
|
||||
it { is_expected.to validate_presence_of :first_name }
|
||||
it { is_expected.not_to validate_presence_of :middle_name }
|
||||
it { is_expected.to validate_presence_of :last_name }
|
||||
it { is_expected.to validate_presence_of :sex }
|
||||
it { is_expected.to validate_presence_of :date_of_birth }
|
||||
it { is_expected.to validate_presence_of :place_of_birth }
|
||||
it { is_expected.to validate_presence_of :series }
|
||||
it { is_expected.to validate_presence_of :number }
|
||||
it { is_expected.to validate_presence_of :issued_by }
|
||||
it { is_expected.to validate_presence_of :unit_code }
|
||||
it { is_expected.to validate_presence_of :date_of_issue }
|
||||
|
||||
describe '#middle_name' do
|
||||
context 'when it is empty' do
|
||||
subject { create :passport_map, middle_name: '' }
|
||||
|
||||
specify do
|
||||
expect(subject.middle_name).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is blank' do
|
||||
subject { create :passport_map, middle_name: ' ' }
|
||||
|
||||
specify do
|
||||
expect(subject.middle_name).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,8 @@ require 'rails_helper'
|
|||
RSpec.describe Person do
|
||||
subject { create :member_person }
|
||||
|
||||
it_behaves_like 'nameable'
|
||||
|
||||
it { is_expected.to belong_to(:regional_office).optional }
|
||||
|
||||
it { is_expected.to have_one(:account).dependent(:restrict_with_exception) }
|
||||
|
@ -32,31 +34,6 @@ RSpec.describe Person do
|
|||
|
||||
it { is_expected.not_to validate_presence_of :regional_office }
|
||||
|
||||
it { is_expected.to validate_presence_of :first_name }
|
||||
it { is_expected.not_to validate_presence_of :middle_name }
|
||||
it { is_expected.to validate_presence_of :last_name }
|
||||
it { is_expected.to validate_presence_of :sex }
|
||||
it { is_expected.to validate_presence_of :date_of_birth }
|
||||
it { is_expected.to validate_presence_of :place_of_birth }
|
||||
|
||||
describe '#middle_name' do
|
||||
context 'when it is empty' do
|
||||
subject { create :member_person, middle_name: '' }
|
||||
|
||||
specify do
|
||||
expect(subject.middle_name).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is blank' do
|
||||
subject { create :member_person, middle_name: ' ' }
|
||||
|
||||
specify do
|
||||
expect(subject.middle_name).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#supporter_since' do
|
||||
def allow_value(*)
|
||||
super.for :supporter_since
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.shared_examples 'nameable' do
|
||||
it { is_expected.to validate_presence_of :first_name }
|
||||
it { is_expected.not_to validate_presence_of :middle_name }
|
||||
it { is_expected.to validate_presence_of :last_name }
|
||||
it { is_expected.to validate_presence_of :sex }
|
||||
it { is_expected.to validate_presence_of :date_of_birth }
|
||||
it { is_expected.to validate_presence_of :place_of_birth }
|
||||
|
||||
describe '#middle_name' do
|
||||
context 'when it is empty' do
|
||||
subject { create :member_person, middle_name: '' }
|
||||
|
||||
specify do
|
||||
expect(subject.middle_name).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is blank' do
|
||||
subject { create :member_person, middle_name: ' ' }
|
||||
|
||||
specify do
|
||||
expect(subject.middle_name).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -37,6 +37,8 @@ require_relative 'support/database_cleaner'
|
|||
require_relative 'support/devise'
|
||||
require_relative 'support/pundit'
|
||||
|
||||
require_relative 'models/shared_examples/nameable'
|
||||
|
||||
# Checks for pending migrations and applies them before tests are run.
|
||||
# If you are not using ActiveRecord, you can remove these lines.
|
||||
begin
|
||||
|
|
Reference in New Issue