瀏覽代碼

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

master
Matt Jankowski 7 年之前
committed by Eugen Rochko
父節點
當前提交
7a7d12d27f
共有 4 個文件被更改,包括 5 次插入6 次删除
  1. +1
    -1
      app/lib/language_detector.rb
  2. +1
    -1
      app/mailers/notification_mailer.rb
  3. +1
    -0
      app/models/account.rb
  4. +2
    -4
      spec/lib/language_detector_spec.rb

+ 1
- 1
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

+ 1
- 1
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


+ 1
- 0
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


+ 2
- 4
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


Loading…
取消
儲存