Remove redundant I18nContent scope
Since two records cannot have the same key, having a scope that will always return just one record is the same as using `find_by_key`.
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
class I18nContent < ApplicationRecord
|
||||
|
||||
scope :by_key, ->(key) { where(key: key) }
|
||||
|
||||
validates :key, uniqueness: true
|
||||
|
||||
translates :value, touch: true
|
||||
|
||||
@@ -9,7 +9,7 @@ module ActionView
|
||||
def t(key, options = {})
|
||||
current_locale = options[:locale].presence || I18n.locale
|
||||
|
||||
i18_content = I18nContent.by_key(key).first
|
||||
i18_content = I18nContent.find_by_key(key)
|
||||
translation = I18nContentTranslation.where(i18n_content_id: i18_content&.id,
|
||||
locale: current_locale).first&.value
|
||||
translation.presence || translate(key, options)
|
||||
|
||||
@@ -14,21 +14,6 @@ RSpec.describe I18nContent, type: :model do
|
||||
expect(i18n_content.errors.size).to eq(1)
|
||||
end
|
||||
|
||||
context "Scopes" do
|
||||
it "return one record when #by_key is used" do
|
||||
content = create(:i18n_content)
|
||||
key = "debates.form.debate_title"
|
||||
debate_title = create(:i18n_content, key: key)
|
||||
|
||||
expect(I18nContent.all.size).to eq(2)
|
||||
|
||||
query = I18nContent.by_key(key)
|
||||
|
||||
expect(query.size).to eq(1)
|
||||
expect(query).to eq([debate_title])
|
||||
end
|
||||
end
|
||||
|
||||
context "Globalize" do
|
||||
it "translates key into multiple languages" do
|
||||
key = "devise_views.mailer.confirmation_instructions.welcome"
|
||||
|
||||
Reference in New Issue
Block a user