diff --git a/app/models/country_state.rb b/app/models/country_state.rb index 1bc7673..dc745d3 100644 --- a/app/models/country_state.rb +++ b/app/models/country_state.rb @@ -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 diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb index be03dd0..5e06d60 100644 --- a/app/views/accounts/show.html.erb +++ b/app/views/accounts/show.html.erb @@ -28,8 +28,10 @@ <% if @account.person&.regional_office %>
- <%= 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, + ) %>
<% end %> diff --git a/spec/models/country_state_spec.rb b/spec/models/country_state_spec.rb index 3a170a0..1bcd177 100644 --- a/spec/models/country_state_spec.rb +++ b/spec/models/country_state_spec.rb @@ -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