Add method CountryState#display_name
This commit is contained in:
parent
2f67836361
commit
f4db735eab
3 changed files with 44 additions and 2 deletions
|
@ -8,4 +8,10 @@ class CountryState < ApplicationRecord
|
|||
validates :english_name, presence: true, uniqueness: true
|
||||
|
||||
validates :native_name, presence: true, uniqueness: true
|
||||
|
||||
def display_name
|
||||
return native_name if I18n.locale == :ru
|
||||
|
||||
english_name
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,8 +28,10 @@
|
|||
<% if @account.person&.regional_office %>
|
||||
<div class="mb-2">
|
||||
<i class="fas fa-map-marker-alt"></i>
|
||||
<%= link_to @account.person.regional_office.country_state.native_name,
|
||||
@account.person.regional_office.country_state %>
|
||||
<%= link_to(
|
||||
@account.person.regional_office.country_state.display_name,
|
||||
@account.person.regional_office.country_state,
|
||||
) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -24,4 +24,38 @@ RSpec.describe CountryState do
|
|||
|
||||
it { is_expected.to validate_uniqueness_of :english_name }
|
||||
it { is_expected.to validate_uniqueness_of :native_name }
|
||||
|
||||
describe '#display_name' do
|
||||
subject { create :country_state, native_name: Faker::Address.unique.state }
|
||||
|
||||
around do |example|
|
||||
I18n.with_locale locale do
|
||||
example.run
|
||||
end
|
||||
end
|
||||
|
||||
context 'when locale is "en"' do
|
||||
let(:locale) { :en }
|
||||
|
||||
specify do
|
||||
expect(subject.display_name).to eq subject.english_name
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.display_name).not_to eq subject.native_name
|
||||
end
|
||||
end
|
||||
|
||||
context 'when locale is "ru"' do
|
||||
let(:locale) { :ru }
|
||||
|
||||
specify do
|
||||
expect(subject.display_name).to eq subject.native_name
|
||||
end
|
||||
|
||||
specify do
|
||||
expect(subject.display_name).not_to eq subject.english_name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue