Permalink
Browse files

Add tolk_ prefix to all the table names

  • Loading branch information...
1 parent c94fdee commit 7db9e0be7378336d44711df727ab19800eceeab4 @lifo lifo committed Apr 8, 2010
View
@@ -1,5 +1,7 @@
module Tolk
class Locale < ActiveRecord::Base
+ set_table_name "tolk_locales"
+
MAPPING = {
'en' => 'English',
'de' => 'German',
@@ -49,8 +51,8 @@ def dump_all(to = self.locales_config_path)
end
def phrases_with_translation(page = nil)
- result = Tolk::Phrase.paginate(:page => page, :conditions => { :'translations.locale_id' => self.id },
- :joins => :translations, :order => 'phrases.id ASC')
+ result = Tolk::Phrase.paginate(:page => page, :conditions => { :'tolk_translations.locale_id' => self.id },
+ :joins => :translations, :order => 'tolk_phrases.id ASC')
Tolk::Phrase.send :preload_associations, result, :translations
result.each do |phrase|
@@ -61,10 +63,10 @@ def phrases_with_translation(page = nil)
end
def phrases_without_translation(page = nil)
- phrases = Tolk::Phrase.scoped(:order => 'phrases.id ASC')
+ phrases = Tolk::Phrase.scoped(:order => 'tolk_phrases.id ASC')
existing_ids = self.phrases
- phrases = phrases.scoped(:conditions => ['phrases.id NOT IN (?)', existing_ids]) if existing_ids.present?
+ phrases = phrases.scoped(:conditions => ['tolk_phrases.id NOT IN (?)', existing_ids]) if existing_ids.present?
result = phrases.paginate(:page => page)
Tolk::Phrase.send :preload_associations, result, :translations
@@ -1,5 +1,7 @@
module Tolk
class Phrase < ActiveRecord::Base
+ set_table_name "tolk_phrases"
+
cattr_accessor :per_page
self.per_page = 30
@@ -1,5 +1,7 @@
module Tolk
class Translation < ActiveRecord::Base
+ set_table_name "tolk_translations"
+
validates_presence_of :text
validates_uniqueness_of :phrase_id, :scope => :locale_id
@@ -0,0 +1,13 @@
+class RenameTables < ActiveRecord::Migration
+ def self.up
+ rename_table :locales, :tolk_locales
+ rename_table :phrases, :tolk_phrases
+ rename_table :translations, :tolk_translations
+ end
+
+ def self.down
+ rename_table :tolk_locales, :locales
+ rename_table :tolk_phrases, :phrases
+ rename_table :tolk_translations, :translations
+ end
+end
View
@@ -9,21 +9,21 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100408173138) do
+ActiveRecord::Schema.define(:version => 20100408174805) do
- create_table "locales", :force => true do |t|
+ create_table "tolk_locales", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
- create_table "phrases", :force => true do |t|
+ create_table "tolk_phrases", :force => true do |t|
t.text "key"
t.datetime "created_at"
t.datetime "updated_at"
end
- create_table "translations", :force => true do |t|
+ create_table "tolk_translations", :force => true do |t|
t.integer "phrase_id"
t.integer "locale_id"
t.text "text"
@@ -1,18 +1,18 @@
class CreateTolkTables < ActiveRecord::Migration
def self.up
- create_table :locales do |t|
+ create_table :tolk_locales do |t|
t.string :name
t.datetime :created_at
t.datetime :updated_at
end
- create_table :phrases do |t|
+ create_table :tolk_phrases do |t|
t.text :key
t.datetime :created_at
t.datetime :updated_at
end
- create_table :translations do |t|
+ create_table :tolk_translations do |t|
t.integer :phrase_id
t.integer :locale_id
t.text :text
@@ -24,8 +24,8 @@ def self.up
end
def self.down
- drop_table :translations
- drop_table :phrases
- drop_table :locales
+ drop_table :tolk_translations
+ drop_table :tolk_phrases
+ drop_table :tolk_locales
end
end
View
@@ -26,9 +26,9 @@ def sync_phrases(translations)
secondary_locales = self.secondary_locales
# Handle deleted phrases
- translations.present? ? Phrase.destroy_all(["phrases.key NOT IN (?)", translations.keys]) : Phrase.destroy_all
+ translations.present? ? Tolk::Phrase.destroy_all(["tolk_phrases.key NOT IN (?)", translations.keys]) : Tolk::Phrase.destroy_all
- phrases = Phrase.all
+ phrases = Tolk::Phrase.all
translations.each do |key, value|
# Create phrase and primary translation if missing
File renamed without changes.
File renamed without changes.
View
@@ -16,5 +16,5 @@ class ActiveSupport::TestCase
fixtures :all
- self.fixture_class_names = {:locales => 'Tolk::Locale', :phrases => 'Tolk::Phrase', :translation => 'Tolk::Translation'}
+ self.fixture_class_names = {:tolk_locales => 'Tolk::Locale', :tolk_phrases => 'Tolk::Phrase', :tolk_translation => 'Tolk::Translation'}
end
View
@@ -2,7 +2,7 @@
class LocaleTest < ActiveSupport::TestCase
test "turning locale without nested phrases into a hash" do
- assert_equal({ "se" => { "hello_world" => "Hejsan Verdon" } }, locales(:se).to_hash)
+ assert_equal({ "se" => { "hello_world" => "Hejsan Verdon" } }, tolk_locales(:se).to_hash)
end
test "turning locale with nested phrases into a hash" do
@@ -12,16 +12,16 @@ class LocaleTest < ActiveSupport::TestCase
"hello_world" => "Nested Hello World",
"hello_country" => "Nested Hello Country"
}
- }}, locales(:en).to_hash)
+ }}, tolk_locales(:en).to_hash)
end
test "phrases without translations" do
- assert locales(:en).phrases_without_translation.include?(phrases(:cozy))
+ assert tolk_locales(:en).phrases_without_translation.include?(tolk_phrases(:cozy))
end
test "paginating phrases without translations" do
Tolk::Phrase.per_page = 2
- locale = locales(:se)
+ locale = tolk_locales(:se)
page1 = locale.phrases_without_translation
assert_equal [2, 3], page1.map(&:id)
@@ -35,7 +35,7 @@ class LocaleTest < ActiveSupport::TestCase
test "paginating phrases with translations" do
Tolk::Phrase.per_page = 3
- locale = locales(:en)
+ locale = tolk_locales(:en)
page1 = locale.phrases_with_translation
assert_equal [1, 2, 3], page1.map(&:id)
@@ -65,7 +65,7 @@ class LocaleTest < ActiveSupport::TestCase
end
test "human language name" do
- assert_equal 'English', locales(:en).language_name
+ assert_equal 'English', tolk_locales(:en).language_name
assert_equal 'pirate', Tolk::Locale.new(:name => 'pirate').language_name
end
end

0 comments on commit 7db9e0b

Please sign in to comment.