Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove deprecated dynamic finders

  • Loading branch information...
commit 41138e79608f3d28c6cefac2cfc0cd5550679345 1 parent 984e35d
Konstantin Ilchenko simpl1g authored
8 app/models/tolk/locale.rb
View
@@ -38,7 +38,7 @@ def primary_locale(reload = false)
@_primary_locale = nil if reload
@_primary_locale ||= begin
raise "Primary locale is not set. Please set Locale.primary_locale_name in your application's config file" unless self.primary_locale_name
- find_or_create_by(name: self.primary_locale_name)
+ where(name: self.primary_locale_name).first_or_create
end
end
@@ -55,7 +55,7 @@ def dump_all(*args)
end
def dump_yaml(name, *args)
- find_by_name(name).dump(*args)
+ where(name: name).first.dump(*args)
end
def special_key_or_prefix?(prefix, key)
@@ -162,7 +162,7 @@ def language_name
end
def get(key)
- if phrase = Tolk::Phrase.find_by_key(key)
+ if phrase = Tolk::Phrase.where(key: key).first
t = self.translations.where(:phrase_id => phrase.id).first
t.text if t
end
@@ -179,7 +179,7 @@ def self.rename(old_name, new_name)
if old_name.blank? || new_name.blank?
"You need to provide both names, aborting."
else
- if locale = find_by_name(old_name)
+ if locale = where(name: old_name).first
locale.name = new_name
locale.save
"Locale ' #{old_name}' was renamed '#{new_name}'"
4 app/views/tolk/searches/show.html.erb
View
@@ -19,7 +19,7 @@
</tr>
<% @phrases.each do |phrase| %>
- <% if translation = phrase.translations.find_by_locale_id(@locale.id) || Tolk::Translation.new(:locale => @locale, :phrase => phrase) %>
+ <% if translation = phrase.translations.where(locale_id: @locale.id).first || Tolk::Translation.new(:locale => @locale, :phrase => phrase) %>
<tr>
<td class="translation">
<%= hidden_field_tag :"translations[][id]", translation.id, :id => "#{translation.object_id}_id" %>
@@ -40,7 +40,7 @@
<%= format_i18n_value(phrase.translations.primary.text) -%>
<% end -%>
<%= boolean_warning if phrase.translations.primary.boolean? -%>
-
+
<span class="key" title="<%= phrase.key %>"><%= params[:k].present? ?
highlight(h(truncate(phrase.key, :length => 100)), params[:k]) :
h(truncate(phrase.key, :length => 100)) %></span>
2  lib/tolk/import.rb
View
@@ -20,7 +20,7 @@ def import_secondary_locales
end
def import_locale(locale_name)
- locale = Tolk::Locale.find_or_create_by_name(locale_name)
+ locale = Tolk::Locale.where(name: locale_name).first_or_create
data = locale.read_locale_file
return unless data
2  test/integration/translation_process_test.rb
View
@@ -65,7 +65,7 @@ def add_locale(name)
select name, :from => "select_tolk_locale_name"
click_button 'Add'
- Tolk::Locale.find_by_name!(Tolk.config.mapping.key(name))
+ Tolk::Locale.where(name: Tolk.config.mapping.key(name)).first!
end
def setup_locales
8 test/unit/sync_test.rb
View
@@ -64,8 +64,8 @@ def test_sync_marks_translations_for_review_when_the_primary_translation_has_cha
Tolk::Locale.create!(:name => 'es')
phrase = Tolk::Phrase.create! :key => 'number.precision'
- english_translation = phrase.translations.create!(:text => "1", :locale => Tolk::Locale.find_by_name("en"))
- spanish_translation = phrase.translations.create!(:text => "1", :locale => Tolk::Locale.find_by_name("es"))
+ english_translation = phrase.translations.create!(:text => "1", :locale => Tolk::Locale.where(name: "en").first)
+ spanish_translation = phrase.translations.create!(:text => "1", :locale => Tolk::Locale.where(name: "es").first)
Tolk::Locale.expects(:load_translations).returns({'number.precision' => "1"}).at_least_once
Tolk::Locale.sync! and spanish_translation.reload
@@ -93,7 +93,7 @@ def test_sync_creates_locale_phrases_translations
Tolk::Locale.sync!
# Created by sync!
- primary_locale = Tolk::Locale.find_by_name!(Tolk::Locale.primary_locale_name)
+ primary_locale = Tolk::Locale.where(name: Tolk::Locale.primary_locale_name).first!
assert_equal ["Hello World", "Nested Hello Country"], primary_locale.translations.map(&:text).sort
assert_equal ["hello_world", "nested.hello_country"], Tolk::Phrase.all.map(&:key).sort
@@ -145,7 +145,7 @@ def test_sync_handles_deleted_keys_and_updated_translations
Tolk::Locale.expects(:load_translations).returns({"hello_world" => "Hello Super World"}).at_least_once
Tolk::Locale.sync!
- primary_locale = Tolk::Locale.find_by_name!(Tolk::Locale.primary_locale_name)
+ primary_locale = Tolk::Locale.where(name: Tolk::Locale.primary_locale_name).first!
assert_equal ['Hello Super World'], primary_locale.translations.map(&:text)
assert_equal ['hello_world'], Tolk::Phrase.all.map(&:key).sort
Please sign in to comment.
Something went wrong with that request. Please try again.