Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Andersson
committed
Feb 19, 2009
1 parent
fd1c222
commit 7ccac99
Showing
3 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,58 @@ | ||
require 'test/unit' | ||
require 'test_helper' | ||
|
||
class ModelTranslationsTest < Test::Unit::TestCase | ||
# Replace this with your real tests. | ||
test "the truth" do | ||
assert true | ||
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:") | ||
|
||
def setup_db | ||
ActiveRecord::Schema.define(:version => 1) do | ||
create_table :posts do |t| | ||
t.timestamps | ||
end | ||
create_table :post_translations do |t| | ||
t.string :locale | ||
t.references :post | ||
t.string :title | ||
t.text :text | ||
t.timestamps | ||
end | ||
end | ||
end | ||
|
||
def teardown_db | ||
ActiveRecord::Base.connection.tables.each do |table| | ||
ActiveRecord::Base.connection.drop_table(table) | ||
end | ||
end | ||
|
||
class Post < ActiveRecord::Base | ||
translates :title, :text | ||
end | ||
|
||
class ModelTranslationsTest < ActiveSupport::TestCase | ||
def setup | ||
setup_db | ||
I18n.locale = I18n.default_locale = :en | ||
Post.create(:title => 'English title', :text => 'Text') | ||
end | ||
|
||
def teardown | ||
teardown_db | ||
end | ||
|
||
test "database setup" do | ||
assert Post.count == 1 | ||
end | ||
|
||
test "allow translation" do | ||
I18n.locale = :sv | ||
Post.first.update_attribute :title, 'Svensk titel' | ||
assert Post.first.title == 'Svensk titel' | ||
I18n.locale = :en | ||
assert Post.first.title == 'English title' | ||
end | ||
|
||
test "assert fallback to default" do | ||
assert Post.first.title == 'English title' | ||
I18n.locale = :sv | ||
assert Post.first.title == 'English title' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rubygems' | ||
require 'active_support' | ||
require 'active_support/test_case' |