logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe
commit: 7a7d12d27f16370c3789aa97514da25c6e91ae4c
parent: cd830a2fab3f3c640daeb55e024324b56c079557
Author: Matt Jankowski <mjankowski@thoughtbot.com>
Date:   Mon,  8 May 2017 17:10:50 -0400

Delegate Account#user_locale method and allow nil (#2927)


Diffstat:

Mapp/lib/language_detector.rb2+-
Mapp/mailers/notification_mailer.rb2+-
Mapp/models/account.rb1+
Mspec/lib/language_detector_spec.rb6++----
4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/app/lib/language_detector.rb b/app/lib/language_detector.rb @@ -35,6 +35,6 @@ class LanguageDetector end def default_locale - account&.user&.locale || I18n.default_locale + account&.user_locale || I18n.default_locale end end diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb @@ -71,7 +71,7 @@ class NotificationMailer < ApplicationMailer private def locale_for_account(account) - I18n.with_locale(account.user.locale || I18n.default_locale) do + I18n.with_locale(account.user_locale || I18n.default_locale) do yield end end diff --git a/app/models/account.rb b/app/models/account.rb @@ -111,6 +111,7 @@ class Account < ApplicationRecord :current_sign_in_ip, :current_sign_in_at, :confirmed?, + :locale, to: :user, prefix: true, allow_nil: true diff --git a/spec/lib/language_detector_spec.rb b/spec/lib/language_detector_spec.rb @@ -43,16 +43,14 @@ describe LanguageDetector do describe 'with an account' do it 'uses the account locale when present' do - user = double(:user, locale: 'fr') - account = double(:account, user: user) + account = double(user_locale: 'fr') result = described_class.new('', account).to_iso_s expect(result).to eq :fr end it 'uses default locale when account is present but has no locale' do - user = double(:user, locale: nil) - account = double(:accunt, user: user) + account = double(user_locale: nil) result = described_class.new('', account).to_iso_s expect(result).to eq :en