]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/globalize2/test/model/active_record/migration_test.rb
Merged I18N branch to head.
[rails.git] / vendor / plugins / globalize2 / test / model / active_record / migration_test.rb
1 require File.join( File.dirname(__FILE__), '..', '..', 'test_helper' )
2 require 'active_record'
3 require 'globalize/model/active_record'
4
5 # Hook up model translation
6 ActiveRecord::Base.send(:include, Globalize::Model::ActiveRecord::Translated)
7
8 # Load Post model
9 require File.join( File.dirname(__FILE__), '..', '..', 'data', 'post' )
10
11 class MigrationTest < ActiveSupport::TestCase
12   def setup
13     reset_db! File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'no_globalize_schema.rb'))
14   end
15   
16   test 'globalize table added' do
17     assert !Post.connection.table_exists?( :post_translations )
18     Post.create_translation_table! :subject => :string, :content => :text
19     assert Post.connection.table_exists?( :post_translations )      
20     columns = Post.connection.columns( :post_translations )
21     assert locale = columns.detect {|c| c.name == 'locale' }
22     assert_equal :string, locale.type
23     assert subject = columns.detect {|c| c.name == 'subject' }
24     assert_equal :string, subject.type
25     assert content = columns.detect {|c| c.name == 'content' }
26     assert_equal :text, content.type
27     assert post_id = columns.detect {|c| c.name == 'post_id' }
28     assert_equal :integer, post_id.type
29     assert created_at = columns.detect {|c| c.name == 'created_at' }
30     assert_equal :datetime, created_at.type
31     assert updated_at = columns.detect {|c| c.name == 'updated_at' }
32     assert_equal :datetime, updated_at.type
33   end
34   
35   test 'globalize table dropped' do
36     assert !Post.connection.table_exists?( :post_translations )
37     Post.create_translation_table! :subject => :string, :content => :text
38     assert Post.connection.table_exists?( :post_translations )      
39     Post.drop_translation_table!
40     assert !Post.connection.table_exists?( :post_translations )
41   end
42
43   test 'exception on untranslated field inputs' do
44     assert_raise Globalize::Model::UntranslatedMigrationField do
45       Post.create_translation_table! :subject => :string, :content => :text, :bogus => :string
46     end
47   end
48   
49   test 'exception on missing field inputs' do
50     assert_raise Globalize::Model::MigrationMissingTranslatedField do
51       Post.create_translation_table! :content => :text
52     end
53   end
54   
55   test 'exception on bad input type' do
56     assert_raise Globalize::Model::BadMigrationFieldType do
57       Post.create_translation_table! :subject => :string, :content => :integer
58     end
59   end
60   
61   test 'create_translation_table! should not be called on non-translated models' do
62     assert_raise NoMethodError do
63       Blog.create_translation_table! :name => :string      
64     end
65   end
66
67   test 'drop_translation_table! should not be called on non-translated models' do
68     assert_raise NoMethodError do
69       Blog.drop_translation_table!      
70     end
71   end
72
73 end